mirror of
https://github.com/e107inc/e107.git
synced 2025-06-06 02:46:42 +02:00
BC Fix
This commit is contained in:
parent
ea6ef5d648
commit
eb51e9640f
@ -14,6 +14,28 @@
|
||||
|
||||
if (!defined('e107_INIT')) { exit; }
|
||||
|
||||
|
||||
class parseXml extends xmlClass // BC with v1.x
|
||||
{
|
||||
|
||||
function setUrl($feed)
|
||||
{
|
||||
$this->setFeedUrl($feed);
|
||||
}
|
||||
|
||||
function getRemoteXmlFile($address, $timeout = 10)
|
||||
{
|
||||
return $this->getRemoteFile($address, $timeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Simple XML Parser
|
||||
*
|
||||
@ -284,11 +306,12 @@ class xmlClass
|
||||
// Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here
|
||||
$timeout = min($timeout, 120);
|
||||
$timeout = max($timeout, 3);
|
||||
|
||||
$mes = e107::getMessage();
|
||||
|
||||
if($this->_feedUrl) // override option for use when part of the address needs to be encoded.
|
||||
{
|
||||
$address = $this->_feedUrl;
|
||||
echo "address=".$address;
|
||||
$mes->addDebug("getting Remote File: ".$this->_feedUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1001,5 +1024,155 @@ class xmlClass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* DEPRECATED XML Class from v1.x
|
||||
*/
|
||||
class XMLParse
|
||||
{
|
||||
var $rawXML;
|
||||
var $valueArray = array();
|
||||
var $keyArray = array();
|
||||
var $parsed = array();
|
||||
var $index = 0;
|
||||
var $attribKey = 'attributes';
|
||||
var $valueKey = 'value';
|
||||
var $cdataKey = 'cdata';
|
||||
var $isError = false;
|
||||
var $error = '';
|
||||
|
||||
function XMLParse($xml = NULL)
|
||||
{
|
||||
$this->rawXML = $xml;
|
||||
$mes = e107::getMessage();
|
||||
$mes->addDebug("Deprecated class XMLParse used. Please use 'xmlClass' instead");
|
||||
}
|
||||
|
||||
function parse($xml = NULL)
|
||||
{
|
||||
if (!is_null($xml))
|
||||
{
|
||||
$this->rawXML = $xml;
|
||||
}
|
||||
|
||||
$this->isError = false;
|
||||
|
||||
if (!$this->parse_init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->index = 0;
|
||||
$this->parsed = $this->parse_recurse();
|
||||
$this->status = 'parsing complete';
|
||||
|
||||
return $this->parsed;
|
||||
}
|
||||
|
||||
function parse_recurse()
|
||||
{
|
||||
$found = array();
|
||||
$tagCount = array();
|
||||
|
||||
while (isset($this->valueArray[$this->index]))
|
||||
{
|
||||
$tag = $this->valueArray[$this->index];
|
||||
$this->index++;
|
||||
|
||||
if ($tag['type'] == 'close')
|
||||
{
|
||||
return $found;
|
||||
}
|
||||
|
||||
if ($tag['type'] == 'cdata')
|
||||
{
|
||||
$tag['tag'] = $this->cdataKey;
|
||||
$tag['type'] = 'complete';
|
||||
}
|
||||
|
||||
$tagName = $tag['tag'];
|
||||
|
||||
if (isset($tagCount[$tagName]))
|
||||
{
|
||||
if ($tagCount[$tagName] == 1)
|
||||
{
|
||||
$found[$tagName] = array($found[$tagName]);
|
||||
}
|
||||
|
||||
$tagRef =& $found[$tagName][$tagCount[$tagName]];
|
||||
$tagCount[$tagName]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$tagCount[$tagName] = 1;
|
||||
$tagRef =& $found[$tagName];
|
||||
}
|
||||
|
||||
switch ($tag['type'])
|
||||
{
|
||||
case 'open':
|
||||
$tagRef = $this->parse_recurse();
|
||||
|
||||
if (isset($tag['attributes']))
|
||||
{
|
||||
$tagRef[$this->attribKey] = $tag['attributes'];
|
||||
}
|
||||
|
||||
if (isset($tag['value']))
|
||||
{
|
||||
if (isset($tagRef[$this->cdataKey]))
|
||||
{
|
||||
$tagRef[$this->cdataKey] = (array)$tagRef[$this->cdataKey];
|
||||
array_unshift($tagRef[$this->cdataKey], $tag['value']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tagRef[$this->cdataKey] = $tag['value'];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'complete':
|
||||
if (isset($tag['attributes']))
|
||||
{
|
||||
$tagRef[$this->attribKey] = $tag['attributes'];
|
||||
$tagRef =& $tagRef[$this->valueKey];
|
||||
}
|
||||
|
||||
if (isset($tag['value']))
|
||||
{
|
||||
$tagRef = $tag['value'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
function parse_init()
|
||||
{
|
||||
$this->parser = xml_parser_create();
|
||||
|
||||
$parser = $this->parser;
|
||||
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
|
||||
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
|
||||
if (!$res = (bool)xml_parse_into_struct($parser, $this->rawXML, $this->valueArray, $this->keyArray))
|
||||
{
|
||||
$this->isError = true;
|
||||
$this->error = 'error: '.xml_error_string(xml_get_error_code($parser)).' at line '.xml_get_current_line_number($parser);
|
||||
}
|
||||
xml_parser_free($parser);
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user