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

some more xml class fixes, added new demo - e107_admin/db.php - Import prefs screen

This commit is contained in:
secretr
2009-08-27 14:34:20 +00:00
parent 33a91058e3
commit 914344eea5
2 changed files with 61 additions and 35 deletions

View File

@@ -9,8 +9,8 @@
* Administration - Database Utilities * Administration - Database Utilities
* *
* $Source: /cvs_backup/e107_0.8/e107_admin/db.php,v $ * $Source: /cvs_backup/e107_0.8/e107_admin/db.php,v $
* $Revision: 1.15 $ * $Revision: 1.16 $
* $Date: 2009-08-27 12:54:48 $ * $Date: 2009-08-27 14:34:19 $
* $Author: secretr $ * $Author: secretr $
* *
*/ */
@@ -275,28 +275,39 @@ function export_core_prefs()
function importCorePrefs() function importCorePrefs()
{ {
//TODO - Cameron - move to own class and make generic. //TODO - Cameron - move to own class and make generic.
//SecretR - structure changes / improvements proposal
$dummyXml = "<?xml version='1.0' encoding='utf-8' ?> $dummyXml = "<?xml version='1.0' encoding='utf-8' ?>
<e107Export version='0.8.0 (cvs)' timestamp='1250896023' > <e107Export version='0.8.0 (cvs)' timestamp='1250896023' >
<prefs> <corePrefs name='core'>
<core name='install_date'>1165362615</core> <pref name='install_date'>1165362615</pref>
<core name='sitename'>e107 Powered Website</core> <pref name='sitename'><![CDATA[e107 Powered Website]]></pref>
<core name='siteurl'>/e107_0.8/</core> <pref name='siteurl'><![CDATA[/e107_0.8/]]></pref>
<core name='sitebutton'>{e_IMAGE}button.png</core> <pref name='sitebutton'>{e_IMAGE}button.png</pref>
<core name='sitetag'>e107 Website System</core> <pref name='sitetag'><![CDATA[e107 Website System]]></pref>
<core name='sitedescription'></core> <pref name='sitedescription'><![CDATA[]]></pref>
<core name='siteadmin'>admin</core> <pref name='siteadmin'>admin</pref>
<core name='siteadminemail'>user@yoursite.com</core> <pref name='siteadminemail'>user@yoursite.com</pref>
</prefs> </corePrefs>
<tag>tag['value']=this value</tag> <corePrefs name='menu'>
<tag2 name='something'>[tag2][@attribute][name]='something' and [tag2][value] = this text</tag2> <pref name='menu_pref1'><![CDATA[1165362615]]></pref>
<myarray> <pref name='menu_pref2'><![CDATA[e107 Powered Website]]></pref>
<item>myarray['item'][0]['value'] equals this</item> </corePrefs>
</myarray> <pluginPrefs name='myplug'>
<otherArray> <pref name='myplug_pref1'><![CDATA[1165362615]]></pref>
<otherItem>otherArray['otherItem'][0]['value'] equals this</otherItem> <pref name='myplug_pref2'><![CDATA[e107 Powered Website]]></pref>
<otherItem>otherArray['otherItem'][1]['value'] equals this</otherItem> </pluginPrefs>
</otherArray> <!-- Parse Tests Start -->
<tag>tag['value']=this value</tag>
<tag2 name='something'>[tag2][@attribute][name]='something' and [tag2][value] = this text</tag2>
<myarray>
<item>myarray['item'][0]['value'] equals this</item>
</myarray>
<otherArray>
<otherItem>otherArray['otherItem'][0]['value'] equals this</otherItem>
<otherItem>otherArray['otherItem'][1]['value'] equals this</otherItem>
</otherArray>
<!-- Parse Tests end -->
</e107Export> </e107Export>
@@ -304,21 +315,32 @@ function importCorePrefs()
echo "<h1>Example XML</h1><pre>".htmlentities($dummyXml)."</pre>"; echo "<h1>Example XML</h1><pre>".htmlentities($dummyXml)."</pre>";
//$data = $dummyXml;
$data = $dummyXml; echo '<h2>New Core parsing method - default options</h2><hr />';
//NOTE - there is nothing wrong if we call e107::getObject (new instance)
$xml = e107::getSingleton('xmlClass')->parseXml($dummyXml, false); //new instance
print_a($xml);
echo '<h2>New Core parsing method - new options example</h2><hr />';
echo 'Option _optAddRoot: true<br />Option _optValueKey: &quot;myVal&quot;<br />Option _optForceArray: true<br />';
e107::getSingleton('xmlClass')->setOptForceArray(true) //force array variable type for simple tags of first level
->setOptValueKey('myVal') //the default is value
->setOptAddRoot(true); //include root element in the returned array
$xml = e107::getSingleton('xmlClass')->parseXml($dummyXml, false); //new instance
print_a($xml);
// $xml = e107::getSingleton('xmlClass')->loadXMLfile($_FILES['file_userfile']['tmp_name'][0],TRUE); // $xml = e107::getSingleton('xmlClass')->loadXMLfile($_FILES['file_userfile']['tmp_name'][0],TRUE);
$xml = e107::getSingleton('xmlClass')->parseXml($dummyXml); $xml = e107::getSingleton('xmlClass')->parseXml($dummyXml);
echo "<h1>Core XML Class</h1><hr />"; echo "<h2>Old Core XML Class</h2><hr />";
print_a($xml); print_a($xml);
// $data = e107::getSingleton('xmlClass')->xmlFileContents; // $data = e107::getSingleton('xmlClass')->xmlFileContents;
echo '<h1>3rd Party Class</h1><hr />'; //echo '<h1>3rd Party Class</h1><hr />';
$array_3rd = e107::getSingleton('xmlClass')->xml2ary($data); //$array_3rd = e107::getSingleton('xmlClass')->xml2ary($data);
print_a($array_3rd);
//print_a($array_3rd);
foreach ($xll->corePref as $key=>$val) foreach ($xll->corePref as $key=>$val)
{ {

View File

@@ -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.14 $ * $Revision: 1.15 $
* $Date: 2009-08-27 13:58:28 $ * $Date: 2009-08-27 14:34:20 $
* $Author: secretr $ * $Author: secretr $
*/ */
@@ -305,7 +305,11 @@ class xmlClass
*/ */
function parseXml($xml = '', $simple = true) function parseXml($xml = '', $simple = true)
{ {
if ($xml == '' && $this->xmlFileContents) if ($xml)
{
$this->xmlFileContents = $xml;
}
elseif ($this->xmlFileContents)
{ {
$xml = $this->xmlFileContents; $xml = $this->xmlFileContents;
} }
@@ -315,10 +319,6 @@ class xmlClass
} }
$xml = simplexml_load_string($xml); $xml = simplexml_load_string($xml);
if (is_object($xml))
{
$xml = (array) $xml;
}
$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;
} }
@@ -428,6 +428,10 @@ class xmlClass
function xml_convert_to_array($xml, $localFilter = FALSE, $stripComments = TRUE) function xml_convert_to_array($xml, $localFilter = FALSE, $stripComments = TRUE)
{ {
if (is_object($xml))
{
$xml = (array) $xml;
}
if (is_array($xml)) if (is_array($xml))
{ {
foreach ($xml as $k=>$v) foreach ($xml as $k=>$v)