forked from blallo/rss-bridge
[FeedExpander] simplify feed type detection and store it
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
88919a43fd
commit
655b3d578d
1 changed files with 18 additions and 13 deletions
|
@ -5,6 +5,7 @@ abstract class FeedExpander extends BridgeAbstract {
|
||||||
private $name;
|
private $name;
|
||||||
private $uri;
|
private $uri;
|
||||||
private $description;
|
private $description;
|
||||||
|
private $feedType;
|
||||||
|
|
||||||
public function collectExpandableDatas($url, $maxItems = -1){
|
public function collectExpandableDatas($url, $maxItems = -1){
|
||||||
if(empty($url)){
|
if(empty($url)){
|
||||||
|
@ -21,22 +22,26 @@ abstract class FeedExpander extends BridgeAbstract {
|
||||||
$rssContent = simplexml_load_string($content);
|
$rssContent = simplexml_load_string($content);
|
||||||
|
|
||||||
$this->debugMessage('Detecting feed format/version');
|
$this->debugMessage('Detecting feed format/version');
|
||||||
if(isset($rssContent->channel[0])){
|
switch(true){
|
||||||
$this->debugMessage('Detected RSS format');
|
case isset($rssContent->item[0]):
|
||||||
if(isset($rssContent->item[0])){
|
$this->debugMessage('Detected RSS 1.0 format');
|
||||||
$this->debugMessage('Detected RSS 1.0 format');
|
$this->feedType="RSS_1_0";
|
||||||
$this->collect_RSS_1_0_data($rssContent, $maxItems);
|
break;
|
||||||
} else {
|
case isset($rssContent->channel[0]):
|
||||||
$this->debugMessage('Detected RSS 0.9x or 2.0 format');
|
$this->debugMessage('Detected RSS 0.9x or 2.0 format');
|
||||||
$this->collect_RSS_2_0_data($rssContent, $maxItems);
|
$this->feedType="RSS_2_0";
|
||||||
}
|
break;
|
||||||
} elseif(isset($rssContent->entry[0])){
|
case isset($rssContent->entry[0]):
|
||||||
$this->debugMessage('Detected ATOM format');
|
$this->debugMessage('Detected ATOM format');
|
||||||
$this->collect_ATOM_data($rssContent, $maxItems);
|
$this->feedType="ATOM_1_0";
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
$this->debugMessage('Unknown feed format/version');
|
$this->debugMessage('Unknown feed format/version');
|
||||||
$this->returnServerError('The feed format is unknown!');
|
$this->returnServerError('The feed format is unknown!');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->{'collect_'.$this->feedType.'_data'}($rssContent,$maxItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function collect_RSS_1_0_data($rssContent, $maxItems){
|
protected function collect_RSS_1_0_data($rssContent, $maxItems){
|
||||||
|
@ -62,7 +67,7 @@ abstract class FeedExpander extends BridgeAbstract {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function collect_ATOM_data($content, $maxItems){
|
protected function collect_ATOM_1_0_data($content, $maxItems){
|
||||||
$this->load_ATOM_feed_data($content);
|
$this->load_ATOM_feed_data($content);
|
||||||
foreach($content->entry as $item){
|
foreach($content->entry as $item){
|
||||||
$this->debugMessage('parsing item ' . var_export($item, true));
|
$this->debugMessage('parsing item ' . var_export($item, true));
|
||||||
|
|
Loading…
Reference in a new issue