mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 20:00:37 +02:00
Working on the xml class so we are using simplexml when available. Also have a php4 compatible function
This commit is contained in:
@@ -42,5 +42,90 @@ if (!function_exists('stripos'))
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('simplexml_load_string'))
|
||||
{
|
||||
|
||||
?>
|
||||
//CXml class code found on php.net
|
||||
class CXml
|
||||
{
|
||||
var $xml_data;
|
||||
var $obj_data;
|
||||
var $pointer;
|
||||
|
||||
function CXml() { }
|
||||
|
||||
function Set_xml_data( &$xml_data )
|
||||
{
|
||||
$this->index = 0;
|
||||
$this->pointer[] = &$this->obj_data;
|
||||
|
||||
//strip white space between tags
|
||||
$this->xml_data = preg_replace("/>[[:space:]]+</i", "><", $xml_data);
|
||||
$this->xml_parser = xml_parser_create( "UTF-8" );
|
||||
|
||||
xml_parser_set_option( $this->xml_parser, XML_OPTION_CASE_FOLDING, false );
|
||||
xml_set_object( $this->xml_parser, $this );
|
||||
xml_set_element_handler( $this->xml_parser, "_startElement", "_endElement");
|
||||
xml_set_character_data_handler( $this->xml_parser, "_cData" );
|
||||
|
||||
xml_parse( $this->xml_parser, $this->xml_data, true );
|
||||
xml_parser_free( $this->xml_parser );
|
||||
}
|
||||
|
||||
function _startElement( $parser, $tag, $attributeList )
|
||||
{
|
||||
$attributes = '@attributes';
|
||||
foreach( $attributeList as $name => $value )
|
||||
{
|
||||
$value = $this->_cleanString( $value );
|
||||
$object->{$attributes}[$name] = $value;
|
||||
// $object->$name = $value;
|
||||
}
|
||||
//replaces the special characters with the underscore (_) in tag name
|
||||
$tag = preg_replace("/[:\-\. ]/", "_", $tag);
|
||||
eval( "\$this->pointer[\$this->index]->" . $tag . "[] = \$object;" );
|
||||
eval( "\$size = sizeof( \$this->pointer[\$this->index]->" . $tag . " );" );
|
||||
eval( "\$this->pointer[] = &\$this->pointer[\$this->index]->" . $tag . "[\$size-1];" );
|
||||
|
||||
$this->index++;
|
||||
}
|
||||
|
||||
function _endElement( $parser, $tag )
|
||||
{
|
||||
array_pop( $this->pointer );
|
||||
$this->index--;
|
||||
}
|
||||
|
||||
function _cData( $parser, $data )
|
||||
{
|
||||
if (empty($this->pointer[$this->index]))
|
||||
{
|
||||
if (rtrim($data, "\n"))
|
||||
{
|
||||
$this->pointer[$this->index] = $data;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->pointer[$this->index] .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
function _cleanString( $string )
|
||||
{
|
||||
return utf8_decode( trim( $string ) );
|
||||
}
|
||||
}
|
||||
|
||||
function simplexml_load_string($xml)
|
||||
{
|
||||
$xmlClass = new CXml;
|
||||
$xmlClass->Set_xml_data($xml);
|
||||
$data = (array)$xmlClass->obj_data;
|
||||
$tmp = array_keys($data);
|
||||
$data = $data[$tmp[0]][0];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -11,9 +11,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/user_extended_class.php,v $
|
||||
| $Revision: 1.9 $
|
||||
| $Date: 2008-01-15 21:57:38 $
|
||||
| $Author: e107steved $
|
||||
| $Revision: 1.10 $
|
||||
| $Date: 2008-01-20 04:46:35 $
|
||||
| $Author: mcfly_e107 $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -469,40 +469,39 @@ class e107_user_extended
|
||||
}
|
||||
|
||||
require_once(e_HANDLER."xml_class.php");
|
||||
$xml = new CXml;
|
||||
if("getfile" == $contents)
|
||||
{
|
||||
$contents = file_get_contents(e_FILE."cache/user_extended.xml");
|
||||
}
|
||||
$xml->Set_XML_data($contents);
|
||||
$data = $xml->obj_data->e107_extended_user_fields[0];
|
||||
$ret['version'] = $data->version;
|
||||
$xml = new xmlClass;
|
||||
$data = $xml->loadXMLfile(e_FILE."cache/user_extended.xml", true);
|
||||
$ret['version'] = $data['@attributes']['version'];
|
||||
unset($info);
|
||||
foreach($data->item as $item)
|
||||
foreach($data['item'] as $item)
|
||||
{
|
||||
if(is_array($item['include_text']) && !count($item['include_text']))
|
||||
{
|
||||
$item['include_text'] = '';
|
||||
}
|
||||
$info = array(
|
||||
"name" => $item->name,
|
||||
"text" => "UE_LAN_".strtoupper($item->name),
|
||||
"type" => $item->type[0],
|
||||
"values" => $item->values[0],
|
||||
"default" => $item->default[0],
|
||||
"required" => $item->required[0],
|
||||
"read" => $item->read[0],
|
||||
"write" => $item->write[0],
|
||||
"applicable" => $item->applicable[0],
|
||||
"include_text" => $item->include_text[0],
|
||||
"parms" => $item->include_text[0],
|
||||
"regex" => $item->regex[0]
|
||||
"name" => $item['@attributes']['name'],
|
||||
"text" => "UE_LAN_".strtoupper($item['@attributes']['name']),
|
||||
"type" => $item['type'],
|
||||
"values" => $item['values'],
|
||||
"default" => $item['default'],
|
||||
"required" => $item['required'],
|
||||
"read" => $item['read'],
|
||||
"write" => $item['write'],
|
||||
"applicable" => $item['applicable'],
|
||||
"include_text" => $item['include_text'],
|
||||
"parms" => $item['include_text'],
|
||||
"regex" => $item['regex']
|
||||
);
|
||||
if(is_array($item->default) && $item->default[0] == '')
|
||||
if(is_array($item['default']) && $item['default'] == '')
|
||||
{
|
||||
$info['default'] = 0;
|
||||
}
|
||||
if($item->regex[0])
|
||||
if($item['regex'])
|
||||
{
|
||||
$info['parms'] .= $item->include_text[0]."^,^".$item->regex[0]."^,^LAN_UE_FAIL_".strtoupper($item->name);
|
||||
$info['parms'] .= $item['include_text']."^,^".$item['regex']."^,^LAN_UE_FAIL_".strtoupper($item['@attributes']['name']);
|
||||
}
|
||||
$ret[$item->name] = $info;
|
||||
$ret[$item['@attributes']['name']] = $info;
|
||||
}
|
||||
$this->extended_xml = $ret;
|
||||
return $this->extended_xml;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?
|
||||
/*
|
||||
+ ----------------------------------------------------------------------------+
|
||||
| e107 website system
|
||||
@@ -11,28 +11,26 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/xml_class.php,v $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2007-01-24 21:21:11 $
|
||||
| $Author: e107steved $
|
||||
| $Revision: 1.3 $
|
||||
| $Date: 2008-01-20 04:46:35 $
|
||||
| $Author: mcfly_e107 $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
if (!defined('e107_INIT')) { exit; }
|
||||
|
||||
class parseXml {
|
||||
|
||||
var $parser;
|
||||
var $error;
|
||||
var $current_tag;
|
||||
var $start_tag;
|
||||
var $xmlData = array();
|
||||
var $counterArray = array();
|
||||
var $data;
|
||||
class xmlClass
|
||||
{
|
||||
var $xmlFileContents;
|
||||
|
||||
|
||||
function getRemoteXmlFile($address)
|
||||
function getRemoteFile($address)
|
||||
{
|
||||
if(function_exists('file_get_contents'))
|
||||
{
|
||||
if($data = file_get_contents($address))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
if(function_exists("curl_init"))
|
||||
{
|
||||
$cu = curl_init ();
|
||||
@@ -40,14 +38,14 @@ class parseXml {
|
||||
curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt ($cu, CURLOPT_HEADER, 0);
|
||||
curl_setopt ($cu, CURLOPT_TIMEOUT, 10);
|
||||
$this -> xmlFileContents = curl_exec($cu);
|
||||
$this->xmlFileContents = curl_exec($cu);
|
||||
if (curl_error($cu))
|
||||
{
|
||||
$this -> error = "Error: ".curl_errno($cu).", ".curl_error($cu);
|
||||
return FALSE;
|
||||
}
|
||||
curl_close ($cu);
|
||||
return $this -> xmlFileContents;
|
||||
return $this->xmlFileContents;
|
||||
}
|
||||
|
||||
if(ini_get("allow_url_fopen"))
|
||||
@@ -76,163 +74,85 @@ class parseXml {
|
||||
$this -> xmlFileContents = "";
|
||||
while (!feof($remote))
|
||||
{
|
||||
$this -> xmlFileContents .= fgets ($remote, 4096);
|
||||
$this->xmlFileContents .= fgets ($remote, 4096);
|
||||
}
|
||||
fclose ($remote);
|
||||
return $this -> xmlFileContents;
|
||||
return $this->xmlFileContents;
|
||||
}
|
||||
|
||||
|
||||
function parseXmlContents ()
|
||||
function parseXml($xml='')
|
||||
{
|
||||
foreach($this -> xmlData as $key => $value)
|
||||
if($xml == '' && $this->xmlFileContents)
|
||||
{
|
||||
unset($this -> xmlData[$key]);
|
||||
$xml = $this->xmlFileContents;
|
||||
}
|
||||
foreach($this -> counterArray as $key => $value)
|
||||
if(!$xml)
|
||||
{
|
||||
unset($this -> counterArray[$key]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!function_exists('xml_parser_create'))
|
||||
$xml = simplexml_load_string($xml);
|
||||
if(is_object($xml))
|
||||
{
|
||||
$this->error = "XML library not available.";
|
||||
return FALSE;
|
||||
$xml = (array)$xml;
|
||||
}
|
||||
$xml = $this->xml_convert_to_array($xml);
|
||||
return $xml;
|
||||
}
|
||||
|
||||
if(!$this -> xmlFileContents)
|
||||
function xml_convert_to_array($xml)
|
||||
{
|
||||
$this->error = "No XML source specified";
|
||||
return FALSE;
|
||||
if(is_array($xml))
|
||||
{
|
||||
foreach($xml as $k => $v)
|
||||
{
|
||||
if(is_object($v))
|
||||
{
|
||||
$v = (array)$v;
|
||||
}
|
||||
$xml[$k] = $this->xml_convert_to_array($v);
|
||||
}
|
||||
if(count($xml) == 1 && isset($xml[0]))
|
||||
{
|
||||
$xml = $xml[0];
|
||||
}
|
||||
}
|
||||
return $xml;
|
||||
}
|
||||
|
||||
$this->parser = xml_parser_create('');
|
||||
xml_set_object($this->parser, $this);
|
||||
xml_set_element_handler($this->parser, 'startElement', 'endElement');
|
||||
xml_set_character_data_handler( $this->parser, 'characterData' );
|
||||
|
||||
$array = explode("\n", $this -> xmlFileContents);
|
||||
|
||||
foreach($array as $data)
|
||||
function loadXMLfile($fname='', $parse = false)
|
||||
{
|
||||
|
||||
if(strlen($data == 4096))
|
||||
if($fname == '')
|
||||
{
|
||||
$this -> error = "The XML cannot be parsed as it is badly formed.";
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
$xml = false;
|
||||
|
||||
if (!xml_parse($this->parser, $data))
|
||||
if(strpos($filename, '://') !== false)
|
||||
{
|
||||
$this->error = sprintf('XML error: %s at line %d, column %d', xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser),xml_get_current_column_number($this->parser));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
xml_parser_free( $this->parser );
|
||||
return $this -> xmlData;
|
||||
}
|
||||
|
||||
function startElement ($p, $element, &$attrs)
|
||||
{
|
||||
$this -> start_tag = $element;
|
||||
$this -> current_tag = strtolower($element);
|
||||
if(!array_key_exists($this -> current_tag, $this -> counterArray))
|
||||
{
|
||||
$this -> counterArray[$this -> current_tag] = 0;
|
||||
$this -> xmlData[$this -> current_tag][$this -> counterArray[$this -> current_tag]] = "";
|
||||
}
|
||||
}
|
||||
|
||||
function endElement ($p, $element)
|
||||
{
|
||||
if($this -> start_tag == $element)
|
||||
{
|
||||
$this -> counterArray[$this -> current_tag] ++;
|
||||
}
|
||||
}
|
||||
|
||||
function characterData ($p, $data)
|
||||
{
|
||||
$data = trim ( chop ( $data ));
|
||||
$data = preg_replace('/&(?!amp;)/', '&', $data);
|
||||
if(!array_key_exists($this -> current_tag, $this -> xmlData))
|
||||
{
|
||||
$this -> xmlData [$this -> current_tag] = array();
|
||||
}
|
||||
if(array_key_exists($this -> counterArray[$this -> current_tag], $this -> xmlData [$this -> current_tag]))
|
||||
{
|
||||
$this -> xmlData [$this -> current_tag] [$this -> counterArray[$this -> current_tag]] .= $data;
|
||||
$this->getRemoteFile($fname);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this -> xmlData [$this -> current_tag] [$this -> counterArray[$this -> current_tag]] = $data;
|
||||
if($xml = file_get_contents($fname))
|
||||
{
|
||||
$this->xmlFileContents = $xml;
|
||||
}
|
||||
}
|
||||
if($this->xmlFileContents)
|
||||
{
|
||||
if($parse == true)
|
||||
{
|
||||
return $this->parseXML();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->xmlFileContents;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//CXml class code found on php.net
|
||||
class CXml
|
||||
{
|
||||
var $xml_data;
|
||||
var $obj_data;
|
||||
var $pointer;
|
||||
|
||||
function CXml() { }
|
||||
|
||||
function Set_xml_data( &$xml_data )
|
||||
{
|
||||
$this->index = 0;
|
||||
$this->pointer[] = &$this->obj_data;
|
||||
|
||||
//strip white space between tags
|
||||
$this->xml_data = preg_replace("/>[[:space:]]+</i", "><", $xml_data);
|
||||
$this->xml_parser = xml_parser_create( "UTF-8" );
|
||||
|
||||
xml_parser_set_option( $this->xml_parser, XML_OPTION_CASE_FOLDING, false );
|
||||
xml_set_object( $this->xml_parser, $this );
|
||||
xml_set_element_handler( $this->xml_parser, "_startElement", "_endElement");
|
||||
xml_set_character_data_handler( $this->xml_parser, "_cData" );
|
||||
|
||||
xml_parse( $this->xml_parser, $this->xml_data, true );
|
||||
xml_parser_free( $this->xml_parser );
|
||||
}
|
||||
|
||||
function _startElement( $parser, $tag, $attributeList )
|
||||
{
|
||||
foreach( $attributeList as $name => $value )
|
||||
{
|
||||
$value = $this->_cleanString( $value );
|
||||
$object->$name = $value;
|
||||
}
|
||||
//replaces the special characters with the underscore (_) in tag name
|
||||
$tag = preg_replace("/[:\-\. ]/", "_", $tag);
|
||||
eval( "\$this->pointer[\$this->index]->" . $tag . "[] = \$object;" );
|
||||
eval( "\$size = sizeof( \$this->pointer[\$this->index]->" . $tag . " );" );
|
||||
eval( "\$this->pointer[] = &\$this->pointer[\$this->index]->" . $tag . "[\$size-1];" );
|
||||
|
||||
$this->index++;
|
||||
}
|
||||
|
||||
function _endElement( $parser, $tag )
|
||||
{
|
||||
array_pop( $this->pointer );
|
||||
$this->index--;
|
||||
}
|
||||
|
||||
function _cData( $parser, $data )
|
||||
{
|
||||
if (empty($this->pointer[$this->index])) {
|
||||
if (rtrim($data, "\n"))
|
||||
$this->pointer[$this->index] = $data;
|
||||
} else {
|
||||
$this->pointer[$this->index] .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
function _cleanString( $string )
|
||||
{
|
||||
return utf8_decode( trim( $string ) );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -11,9 +11,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_plugins/newsfeed/newsfeed_functions.php,v $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2007-02-07 23:28:17 $
|
||||
| $Author: e107coders $
|
||||
| $Revision: 1.3 $
|
||||
| $Date: 2008-01-20 04:46:35 $
|
||||
| $Author: mcfly_e107 $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,7 @@ if(!function_exists("checkUpdate"))
|
||||
{
|
||||
global $sql, $tp;
|
||||
require_once(e_HANDLER."xml_class.php");
|
||||
$xml = new parseXml;
|
||||
$xml = new xmlClass;
|
||||
require_once(e_HANDLER."magpie_rss.php");
|
||||
|
||||
if ($sql -> db_Select("newsfeed", "*", $tp -> toDB($query, true)))
|
||||
@@ -36,7 +36,7 @@ if(!function_exists("checkUpdate"))
|
||||
extract ($feed);
|
||||
if($newsfeed_timestamp + $newsfeed_updateint < time())
|
||||
{
|
||||
if($rawData = $xml -> getRemoteXmlFile($newsfeed_url))
|
||||
if($rawData = $xml->getRemoteFile($newsfeed_url))
|
||||
{
|
||||
$rss = new MagpieRSS( $rawData );
|
||||
$serializedArray = addslashes(serialize($rss));
|
||||
|
10
signup.php
10
signup.php
@@ -11,9 +11,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/signup.php,v $
|
||||
| $Revision: 1.15 $
|
||||
| $Date: 2008-01-15 21:57:16 $
|
||||
| $Author: e107steved $
|
||||
| $Revision: 1.16 $
|
||||
| $Date: 2008-01-20 04:46:35 $
|
||||
| $Author: mcfly_e107 $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -367,8 +367,8 @@ if (isset($_POST['register']))
|
||||
if($_POST['xupexist'])
|
||||
{
|
||||
require_once(e_HANDLER."xml_class.php");
|
||||
$xml = new parseXml;
|
||||
if(!$rawData = $xml -> getRemoteXmlFile($_POST['xupexist']))
|
||||
$xml = new xmlClass;
|
||||
if(!$rawData = $xml->getRemoteFile($_POST['xupexist']))
|
||||
{
|
||||
echo "Error: Unable to open remote XUP file";
|
||||
}
|
||||
|
Reference in New Issue
Block a user