Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenth committed Mar 13, 2020
2 parents 6848066 + 917281d commit 6453cd4
Show file tree
Hide file tree
Showing 28 changed files with 88 additions and 152 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 2.0.0

- BC: The content of an Item will not be stripped from HTML tags (see Events).
- Switch plugin dependencies from Zend Framework to Laminas.
- Added new events. Check the documentation on how to implement them.
- `vdlp.rssfetcher.item.processTitle`
- `vdlp.rssfetcher.item.processContent`
- `vdlp.rssfetcher.item.processLink`
7 changes: 0 additions & 7 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
<?php

/** @noinspection PhpMissingParentCallCommonInspection */

declare(strict_types=1);

namespace Vdlp\RssFetcher;

use Backend\Helpers\Backend as BackendHelper;
use System\Classes\PluginBase;

/**
* Class Plugin
*
* @package Vdlp\RssFetcher
*/
class Plugin extends PluginBase
{
/**
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Vdlp.RssFetcher OctoberCMS plugin
# Vdlp.RssFetcher October CMS plugin

Fetches RSS/Atom feeds to put on your website. It can be automated using a cronjob or triggered manually.

## Installation

Install this plugin within OctoberCMS. It's available on the OctoberCMS Market Place.
Install this plugin within October CMS. It's available on the October CMS Market Place.

## RSS & Atom feeds

The plugin uses the `zendframework/rss-feed` package to parse the RSS and/or Atom feeds. For more information on this package goto http://framework.zend.com/manual/current/en/index.html#zend-feed
The plugin uses the `laminas/laminas-feed` package to parse the RSS and/or Atom feeds. For more information on this package goto https://docs.laminas.dev/laminas-feed/

## Components

Expand Down Expand Up @@ -67,6 +67,24 @@ is_hidden = 0
{% component 'rssSources' %}
````

## Events

To manipulate RSS items there are a few events which can be used:
- `vdlp.rssfetcher.item.processTitle`
- `vdlp.rssfetcher.item.processContent`
- `vdlp.rssfetcher.item.processLink`

Use them like this:

```
Event::listen('vdlp.rssfetcher.item.processTitle', function (&$title) {
$title = $title . 'A';
});
Event::listen('vdlp.rssfetcher.item.processContent', function (&$content) {
$content = strip_tags($content);
});
```
## Reporting Widgets

This plugin contains also a **RSS Headlines** widget to show the latest headlines on your Dashboard. This widget has three configurable properties: `maxItems`, `title` and `dateFormat`.
Expand Down
38 changes: 25 additions & 13 deletions classes/RssFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@

use Carbon\Carbon;
use Exception;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Collection;
use Laminas\Feed\Reader\Entry\Rss;
use Laminas\Feed\Reader\Reader;
use October\Rain\Support\Traits\Singleton;
use Psr\Log\LoggerInterface;
use stdClass;
use Throwable;
use Vdlp\RssFetcher\Models\Item;
use Vdlp\RssFetcher\Models\Source;
use Zend\Feed\Reader\Entry\Rss;
use Zend\Feed\Reader\Reader;

/**
* Class RssFetcher
*
* @package Vdlp\RssFetcher\Classes
*/

final class RssFetcher
{
use Singleton;
Expand All @@ -29,12 +26,18 @@ final class RssFetcher
*/
private $log;

/**
* @var Dispatcher
*/
private $dispatcher;

/**
* {@inheritDoc}
*/
protected function init(): void
{
$this->log = resolve(LoggerInterface::class);
$this->dispatcher = resolve(Dispatcher::class);
}

/**
Expand All @@ -48,7 +51,7 @@ public function fetch(int $sourceId = null): void
$sources->each(function (Source $source) {
try {
$this->fetchSource($source);
} catch (Exception $e) {
} catch (Throwable $e) {
$this->log->error($e);
}
});
Expand All @@ -71,12 +74,21 @@ private function fetchSource(Source $source): void

$dateCreated = $item->getDateCreated();

$title = $item->getTitle();
$this->dispatcher->fire('vdlp.rssfetcher.item.processTitle', [&$title]);

$content = $item->getContent();
$this->dispatcher->fire('vdlp.rssfetcher.item.processContent', [&$content]);

$link = $item->getLink();
$this->dispatcher->fire('vdlp.rssfetcher.item.processLink', [&$link]);

$attributes = [
'item_id' => $item->getId(),
'source_id' => $source->getAttribute('id'),
'title' => $item->getTitle(),
'link' => $item->getLink(),
'description' => strip_tags($item->getContent()),
'title' => $title,
'link' => $link,
'description' => $content,
'category' => implode(', ', $item->getCategories()->getValues()),
'comments' => $item->getCommentLink(),
'pub_date' => $dateCreated !== null ? $item->getDateCreated()->format('Y-m-d H:i:s') : null,
Expand All @@ -85,7 +97,7 @@ private function fetchSource(Source $source): void

$enclosure = $item->getEnclosure();

if ($enclosure instanceof \stdClass) {
if ($enclosure instanceof stdClass) {
$attributes['enclosure_url'] = $enclosure->url ?? null;
$attributes['enclosure_length'] = $enclosure->length ?? null;
$attributes['enclosure_type'] = $enclosure->type ?? null;
Expand Down
7 changes: 1 addition & 6 deletions commands/FetchRssCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@

namespace Vdlp\RssFetcher\Commands;

use Vdlp\RssFetcher\Classes\RssFetcher;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
use Vdlp\RssFetcher\Classes\RssFetcher;

/**
* Class FetchRssCommand
*
* @package Vdlp\RssFetcher\Commands
*/
class FetchRssCommand extends Command
{
/**
Expand Down
9 changes: 2 additions & 7 deletions components/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@

namespace Vdlp\RssFetcher\Components;

use Throwable;
use Vdlp\RssFetcher\Models\Item;
use Cms\Classes\ComponentBase;
use October\Rain\Support\Collection;
use Throwable;
use Vdlp\RssFetcher\Models\Item;

/**
* Class Items
*
* @package Vdlp\RssFetcher\Components
*/
class Items extends ComponentBase
{
/**
Expand Down
9 changes: 2 additions & 7 deletions components/PaginatableItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@

namespace Vdlp\RssFetcher\Components;

use Throwable;
use Vdlp\RssFetcher\Models\Item;
use Cms\Classes\ComponentBase;
use Illuminate\Pagination\LengthAwarePaginator;
use Throwable;
use Vdlp\RssFetcher\Models\Item;

/**
* Class PaginatableItems
*
* @package Vdlp\RssFetcher\Components
*/
class PaginatableItems extends ComponentBase
{
/**
Expand Down
9 changes: 2 additions & 7 deletions components/Sources.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@

namespace Vdlp\RssFetcher\Components;

use Throwable;
use Vdlp\RssFetcher\Models\Source;
use Cms\Classes\ComponentBase;
use October\Rain\Support\Collection;
use Throwable;
use Vdlp\RssFetcher\Models\Source;

/**
* Class Sources
*
* @package Vdlp\RssFetcher\Components
*/
class Sources extends ComponentBase
{
/**
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
"keywords": ["october", "cms", "rss", "plugin"],
"license": "GPL-2.0",
"authors": [
{
"name": "Van der Let & Partners",
"email": "[email protected]"
},
{
"name": "Alwin Drenth",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.1",
"zendframework/zend-feed": "^2.9",
"zendframework/zend-http": "^2.7"
"laminas/laminas-feed": "^2.9",
"laminas/laminas-http": "^2.7"
}
}
4 changes: 1 addition & 3 deletions controllers/Feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

use Backend\Behaviors\FormController;
use Backend\Behaviors\ListController;
use Backend\Classes\NavigationManager;
use Backend\Classes\Controller;
use Backend\Classes\NavigationManager;

/**
* Class Feeds
*
* @package Vdlp\RssFetcher\Controllers
* @mixin FormController
* @mixin ListController
*/
Expand Down
6 changes: 2 additions & 4 deletions controllers/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@

namespace Vdlp\RssFetcher\Controllers;

use Backend\Classes\NavigationManager;
use Vdlp\RssFetcher\Models\Item;
use Backend\Behaviors\FormController;
use Backend\Behaviors\ListController;
use Backend\Classes\Controller;
use Backend\Classes\NavigationManager;
use Exception;
use Vdlp\RssFetcher\Models\Item;

/**
* Class Items
*
* @package Vdlp\RssFetcher\Controllers
* @mixin FormController
* @mixin ListController
*/
Expand Down
12 changes: 5 additions & 7 deletions controllers/Sources.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@

namespace Vdlp\RssFetcher\Controllers;

use Backend\Behaviors\FormController;
use Backend\Behaviors\ImportExportController;
use Backend\Behaviors\ListController;
use Backend\Classes\Controller;
use Backend\Classes\NavigationManager;
use Exception;
use October\Rain\Exception\ApplicationException;
use October\Rain\Flash\FlashBag;
use October\Rain\Translation\Translator;
use Vdlp\RssFetcher\Classes\RssFetcher;
use Vdlp\RssFetcher\Exceptions\SourceNotEnabledException;
use Vdlp\RssFetcher\Models\Source;
use Backend\Behaviors\FormController;
use Backend\Behaviors\ImportExportController;
use Backend\Behaviors\ListController;
use Backend\Classes\Controller;
use Exception;

/**
* Sources Back-end Controller
*
* @package Vdlp\RssFetcher\Controllers
* @mixin FormController
* @mixin ListController
* @mixin ImportExportController
Expand Down
5 changes: 0 additions & 5 deletions exceptions/SourceNotEnabledException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

use Exception;

/**
* Class SourceNotEnabledException
*
* @package Vdlp\RssFetcher\Exceptions
*/
class SourceNotEnabledException extends Exception
{

Expand Down
5 changes: 0 additions & 5 deletions formwidgets/TextWithPrefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
use Backend\Classes\FormWidgetBase;
use SystemException;

/**
* Class TextWithPrefix
*
* @package Vdlp\RssFetcher\FormWidgets
*/
class TextWithPrefix extends FormWidgetBase
{
/**
Expand Down
19 changes: 7 additions & 12 deletions http/controllers/FeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@

namespace Vdlp\RssFetcher\Http\Controllers;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Response;
use Illuminate\Routing\ResponseFactory;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Arr;
use Laminas\Feed\Writer\Entry;
use Laminas\Feed\Writer\Exception\InvalidArgumentException;
use Laminas\Feed\Writer\Feed;
use October\Rain\Database\Relations\HasMany;
use Vdlp\RssFetcher\Models\Feed as FeedModel;
use Vdlp\RssFetcher\Models\Item;
use Vdlp\RssFetcher\Models\Source;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Zend\Feed\Exception\InvalidArgumentException;
use Zend\Feed\Writer\Entry;
use Zend\Feed\Writer\Feed;

/**
* Class FeedController
*
* @package Vdlp\RssFetcher\Http\Controllers
*/

class FeedController
{
/**
Expand All @@ -47,7 +42,7 @@ public function __construct(UrlGenerator $urlGenerator, ResponseFactory $respons
/**
* @param string $path
* @return Response
* @throws \Zend\Feed\Writer\Exception\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function all(string $path): Response
{
Expand Down
5 changes: 0 additions & 5 deletions models/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
use October\Rain\Database\Model;
use October\Rain\Database\Traits\Validation;

/**
* Class Feed
*
* @package Vdlp\RssFetcher\Models
*/
class Feed extends Model
{
use Validation;
Expand Down
Loading

0 comments on commit 6453cd4

Please sign in to comment.