diff options
author | Andrew Dolgov <[email protected]> | 2013-06-19 19:40:36 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2013-06-19 19:40:36 +0400 |
commit | a9000b03443d64ac5d7137c868862a5e1496e871 (patch) | |
tree | a81ae7e8446bca96e83e48f517668cc4580a9e9a | |
parent | 84acb0b711536def7daa6c3ca7dc4be5664972f8 (diff) |
feedparser: check if initial xpath query for root element returns anything
-rw-r--r-- | classes/feedparser.php | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/classes/feedparser.php b/classes/feedparser.php index d93c575b2..eb8606de9 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -51,24 +51,28 @@ class FeedParser { $this->xpath = $xpath; - $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)")->item(0); + $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)"); if ($root) { - switch (mb_strtolower($root->tagName)) { - case "rdf:rdf": - $this->type = $this::FEED_RDF; - break; - case "channel": - $this->type = $this::FEED_RSS; - break; - case "feed": - $this->type = $this::FEED_ATOM; - break; - default: - if( !isset($this->error) ){ - $this->error = "Unknown/unsupported feed type"; + $root = $root->item(0); + + if ($root) { + switch (mb_strtolower($root->tagName)) { + case "rdf:rdf": + $this->type = $this::FEED_RDF; + break; + case "channel": + $this->type = $this::FEED_RSS; + break; + case "feed": + $this->type = $this::FEED_ATOM; + break; + default: + if( !isset($this->error) ){ + $this->error = "Unknown/unsupported feed type"; + } + return; } - return; } switch ($this->type) { |