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; } } }