2022-04-08 22:13:05 +03:00
|
|
|
<?php
|
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
class FeedMergeBridge extends FeedExpander
|
|
|
|
{
|
|
|
|
const MAINTAINER = 'dvikan';
|
|
|
|
const NAME = 'FeedMerge';
|
|
|
|
const URI = 'https://github.com/RSS-Bridge/rss-bridge';
|
|
|
|
const DESCRIPTION = <<<'TEXT'
|
2022-04-08 22:13:05 +03:00
|
|
|
This bridge merges two or more feeds into a single feed. Max 10 items are fetched from each feed.
|
|
|
|
TEXT;
|
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
const PARAMETERS = [
|
|
|
|
[
|
|
|
|
'feed_name' => [
|
|
|
|
'name' => 'Feed name',
|
|
|
|
'type' => 'text',
|
|
|
|
'exampleValue' => 'rss-bridge/FeedMerger',
|
|
|
|
],
|
|
|
|
'feed_1' => [
|
|
|
|
'name' => 'Feed url',
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'https://lorem-rss.herokuapp.com/feed?unit=day'
|
|
|
|
],
|
|
|
|
'feed_2' => ['name' => 'Feed url', 'type' => 'text'],
|
|
|
|
'feed_3' => ['name' => 'Feed url', 'type' => 'text'],
|
|
|
|
'feed_4' => ['name' => 'Feed url', 'type' => 'text'],
|
|
|
|
'feed_5' => ['name' => 'Feed url', 'type' => 'text'],
|
2022-06-22 19:34:05 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
'limit' => self::LIMIT,
|
|
|
|
]
|
|
|
|
];
|
2022-04-08 22:13:05 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$limit = (int)($this->getInput('limit') ?: 10);
|
|
|
|
$feeds = [
|
|
|
|
$this->getInput('feed_1'),
|
|
|
|
$this->getInput('feed_2'),
|
|
|
|
$this->getInput('feed_3'),
|
|
|
|
$this->getInput('feed_4'),
|
|
|
|
$this->getInput('feed_5'),
|
|
|
|
];
|
2022-07-05 16:39:00 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
// Remove empty values
|
|
|
|
$feeds = array_filter($feeds);
|
2022-07-05 16:39:00 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
foreach ($feeds as $feed) {
|
|
|
|
// Fetch all items from the feed
|
|
|
|
$this->collectExpandableDatas($feed);
|
|
|
|
}
|
2022-07-05 16:39:00 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
// Sort by timestamp descending
|
Fix coding style missed by phpbcf (#2901)
$ composer require --dev friendsofphp/php-cs-fixer
$ echo >.php-cs-fixer.dist.php "<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);
$rules = [
'@PSR12' => true,
// '@PSR12:risky' => true,
'@PHP74Migration' => true,
// '@PHP74Migration:risky' => true,
// buggy, duplicates existing comment sometimes
'no_break_comment' => false,
'array_syntax' => true,
'lowercase_static_reference' => true,
'visibility_required' => false,
// Too much noise
'binary_operator_spaces' => false,
'heredoc_indentation' => false,
'trailing_comma_in_multiline' => false,
];
$config = new PhpCsFixer\Config();
return $config
->setRules($rules)
// ->setRiskyAllowed(true)
->setFinder($finder);
"
$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.7
$ vendor/bin/php-cs-fixer fix
$ rm .php-cs-fixer.cache
$ vendor/bin/php-cs-fixer fix
2022-07-08 14:00:52 +03:00
|
|
|
usort($this->items, fn ($a, $b) => $b['timestamp'] <=> $a['timestamp']);
|
2022-07-05 16:39:00 +03:00
|
|
|
|
|
|
|
// Remove duplicates
|
|
|
|
$items = [];
|
|
|
|
foreach ($this->items as $item) {
|
|
|
|
$index = $item['uri'] ?? null;
|
|
|
|
if ($index) {
|
|
|
|
// Overwrite duplicates
|
|
|
|
$items[$index] = $item;
|
|
|
|
} else {
|
|
|
|
$items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
// Grab the first $limit items
|
2022-07-05 16:39:00 +03:00
|
|
|
$this->items = array_slice(array_values($items), 0, $limit);
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2022-04-08 22:13:05 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function getIcon()
|
|
|
|
{
|
|
|
|
return 'https://cdn.jsdelivr.net/npm/famfamfam-silk@1.0.0/dist/png/folder_feed.png';
|
|
|
|
}
|
2022-04-08 22:13:05 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->getInput('feed_name') ?: 'rss-bridge/FeedMerger';
|
|
|
|
}
|
2022-04-08 22:13:05 +03:00
|
|
|
}
|