summaryrefslogtreecommitdiffstats
path: root/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php')
-rw-r--r--vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php48
1 files changed, 39 insertions, 9 deletions
diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php
index 810494b70..918cdef33 100644
--- a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php
+++ b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php
@@ -58,7 +58,7 @@ abstract class Parser
protected $fallback_url = '';
/**
- * XML namespaces
+ * XML namespaces supported by parser
*
* @access protected
* @var array
@@ -66,6 +66,14 @@ abstract class Parser
protected $namespaces = array();
/**
+ * XML namespaces used in document
+ *
+ * @access protected
+ * @var array
+ */
+ protected $used_namespaces = array();
+
+ /**
* Enable the content filtering
*
* @access private
@@ -117,9 +125,6 @@ abstract class Parser
// Encode everything in UTF-8
Logger::setMessage(get_called_class().': HTTP Encoding "'.$http_encoding.'" ; XML Encoding "'.$xml_encoding.'"');
$this->content = Encoding::convert($this->content, $xml_encoding ?: $http_encoding);
-
- // Workarounds
- $this->content = Filter::normalizeData($this->content);
}
/**
@@ -135,12 +140,19 @@ abstract class Parser
$xml = XmlParser::getSimpleXml($this->content);
if ($xml === false) {
- Logger::setMessage(get_called_class().': XML parsing error');
- Logger::setMessage(XmlParser::getErrors());
- throw new MalformedXmlException('XML parsing error');
+ Logger::setMessage(get_called_class().': Applying XML workarounds');
+ $this->content = Filter::normalizeData($this->content);
+ $xml = XmlParser::getSimpleXml($this->content);
+
+ if ($xml === false) {
+ Logger::setMessage(get_called_class().': XML parsing error');
+ Logger::setMessage(XmlParser::getErrors());
+ throw new MalformedXmlException('XML parsing error');
+ }
}
- $this->namespaces = $xml->getNamespaces(true);
+ $this->used_namespaces = $xml->getNamespaces(true);
+ $xml = $this->registerSupportedNamespaces($xml);
$feed = new Feed;
@@ -160,9 +172,11 @@ abstract class Parser
foreach ($this->getItemsTree($xml) as $entry) {
+ $entry = $this->registerSupportedNamespaces($entry);
+
$item = new Item;
$item->xml = $entry;
- $item->namespaces = $this->namespaces;
+ $item->namespaces = $this->used_namespaces;
$this->findItemAuthor($xml, $entry, $item);
@@ -418,6 +432,22 @@ abstract class Parser
}
/**
+ * Register all supported namespaces to be used within an xpath query
+ *
+ * @access public
+ * @param SimpleXMLElement $xml Feed xml
+ * @return SimpleXMLElement
+ */
+ public function registerSupportedNamespaces(SimpleXMLElement $xml)
+ {
+ foreach ($this->namespaces as $prefix => $ns) {
+ $xml->registerXPathNamespace($prefix, $ns);
+ }
+
+ return $xml;
+ }
+
+ /**
* Find the feed url
*
* @access public