00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00086 class t3lib_xml {
00087 var $topLevelName = 'typo3_test';
00088 var $XML_recFields = array();
00089
00090 var $XMLIndent=0;
00091 var $Icode='';
00092 var $XMLdebug=0;
00093 var $includeNonEmptyValues=0;
00094 var $lines=array();
00095
00102 function t3lib_xml($topLevelName) {
00103 $this->topLevelName = $topLevelName;
00104 }
00105
00113 function setRecFields($table,$list) {
00114 $this->XML_recFields[$table]=$list;
00115 }
00116
00122 function getResult() {
00123 $content = implode(chr(10),$this->lines);
00124 return $this->output($content);
00125 }
00126
00132 function WAPHeader() {
00133 $this->lines[]='<?xml version="1.0"?>';
00134 $this->lines[]='<!DOCTYPE '.$this->topLevelName.' PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">';
00135 $this->newLevel($this->topLevelName,1);
00136 }
00137
00144 function renderHeader() {
00145 $this->lines[]='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
00146 $this->lines[]='<!DOCTYPE '.$this->topLevelName.'>';
00147 $this->newLevel($this->topLevelName,1);
00148 }
00149
00155 function renderFooter() {
00156 $this->newLevel($this->topLevelName,0);
00157 }
00158
00167 function newLevel($name,$beginEndFlag=0,$params=array()) {
00168 if ($beginEndFlag) {
00169 $pList='';
00170 if (count($params)) {
00171 $par=array();
00172 reset($params);
00173 while(list($key,$val)=each($params)) {
00174 $par[]=$key.'="'.htmlspecialchars($val).'"';
00175 }
00176 $pList=' '.implode(' ',$par);
00177 }
00178 $this->lines[]=$this->Icode.'<'.$name.$pList.'>';
00179 $this->indent(1);
00180 } else {
00181 $this->indent(0);
00182 $this->lines[]=$this->Icode.'</'.$name.'>';
00183 }
00184 }
00185
00192 function output($content) {
00193 if ($this->XMLdebug) {
00194 return '<pre>'.htmlspecialchars($content).'</pre>
00195 <hr /><font color="red">Size: '.strlen($content).'</font>';
00196 } else {
00197 return $content;
00198 }
00199 }
00200
00208 function indent($b) {
00209 if ($b) $this->XMLIndent++; else $this->XMLIndent--;
00210 $this->Icode='';
00211 for ($a=0;$a<$this->XMLIndent;$a++) {
00212 $this->Icode.=chr(9);
00213 }
00214 return $this->Icode;
00215 }
00216
00224 function renderRecords($table,$res) {
00225 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00226 $this->addRecord($table,$row);
00227 }
00228 }
00229
00237 function addRecord($table,$row) {
00238 $this->lines[]=$this->Icode.'<'.$table.' uid="'.$row["uid"].'">';
00239 $this->indent(1);
00240 $this->getRowInXML($table,$row);
00241 $this->indent(0);
00242 $this->lines[]=$this->Icode.'</'.$table.'>';
00243 }
00244
00255 function getRowInXML($table,$row) {
00256 $fields = t3lib_div::trimExplode(',',$this->XML_recFields[$table],1);
00257 reset($fields);
00258 while(list(,$field)=each($fields)) {
00259 if ($row[$field] || $this->includeNonEmptyValues) {
00260 $this->lines[]=$this->Icode.$this->fieldWrap($field,$this->substNewline($this->utf8(htmlspecialchars($row[$field]))));
00261 }
00262 }
00263 }
00264
00271 function utf8($content) {
00272 return utf8_encode($content);
00273 }
00274
00281 function substNewline($string) {
00282 return ereg_replace(chr(10),'<newline/>',$string);
00283 }
00284
00292 function fieldWrap($field,$value) {
00293 return '<'.$field.'>'.$value.'</'.$field.'>';
00294 }
00295
00301 function WAPback() {
00302 $this->newLevel('template',1);
00303 $this->newLevel('do',1,array('type'=>'accept','label'=>'Back'));
00304 $this->addLine('<prev/>');
00305 $this->newLevel('do');
00306 $this->newLevel('template');
00307 }
00308
00315 function addLine($str) {
00316 $this->lines[]=$this->Icode.$str;
00317 }
00318 }
00319
00320
00321 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_xml.php']) {
00322 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_xml.php']);
00323 }
00324 ?>