1
0
Fork 0
forked from blallo/rss-bridge

[Bridge] Add RSS 1.0 and 2.0 parser

This commit is contained in:
logmanoriginal 2016-09-04 12:32:56 +02:00
parent f781965825
commit 51a3a75aac

View file

@ -606,17 +606,33 @@ abstract class RssExpander extends HttpCachingBridgeAbstract {
$rssContent = simplexml_load_string($content); $rssContent = simplexml_load_string($content);
$this->debugMessage('loaded RSS from ' . $url); $this->debugMessage('loaded RSS from ' . $url);
if(isset($rssContent->channel[0])){ // RSS format $this->debugMessage('Detecting feed format/version');
// TODO insert RSS format detection if(isset($rssContent->channel[0])){
// For now we always assume RSS 2.0 $this->debugMessage('Detected RSS format');
$this->collect_RSS_2_0_data($rssContent); if(isset($rssContent->item[0])){
} elseif(isset($rssContent->entry[0])){ // ATOM format $this->debugMessage('Detected RSS 1.0 format');
$this->collect_RSS_1_0_data($rssContent);
} else {
$this->debugMessage('Detected RSS 0.9x or 2.0 format');
$this->collect_RSS_2_0_data($rssContent);
}
} elseif(isset($rssContent->entry[0])){
$this->debugMessage('Detected ATOM format');
$this->collect_ATOM_data($rssContent); $this->collect_ATOM_data($rssContent);
} else { // Unknown format } else {
$this->debugMessage('Unknown feed format/version');
$this->returnServerError('The feed format is unknown!'); $this->returnServerError('The feed format is unknown!');
} }
} }
protected function collect_RSS_1_0_data($rssContent){
$this->load_RSS_2_0_feed_data($rssContent->channel[0]);
foreach($rssContent->item as $item){
$this->debugMessage('parsing item ' . var_export($item, true));
$this->items[] = $this->parseRSSItem($item);
}
}
protected function collect_RSS_2_0_data($rssContent){ protected function collect_RSS_2_0_data($rssContent){
$rssContent = $rssContent->channel[0]; $rssContent = $rssContent->channel[0];
$this->debugMessage('RSS content is ===========\n' . var_export($rssContent, true) . '==========='); $this->debugMessage('RSS content is ===========\n' . var_export($rssContent, true) . '===========');
@ -688,6 +704,29 @@ abstract class RssExpander extends HttpCachingBridgeAbstract {
return $item; return $item;
} }
protected function parseRSS_1_0_Item($feedItem){
// 1.0 adds optional elements around the 0.91 standard
return $this->parseRSS_0_9_1_Item($feedItem);
}
protected function parseRSS_2_0_Item($feedItem){
// Primary data is compatible to 0.91
$item = $this->parseRSS_0_9_1_Item($feedItem);
if(isset($feedItem->pubDate)) $item['timestamp'] = strtotime($feedItem->pubDate);
if(isset($feedItem->author)){
$item['author'] = $feedItem->author;
} else {
// Feed might use 'dc' namespace
$namespaces = $feedItem->getNamespaces(true);
if(isset($namespaces['dc'])){
$dc = $feedItem->children($namespaces['dc']);
if(isset($dc->creator))
$item['author'] = $dc->creator;
}
}
return $item;
}
/** /**
* Method should return, from a source RSS item given by lastRSS, one of our Items objects * Method should return, from a source RSS item given by lastRSS, one of our Items objects
* @param $item the input rss item * @param $item the input rss item