summaryrefslogtreecommitdiffstats
path: root/vendor/fguillot/picofeed/lib/PicoFeed/Parser
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/fguillot/picofeed/lib/PicoFeed/Parser')
-rw-r--r--vendor/fguillot/picofeed/lib/PicoFeed/Parser/Item.php41
-rw-r--r--vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php3
-rw-r--r--vendor/fguillot/picofeed/lib/PicoFeed/Parser/XmlParser.php30
3 files changed, 47 insertions, 27 deletions
diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Item.php b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Item.php
index 1585131c7..d891ef41c 100644
--- a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Item.php
+++ b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Item.php
@@ -100,6 +100,47 @@ class Item
public $language = '';
/**
+ * Raw XML
+ *
+ * @access public
+ * @var \SimpleXMLElement
+ */
+ public $xml;
+
+ /**
+ * List of namespaces
+ *
+ * @access public
+ * @var array
+ */
+ public $namespaces = array();
+
+ /**
+ * Get specific XML tag or attribute value
+ *
+ * @access public
+ * @param string $tag Tag name (examples: guid, media:content)
+ * @param string $attribute Tag attribute
+ * @return string
+ */
+ public function getTag($tag, $attribute = '')
+ {
+ // Get namespaced value
+ if (strpos($tag, ':') !== false) {
+ list(,$tag) = explode(':', $tag);
+ return XmlParser::getNamespaceValue($this->xml, $this->namespaces, $tag, $attribute);
+ }
+
+ // Return attribute value
+ if (! empty($attribute)) {
+ return (string) $this->xml->{$tag}[$attribute];
+ }
+
+ // Return tag content
+ return (string) $this->xml->$tag;
+ }
+
+ /**
* Return item information
*
* @access public
diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php
index 4d45f539c..7ef904f0a 100644
--- a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php
+++ b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php
@@ -153,6 +153,9 @@ abstract class Parser
foreach ($this->getItemsTree($xml) as $entry) {
$item = new Item;
+ $item->xml = $entry;
+ $item->namespaces = $this->namespaces;
+
$this->findItemAuthor($xml, $entry, $item);
$this->findItemUrl($entry, $item);
diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/XmlParser.php b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/XmlParser.php
index 2c68c50a5..feda8c254 100644
--- a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/XmlParser.php
+++ b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/XmlParser.php
@@ -212,21 +212,7 @@ class XmlParser
}
/**
- * Extract charset from meta tag
- *
- * @static
- * @access public
- * @param string $data meta tag content
- * @return string
- */
- public static function findCharset($data)
- {
- $result = explode('charset=', $data);
- return isset($result[1]) ? $result[1] : $data;
- }
-
- /**
- * Get the encoding from a xml tag
+ * Get the charset from a meta tag
*
* @static
* @access public
@@ -237,18 +223,8 @@ class XmlParser
{
$encoding = '';
- $dom = static::getHtmlDocument($data);
- $xpath = new DOMXPath($dom);
-
- $tags = array(
- '/html/head/meta[translate(@http-equiv, "CENOPTY", "cenopty")="content-type"]/@content', //HTML4, convert upper to lower-case
- '/html/head/meta/@charset', //HTML5
- );
-
- $nodes = $xpath->query(implode(' | ', $tags));
-
- foreach ($nodes as $node) {
- $encoding = static::findCharset($node->nodeValue);
+ if (preg_match('/<meta.*?charset\s*=\s*["\']?\s*([^"\'\s\/>;]+)/i', $data, $match) === 1) {
+ $encoding = strtolower($match[1]);
}
return $encoding;