From 35e07a8903ad24c499fb723da6e9373f32a0c01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sat, 24 May 2014 12:21:07 -0400 Subject: [PATCH] Fix bug for Rss 2.0 feeds with Atom namespace --- vendor/PicoFeed/Parser.php | 26 ++++++++++++++++++++++---- vendor/PicoFeed/Parsers/Rss20.php | 17 ++++++++++------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/vendor/PicoFeed/Parser.php b/vendor/PicoFeed/Parser.php index edc2e81..52c6057 100644 --- a/vendor/PicoFeed/Parser.php +++ b/vendor/PicoFeed/Parser.php @@ -205,9 +205,16 @@ abstract class Parser */ public function normalizeData($data) { - $data = str_replace("\x10", '', $data); - $data = str_replace("\xc3\x20", '', $data); - $data = str_replace("", '', $data); + $invalid_chars = array( + "\x10", + "\xc3\x20", + "", + ); + + foreach ($invalid_chars as $needle) { + $data = str_replace($needle, '', $data); + } + $data = $this->replaceEntityAttribute($data); return $data; } @@ -474,14 +481,25 @@ abstract class Parser * @param SimpleXMLElement $xml XML element * @param array $namespaces XML namespaces * @param string $property XML tag name + * @param string $attribute XML attribute name * @return string */ - public function getNamespaceValue(SimpleXMLElement $xml, array $namespaces, $property) + public function getNamespaceValue(SimpleXMLElement $xml, array $namespaces, $property, $attribute = '') { foreach ($namespaces as $name => $url) { $namespace = $xml->children($namespaces[$name]); if ($namespace->$property->count() > 0) { + + if ($attribute) { + + foreach ($namespace->$property->attributes() as $xml_attribute => $xml_value) { + if ($xml_attribute === $attribute && $xml_value) { + return (string) $xml_value; + } + } + } + return (string) $namespace->$property; } } diff --git a/vendor/PicoFeed/Parsers/Rss20.php b/vendor/PicoFeed/Parsers/Rss20.php index 7af0b9a..5c7c4cf 100644 --- a/vendor/PicoFeed/Parsers/Rss20.php +++ b/vendor/PicoFeed/Parsers/Rss20.php @@ -193,14 +193,17 @@ class Rss20 extends Parser */ public function findItemUrl(SimpleXMLElement $entry, Item $item) { - $item->url = $this->getNamespaceValue($entry, $this->namespaces, 'origLink'); + $links = array( + $this->getNamespaceValue($entry, $this->namespaces, 'origLink'), + isset($entry->link) ? (string) $entry->link : '', + $this->getNamespaceValue($entry, $this->namespaces, 'link', 'href'), + isset($entry->guid) ? (string) $entry->guid : '', + ); - if (empty($item->url)) { - if (isset($entry->link)) { - $item->url = (string) $entry->link; - } - else if (isset($entry->guid)) { - $item->url = (string) $entry->guid; + foreach ($links as $link) { + if (! empty($link) && filter_var($link, FILTER_VALIDATE_URL) !== false) { + $item->url = $link; + break; } } }