2017-06-24 15:11:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class FilterBridge extends FeedExpander {
|
|
|
|
|
|
|
|
const MAINTAINER = 'Frenzie';
|
|
|
|
const NAME = 'Filter';
|
|
|
|
const CACHE_TIMEOUT = 3600; // 1h
|
|
|
|
const DESCRIPTION = 'Filters a feed of your choice';
|
2018-08-05 15:53:45 +02:00
|
|
|
const URI = 'https://github.com/rss-bridge/rss-bridge';
|
2017-06-24 15:11:40 +02:00
|
|
|
|
|
|
|
const PARAMETERS = array(array(
|
|
|
|
'url' => array(
|
|
|
|
'name' => 'Feed URL',
|
|
|
|
'required' => true,
|
|
|
|
),
|
|
|
|
'filter' => array(
|
|
|
|
'name' => 'Filter item title (regular expression)',
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
'filter_type' => array(
|
|
|
|
'name' => 'Filter type',
|
|
|
|
'type' => 'list',
|
|
|
|
'required' => false,
|
|
|
|
'values' => array(
|
|
|
|
'Permit' => 'permit',
|
|
|
|
'Block' => 'block',
|
|
|
|
),
|
|
|
|
'defaultValue' => 'permit',
|
|
|
|
),
|
2018-08-04 20:46:55 +02:00
|
|
|
'title_from_content' => array(
|
|
|
|
'name' => 'Generate title from content',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'required' => false,
|
|
|
|
)
|
2017-06-24 15:11:40 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
protected function parseItem($newItem){
|
|
|
|
$item = parent::parseItem($newItem);
|
|
|
|
|
2018-08-04 20:46:55 +02:00
|
|
|
if($this->getInput('title_from_content') && array_key_exists('content', $item)) {
|
|
|
|
|
|
|
|
$content = str_get_html($item['content']);
|
|
|
|
|
|
|
|
$pos = strpos($item['content'], ' ', 50);
|
|
|
|
|
|
|
|
$item['title'] = substr(
|
|
|
|
$content->plaintext,
|
|
|
|
0,
|
|
|
|
$pos
|
|
|
|
);
|
|
|
|
|
|
|
|
if(strlen($content->plaintext) >= $pos) {
|
|
|
|
$item['title'] .= '...';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
switch(true) {
|
2017-06-24 15:11:40 +02:00
|
|
|
case $this->getFilterType() === 'permit':
|
|
|
|
if (preg_match($this->getFilter(), $item['title'])) {
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case $this->getFilterType() === 'block':
|
|
|
|
if (!preg_match($this->getFilter(), $item['title'])) {
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getFilter(){
|
|
|
|
return '/' . $this->getInput('filter') . '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getFilterType(){
|
|
|
|
return $this->getInput('filter_type');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI(){
|
|
|
|
$url = $this->getInput('url');
|
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
if(empty($url)) {
|
2017-06-24 15:11:40 +02:00
|
|
|
$url = parent::getURI();
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function collectData(){
|
2017-07-29 19:28:00 +02:00
|
|
|
if($this->getInput('url') && substr($this->getInput('url'), 0, strlen('http')) !== 'http') {
|
2017-06-24 15:11:40 +02:00
|
|
|
// just in case someone find a way to access local files by playing with the url
|
|
|
|
returnClientError('The url parameter must either refer to http or https protocol.');
|
|
|
|
}
|
|
|
|
try{
|
|
|
|
$this->collectExpandableDatas($this->getURI());
|
2018-11-18 16:53:21 +01:00
|
|
|
} catch (Exception $e) {
|
2017-06-24 15:11:40 +02:00
|
|
|
$this->collectExpandableDatas($this->getURI());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|