crabs_cms-1.0.4 ©2006-2008 - Christophe Cazajus (crabs-mettre_le_signe_at-crabs-world.com)
1 <?php 2 // 3 // ============================================================================= 4 // crabs_cms-1.0.4 : Crabs Contents Management System 5 // Copyright (C) 2006-2008 : Christophe Cazajus (crabs-mettre_le_signe_at-crabs-world.com) 6 // 7 // Ce source fait partie d'un projet logiciel libre. Vous pouvez le distribuer 8 // et/ou le modifier en respectant les termes de la GNU General Public License 9 // version 2 ou (suite a votre propre choix) une version ulterieure. 10 // 11 // Ce programme est distribue dans l'espoir qu'il puisse etre utile, mais 12 // sans aucune garantie, meme si il est associe a un produit qui vous en 13 // propose une. Conformez-vous a la GNU General Public License pour avoir 14 // plus de precisions. 15 // 16 // L'auteur ne peut etre tenu responsable de l'utilisation faite des 17 // composantes associees a ce projet (en partie ou dans leur totalite). 18 // 19 // Une copie du fichier de la GNU GPL est fournie dans le repertoire DOC 20 // de ce projet sous le nom gnu_gpl.txt 21 // 22 // ============================================================================= 23 // 24 class XML 25 { 26 var $racine ; 27 var $pere ; 28 var $fils ; 29 var $nom ; 30 var $text ; 31 var $text_empty ; 32 var $attributs ; 33 var $simple ; 34 var $xsl ; 35 36 function XML( $pere=false) 37 { 38 if ( $pere ) 39 { 40 $this->pere = $pere ; 41 $this->racine = $pere->racine ; 42 } 43 else 44 { 45 $this->racine = $this ; 46 $this->pere = false ; 47 $this->nom = 'document' ; 48 } 49 $this->fils = false ; 50 $this->text = false ; 51 $this->text_empty = true ; 52 } 53 54 function &addElement( $nom, $attr=false ) 55 { 56 if ( $this->simple ) return false ; 57 $e = new XML( $this ) ; 58 $e->nom = $nom ; $e->attributs = $attr ; $e->simple=false ; 59 if ( $this->fils == false ) $this->fils = array() ; 60 $this->fils[] = &$e ; 61 return $e ; 62 } 63 64 function &addElementSimple( $nom, $attr=false ) 65 { 66 if ( $this->simple ) return false ; 67 $e = new XML( $this ) ; 68 $e->nom = $nom ; $e->attributs = $attr ; $e->simple=true ; 69 if ( $this->fils == false ) $this->fils = array() ; 70 $this->fils[] = &$e ; 71 return $e ; 72 } 73 74 function &addElementText( $nom, $txt, $attr=false ) 75 { 76 if ( $this->simple ) return false ; 77 $e = new XML( $this ) ; 78 $e->nom = $nom ; $e->attributs = $attr ; $e->simple=false ; 79 $e->text = "$txt" ; $e->text_empty = false ; 80 if ( $this->fils == false ) $this->fils = array() ; 81 $this->fils[] = &$e ; 82 return $e ; 83 } 84 85 function affiche() 86 { 87 header( 'Content-type: text/xml' ) ; 88 $nl = "\n" ; 89 echo '<?xml version="1.0" encoding="iso-8859-15" ?>',$nl ; 90 if ( $this->xsl ) 91 echo '<?xml-stylesheet type="text/xsl" href="',$this->xsl, 92 '" ?>',$nl; 93 $this->afficheElement() ; 94 } 95 function afficheElement( $indent='' ) 96 { 97 if ( $this->simple ) 98 { $end_tag = ' />' ; $close_tag = '' ; } 99 else 100 { $end_tag = '>' ; $close_tag = $indent."</".$this->nom.">\n" ; } 101 echo $indent,'<',$this->nom ; 102 if ( $this->attributs != false ) 103 foreach( $this->attributs as $var => $val ) 104 echo ' ',$var,'="',$val,'"' ; 105 if ( $this->text_empty == true ) 106 echo $end_tag,"\n" ; 107 else 108 { echo $end_tag,$this->text; $close_tag = "</".$this->nom.">\n"; } 109 if ( $this->fils != false ) 110 foreach( $this->fils as $f ) $f->afficheElement( $indent."\t" ) ; 111 echo $close_tag ; 112 } 113 function toString() 114 { 115 $nl = "\n" ; 116 $res = '<?xml version="1.0" encoding="iso-8859-15" ?>'.$nl ; 117 if ( $this->xsl ) 118 $res.= '<?xml-stylesheet type="text/xsl" href="'.$this->xsl. 119 '" ?>'.$nl; 120 $res.= $this->toStringElement() ; 121 return $res ; 122 } 123 function toStringElement() 124 { 125 if ( $this->simple ) 126 { $end_tag = ' />' ; $close_tag = '' ; } 127 else 128 { $end_tag = '>' ; $close_tag = "</".$this->nom.">\n" ; } 129 $res = '<'.$this->nom ; 130 if ( $this->attributs != false ) 131 foreach( $this->attributs as $var => $val ) 132 $res.= ' '.$var.'="'.$val.'"' ; 133 if ( $this->text_empty == true ) 134 $res.= $end_tag."\n" ; 135 else 136 { $res.= $end_tag.$this->text; $close_tag = "</".$this->nom.">\n"; } 137 if ( $this->fils != false ) 138 foreach( $this->fils as $f ) $res.= $f->toStringElement() ; 139 $res.= $close_tag ; 140 return $res ; 141 } 142 function toHTML() 143 { 144 $d_xml = new DOMDocument; 145 $d_xml->loadXML( $this->toString() ) ; 146 $d_xsl = new DOMDocument; 147 $d_xsl->load( $this->xsl ); 148 $proc = new XSLTProcessor; 149 $proc->importStyleSheet( $d_xsl ); 150 echo $proc->transformToXML( $d_xml ); 151 } 152 } 153 ?>
Date de génération : 24/10/2008 21:34