mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-26 19:36:52 +03:00
951092eef3
$ 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
81 lines
2.4 KiB
PHP
81 lines
2.4 KiB
PHP
<?php
|
|
|
|
class FeedMergeBridge extends FeedExpander
|
|
{
|
|
const MAINTAINER = 'dvikan';
|
|
const NAME = 'FeedMerge';
|
|
const URI = 'https://github.com/RSS-Bridge/rss-bridge';
|
|
const DESCRIPTION = <<<'TEXT'
|
|
This bridge merges two or more feeds into a single feed. Max 10 items are fetched from each feed.
|
|
TEXT;
|
|
|
|
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'],
|
|
|
|
'limit' => self::LIMIT,
|
|
]
|
|
];
|
|
|
|
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'),
|
|
];
|
|
|
|
// Remove empty values
|
|
$feeds = array_filter($feeds);
|
|
|
|
foreach ($feeds as $feed) {
|
|
// Fetch all items from the feed
|
|
$this->collectExpandableDatas($feed);
|
|
}
|
|
|
|
// Sort by timestamp descending
|
|
usort($this->items, fn ($a, $b) => $b['timestamp'] <=> $a['timestamp']);
|
|
|
|
// Remove duplicates
|
|
$items = [];
|
|
foreach ($this->items as $item) {
|
|
$index = $item['uri'] ?? null;
|
|
if ($index) {
|
|
// Overwrite duplicates
|
|
$items[$index] = $item;
|
|
} else {
|
|
$items[] = $item;
|
|
}
|
|
}
|
|
|
|
// Grab the first $limit items
|
|
$this->items = array_slice(array_values($items), 0, $limit);
|
|
}
|
|
|
|
public function getIcon()
|
|
{
|
|
return 'https://cdn.jsdelivr.net/npm/famfamfam-silk@1.0.0/dist/png/folder_feed.png';
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
return $this->getInput('feed_name') ?: 'rss-bridge/FeedMerger';
|
|
}
|
|
}
|