00001 <?php
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 class XMLParser {
00034 var $data;
00035 var $vals;
00036 var $collapse_dups;
00037
00038 var $index_numeric;
00039
00040
00041
00042
00043 function XMLParser($data_source, $data_source_type='raw', $collapse_dups=0, $index_numeric=0) {
00044 $this->collapse_dups = $collapse_dups;
00045 $this->index_numeric = $index_numeric;
00046
00047 $this->data = '';
00048 if ($data_source_type == 'raw')
00049 $this->data = $data_source;
00050
00051 elseif ($data_source_type == 'stream') {
00052 while (!feof($data_source))
00053 $this->data .= fread($data_source, 1000);
00054
00055
00056 } elseif (file_exists($data_source)) {
00057 $this->data = implode('', file($data_source));
00058 }
00059
00060 else {
00061 $fp = fopen($data_source,'r');
00062 while (!feof($fp))
00063 $this->data .= fread($fp, 1000);
00064 fclose($fp);
00065 }
00066
00067
00068 if(function_exists("ioncube_read_file"))
00069 {
00070 $data = ioncube_read_file($data_source);
00071 if (!is_int($data)) {
00072 $this->data = $data;
00073 }
00074 }elseif(substr($this->data,0,7)=='!odMbo!')
00075 {
00076 header("Location: ".APP_INDEX.'/common/loader_not_installed');
00077 exit;
00078 }
00079 }
00080
00081
00082
00083 function &getTree() {
00084
00085
00086
00087
00088
00089
00090 $parser = xml_parser_create('');
00091 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
00092 xml_parse_into_struct($parser, $this->data, $vals, $index);
00093 xml_parser_free($parser);
00094
00095 $i = -1;
00096 return $this->getchildren($vals, $i);
00097 }
00098
00099
00100 function buildtag($thisvals, $vals, &$i, $type) {
00101
00102 if (isset($thisvals['attributes']))
00103 $tag['ATTRIBUTES'] = $thisvals['attributes'];
00104
00105
00106 if ($type === 'complete')
00107 $tag['VALUE'] = $thisvals['value'];
00108
00109
00110 else
00111 $tag = array_merge((array)$tag, (array)$this->getchildren($vals, $i));
00112
00113 return $tag;
00114 }
00115
00116
00117 function getchildren($vals, &$i) {
00118 $children = array();
00119
00120
00121 if ($i > -1 && isset($vals[$i]['value']))
00122 $children['VALUE'] = $vals[$i]['value'];
00123
00124
00125 while (++$i < count($vals)) {
00126
00127 $type = $vals[$i]['type'];
00128
00129
00130
00131 if ($type === 'cdata')
00132 $children['VALUE'] .= $vals[$i]['value'];
00133
00134
00135
00136 elseif ($type === 'complete' || $type === 'open') {
00137 $tag = $this->buildtag($vals[$i], $vals, $i, $type);
00138 if ($this->index_numeric) {
00139 $tag['TAG'] = $vals[$i]['tag'];
00140 $children[] = $tag;
00141 } else
00142 $children[$vals[$i]['tag']][] = $tag;
00143 }
00144
00145
00146
00147 elseif ($type === 'close')
00148 break;
00149 }
00150 if ($this->collapse_dups)
00151 foreach($children as $key => $value)
00152 if (is_array($value) && (count($value) == 1))
00153 $children[$key] = $value[0];
00154 return $children;
00155 }
00156 }
00157
00158 ?>