1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

Bugfix: Xml feed was failing under some circumstances

This commit is contained in:
CaMer0n
2010-02-07 00:44:08 +00:00
parent 8357a97f04
commit 9af9c97d58

View File

@@ -9,9 +9,9 @@
* Simple XML Parser * Simple XML Parser
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/xml_class.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/xml_class.php,v $
* $Revision: 1.38 $ * $Revision: 1.39 $
* $Date: 2009-11-26 17:14:06 $ * $Date: 2010-02-07 00:44:08 $
* $Author: secretr $ * $Author: e107coders $
*/ */
if (!defined('e107_INIT')) { exit; } if (!defined('e107_INIT')) { exit; }
@@ -27,10 +27,10 @@ if (!defined('e107_INIT')) { exit; }
*/ */
class xmlClass class xmlClass
{ {
/** /**
* Loaded XML string * Loaded XML string
* *
* @var string * @var string
*/ */
public $xmlFileContents = ''; public $xmlFileContents = '';
@@ -47,7 +47,7 @@ class xmlClass
* 'management' => array('install' => FALSE) * 'management' => array('install' => FALSE)
* ); * );
* </code> * </code>
* *
* @see setOptFilter() * @see setOptFilter()
* @see parseXml() * @see parseXml()
* @see xml2array() * @see xml2array()
@@ -56,91 +56,91 @@ class xmlClass
public $filter = false; // Optional filter for loaded XML public $filter = false; // Optional filter for loaded XML
/** /**
* Set true to strip all mention of comments from the returned array (default); * Set true to strip all mention of comments from the returned array (default);
* FALSE to return comment markers (object SimpleXMLElement) * FALSE to return comment markers (object SimpleXMLElement)
* *
* @see setOptStripComments() * @see setOptStripComments()
* @see parseXml() * @see parseXml()
* @see xml2array() * @see xml2array()
* @var boolean * @var boolean
*/ */
public $stripComments = true; public $stripComments = true;
/** /**
* Log of all paths replaced. * Log of all paths replaced.
* *
* @var array * @var array
*/ */
public $fileConvertLog = array(); public $fileConvertLog = array();
public $convertFilePaths = FALSE; public $convertFilePaths = FALSE;
public $filePathDestination = FALSE; public $filePathDestination = FALSE;
public $convertFileTypes = array("jpg", "gif", "png", "jpeg"); public $convertFileTypes = array("jpg", "gif", "png", "jpeg");
public $filePathPrepend = array(); public $filePathPrepend = array();
public $filePathConvKeys = array(); public $filePathConvKeys = array();
public $errors; public $errors;
private $arrayTags = false; private $arrayTags = false;
private $stringTags = false; private $stringTags = false;
/** /**
* Add root element to the result array * Add root element to the result array
* Exmple: * Exmple:
* <code> * <code>
* <root> * <root>
* <tag>some value</tag> * <tag>some value</tag>
* </root> * </root>
* </code> * </code>
* *
* if * if
* <code>$_optAddRoot = true;</code> * <code>$_optAddRoot = true;</code>
* xml2array() result is array('root' => array('tag' => 'some value')); * xml2array() result is array('root' => array('tag' => 'some value'));
* *
* if * if
* <code>$_optAddRoot = false;</code> * <code>$_optAddRoot = false;</code>
* xml2array() result is array('tag' => 'some value'); * xml2array() result is array('tag' => 'some value');
* *
* @see xml2array() * @see xml2array()
* @see setOptAddRoot() * @see setOptAddRoot()
* @var boolean * @var boolean
*/ */
protected $_optAddRoot = false; protected $_optAddRoot = false;
/** /**
* Always return array, even for single first level tag => value pair * Always return array, even for single first level tag => value pair
* Exmple: * Exmple:
* <code> * <code>
* <root> * <root>
* <tag>some value</tag> * <tag>some value</tag>
* </root> * </root>
* </code> * </code>
* *
* if * if
* <code>$_optForceArray = true;</code> * <code>$_optForceArray = true;</code>
* xml2array() result is array('tag' => array('value' => 'some value')); * xml2array() result is array('tag' => array('value' => 'some value'));
* where 'value' is the value of $_optValueKey * where 'value' is the value of $_optValueKey
* *
* If * If
* <code>$_optForceArray = false;</code> * <code>$_optForceArray = false;</code>
* xml2array() result is array('tag' => 'some value'); * xml2array() result is array('tag' => 'some value');
* *
* @see xml2array() * @see xml2array()
* @see setOptForceArray() * @see setOptForceArray()
* @var boolean * @var boolean
*/ */
protected $_optForceArray = false; protected $_optForceArray = false;
/** /**
* Key name for simple tag => value pairs * Key name for simple tag => value pairs
* *
* @see xml2array() * @see xml2array()
* @see setOptValueKey() * @see setOptValueKey()
* @var string * @var string
@@ -149,32 +149,32 @@ class xmlClass
/** /**
* Constructor - set defaults * Constructor - set defaults
* *
*/ */
function __constructor() function __constructor()
{ {
$this->reset(); $this->reset();
if(count($this->filePathConversions)) if(count($this->filePathConversions))
{ {
$this->filePathConvKeys = array_keys($this->filePathConversions); $this->filePathConvKeys = array_keys($this->filePathConversions);
} }
} }
/** /**
* Reset object * Reset object
* *
* @param boolean $xml_contents [optional] * @param boolean $xml_contents [optional]
* @return xmlClass * @return xmlClass
*/ */
function reset($xml_contents = true) function reset($xml_contents = true)
{ {
if($xml_contents) if($xml_contents)
{ {
$this->xmlFileContents = ''; $this->xmlFileContents = '';
} }
$this->filter = false; $this->filter = false;
$this->stripComments = true; $this->stripComments = true;
$this->_optAddRoot = false; $this->_optAddRoot = false;
$this->_optValueKey = '@value'; $this->_optValueKey = '@value';
$this->_optForceArray = false; $this->_optForceArray = false;
@@ -183,7 +183,7 @@ class xmlClass
/** /**
* Set addRoot option * Set addRoot option
* *
* @param boolean $flag * @param boolean $flag
* @return xmlClass * @return xmlClass
*/ */
@@ -192,7 +192,7 @@ class xmlClass
$this->_optAddRoot = (boolean) $flag; $this->_optAddRoot = (boolean) $flag;
return $this; return $this;
} }
/** /**
* Set Xml tags that should always return arrays. * Set Xml tags that should always return arrays.
* *
@@ -205,16 +205,16 @@ class xmlClass
$this->arrayTags = (array) explode(",", $string); $this->arrayTags = (array) explode(",", $string);
return $this; return $this;
} }
public function setOptStringTags($string) public function setOptStringTags($string)
{ {
$this->stringTags = (array) explode(",", $string); $this->stringTags = (array) explode(",", $string);
return $this; return $this;
} }
/** /**
* Set forceArray option * Set forceArray option
* *
* @param boolean $flag * @param boolean $flag
* @return xmlClass * @return xmlClass
*/ */
@@ -223,10 +223,10 @@ class xmlClass
$this->_optForceArray = (boolean) $flag; $this->_optForceArray = (boolean) $flag;
return $this; return $this;
} }
/** /**
* Set valueKey option * Set valueKey option
* *
* @param string $str * @param string $str
* @return xmlClass * @return xmlClass
*/ */
@@ -235,10 +235,10 @@ class xmlClass
$this->_optValueKey = trim((string) $str); $this->_optValueKey = trim((string) $str);
return $this; return $this;
} }
/** /**
* Set strpComments option * Set strpComments option
* *
* @param boolean $flag * @param boolean $flag
* @return xmlClass * @return xmlClass
*/ */
@@ -247,10 +247,10 @@ class xmlClass
$this->stripComments = (boolean) $flag; $this->stripComments = (boolean) $flag;
return $this; return $this;
} }
/** /**
* Set strpComments option * Set strpComments option
* *
* @param array $filter * @param array $filter
* @return xmlClass * @return xmlClass
*/ */
@@ -278,7 +278,7 @@ class xmlClass
{ {
$old_timeout = e107_ini_set('default_socket_timeout', $timeout); $old_timeout = e107_ini_set('default_socket_timeout', $timeout);
$data = file_get_contents(urldecode($address)); $data = file_get_contents(urldecode($address));
// $data = file_get_contents(htmlspecialchars($address)); // buggy - sometimes fails. // $data = file_get_contents(htmlspecialchars($address)); // buggy - sometimes fails.
if ($old_timeout !== FALSE) if ($old_timeout !== FALSE)
{ {
@@ -286,6 +286,7 @@ class xmlClass
} }
if ($data) if ($data)
{ {
$this->xmlFileContents = $data;
return $data; return $data;
} }
} }
@@ -348,8 +349,8 @@ class xmlClass
/** /**
* Parse $xmlFileContents XML string to array * Parse $xmlFileContents XML string to array
* *
* @param string $xml [optional] * @param string $xml [optional]
* @param boolean $simple [optional] false - use xml2array(), true - use xml_convert_to_array() * @param boolean $simple [optional] false - use xml2array(), true - use xml_convert_to_array()
* @return string * @return string
*/ */
@@ -370,18 +371,18 @@ class xmlClass
if(!$xml = simplexml_load_string($xmlData)) if(!$xml = simplexml_load_string($xmlData))
{ {
$this->errors = $this->getErrors($xmlData); $this->errors = $this->getErrors($xmlData);
return FALSE; return FALSE;
}; };
$xml = $simple ? $this->xml_convert_to_array($xml, $this->filter, $this->stripComments) : $this->xml2array($xml); $xml = $simple ? $this->xml_convert_to_array($xml, $this->filter, $this->stripComments) : $this->xml2array($xml);
return $xml; return $xml;
} }
/** /**
* Advanced XML parser - handles tags with attributes and values * Advanced XML parser - handles tags with attributes and values
* properly. * properly.
* TODO - filter (see xml_convert_to_array) * TODO - filter (see xml_convert_to_array)
* *
* @param SimpleXMLElement $xml * @param SimpleXMLElement $xml
* @param string $rec_parent used for recursive calls only * @param string $rec_parent used for recursive calls only
* @return array * @return array
@@ -390,25 +391,25 @@ class xmlClass
{ {
$ret = array(); $ret = array();
$tags = get_object_vars($xml); $tags = get_object_vars($xml);
//remove comments //remove comments
if($this->stripComments && isset($tags['comment'])) if($this->stripComments && isset($tags['comment']))
{ {
unset($tags['comment']); unset($tags['comment']);
} }
//first call //first call
if(!$rec_parent) if(!$rec_parent)
{ {
//$ret = $this->xml2array($xml, true); //$ret = $this->xml2array($xml, true);
//repeating code because of the _optForceArray functionality //repeating code because of the _optForceArray functionality
if(!is_object($xml)) if(!is_object($xml))
{ {
return array(); return array();
} }
$tags = array_keys($tags); $tags = array_keys($tags);
foreach ($tags as $tag) foreach ($tags as $tag)
{ {
if($tag == '@attributes') if($tag == '@attributes')
@@ -429,19 +430,19 @@ class xmlClass
} }
$ret[$tag] = $this->xml2array($xml->{$tag}, $tag); $ret[$tag] = $this->xml2array($xml->{$tag}, $tag);
} }
$ret = $this->parseArrayTags($ret); $ret = $this->parseArrayTags($ret);
$ret = $this->parseStringTags($ret); $ret = $this->parseStringTags($ret);
return ($this->_optAddRoot ? array($xml->getName() => $ret) : $ret); return ($this->_optAddRoot ? array($xml->getName() => $ret) : $ret);
} }
//Recursive calls start here //Recursive calls start here
if($tags) if($tags)
{ {
$tags = array_keys($tags); $tags = array_keys($tags);
$count_tags = count($tags); $count_tags = count($tags);
//loop through tags //loop through tags
foreach ($tags as $tag) foreach ($tags as $tag)
{ {
@@ -450,19 +451,19 @@ class xmlClass
case '@attributes': case '@attributes':
$tmp = (array) $xml->attributes(); $tmp = (array) $xml->attributes();
$ret['@attributes'] = $tmp['@attributes']; $ret['@attributes'] = $tmp['@attributes'];
if($count_tags == 1) //only attributes & possible value if($count_tags == 1) //only attributes & possible value
{ {
$ret[$this->_optValueKey] = trim((string) $xml); $ret[$this->_optValueKey] = trim((string) $xml);
return $ret; return $ret;
} }
break; break;
case 'comment': case 'comment':
$ret[$this->_optValueKey] = trim((string) $xml); $ret[$this->_optValueKey] = trim((string) $xml);
$ret['comment'] = $xml->comment; $ret['comment'] = $xml->comment;
break; break;
//more cases? //more cases?
default: default:
$count = count($xml->{$tag}); $count = count($xml->{$tag});
@@ -472,7 +473,7 @@ class xmlClass
{ {
$ret[$tag][$i] = $this->xml2array($xml->{$tag}[$i], $tag); $ret[$tag][$i] = $this->xml2array($xml->{$tag}[$i], $tag);
$ret[$tag][$i] = $this->parseStringTags($ret[$tag][$i]); $ret[$tag][$i] = $this->parseStringTags($ret[$tag][$i]);
} }
} }
else //single element else //single element
@@ -486,10 +487,10 @@ class xmlClass
$ret = $this->parseStringTags($ret); $ret = $this->parseStringTags($ret);
return $ret; return $ret;
} }
//parse value only //parse value only
$ret = trim((string) $xml); $ret = trim((string) $xml);
return ($this->_optForceArray ? array($this->_optValueKey => $ret) : $ret); return ($this->_optForceArray ? array($this->_optValueKey => $ret) : $ret);
} }
@@ -536,19 +537,19 @@ class xmlClass
if (count($xml) == 1 && isset($xml[0])) if (count($xml) == 1 && isset($xml[0]))
{ {
$xml = $xml[0]; $xml = $xml[0];
} }
} }
$xml = $this->parseArrayTags($xml); $xml = $this->parseArrayTags($xml);
// $xml = $this->parseStringTags($xml); // $xml = $this->parseStringTags($xml);
return $xml; return $xml;
} }
/** /**
* Convert Array(0) to String based on specified Tags. * Convert Array(0) to String based on specified Tags.
* *
* @param array|string $vars * @param array|string $vars
* @return string * @return string
@@ -559,21 +560,21 @@ class xmlClass
{ {
return $vars; return $vars;
} }
foreach($this->stringTags as $vl) foreach($this->stringTags as $vl)
{ {
if(varset($vars[$vl][0])) if(varset($vars[$vl][0]))
{ {
$vars[$vl] = $vars[$vl][0]; $vars[$vl] = $vars[$vl][0];
} }
} }
return $vars; return $vars;
} }
/** /**
* Return as an array, even when a single xml tag value is found * Return as an array, even when a single xml tag value is found
* Use setArrayTags() to set which tags are affected. * Use setArrayTags() to set which tags are affected.
* *
* @param array $vars * @param array $vars
* @return array * @return array
@@ -589,30 +590,32 @@ class xmlClass
foreach($this->arrayTags as $vl) foreach($this->arrayTags as $vl)
{ {
if(isset($vars[$vl]) && is_array($vars[$vl]) && !varset($vars[$vl][0])) if(isset($vars[$vl]) && is_array($vars[$vl]) && !varset($vars[$vl][0]))
{ {
$vars[$vl] = array($vars[$vl]); $vars[$vl] = array($vars[$vl]);
} }
} }
return $vars; return $vars;
} }
/** /**
* Load XML file and parse it (optional) * Load XML file and parse it (optional)
* *
* @param string $fname local or remote XML source file path * @param string $fname local or remote XML source file path
* @param boolean|string $parse false - no parse; * @param boolean|string $parse false - no parse;
* true - use xml_convert_to_array(); * true - use xml_convert_to_array();
* in any other case - use xml2array() * in any other case - use xml2array()
* *
* @param boolean $replace_constants [optional] * @param boolean $replace_constants [optional]
* @return mixed * @return mixed
*/ */
function loadXMLfile($fname, $parse = false, $replace_constants = false) function loadXMLfile($fname, $parse = false, $replace_constants = false)
{ {
global $tp;
if (empty($fname)) if (empty($fname))
{ {
return false; return false;
@@ -633,7 +636,7 @@ class xmlClass
{ {
if ($replace_constants == true) if ($replace_constants == true)
{ {
$this->xmlFileContents = e107::getParser()->replaceConstants($this->xmlFileContents, '', true); $this->xmlFileContents = $tp->replaceConstants($this->xmlFileContents, '', true);
} }
if ($parse) if ($parse)
{ {
@@ -646,9 +649,9 @@ class xmlClass
} }
return false; return false;
} }
/** /**
* Convert file path for inclusion in XML file. * Convert file path for inclusion in XML file.
* @see e107ExportValue() * @see e107ExportValue()
* @param string $text - callback function * @param string $text - callback function
@@ -659,49 +662,49 @@ class xmlClass
$fullpath = e107::getParser()->replaceConstants($text[1]); $fullpath = e107::getParser()->replaceConstants($text[1]);
$this->fileConvertLog[] = $fullpath; $this->fileConvertLog[] = $fullpath;
$file = basename($fullpath); $file = basename($fullpath);
return $this->filePathDestination.$file; return $this->filePathDestination.$file;
} }
/** /**
* Process data values for XML file. If $this->convertFilePaths is TRUE, convert paths * Process data values for XML file. If $this->convertFilePaths is TRUE, convert paths
* *
* @see replaceFilePaths() * @see replaceFilePaths()
* @param mixed $val * @param mixed $val
* @param string $key key for the current value. Used for exception processing. * @param string $key key for the current value. Used for exception processing.
* @return mixed * @return mixed
*/ */
private function e107ExportValue($val, $key = '') private function e107ExportValue($val, $key = '')
{ {
if($key && isset($this->filePathPrepend[$key])) if($key && isset($this->filePathPrepend[$key]))
{ {
$val = $this->filePathPrepend[$key].$val; $val = $this->filePathPrepend[$key].$val;
} }
if($this->convertFilePaths) if($this->convertFilePaths)
{ {
$types = implode("|",$this->convertFileTypes); $types = implode("|",$this->convertFileTypes);
$val = preg_replace_callback("#({e_.*?\.(".$types."))#i", array($this,'replaceFilePaths'), $val); $val = preg_replace_callback("#({e_.*?\.(".$types."))#i", array($this,'replaceFilePaths'), $val);
} }
if(is_array($val)) if(is_array($val))
{ {
return "<![CDATA[".e107::getArrayStorage()->WriteArray($val,FALSE)."]]>"; return "<![CDATA[".e107::getArrayStorage()->WriteArray($val,FALSE)."]]>";
} }
if((strpos($val,"<")!==FALSE) || (strpos($val,">")!==FALSE) || (strpos($val,"&")!==FALSE)) if((strpos($val,"<")!==FALSE) || (strpos($val,">")!==FALSE) || (strpos($val,"&")!==FALSE))
{ {
return "<![CDATA[". $val."]]>"; return "<![CDATA[". $val."]]>";
} }
return $val; return $val;
} }
/** /**
* Create an e107 Export File in XML format * Create an e107 Export File in XML format
* Note: If $this->filePathDestination has a value, then the file will be saved there. * Note: If $this->filePathDestination has a value, then the file will be saved there.
* *
* @param array $prefs - see e_core_pref $aliases (eg. core, ipool etc) * @param array $prefs - see e_core_pref $aliases (eg. core, ipool etc)
* @param array $tables - table names without the prefix * @param array $tables - table names without the prefix
@@ -711,12 +714,12 @@ class xmlClass
public function e107Export($xmlprefs, $tables, $debug = FALSE) public function e107Export($xmlprefs, $tables, $debug = FALSE)
{ {
require_once(e_ADMIN."ver.php"); require_once(e_ADMIN."ver.php");
$text = "<?xml version='1.0' encoding='utf-8' ?".">\n"; $text = "<?xml version='1.0' encoding='utf-8' ?".">\n";
$text .= "<e107Export version='".$e107info['e107_version']."' timestamp='".time()."' >\n"; $text .= "<e107Export version='".$e107info['e107_version']."' timestamp='".time()."' >\n";
if(varset($xmlprefs)) // Export Core Preferences. if(varset($xmlprefs)) // Export Core Preferences.
{ {
$text .= "\t<prefs>\n"; $text .= "\t<prefs>\n";
foreach($xmlprefs as $type) foreach($xmlprefs as $type)
{ {
@@ -732,7 +735,7 @@ class xmlClass
} }
$text .= "\t</prefs>\n"; $text .= "\t</prefs>\n";
} }
if(varset($tables)) if(varset($tables))
{ {
$text .= "\t<database>\n"; $text .= "\t<database>\n";
@@ -748,23 +751,23 @@ class xmlClass
{ {
$text .= "\t\t\t<field name='".$key."'>".$this->e107ExportValue($val,$key)."</field>\n"; $text .= "\t\t\t<field name='".$key."'>".$this->e107ExportValue($val,$key)."</field>\n";
} }
$text .= "\t\t</item>\n"; $text .= "\t\t</item>\n";
} }
$text .= "\t</dbTable>\n"; $text .= "\t</dbTable>\n";
} }
$text .= "\t</database>\n"; $text .= "\t</database>\n";
} }
$text .= "</e107Export>"; $text .= "</e107Export>";
if($debug==TRUE) if($debug==TRUE)
{ {
echo "<pre>".htmlentities($text)."</pre>"; echo "<pre>".htmlentities($text)."</pre>";
return TRUE; return TRUE;
} }
else else
{ {
@@ -772,24 +775,24 @@ class xmlClass
{ {
return FALSE; return FALSE;
} }
$path = e107::getParser()->replaceConstants($this->filePathDestination); $path = e107::getParser()->replaceConstants($this->filePathDestination);
if($path) if($path)
{ {
file_put_contents($path."install.xml",$text,FILE_TEXT); file_put_contents($path."install.xml",$text,FILE_TEXT);
return true; return true;
} }
header('Content-type: application/xml', TRUE); header('Content-type: application/xml', TRUE);
header("Content-disposition: attachment; filename= e107Export_" . date("Y-m-d").".xml"); header("Content-disposition: attachment; filename= e107Export_" . date("Y-m-d").".xml");
header("Cache-Control: max-age=30"); header("Cache-Control: max-age=30");
header("Pragma: public"); header("Pragma: public");
echo $text; echo $text;
exit; exit;
} }
} }
/** /**
* Return an Array of core preferences from e107 XML Dump data * Return an Array of core preferences from e107 XML Dump data
* *
@@ -802,22 +805,22 @@ class xmlClass
if(!vartrue($XMLData['prefs'][$prefType])) if(!vartrue($XMLData['prefs'][$prefType]))
{ {
return; return;
} }
$mes = eMessage::getInstance(); $mes = eMessage::getInstance();
$pref = array(); $pref = array();
foreach($XMLData['prefs'][$prefType] as $val) foreach($XMLData['prefs'][$prefType] as $val)
{ {
$name = $val['@attributes']['name']; $name = $val['@attributes']['name'];
$value = (substr($val['@value'],0,7) == "array (") ? e107::getArrayStorage()->ReadArray($val['@value']) : $val['@value']; $value = (substr($val['@value'],0,7) == "array (") ? e107::getArrayStorage()->ReadArray($val['@value']) : $val['@value'];
$pref[$name] = $value; $pref[$name] = $value;
// $mes->add("Setting up ".$prefType." Pref [".$name."] => ".$value, E_MESSAGE_DEBUG); // $mes->add("Setting up ".$prefType." Pref [".$name."] => ".$value, E_MESSAGE_DEBUG);
} }
return $pref; return $pref;
} }
/** /**
@@ -826,13 +829,13 @@ class xmlClass
* @param path $file - e107 XML file path * @param path $file - e107 XML file path
* @param string $mode[optional] - add|replace * @param string $mode[optional] - add|replace
* @param boolean $debug [optional] * @param boolean $debug [optional]
* @return array with keys 'success' and 'failed' - DB table entry status. * @return array with keys 'success' and 'failed' - DB table entry status.
*/ */
public function e107Import($file,$mode='replace',$debug=FALSE) public function e107Import($file,$mode='replace',$debug=FALSE)
{ {
$xmlArray = $this->loadXMLfile($file,'advanced'); $xmlArray = $this->loadXMLfile($file,'advanced');
if($debug) if($debug)
{ {
// $message = print_r($xmlArray); // $message = print_r($xmlArray);
@@ -841,8 +844,8 @@ class xmlClass
} }
$ret = array(); $ret = array();
//FIXME - doesn't work from install_.php. //FIXME - doesn't work from install_.php.
if(vartrue($xmlArray['prefs'])) // Save Core Prefs if(vartrue($xmlArray['prefs'])) // Save Core Prefs
{ {
foreach($xmlArray['prefs'] as $type=>$array) foreach($xmlArray['prefs'] as $type=>$array)
@@ -854,22 +857,22 @@ class xmlClass
} }
else else
{ {
e107::getConfig($type)->addPref($pArray); // FIXME addPref() doesn't behave the same way as setPref() with arrays. e107::getConfig($type)->addPref($pArray); // FIXME addPref() doesn't behave the same way as setPref() with arrays.
} }
if($debug == FALSE) if($debug == FALSE)
{ {
e107::getConfig($type)->save(FALSE,TRUE); e107::getConfig($type)->save(FALSE,TRUE);
} }
} }
} }
if(vartrue($xmlArray['database'])) if(vartrue($xmlArray['database']))
{ {
foreach($xmlArray['database']['dbTable'] as $val) foreach($xmlArray['database']['dbTable'] as $val)
{ {
$table = $val['@attributes']['name']; $table = $val['@attributes']['name'];
foreach($val['item'] as $item) foreach($val['item'] as $item)
{ {
$insert_array = array(); $insert_array = array();
@@ -877,46 +880,46 @@ class xmlClass
{ {
$fieldkey = $f['@attributes']['name']; $fieldkey = $f['@attributes']['name'];
$fieldval = (isset($f['@value'])) ? $f['@value'] : ""; $fieldval = (isset($f['@value'])) ? $f['@value'] : "";
$insert_array[$fieldkey] = $fieldval; $insert_array[$fieldkey] = $fieldval;
} }
if(($mode == "replace") && e107::getDB()->db_Replace($table, $insert_array)!==FALSE) if(($mode == "replace") && e107::getDB()->db_Replace($table, $insert_array)!==FALSE)
{ {
$ret['success'][] = $table; $ret['success'][] = $table;
} }
elseif(($mode == "add") && e107::getDB()->db_Insert($table, $insert_array)!==FALSE) elseif(($mode == "add") && e107::getDB()->db_Insert($table, $insert_array)!==FALSE)
{ {
$ret['success'][] = $table; $ret['success'][] = $table;
} }
else else
{ {
$ret['failed'][] = $table; $ret['failed'][] = $table;
} }
} }
} }
} }
return $ret; return $ret;
} }
function getErrors($xml) function getErrors($xml)
{ {
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$sxe = simplexml_load_string($xml); $sxe = simplexml_load_string($xml);
$errors = array(); $errors = array();
if (!$sxe) if (!$sxe)
{ {
foreach(libxml_get_errors() as $error) foreach(libxml_get_errors() as $error)
{ {
$errors[] = $error->message. "Line:".$error->line." Column:".$error->column; $errors[] = $error->message. "Line:".$error->line." Column:".$error->column;
} }
return $errors; return $errors;
} }
return FALSE; return FALSE;
} }
} }