This commit is contained in:
rGaillard
2011-07-06 10:10:43 +00:00
parent 31d94236ac
commit d1a13007b9
4695 changed files with 0 additions and 339293 deletions
@@ -1,94 +0,0 @@
<?php
/*
Copyright (C) 2006 Google Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* Classes used to generate XML data
* Based on sample code available at http://simon.incutio.com/code/php/XmlWriter.class.php.txt
*/
/**
* Generates xml data
*/
class gc_XmlBuilder {
var $xml;
var $indent;
var $stack = array();
function gc_XmlBuilder($indent = ' ') {
$this->indent = $indent;
$this->xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
}
function _indent() {
for ($i = 0, $j = count($this->stack); $i < $j; $i++) {
$this->xml .= $this->indent;
}
}
//Used when an element has sub-elements
// This function adds an open tag to the output
function Push($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= ">\n";
$this->stack[] = $element;
}
//Used when an element has no subelements.
//Data within the open and close tags are provided with the
//contents variable
function Element($element, $content, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= '>'.htmlentities($content).'</'.$element.'>'."\n";
}
function EmptyElement($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= " />\n";
}
//Used to close an open tag
function Pop($pop_element) {
$element = array_pop($this->stack);
$this->_indent();
if($element !== $pop_element)
die('XML Error: Tag Mismatch when trying to close "'. $pop_element. '"');
else
$this->xml .= "</$element>\n";
}
function GetXML() {
if(count($this->stack) != 0)
die ('XML Error: No matching closing tag found for " '. array_pop($this->stack). '"');
else
return $this->xml;
}
}
@@ -1,202 +0,0 @@
<?php
/**
* Classes used to parse xml data
*/
/*
Copyright (C) 2007 Google Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
For more info: http://code.google.com/p/google-checkout-php-sample-code/
Upgrades (05/23/2007) ropu:
Remove UpdateRecursive()
Support for empty tags (like <world-area/>)
Accept multiple options in a second parameter
*
**/
/* This uses SAX parser to convert XML data into PHP associative arrays
* When invoking the constructor with the input data, strip out the first XML line
*
* Member field Description:
* $params: This stores the XML data. The attributes and contents of XML tags
* can be accessed as follows
*
* <addresses>
* <anonymous-address id="123"> <test>data 1 </test>
* </anonymous-address>
* <anonymous-address id="456"> <test>data 2 </test>
* </anonymous-address>
* </addresses>
*
* print_r($this->params) will return
Array
(
[addresses] => Array
(
[anonymous-address] => Array
(
[0] => Array
(
[id] => 123
[test] => Array
(
[VALUE] => data 1
)
)
[1] => Array
(
[id] => 456
[test] => Array
(
[VALUE] => data 2
)
)
)
)
)
* gc_xmlparser returns an empty params array if it encounters
* any error during parsing
*/
// XML to Array
class gc_xmlparser {
var $params = array(); //Stores the object representation of XML data
var $root = NULL;
var $global_index = -1;
var $fold = false;
/* Constructor for the class
* Takes in XML data as input( do not include the <xml> tag
*/
function gc_xmlparser($input, $xmlParams=array(XML_OPTION_CASE_FOLDING => 0)) {
$xmlp = xml_parser_create();
foreach($xmlParams as $opt => $optVal) {
switch( $opt ) {
case XML_OPTION_CASE_FOLDING:
$this->fold = $optVal;
break;
default:
break;
}
xml_parser_set_option($xmlp, $opt, $optVal);
}
if(xml_parse_into_struct($xmlp, $input, $vals, $index)) {
$this->root = $this->_foldCase($vals[0]['tag']);
$this->params = $this->xml2ary($vals);
}
xml_parser_free($xmlp);
}
function _foldCase($arg) {
return( $this->fold ? strtoupper($arg) : $arg);
}
/*
* Credits for the structure of this function
* http://mysrc.blogspot.com/2007/02/php-xml-to-array-and-backwards.html
*
* Adapted by Ropu - 05/23/2007
*
*/
function xml2ary($vals) {
$mnary=array();
$ary=&$mnary;
foreach ($vals as $r) {
$t=$r['tag'];
if ($r['type']=='open') {
if (isset($ary[$t]) && !empty($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];
}
$cv=array();
if (isset($r['attributes'])) {
foreach ($r['attributes'] as $k=>$v) {
$cv[$k]=$v;
}
}
$cv['_p']=&$ary;
$ary=&$cv;
} else if ($r['type']=='complete') {
if (isset($ary[$t]) && !empty($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[$k]=$v;
}
}
$cv['VALUE'] = (isset($r['value']) ? $r['value'] : '');
} elseif ($r['type']=='close') {
$ary=&$ary['_p'];
}
}
$this->_del_p($mnary);
return $mnary;
}
// _Internal: Remove recursion in result array
function _del_p(&$ary) {
foreach ($ary as $k=>$v) {
if ($k==='_p') {
unset($ary[$k]);
}
else if(is_array($ary[$k])) {
$this->_del_p($ary[$k]);
}
}
}
/* Returns the root of the XML data */
function GetRoot() {
return $this->root;
}
/* Returns the array representing the XML data */
function GetData() {
return $this->params;
}
}