mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-04 01:55:21 +02:00
Rewritten those bridge to use a new mechanism ! RSS expander will get data from the RSS feed and expand the truncated entries to their full values.
This commit is contained in:
parent
fd71ceae82
commit
ce28cfad22
5 changed files with 147 additions and 157 deletions
68
bridges/RssExpander.php
Normal file
68
bridges/RssExpander.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* A class providing facilities for RSS expansion. The goal here is to facilitate, as much as possible, writing bridges such as FreeNews, Gawker and other ones
|
||||
* @name RssExpander
|
||||
* @description Un bridge générique d'expansion automatique de contenu RSS ... pour tous ces sites qui ont un flux RSS mochement tonqué.
|
||||
* @update 15/03/2015
|
||||
* @use1(url="URL du flux dont vous souhaitez le contenu complet")
|
||||
*/
|
||||
|
||||
abstract class RssExpander extends HttpCachingBridgeAbstract{
|
||||
protected $name;
|
||||
private $uri;
|
||||
private $description;
|
||||
public function collectData(array $param){
|
||||
if (empty($param['url'])) {
|
||||
$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($param['url']) or $this->returnError('Could not request '.$param['url'], 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);
|
||||
}
|
||||
|
||||
private 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