Documentation TYPO3 par Ameos

class.t3lib_xml.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00086 class t3lib_xml {
00087         var $topLevelName = 'typo3_test';       // Top element name
00088         var $XML_recFields = array();           // Contains a list of fields for each table which should be presented in the XML output
00089 
00090         var $XMLIndent=0;
00091         var $Icode='';
00092         var $XMLdebug=0;
00093         var $includeNonEmptyValues=0;   // if set, all fields from records are rendered no matter their content. If not set, only 'true' (that is '' or zero) fields make it to the document.
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 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6