Fix bug for Rss 2.0 feeds with Atom namespace

This commit is contained in:
Frédéric Guillot 2014-05-24 12:21:07 -04:00
parent c5ed4d97be
commit 35e07a8903
2 changed files with 32 additions and 11 deletions

View File

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

View File

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