Little refactoring to reduce logic on index.php.
Moved RssExpander as a core logic system to lib/Bridge.php Signed-off-by: teromene <teromene@teromene.fr>
This commit is contained in:
parent
80008f01f8
commit
38829e7739
9 changed files with 201 additions and 212 deletions
lib
|
@ -293,6 +293,72 @@ class Bridge{
|
|||
|
||||
return $listBridge;
|
||||
}
|
||||
static function isWhitelisted( $whitelist, $name ) {
|
||||
if(in_array("$name", $whitelist) or in_array("$name.php", $whitelist))
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
abstract class RssExpander extends HttpCachingBridgeAbstract{
|
||||
|
||||
public $name;
|
||||
public $uri;
|
||||
public $description;
|
||||
|
||||
public function collectExpandableDatas(array $param, $name){
|
||||
if (empty($name)) {
|
||||
$this->returnError('There is no $param[\'url\'] for this RSS expander', 404);
|
||||
}
|
||||
// $this->message("Loading from ".$param['url']);
|
||||
// Notice WE DO NOT use cache here on purpose : we want a fresh view of the RSS stream each time
|
||||
$rssContent = simplexml_load_file($name) or $this->returnError('Could not request '.$name, 404);
|
||||
// $this->message("loaded RSS from ".$param['url']);
|
||||
// TODO insert RSS format detection
|
||||
// we suppose for now, we have some RSS 2.0
|
||||
$this->collect_RSS_2_0_data($rssContent);
|
||||
}
|
||||
|
||||
protected function collect_RSS_2_0_data($rssContent) {
|
||||
$rssContent = $rssContent->channel[0];
|
||||
// $this->message("RSS content is ===========\n".var_export($rssContent, true)."===========");
|
||||
$this->load_RSS_2_0_feed_data($rssContent);
|
||||
foreach($rssContent->item as $item) {
|
||||
// $this->message("parsing item ".var_export($item, true));
|
||||
$this->items[] = $this->parseRSSItem($item);
|
||||
}
|
||||
}
|
||||
|
||||
protected function RSS_2_0_time_to_timestamp($item) {
|
||||
return DateTime::createFromFormat('D, d M Y H:i:s e', $item->pubDate)->getTimestamp();
|
||||
}
|
||||
|
||||
// TODO set title, link, description, language, and so on
|
||||
protected function load_RSS_2_0_feed_data($rssContent) {
|
||||
$this->name = trim($rssContent->title);
|
||||
$this->uri = trim($rssContent->link);
|
||||
$this->description = trim($rssContent->description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method should return, from a source RSS item given by lastRSS, one of our Items objects
|
||||
* @param $item the input rss item
|
||||
* @return a RSS-Bridge Item, with (hopefully) the whole content)
|
||||
*/
|
||||
abstract protected function parseRSSItem($item);
|
||||
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getURI(){
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue