mirror of
https://github.com/e107inc/e107.git
synced 2025-07-15 03:56:20 +02:00
plugin xml array-parsing fixes
This commit is contained in:
@ -11,9 +11,9 @@
|
|||||||
| GNU General Public License (http://gnu.org).
|
| GNU General Public License (http://gnu.org).
|
||||||
|
|
|
|
||||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $
|
||||||
| $Revision: 1.85 $
|
| $Revision: 1.86 $
|
||||||
| $Date: 2009-09-15 16:10:32 $
|
| $Date: 2009-09-16 13:01:17 $
|
||||||
| $Author: secretr $
|
| $Author: e107coders $
|
||||||
+----------------------------------------------------------------------------+
|
+----------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -1779,7 +1779,9 @@ class e107plugin
|
|||||||
// loadLanFiles($plugName, 'admin'); // Look for LAN files on default paths
|
// loadLanFiles($plugName, 'admin'); // Look for LAN files on default paths
|
||||||
require_once(e_HANDLER.'xml_class.php');
|
require_once(e_HANDLER.'xml_class.php');
|
||||||
$xml = new xmlClass;
|
$xml = new xmlClass;
|
||||||
|
$xml->setOptArrayTags('extendedField,userclass,menuLink'); // always arrays for these tags.
|
||||||
$this->plug_vars = $xml->loadXMLfile(e_PLUGIN.$plugName.'/plugin.xml', true, true);
|
$this->plug_vars = $xml->loadXMLfile(e_PLUGIN.$plugName.'/plugin.xml', true, true);
|
||||||
|
|
||||||
if ($this->plug_vars === FALSE)
|
if ($this->plug_vars === FALSE)
|
||||||
{
|
{
|
||||||
require_once(e_HANDLER."message_handler.php");
|
require_once(e_HANDLER."message_handler.php");
|
||||||
@ -1789,29 +1791,11 @@ class e107plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->plug_vars['category'] = $this->manage_category($this->plug_vars['category']);
|
$this->plug_vars['category'] = $this->manage_category($this->plug_vars['category']);
|
||||||
$this->plug_vars = $this->cleanXML($this->plug_vars);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return as an array, even when a single xml tag value is found
|
|
||||||
* @param object $vars
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function cleanXml($vars)
|
|
||||||
{
|
|
||||||
$array_tags = array("extendedField","userclass","menuLink");
|
|
||||||
foreach($array_tags as $vl)
|
|
||||||
{
|
|
||||||
if(is_array($vars[$vl]) && !varset($vars[$vl][0]))
|
|
||||||
{
|
|
||||||
$vars[$vl] = array($vars[$vl]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $vars;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
* 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.24 $
|
* $Revision: 1.25 $
|
||||||
* $Date: 2009-09-10 09:49:01 $
|
* $Date: 2009-09-16 13:01:19 $
|
||||||
* $Author: e107coders $
|
* $Author: e107coders $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -82,6 +82,7 @@ class xmlClass
|
|||||||
|
|
||||||
public $filePathConvKeys = array();
|
public $filePathConvKeys = array();
|
||||||
|
|
||||||
|
private $arrayTags = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add root element to the result array
|
* Add root element to the result array
|
||||||
@ -189,6 +190,17 @@ class xmlClass
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Xml tags that should always return arrays.
|
||||||
|
* @param object $array
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function setOptArrayTags($string)
|
||||||
|
{
|
||||||
|
$this->arrayTags = (array) explode(",",$string);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set forceArray option
|
* Set forceArray option
|
||||||
*
|
*
|
||||||
@ -403,6 +415,8 @@ class xmlClass
|
|||||||
$ret[$tag] = $this->xml2array($xml->{$tag}, $tag);
|
$ret[$tag] = $this->xml2array($xml->{$tag}, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ret = $this->parseArrayTags($ret);
|
||||||
|
|
||||||
return ($this->_optAddRoot ? array($xml->getName() => $ret) : $ret);
|
return ($this->_optAddRoot ? array($xml->getName() => $ret) : $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,11 +464,13 @@ class xmlClass
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,9 +519,46 @@ class xmlClass
|
|||||||
$xml = $xml[0];
|
$xml = $xml[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$xml = $this->parseArrayTags($xml);
|
||||||
|
|
||||||
return $xml;
|
return $xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return as an array, even when a single xml tag value is found
|
||||||
|
* Use setArrayTags() to set which tags are affected.
|
||||||
|
* @param object $vars
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function parseArrayTags($vars)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!$this->arrayTags)
|
||||||
|
{
|
||||||
|
return $vars;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $array_tags = array("extendedField","userclass","menuLink");
|
||||||
|
foreach($this->arrayTags as $vl)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(is_array($vars[$vl]) && !varset($vars[$vl][0]))
|
||||||
|
{
|
||||||
|
|
||||||
|
$vars[$vl] = array($vars[$vl]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $vars;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load XML file and parse it (optional)
|
* Load XML file and parse it (optional)
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user