From eb51e9640f86b4871f79bd4a109aee03f6e8e108 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 13 Mar 2013 21:54:57 -0700 Subject: [PATCH] BC Fix --- e107_handlers/xml_class.php | 177 +++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 2 deletions(-) diff --git a/e107_handlers/xml_class.php b/e107_handlers/xml_class.php index af95efe05..6014ce08d 100644 --- a/e107_handlers/xml_class.php +++ b/e107_handlers/xml_class.php @@ -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; + } +} +