159 lines
5.5 KiB
PHP
159 lines
5.5 KiB
PHP
<?php
|
|
class RSSFilterBridge extends FeedExpander {
|
|
|
|
const MAINTAINER = 'Akamaru';
|
|
const NAME = 'RSS Filter Bridge';
|
|
const URI = 'https://github.com/RSS-Bridge/rss-bridge';
|
|
const CACHE_TIMEOUT = 3600;
|
|
const DESCRIPTION = 'Filter and modify elements from any RSS/Atom feed';
|
|
|
|
const PARAMETERS = [
|
|
[
|
|
'feed_url' => [
|
|
'name' => 'Feed URL',
|
|
'type' => 'text',
|
|
'required' => true,
|
|
'exampleValue' => 'https://example.com/rss.xml',
|
|
'title' => 'URL of the RSS/Atom feed to filter'
|
|
],
|
|
'custom_icon' => [
|
|
'name' => 'Custom Icon URL',
|
|
'type' => 'text',
|
|
'required' => false,
|
|
'exampleValue' => 'https://example.com/icon.png',
|
|
'title' => 'Optional: Custom icon URL (if empty, will try to extract favicon from feed URL)'
|
|
],
|
|
'remove_description' => [
|
|
'name' => 'Remove Description',
|
|
'type' => 'checkbox',
|
|
'title' => 'Remove the description/content from feed items'
|
|
],
|
|
'remove_content' => [
|
|
'name' => 'Remove Content',
|
|
'type' => 'checkbox',
|
|
'title' => 'Remove the full content from feed items'
|
|
],
|
|
'remove_author' => [
|
|
'name' => 'Remove Author',
|
|
'type' => 'checkbox',
|
|
'title' => 'Remove author information'
|
|
],
|
|
'remove_categories' => [
|
|
'name' => 'Remove Categories',
|
|
'type' => 'checkbox',
|
|
'title' => 'Remove categories/tags'
|
|
],
|
|
'remove_enclosures' => [
|
|
'name' => 'Remove Enclosures',
|
|
'type' => 'checkbox',
|
|
'title' => 'Remove attachments/media (images, audio, video)'
|
|
],
|
|
'remove_timestamp' => [
|
|
'name' => 'Remove Timestamp',
|
|
'type' => 'checkbox',
|
|
'title' => 'Remove date/time information'
|
|
],
|
|
'title_only' => [
|
|
'name' => 'Title Only Mode',
|
|
'type' => 'checkbox',
|
|
'title' => 'Keep only title and link (removes everything else)'
|
|
],
|
|
'limit' => [
|
|
'name' => 'Item Limit',
|
|
'type' => 'number',
|
|
'required' => false,
|
|
'defaultValue' => 20,
|
|
'title' => 'Maximum number of items to return (default: 20)'
|
|
]
|
|
]
|
|
];
|
|
|
|
public function collectData() {
|
|
$feedUrl = $this->getInput('feed_url');
|
|
|
|
if (empty($feedUrl)) {
|
|
returnClientError('Feed URL is required');
|
|
}
|
|
|
|
$this->collectExpandableDatas($feedUrl);
|
|
}
|
|
|
|
protected function parseItem(array $item) {
|
|
$filteredItem = [];
|
|
|
|
// Title and URI are always kept (required for RSS)
|
|
$filteredItem['title'] = $item['title'] ?? 'No title';
|
|
$filteredItem['uri'] = $item['uri'] ?? $item['link'] ?? '';
|
|
$filteredItem['uid'] = $item['uid'] ?? $item['guid'] ?? $filteredItem['uri'];
|
|
|
|
// Title Only Mode - skip all other fields
|
|
if ($this->getInput('title_only')) {
|
|
return $filteredItem;
|
|
}
|
|
|
|
// Content/Description filtering
|
|
if (!$this->getInput('remove_content') && !$this->getInput('remove_description')) {
|
|
$filteredItem['content'] = $item['content'] ?? $item['description'] ?? '';
|
|
} elseif (!$this->getInput('remove_content') && isset($item['content'])) {
|
|
$filteredItem['content'] = $item['content'];
|
|
} elseif (!$this->getInput('remove_description') && isset($item['description'])) {
|
|
$filteredItem['content'] = $item['description'];
|
|
}
|
|
|
|
// Author filtering
|
|
if (!$this->getInput('remove_author') && isset($item['author'])) {
|
|
$filteredItem['author'] = $item['author'];
|
|
}
|
|
|
|
// Categories filtering
|
|
if (!$this->getInput('remove_categories') && isset($item['categories'])) {
|
|
$filteredItem['categories'] = $item['categories'];
|
|
}
|
|
|
|
// Enclosures filtering (images, audio, video)
|
|
if (!$this->getInput('remove_enclosures') && isset($item['enclosures'])) {
|
|
$filteredItem['enclosures'] = $item['enclosures'];
|
|
}
|
|
|
|
// Timestamp filtering
|
|
if (!$this->getInput('remove_timestamp') && isset($item['timestamp'])) {
|
|
$filteredItem['timestamp'] = $item['timestamp'];
|
|
}
|
|
|
|
return $filteredItem;
|
|
}
|
|
|
|
public function getItems() {
|
|
$items = parent::getItems();
|
|
$limit = $this->getInput('limit') ?: 20;
|
|
|
|
return array_slice($items, 0, $limit);
|
|
}
|
|
|
|
public function getName() {
|
|
if ($this->getInput('feed_url')) {
|
|
return 'RSS Filter: ' . parse_url($this->getInput('feed_url'), PHP_URL_HOST);
|
|
}
|
|
return parent::getName();
|
|
}
|
|
|
|
public function getIcon() {
|
|
// Use custom icon if provided
|
|
if ($this->getInput('custom_icon')) {
|
|
return $this->getInput('custom_icon');
|
|
}
|
|
|
|
// Extract favicon from feed URL
|
|
$feedUrl = $this->getInput('feed_url');
|
|
if ($feedUrl) {
|
|
$parsedUrl = parse_url($feedUrl);
|
|
if (isset($parsedUrl['scheme']) && isset($parsedUrl['host'])) {
|
|
return $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . '/favicon.ico';
|
|
}
|
|
}
|
|
|
|
// Fallback to default
|
|
return parent::getIcon();
|
|
}
|
|
}
|