Fix bug for Rss 2.0 feeds with Atom namespace
This commit is contained in:
parent
c5ed4d97be
commit
35e07a8903
26
vendor/PicoFeed/Parser.php
vendored
26
vendor/PicoFeed/Parser.php
vendored
@ -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;
|
||||
}
|
||||
}
|
||||
|
17
vendor/PicoFeed/Parsers/Rss20.php
vendored
17
vendor/PicoFeed/Parsers/Rss20.php
vendored
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user