1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-28 10:20:45 +02:00

3rd party functions added for comparison test

This commit is contained in:
CaMer0n
2009-08-24 00:58:32 +00:00
parent 9863e49cdb
commit e600b3c0db
2 changed files with 254 additions and 102 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.12 $ * $Revision: 1.13 $
* $Date: 2009-08-22 00:28:54 $ * $Date: 2009-08-24 00:58:32 $
* $Author: e107coders $ * $Author: e107coders $
* *
*/ */
@@ -285,12 +285,42 @@ 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.
$xml = e107::getSingleton('xmlClass')->loadXMLfile($_FILES['file_userfile']['tmp_name'][0],TRUE);
$data = e107::getSingleton('xmlClass')->xmlFileContents; $dummyXml = "<?xml version='1.0' encoding='utf-8' ?>
$xll = new SimpleXMLElement($data); <e107Export version='0.8.0 (cvs)' timestamp='1250896023' >
<prefs>
<core name='install_date'>1165362615</core>
<core name='sitename'>e107 Powered Website</core>
<core name='siteurl'>/e107_0.8/</core>
<core name='sitebutton'>{e_IMAGE}button.png</core>
<core name='sitetag'>e107 Website System</core>
<core name='sitedescription'></core>
<core name='siteadmin'>admin</core>
<core name='siteadminemail'>user@yoursite.com</core>
</prefs>
</e107Export>
";
echo "<h1>Example XML</h1><pre>".htmlentities($dummyXml)."</pre>";
$data = $dummyXml;
// $xml = e107::getSingleton('xmlClass')->loadXMLfile($_FILES['file_userfile']['tmp_name'][0],TRUE);
$xml = e107::getSingleton('xmlClass')->parseXml($dummyXml);
echo "<h1>Core XML Class</h1><hr />";
print_a($xml);
// $data = e107::getSingleton('xmlClass')->xmlFileContents;
echo '<h1>3rd Party Class</h1><hr />';
$array_3rd = e107::getSingleton('xmlClass')->xml2ary($data);
print_a($array_3rd);
print_a($xll);
foreach ($xll->corePref as $key=>$val) foreach ($xll->corePref as $key=>$val)
{ {
// echo "<br />". $xll->corePref['@attributes'] ." = ".$val; // echo "<br />". $xll->corePref['@attributes'] ." = ".$val;
@@ -312,6 +342,10 @@ function importCorePrefs()
function importCorePrefsForm() function importCorePrefsForm()
{ {
//TODO - Fix Core XML class - array returned is incorrect.
importCorePrefs();
return;
// Get largest allowable file upload // Get largest allowable file upload
$frm = e107::getSingleton('e_form'); $frm = e107::getSingleton('e_form');

View File

@@ -3,7 +3,7 @@
+ ----------------------------------------------------------------------------+ + ----------------------------------------------------------------------------+
| e107 website system | e107 website system
| |
| <20>Steve Dunstan 2001-2002 | <20>Steve Dunstan 2001-2002
| http://e107.org | http://e107.org
| jalist@e107.org | jalist@e107.org
| |
@@ -11,15 +11,18 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $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.12 $ | $Revision: 1.13 $
| $Date: 2009-08-17 12:48:52 $ | $Date: 2009-08-24 00:58:01 $
| $Author: e107coders $ | $Author: e107coders $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
class xmlClass class xmlClass
{ {
var $xmlFileContents; var $xmlFileContents;
var $filter; // Optional filter for loaded XML var $filter; // Optional filter for loaded XML
// Set to FALSE if not enabled (default on initialisation) // Set to FALSE if not enabled (default on initialisation)
// Otherwise mirrors the required subset of the loaded XML - set a field FALSE to accept all // Otherwise mirrors the required subset of the loaded XML - set a field FALSE to accept all
@@ -29,10 +32,11 @@ class xmlClass
// 'administration' => FALSE, // 'administration' => FALSE,
// 'management' => array('install' => FALSE) // 'management' => array('install' => FALSE)
// ); // );
var $stripComments; // Set true to strip all mention of comments from the returned array (default); FALSE to return comment markers var $stripComments; // Set true to strip all mention of comments from the returned array (default); FALSE to return comment markers
// Constructor - set defaults // Constructor - set defaults
function xmlClass() function xmlClass()
{ {
$this->xmlFileContents = ''; $this->xmlFileContents = '';
@@ -40,29 +44,29 @@ class xmlClass
$this->stripComments = TRUE; // Don't usually want comments back $this->stripComments = TRUE; // Don't usually want comments back
} }
function getRemoteFile($address, $timeout = 10) function getRemoteFile($address, $timeout = 10)
{ {
// Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here // Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here
$timeout = min($timeout, 120); $timeout = min($timeout, 120);
$timeout = max($timeout, 3); $timeout = max($timeout, 3);
$address = str_replace(array("\r", "\n", "\t"), '', $address); // May be paranoia, but streaky thought it might be a good idea $address = str_replace(array("\r", "\n", "\t"), '', $address); // May be paranoia, but streaky thought it might be a good idea
// ... and there shouldn't be unprintable characters in the URL anyway // ... and there shouldn't be unprintable characters in the URL anyway
if (function_exists('file_get_contents')) if (function_exists('file_get_contents'))
{ {
$old_timeout = e107_ini_set('default_socket_timeout', $timeout); $old_timeout = e107_ini_set('default_socket_timeout', $timeout);
$data = file_get_contents(urlencode($address)); $data = file_get_contents(urlencode($address));
echo "data=".$data;
// $data = file_get_contents(htmlspecialchars($address)); // buggy - sometimes fails. // $data = file_get_contents(htmlspecialchars($address)); // buggy - sometimes fails.
if ($old_timeout !== FALSE) { e107_ini_set('default_socket_timeout', $old_timeout); } if ($old_timeout !== FALSE)
{
e107_ini_set('default_socket_timeout', $old_timeout);
}
if ($data) if ($data)
{ {
return $data; return $data;
} }
} }
if (function_exists("curl_init")) if (function_exists("curl_init"))
{ {
$cu = curl_init(); $cu = curl_init();
@@ -79,7 +83,6 @@ class xmlClass
curl_close($cu); curl_close($cu);
return $this->xmlFileContents; return $this->xmlFileContents;
} }
if (ini_get("allow_url_fopen")) if (ini_get("allow_url_fopen"))
{ {
$old_timeout = e107_ini_set('default_socket_timeout', $timeout); $old_timeout = e107_ini_set('default_socket_timeout', $timeout);
@@ -105,7 +108,6 @@ class xmlClass
fputs($remote, "GET ".urlencode($address)." HTTP/1.0\r\n\r\n"); fputs($remote, "GET ".urlencode($address)." HTTP/1.0\r\n\r\n");
} }
} }
$this->xmlFileContents = ""; $this->xmlFileContents = "";
while (!feof($remote)) while (!feof($remote))
{ {
@@ -114,13 +116,15 @@ class xmlClass
fclose($remote); fclose($remote);
if ($old_timeout != $timeout) if ($old_timeout != $timeout)
{ {
if ($old_timeout !== FALSE) { e107_ini_set('default_socket_timeout', $old_timeout); } if ($old_timeout !== FALSE)
{
e107_ini_set('default_socket_timeout', $old_timeout);
}
} }
return $this->xmlFileContents; return $this->xmlFileContents;
} }
function parseXml($xml = '') function parseXml($xml = '')
{ {
if ($xml == '' && $this->xmlFileContents) if ($xml == '' && $this->xmlFileContents)
@@ -131,7 +135,6 @@ class xmlClass
{ {
return false; return false;
} }
$xml = simplexml_load_string($xml); $xml = simplexml_load_string($xml);
if (is_object($xml)) if (is_object($xml))
{ {
@@ -141,6 +144,7 @@ class xmlClass
return $xml; return $xml;
} }
function xml_convert_to_array($xml, $localFilter = FALSE, $stripComments = TRUE) function xml_convert_to_array($xml, $localFilter = FALSE, $stripComments = TRUE)
{ {
if (is_array($xml)) if (is_array($xml))
@@ -185,7 +189,6 @@ class xmlClass
} }
function loadXMLfile($fname = '', $parse = false, $replace_constants = false) function loadXMLfile($fname = '', $parse = false, $replace_constants = false)
{ {
if ($fname == '') if ($fname == '')
@@ -193,7 +196,6 @@ class xmlClass
return false; return false;
} }
$xml = false; $xml = false;
if (strpos($fname, '://') !== false) if (strpos($fname, '://') !== false)
{ {
$this->getRemoteFile($fname); $this->getRemoteFile($fname);
@@ -230,5 +232,121 @@ class xmlClass
} }
function xml2ary(&$string)
{
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($parser, $string, $vals, $index);
xml_parser_free($parser);
$mnary = array();
$ary = &$mnary;
foreach ($vals as $r)
{
$t = $r['tag'];
if ($r['type'] == 'open')
{
if (isset($ary[$t]))
{
if (isset($ary[$t][0]))
$ary[$t][] = array();
else
$ary[$t] = array($ary[$t], array());
$cv = &$ary[$t][count($ary[$t]) - 1];
} }
else
$cv = &$ary[$t];
if (isset($r['attributes']))
{
foreach ($r['attributes'] as $k=>$v)
$cv['_a'][$k] = $v;
}
$cv['_c'] = array();
$cv['_c']['_p'] = &$ary;
$ary = &$cv['_c'];
}
elseif ($r['type'] == 'complete')
{
if (isset($ary[$t]))
{ // same as open
if (isset($ary[$t][0]))
$ary[$t][] = array();
else
$ary[$t] = array($ary[$t], array());
$cv = &$ary[$t][count($ary[$t]) - 1];
}
else
$cv = &$ary[$t];
if (isset($r['attributes']))
{
foreach ($r['attributes'] as $k=>$v)
$cv['_a'][$k] = $v;
}
$cv['_v'] = (isset($r['value']) ? $r['value'] : '');
}
elseif ($r['type'] == 'close')
{
$ary = &$ary['_p'];
}
}
$this->_del_p($mnary);
return $mnary;
}
function _del_p(&$ary)
{
foreach ($ary as $k=>$v)
{
if ($k === '_p')
unset($ary[$k]);
elseif (is_array($ary[$k]))
$this->_del_p($ary[$k]);
}
}
// Array to XML
function ary2xml($cary, $d = 0, $forcetag = '')
{
$res = array();
foreach ($cary as $tag=>$r)
{
if (isset($r[0]))
{
$res[] = $this->ary2xml($r, $d, $tag);
}
else
{
if ($forcetag)
$tag = $forcetag;
$sp = str_repeat("\t", $d);
$res[] = "$sp<$tag";
if (isset($r['_a']))
{
foreach ($r['_a'] as $at=>$av)
$res[] = " $at=\"$av\"";
}
$res[] = ">".((isset($r['_c'])) ? "\n" : '');
if (isset($r['_c']))
$res[] = $this->ary2xml($r['_c'], $d + 1);
elseif (isset($r['_v']))
$res[] = $r['_v'];
$res[] = (isset($r['_c']) ? $sp : '')."</$tag>\n";
}
}
return implode('', $res);
}
// Insert element into array
function ins2ary(&$ary, $element, $pos)
{
$ar1 = array_slice($ary, 0, $pos);
$ar1[] = $element;
$ary = array_merge($ar1, array_slice($ary, $pos));
}
}
?> ?>