rss-bridge/bridges/FeedProxyBridge.php
Cristian 'void' Giustini a7b6d36508
Some checks failed
Lint / phpcompatibility (7.4) (push) Waiting to run
Lint / executable_php_files_check (push) Waiting to run
Tests / phpunit8 (7.4) (push) Waiting to run
Tests / phpunit8 (8.0) (push) Waiting to run
Tests / phpunit8 (8.1) (push) Waiting to run
Build Image on Commit and Release / bake (push) Failing after 1m51s
Lint / phpcs (7.4) (push) Has been cancelled
add cybermonit, feedproxy and OSV bridges
2025-03-23 06:21:49 +01:00

51 lines
1.3 KiB
PHP
Executable File

<?php
class FeedProxyBridge extends FeedExpander
{
const MAINTAINER = 'void';
const NAME = 'FeedProxy';
const URI = '';
const DESCRIPTION = <<<'TEXT'
This bridge simply parse an external RSS<br>
TEXT;
const PARAMETERS = [
[
'feed_name' => [
'name' => 'Feed name',
'type' => 'text',
'exampleValue' => 'FeedProxy',
],
'feed_1' => [
'name' => 'Feed url',
'type' => 'text',
'required' => true,
'exampleValue' => 'https://lorem-rss.herokuapp.com/feed?unit=day'
],
'limit' => self::LIMIT,
]
];
/**
* TODO: Consider a strategy which produces a shorter feed url
*/
public function collectData()
{
$limit = (int)($this->getInput('limit') ?: 99);
$feed = $this->getInput('feed_1');
$this->collectExpandableDatas($feed, $limit);
// Sort by timestamp, uri, title in descending order
usort($this->items, function ($a, $b) {
$t1 = $a['timestamp'] ?? $a['uri'] ?? $a['title'];
$t2 = $b['timestamp'] ?? $b['uri'] ?? $b['title'];
return $t2 <=> $t1;
});
}
public function getName()
{
return $this->getInput('feed_name') ?: 'FeedProxy';
}
}