crabs_todo-2.0 ©2008-2011 - Christophe Cazajus (crabs-mettre_le_signe_at-crabs-world.com)
1 <?php 2 // 3 // ============================================================================= 4 // crabs_todo-2.0 : Gestion simplissime des Todo 5 // Copyright (C) 2008-2011 : 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 // Cette classe fait partie du projet crabs_phplib 1.0 25 // Timestamp [[GPLLIB_TIMESTAMP=20101209-130344]] 26 class XML 27 { 28 var $racine ; 29 var $pere ; 30 var $fils ; 31 var $nom ; 32 var $text ; 33 var $text_empty ; 34 var $attributs ; 35 var $simple ; 36 var $xsl ; 37 38 function XML( $pere=false) 39 { 40 if ( $pere ) 41 { 42 $this->pere = $pere ; 43 $this->racine = $pere->racine ; 44 } 45 else 46 { 47 $this->racine = $this ; 48 $this->pere = false ; 49 $this->nom = 'document' ; 50 } 51 $this->fils = false ; 52 $this->text = false ; 53 $this->text_empty = true ; 54 } 55 56 function &addElement( $nom, $attr=false ) 57 { 58 if ( $this->simple ) return false ; 59 $e = new XML( $this ) ; 60 $e->nom = $nom ; $e->attributs = $attr ; $e->simple=false ; 61 if ( $this->fils == false ) $this->fils = array() ; 62 $this->fils[] = &$e ; 63 return $e ; 64 } 65 66 function &addElementSimple( $nom, $attr=false ) 67 { 68 if ( $this->simple ) return false ; 69 $e = new XML( $this ) ; 70 $e->nom = $nom ; $e->attributs = $attr ; $e->simple=true ; 71 if ( $this->fils == false ) $this->fils = array() ; 72 $this->fils[] = &$e ; 73 return $e ; 74 } 75 76 function &addElementText( $nom, $txt, $attr=false ) 77 { 78 if ( $this->simple ) return false ; 79 $e = new XML( $this ) ; 80 $e->nom = $nom ; $e->attributs = $attr ; $e->simple=false ; 81 $e->text = "$txt" ; $e->text_empty = false ; 82 if ( $this->fils == false ) $this->fils = array() ; 83 $this->fils[] = &$e ; 84 return $e ; 85 } 86 87 function affiche() 88 { 89 header( 'Content-type: text/xml' ) ; 90 $nl = "\n" ; 91 echo '<?xml version="1.0" encoding="iso-8859-15" ?>',$nl ; 92 if ( $this->xsl ) 93 echo '<?xml-stylesheet type="text/xsl" href="',$this->xsl, 94 '" ?>',$nl; 95 $this->afficheElement() ; 96 } 97 function afficheElement( $indent='' ) 98 { 99 if ( $this->simple ) 100 { $end_tag = ' />' ; $close_tag = '' ; } 101 else 102 { $end_tag = '>' ; $close_tag = $indent."</".$this->nom.">\n" ; } 103 echo $indent,'<',$this->nom ; 104 if ( $this->attributs != false ) 105 foreach( $this->attributs as $var => $val ) 106 echo ' ',$var,'="',$val,'"' ; 107 if ( $this->text_empty == true ) 108 echo $end_tag,"\n" ; 109 else 110 { echo $end_tag,$this->text; $close_tag = "</".$this->nom.">\n"; } 111 if ( $this->fils != false ) 112 foreach( $this->fils as $f ) $f->afficheElement( $indent."\t" ) ; 113 echo $close_tag ; 114 } 115 function toString() 116 { 117 $nl = "\n" ; 118 $res = '<?xml version="1.0" encoding="iso-8859-15" ?>'.$nl ; 119 if ( $this->xsl ) 120 $res.= '<?xml-stylesheet type="text/xsl" href="'.$this->xsl. 121 '" ?>'.$nl; 122 $res.= $this->toStringElement() ; 123 return $res ; 124 } 125 function toStringElement() 126 { 127 if ( $this->simple ) 128 { $end_tag = ' />' ; $close_tag = '' ; } 129 else 130 { $end_tag = '>' ; $close_tag = "</".$this->nom.">\n" ; } 131 $res = '<'.$this->nom ; 132 if ( $this->attributs != false ) 133 foreach( $this->attributs as $var => $val ) 134 $res.= ' '.$var.'="'.$val.'"' ; 135 if ( $this->text_empty == true ) 136 $res.= $end_tag."\n" ; 137 else 138 { $res.= $end_tag.$this->text; $close_tag = "</".$this->nom.">\n"; } 139 if ( $this->fils != false ) 140 foreach( $this->fils as $f ) $res.= $f->toStringElement() ; 141 $res.= $close_tag ; 142 return $res ; 143 } 144 function toHTML() 145 { 146 $d_xml = new DOMDocument; 147 $d_xml->loadXML( $this->toString() ) ; 148 $d_xsl = new DOMDocument; 149 $d_xsl->load( $this->xsl ); 150 $proc = new XSLTProcessor; 151 $proc->importStyleSheet( $d_xsl ); 152 echo $proc->transformToXML( $d_xml ); 153 } 154 } 155 ?>
Date de génération : 22/09/2011 21:49