// Merge -> revision 8720

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8722 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-09-22 15:45:10 +00:00
parent 69db63f26c
commit 4f2a090e24
87 changed files with 1591 additions and 724 deletions
+3 -3
View File
@@ -39,7 +39,7 @@ require_once (_PS_PEAR_XML_PARSER_PATH_.'Parser/Exception.php');
* to the entire feed.
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
*/
class XML_Feed_Parser implements Iterator
@@ -87,13 +87,13 @@ class XML_Feed_Parser implements Iterator
function __construct($feed, $strict = false, $suppressWarnings = false, $tidy = false)
{
$this->model = new DOMDocument;
if (! $this->model->loadXML($feed)) {
if (! @$this->model->loadXML($feed)) { /* PrestaShop - no error display */
if (extension_loaded('tidy') && $tidy) {
$tidy = new tidy;
$tidy->parseString($feed,
array('input-xml' => true, 'output-xml' => true));
$tidy->cleanRepair();
if (! $this->model->loadXML((string) $tidy)) {
if (! @$this->model->loadXML((string) $tidy)) { /* PrestaShop - no error display */
throw new XML_Feed_Parser_Exception('Invalid input: this is not ' .
'valid XML');
}
+9 -9
View File
@@ -30,7 +30,7 @@
* person - defaults to name, but parameter based access
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
*/
class XML_Feed_Parser_Atom extends XML_Feed_Parser_Type
@@ -39,7 +39,7 @@ class XML_Feed_Parser_Atom extends XML_Feed_Parser_Type
* The URI of the RelaxNG schema used to (optionally) validate the feed
* @var string
*/
private $relax = 'atom.rnc';
protected $relax = 'atom.rng';
/**
* We're likely to use XPath, so let's keep it global
@@ -117,7 +117,7 @@ class XML_Feed_Parser_Atom extends XML_Feed_Parser_Type
$this->model = $model;
if ($strict) {
if (! $this->model->relaxNGValidateSource($this->relax)) {
if (! $this->relaxNGValidate()) {
throw new XML_Feed_Parser_Exception('Failed required validation');
}
}
@@ -148,7 +148,7 @@ class XML_Feed_Parser_Atom extends XML_Feed_Parser_Type
if ($entries->length > 0) {
$xmlBase = $entries->item(0)->baseURI;
$entry = new $this->itemElement($entries->item(0), $this, $xmlBase);
$entry = new $this->itemClass($entries->item(0), $this, $xmlBase);
if (in_array('evaluate', get_class_methods($this->xpath))) {
$offset = $this->xpath->evaluate("count(preceding-sibling::atom:entry)", $entries->item(0));
@@ -232,6 +232,7 @@ class XML_Feed_Parser_Atom extends XML_Feed_Parser_Type
}
return false;
}
return $this->parseTextConstruct($content);
}
@@ -258,12 +259,11 @@ class XML_Feed_Parser_Atom extends XML_Feed_Parser_Type
if (strpos($type, 'text/') === 0) {
$type = 'text';
}
switch ($type) {
case 'text':
return $content->nodeValue;
break;
case 'html':
return str_replace('&lt;', '<', $content->nodeValue);
return $content->textContent;
break;
case 'xhtml':
$container = $content->getElementsByTagName('div');
@@ -277,7 +277,7 @@ class XML_Feed_Parser_Atom extends XML_Feed_Parser_Type
foreach ($contents->childNodes as $node) {
$result .= $this->traverseNode($node);
}
return utf8_decode($result);
return $result;
}
break;
case preg_match('@^[a-zA-Z]+/[a-zA-Z+]*xml@i', $type) > 0:
@@ -362,4 +362,4 @@ class XML_Feed_Parser_Atom extends XML_Feed_Parser_Type
}
}
?>
?>
+1 -1
View File
@@ -26,7 +26,7 @@
* XML_Feed_Parser_Atom with which it shares many methods.
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
*/
class XML_Feed_Parser_AtomElement extends XML_Feed_Parser_Atom
+1 -1
View File
@@ -31,7 +31,7 @@ require_once(dirname(__FILE__).'/../../pear/PEAR.php');
* to help with identification of the source of exceptions.
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
*/
class XML_Feed_Parser_Exception extends PEAR_Exception
+10 -3
View File
@@ -25,7 +25,7 @@
* This class handles RSS0.9 feeds.
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
* @todo Find a Relax NG URI we can use
*/
@@ -35,7 +35,7 @@ class XML_Feed_Parser_RSS09 extends XML_Feed_Parser_Type
* The URI of the RelaxNG schema used to (optionally) validate the feed
* @var string
*/
private $relax = '';
protected $relax = '';
/**
* We're likely to use XPath, so let's keep it global
@@ -209,6 +209,13 @@ class XML_Feed_Parser_RSS09 extends XML_Feed_Parser_Type
$link = $links->item($offset);
return $this->addBase($link->nodeValue, $link);
}
/**
* Not implemented - no available validation.
*/
public function relaxNGValidate() {
return true;
}
}
?>
?>
@@ -26,7 +26,7 @@
* XML_Feed_Parser_RSS09 with which it shares many methods.
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
*/
class XML_Feed_Parser_RSS09Element extends XML_Feed_Parser_RSS09
+4 -6
View File
@@ -25,7 +25,7 @@
* This class handles RSS1.0 feeds.
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
* @todo Find a Relax NG URI we can use
*/
@@ -35,7 +35,7 @@ class XML_Feed_Parser_RSS1 extends XML_Feed_Parser_Type
* The URI of the RelaxNG schema used to (optionally) validate the feed
* @var string
*/
private $relax = 'rss10.rnc';
protected $relax = 'rss10.rng';
/**
* We're likely to use XPath, so let's keep it global
@@ -121,9 +121,7 @@ class XML_Feed_Parser_RSS1 extends XML_Feed_Parser_Type
{
$this->model = $model;
if ($strict) {
$validate = $this->model->relaxNGValidate(self::getSchemaDir .
DIRECTORY_SEPARATOR . $this->relax);
if (! $validate) {
if (! $this->relaxNGValidate()) {
throw new XML_Feed_Parser_Exception('Failed required validation');
}
}
@@ -274,4 +272,4 @@ class XML_Feed_Parser_RSS1 extends XML_Feed_Parser_Type
}
}
?>
?>
+4 -6
View File
@@ -26,7 +26,7 @@
* http://inamidst.com/rss1.1/
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
* @todo Support for RDF:List
* @todo Ensure xml:lang is accessible to users
@@ -37,7 +37,7 @@ class XML_Feed_Parser_RSS11 extends XML_Feed_Parser_Type
* The URI of the RelaxNG schema used to (optionally) validate the feed
* @var string
*/
private $relax = 'rss11.rnc';
protected $relax = 'rss11.rng';
/**
* We're likely to use XPath, so let's keep it global
@@ -123,9 +123,7 @@ class XML_Feed_Parser_RSS11 extends XML_Feed_Parser_Type
$this->model = $model;
if ($strict) {
$validate = $this->model->relaxNGValidate(self::getSchemaDir .
DIRECTORY_SEPARATOR . $this->relax);
if (! $validate) {
if (! $this->relaxNGValidate()) {
throw new XML_Feed_Parser_Exception('Failed required validation');
}
}
@@ -273,4 +271,4 @@ class XML_Feed_Parser_RSS11 extends XML_Feed_Parser_Type
}
}
?>
?>
@@ -26,7 +26,7 @@
* XML_Feed_Parser_RSS11 with which it shares many methods.
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
*/
class XML_Feed_Parser_RSS11Element extends XML_Feed_Parser_RSS11
@@ -65,7 +65,7 @@ class XML_Feed_Parser_RSS11Element extends XML_Feed_Parser_RSS11
protected $compatMap = array(
'content' => array('content'),
'updated' => array('lastBuildDate'),
'published' => array('pubdate'),
'published' => array('date'),
'subtitle' => array('description'),
'updated' => array('date'),
'author' => array('creator'),
@@ -148,4 +148,4 @@ class XML_Feed_Parser_RSS11Element extends XML_Feed_Parser_RSS11
}
}
?>
?>
+3 -3
View File
@@ -26,7 +26,7 @@
* XML_Feed_Parser_RSS1 with which it shares many methods.
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
*/
class XML_Feed_Parser_RSS1Element extends XML_Feed_Parser_RSS1
@@ -65,7 +65,7 @@ class XML_Feed_Parser_RSS1Element extends XML_Feed_Parser_RSS1
protected $compatMap = array(
'content' => array('content'),
'updated' => array('lastBuildDate'),
'published' => array('pubdate'),
'published' => array('date'),
'subtitle' => array('description'),
'updated' => array('date'),
'author' => array('creator'),
@@ -113,4 +113,4 @@ class XML_Feed_Parser_RSS1Element extends XML_Feed_Parser_RSS1
}
}
?>
?>
+5 -5
View File
@@ -25,7 +25,7 @@
* This class handles RSS2 feeds.
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
*/
class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type
@@ -34,7 +34,7 @@ class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type
* The URI of the RelaxNG schema used to (optionally) validate the feed
* @var string
*/
private $relax = 'rss20.rnc';
protected $relax = 'rss20.rng';
/**
* We're likely to use XPath, so let's keep it global
@@ -116,7 +116,7 @@ class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type
$this->model = $model;
if ($strict) {
if (! $this->model->relaxNGValidate($this->relax)) {
if (! $this->relaxNGValidate()) {
throw new XML_Feed_Parser_Exception('Failed required validation');
}
}
@@ -194,7 +194,7 @@ class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type
*/
protected function getImage()
{
$images = $this->model->getElementsByTagName('image');
$images = $this->xpath->query("//image");
if ($images->length > 0) {
$image = $images->item(0);
$desc = $image->getElementsByTagName('description');
@@ -331,4 +331,4 @@ class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type
}
}
?>
?>
+1 -1
View File
@@ -26,7 +26,7 @@
* called by XML_Feed_Parser_RSS2 with which it shares many methods.
*
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
* @package XML_Feed_Parser
*/
class XML_Feed_Parser_RSS2Element extends XML_Feed_Parser_RSS2
+42 -8
View File
@@ -27,7 +27,7 @@
*
* @package XML_Feed_Parser
* @author James Stewart <james@jystewart.net>
* @version Release: 1.0.2
* @version Release: @package_version@
*/
abstract class XML_Feed_Parser_Type
{
@@ -49,6 +49,11 @@ abstract class XML_Feed_Parser_Type
*/
public $entries = array();
/**
* Store mappings between entry IDs and their position in the feed
*/
public $idMappings = array();
/**
* Proxy to allow use of element names as method names
*
@@ -195,7 +200,7 @@ abstract class XML_Feed_Parser_Type
$this->entries[$offset] = new $this->itemClass(
$entries->item($offset), $this, $xmlBase);
if ($id = $this->entries[$offset]->id) {
@$this->idMappings[$id] = $this->entries[$offset];
$this->idMappings[$id] = $this->entries[$offset];
}
} else {
throw new XML_Feed_Parser_Exception('No entries found');
@@ -219,7 +224,7 @@ abstract class XML_Feed_Parser_Type
protected function getDate($method, $arguments)
{
$time = $this->model->getElementsByTagName($method);
if ($time->length == 0) {
if ($time->length == 0 || empty($time->item(0)->nodeValue)) {
return false;
}
return strtotime($time->item(0)->nodeValue);
@@ -307,12 +312,12 @@ abstract class XML_Feed_Parser_Type
$return = '';
foreach ($node->attributes as $attribute) {
if ($attribute->name == 'src' or $attribute->name == 'href') {
$attribute->value = $this->addBase($attribute->value, $attribute);
$attribute->value = $this->addBase(htmlentities($attribute->value, NULL, 'utf-8'), $attribute);
}
if ($attribute->name == 'base') {
continue;
}
$return .= $attribute->name . '="' . $attribute->value .'" ';
$return .= $attribute->name . '="' . htmlentities($attribute->value, NULL, 'utf-8') .'" ';
}
if (! empty($return)) {
return ' ' . trim($return);
@@ -320,13 +325,34 @@ abstract class XML_Feed_Parser_Type
return '';
}
/**
* Convert HTML entities based on the current character set.
*
* @param String
* @return String
*/
function processEntitiesForNodeValue($node)
{
if (function_exists('iconv')) {
$current_encoding = $node->ownerDocument->encoding;
$value = iconv($current_encoding, 'UTF-8', $node->nodeValue);
} else if ($current_encoding == 'iso-8859-1') {
$value = utf8_encode($node->nodeValue);
} else {
$value = $node->nodeValue;
}
$decoded = html_entity_decode($value, NULL, 'UTF-8');
return htmlentities($decoded, NULL, 'UTF-8');
}
/**
* Part of our xml:base processing code
*
* We need a couple of methods to access XHTML content stored in feeds.
* This is because we dereference all xml:base references before returning
* the element. This method recurs through the tree descending from the node
* and builds our string
* and builds our string.
*
* @param DOMElement $node The DOM node we are processing
* @return string
@@ -349,7 +375,7 @@ abstract class XML_Feed_Parser_Type
}
if ($node instanceof DOMText) {
$content .= htmlentities($node->nodeValue);
$content .= $this->processEntitiesForNodeValue($node);
}
/* Add the closing of this node to the content */
@@ -436,6 +462,14 @@ abstract class XML_Feed_Parser_Type
$config = new PEAR_Config;
return $config->get('data_dir') . '/XML_Feed_Parser/schemas';
}
public function relaxNGValidate() {
$dir = self::getSchemaDir();
$path = $dir . '/' . $this->relax;
return $this->model->relaxNGValidate($path);
}
}
?>
?>