2 //PUNTO DE ENTRADA DE TODOS LOS ELEMENTOS DEL DOM CREADOS:
3 //CONSTANTES A TRAVES DE INI [solo deben conocerse ruta al ini y nombre de la seccion del ini para las constantes]
4 $config = parse_ini_file('config.ini'); //RUTA AL ARCHIVO INI DE CONFIGURACION
5 $seccConsts = $config['_SECC_CONSTS_INI_DOM']; //SECCION DEL INI DONDE SE ENCUENTRAN LAS CONSTANTES
6 //echo '<div style="background:green;">'.$seccConsts.'</div>';
7 $config = parse_ini_file('config.ini', true); //AHORA POR SECCIONES
8 //ESTABLECIENDO LAS CONSTANTES DEL PAKETE
9 foreach($config as $key => $value) {
10 if($key==$seccConsts){
11 foreach($value as $k => $v) {
12 //echo "[".$seccConsts."] ".$k." = ".$v."<br />";
13 if(! defined($k)) define($k, $v);
17 if(! defined('QUOTE')) define('QUOTE', '"'); //Permite utilizar " en el archivo ini mediante QUOTE
18 if(! defined("_PATH_CLASS_DOM_")) define("_PATH_CLASS_DOM_", realpath( dirname(__FILE__) ));//"."
20 //TODO: BORRAR: LAS SIGUIENTES DEFINICIONES SE MANTIENEN POR COMODIDAD EN EL DESARROLLO CON ECLIPSE
21 if(! defined("_PATH_EXCEPTION_DOM_")) define("_PATH_EXCEPTION_DOM_", "/exceptions");
22 if(! defined("_PATH_UTIL_DOM_")) define("_PATH_UTIL_DOM_", "/util");
23 if(! defined("_CONF_INI_FILE_DOM_")) define("_CONF_INI_FILE_DOM_", "config.ini");
24 if(! defined("_SECC_CONF_INI_DOM")) define("_SECC_CONF_INI_DOM", "[CONF_SECC]");
25 if(! defined('QUOTE')) define('QUOTE', '"'); //Permite utilizar " en el archivo ini mediante QUOTE
28 //define("TAG", "LinkClass");
29 // we've writen this code where we need
30 function __autoload($classname) {
31 $ruta=_PATH_CLASS_DOM_;
32 if(substr($classname, -9)=="Exception") $ruta .= _PATH_EXCEPTION_DOM_;
33 //if(substr($classname, -9)=="Configuration") $ruta .= "/conf";
34 if(substr($classname, 3)=="INI") $ruta .= _PATH_UTIL_DOM_;
35 $filename = $ruta."/". $classname .".php";
37 include_once($filename);
38 //parent::__autoload($classname);
39 } catch (Exception $e){
40 throw new Exception("Imposible cargar $classname desde el directorio $ruta. ERROR: ".$e->getMessage().PHP_EOL);
44 * Clase padre para crear cualquier elemento del DOM. Admite CONCATENACION DE METODOS mediante el retorno de la construccion '$this'
45 * en todos los metodos 'NO-GETTER': … <code>$this->setText('text')->removeChild($child)->importConfINI();</code> …
47 class DOM_element extends DOM_attribs implements DOM_Interface {
50 * Constante de cadena que representa el nombre de esta Clase, util para labores de Depuracion
51 * (agregandola a las sentencias del log o de trade...)
52 * @var String constant
55 const N_C = __CLASS__;
57 //------------ BEGIN: CONFIGURACION -----------------
59 * ¿ Permitir el patron SINGLETON ?
61 const PATRON_SINGLETON=true;
63 * <h1>Boolean indicando si los atributos de este elemento son DE SOLO LECTURA O ESCRIBIBLES.</h1>
67 protected $_READ_ONLY=false;//=boolean;
70 * Variable de cadena indicando la etiqueta DOM (HTML) de este elemento
76 * Variable de cadena indicando el tipo DOM de este elemento
80 protected $TYPE = "container";
82 * Variable de cadena indicando la descripcion de este elemento
86 protected $DESC = "DOM's container element";
87 //CONSTANTES QUE REPRESENTAN LAS APERTURA Y CIERRE DE ETIQUETAS DE LOS ELEMENTOS DOM.
88 //Algunos elementos autocontendidos (como '<img />') pueden modificarlas, o incluso anularlas (como 'textNode')
90 * Variable de cadena indicando la apertura de la etiqueta HTML de este elemento
91 * <p style="background:yellow; color: navy">Algunos elementos autocontendidos (como '<img />')
92 * pueden modificarlas, o incluso anularlas (como 'textNode')</p>
96 protected $OPEN_TAG_LEFT="<";
98 * Variable de cadena indicando el cierre de la etiqueta HTML de apertura de este elemento
99 * <p style="background:yellow; color: navy">Algunos elementos autocontendidos (como '<img />')
100 * pueden modificarlas, o incluso anularlas (como 'textNode')</p>
104 protected $OPEN_TAG_RIGHT=">";
106 * Variable de cadena indicando la apertura de la etiqueta HTML de cierre de este elemento
107 * <p style="background:yellow; color: navy">Algunos elementos autocontendidos (como '<img />')
108 * pueden modificarlas, o incluso anularlas (como 'textNode')</p>
112 protected $CLOSE_TAG_LEFT="</";
114 * Variable de cadena indicando el cierre de la etiqueta HTML de este elemento
115 * <p style="background:yellow; color: navy">Algunos elementos autocontendidos (como '<img />')
116 * pueden modificarlas, o incluso anularlas (como 'textNode')</p>
120 protected $CLOSE_TAG_RIGHT=">";
122 //---- BEGIN: AVISOS ------
124 * ¿ Lanzar Aviso cuando se intenta tomar una instancia estatica mediante el 'Patron SINGLETON' sin estar permitida por
125 * '<a href="DOM_attribs::PATRON_SINGLETON" title="PATRON_SINGLETON">'PATRON SINGLETON'</a> ?
127 const AVISO_SINGLETON=true;
129 * ¿ Lanzar Aviso cuando se lee un atributo que no existe ?
131 protected $AVISO_GET=false;
132 //---- END: AVISOS ------
136 protected static final $DTD_DOCTYPE_HTML=0;
137 protected static final $DTD_DOCTYPE_XHTML_TRANSITIONAL=10;
138 protected static final $DTD_DOCTYPE_XHTML_STRICT=10;
139 protected static final $DTD_XML_1_0=20;*/
140 protected static $DTD_DOCTYPE_HTML=0;
141 protected static $DTD_DOCTYPE_XHTML_TRANSITIONAL=10;
142 protected static $DTD_DOCTYPE_XHTML_STRICT=10;
143 protected static $DTD_XML_1_0=20;
144 protected static $LINE_BREAK="\n";
145 //------------ END: CONFIGURACION ------------------------
148 * Clave de este elemento
154 * Texto que contiene este elemento.
160 * Array de elementos del DOM hijos de este
161 * @var Array DOM_element
164 protected $_children=array();
166 //--------------------- BEGIN: PATRON SINGLETON -------------------
168 * PATRON ESTATICO SINGLETON
172 protected static $instance;
174 * PATRON SINGLETON. Tomar una instancia de forma estatica.<br />
175 * $attrbs = DOM_attribs::getInstance();
177 public static function getInstance() {
178 if(self::PATRON_SINGLETON){
179 //if (!isset(self::$instance)) {
180 if (is_null(self::$instance)) {
181 $c = __CLASS__; //self::TAG
182 //$instance = new $c;
183 self::$instance = new $c();
185 return self::$instance;
188 if(self::AVISO_SINGLETON) throw new DOMBasicSingletonException();
189 }catch (Exception $e){
190 self::writeLog($e->getMessage(), $e->getTrace());
194 private function setInstance() {
196 $this->tryingWrite("INSTANCE");
197 self::$instance=$this;
198 }catch(Exception $e){
199 $this::writeLog($e->getMessage(), $e->getTrace());
202 //---------------------- END: PATRON SINGLETON --------------------
204 //---------------------- BEGIN: MAGICS METHODS --------------------
206 public function __construct($key=null){
207 if($key != null) $this->_key=$key;
208 $this->importConfINI();
209 $this->reinicializar();
210 $this::$instance=$this;
214 public function __destruct(){
215 parent::__destruct();
216 //echo "<h1>DESTRUYENDO ".$this->getKey()."</h1>";
217 $this::$instance=null;
218 $this->_children=null;
221 public function __clone(){
222 //return self::getInstance();
223 $clase=__CLASS__; //self::TAG;
224 $clon=new $clase($this->_key);
225 $clon->setReadOnly(false);
226 $clon->setChildren($this->_children);
227 $clon->setAttribs($this->getAttribs());
228 $clon->setConfiguration($this->getConfiguration());
229 $clon->setReadOnly($this->getReadOnly());
230 return $clon; //DA ERRORES EN PHP 4.0
234 * <h1>Desde PHP 5.1.0</h1>
235 * @throws DOMBasicElementReadOnlyException If 'Read Only' ON.
236 * @throws DOMBasicElementNotFoundException
237 * If $attrib is not a key in the $_attribs array.
238 * @param DOM_element $child The element to unset.
240 public function __unset($child) {
241 //echo "Eliminando '$child'\n";
243 $this->tryingWrite($child);
244 if(in_array($child,$this->_children)){
245 $index=array_search($child, $this->_children);
246 unset($this->_children[$index]);
248 }catch(Exception $e){
249 $this->writeLog($e->getMessage(), $e->getTrace());
253 public function __toString() {
254 //return $this->_text;
255 return $this->getOpenTag() . $this->_text . $this->getCloseTag();
259 public static function __set_state($an_array) // A partir de PHP 5.1.0
261 $obj = new self($an_array['_key']);
262 $obj->setReadOnly($an_array['_READ_ONLY']);
263 $obj->setTag($an_array['TAG']+"_22");
264 $obj->TYPE = $an_array['TYPE'];
265 $obj->DESC = $an_array['DESC'];
266 $obj->OPEN_TAG_LEFT = $an_array['OPEN_TAG_LEFT'];
267 $obj->OPEN_TAG_RIGHT = $an_array['OPEN_TAG_RIGHT'];
268 $obj->CLOSE_TAG_LEFT = $an_array['CLOSE_TAG_LEFT'];
269 $obj->CLOSE_TAG_RIGHT = $an_array['CLOSE_TAG_RIGHT'];
270 $obj->AVISO_GET = $an_array['AVISO_GET'];
271 //$obj->_key = $an_array['_key'];
272 $obj->setText( $an_array['_text'] );
273 $obj->_children = $an_array['_children'];
278 //----------------- END: MAGICS METHODS -----------------------------
280 //----------------- BEGIN: ABSTRACT METHODS IN PARENT ----------------
281 public function reinicializar(){
282 //$this->_attribs=array();
284 $this->tryingWrite("[".$this->_key."]".$this->TAG);
285 $this->_children=array();
286 }catch(Exception $e){
287 $this->writeLog($e->getMessage(), $e->getTrace());
289 //TODO: ¡¡OJO NO ACTIVAR!! PUEDE PROVOCAR UNA EXCEPCION AL SER LLAMADA DESDE UN CONSTRUCTOR.
290 //register_shutdown_function(array($this, '__destruct')); //para evitar un bug en PHP 5.3.10 con la destruccion de objetos
293 //ABSTRACT METHOD IN PARENT
294 public function setReadOnly($readOnly){
295 $this->_READ_ONLY=$readOnly;
298 public function getReadOnly(){
299 return $this->_READ_ONLY;
302 //------------ OVERRIDE -------------
304 * <p><b>:OVERRIDE-PARENT:</b></p>
305 * <p>Notifica una accion de escritura al objeto; Si es de solo-lectura lanzara una Excepcion.</p>
306 * @return boolean TRUE=OK, FALSE=throw DOMBasicElementReadOnlyException()
307 * @throws DOMBasicElementReadOnlyException;
309 protected function tryingWrite($arg="") {
310 //parent::tryingWrite($arg);
311 if($this->_READ_ONLY){
312 //$mensaje="Intentando escribir en un Objeto de Solo-Lectura!!";
313 throw new DOMBasicElementReadOnlyException($arg, DOMBasicElementReadOnlyException::READ);
318 //----------------- END: ABSTRACT METHODS IN PARENT ----------------
320 //----------------- BEGIN: GETTER & SETTER -------------------------
321 public function setKey(string $key=null){
323 $this->tryingWrite("[".$this->_key."]".$this->TAG);
324 if(! is_null($key))$this->_key=$key;
325 }catch(Exception $e){
326 $this->writeLog($e->getMessage(), $e->getTrace());
330 public function getKey(){
333 public function getTag(){
336 public function setTag($tag){
340 public function getOpenTag(){
341 return ($this->OPEN_TAG_LEFT . $this->TAG . parent::getAttribsStr() . $this->OPEN_TAG_RIGHT);
343 public function getCloseTag(){
344 if(strlen( $this->CLOSE_TAG_LEFT . $this->CLOSE_TAG_RIGHT ) == 0){
347 return ($this->CLOSE_TAG_LEFT . $this->TAG . $this->CLOSE_TAG_RIGHT);
350 public function getType(){
353 public function getDesc(){
356 //-------------------- END: GETTER & SETTER -------------
358 //-------------------- BEGIN: TEXT ----------------------
359 public function clearText(){
362 $this->tryingWrite("[".$this->_key."]".$this->TAG);
363 $textoAnterior=$this->getText();
364 $objTxt=new DOM_textNode();
365 $this->removeChildrenByType($objTxt->getType(), false);
366 }catch(Exception $e){
367 $this->writeLog($e->getMessage(), $e->getTrace());
369 //return $textoAnterior;
374 * Agreaga un hijo de texto (textNode) a este elemento DOM, eliminando los hijos tipo 'textNode' que tubiese
375 * @param string $text para este elemento.
376 * @return string con el texto anterior.
378 public function setText($text){
379 //$textoAnterior=$this->getText();
381 //$this->tryingWrite("[".$this->_key."]".$this->TAG);
383 //$this->_text=$text;
384 $txt=new DOM_textNode();
385 $txt->setText($text);
386 $this->addChild($txt);
387 }catch(Exception $e){
388 $this->writeLog($e->getMessage(), $e->getTrace());
390 //return $textoAnterior;
394 public function addText($text){
396 $this->tryingWrite("[".$this->_key."]".$this->TAG);
397 $txt=new DOM_textNode();
398 $txt->setText($text);
399 $this->addChild($txt);
400 }catch(Exception $e){
401 $this->writeLog($e->getMessage(), $e->getTrace());
406 /** Retorna todo el texto encontrado en este elemento y en sus hijos.
407 * @param $filter [boolean] Permite especificar si el texto se retorna filtrado mediante 'htmlspecialchars_decode(...)' y
408 * 'stripcslashes(...)' o no. [Por defecto NO]
409 * @return string con el texto de todos los nodos tipo 'textNode' de este elemento y sus hijos.
411 public function getTextAll($filter=false){
412 $texto = $filter ? htmlspecialchars_decode(stripslashes( $this->_text )) : $this->_text;
413 if( is_null($this->getChildren()) ) return $texto;
414 foreach ($this->getChildren() as $child){
415 if( is_null($child) ) continue;
416 $texto .= $filter ? htmlspecialchars_decode(stripslashes( $child->getText($filter) )) : $this->getText($filter);
421 * Metodo para retornar el texto de este elemento DOM (la concatenacion de los textos de todos los elementos textNode).
422 * @param $filter [boolean] Permite especificar si el texto se retorna filtrado mediante 'htmlspecialchars_decode(...)' y
423 * 'stripcslashes(...)' o no. [Por defecto NO]
424 * @return string con el texto de todos los nodos tipo 'textNode' de este elemento.
426 public function getText($filter=false){
427 $texto = $filter ? htmlspecialchars_decode(stripslashes( $this->_text )) : $this->_text;
428 if( is_null($this->getChildren()) ) return $texto;
429 foreach ($this->getChildren() as $child){
430 //echo "<div>".$child->TYPE."</div>";
431 if( is_null($child) || ($child->TYPE != "textNode") ) continue;
432 //$texto =" :: " . $child->TYPE ." :: ";
433 $texto .= $filter ? htmlspecialchars_decode(stripslashes( $child->_text )) : $this->_text;
434 //htmlspecialchars_decode(stripslashes( $child->getText($grandchildren) ));
438 //----------------- END: TEXT -----------------------
440 //----------------- BEGIN: CHILDREN HANDLER ----------
441 public function addChild(DOM_element $child=null){
443 $this->tryingWrite("[".$this->_key."]".$this->TAG);
444 if(! is_null($child)){
445 $this->_children[]=$child;
447 }catch(Exception $e){
448 $this->writeLog($e->getMessage(), $e->getTrace());
450 //return count($this->_children);
454 public function addChildren(array $children=null){
456 $this->tryingWrite("[".$this->_key."]".$this->TAG);
457 if( is_null($this->_children) ) $this->_children=array();
458 if(is_array($children)){
459 foreach ($children as $child){
460 $this->_children[]=$child;
463 }catch(Exception $e){
464 $this->writeLog($e->getMessage(), $e->getTrace());
466 //return count($this->_children);
470 public function setChildren(array $children=null){
472 $this->tryingWrite("[".$this->_key."]".$this->TAG);
473 $this->_children=$children;
474 }catch(Exception $e){
475 $this->writeLog($e->getMessage(), $e->getTrace());
481 public function getChildren(){
482 return $this->_children;
485 public function getChildrenAll(){
487 foreach ($this->getChildren() as $child){
489 if( count($child->getChildren())>0 ) $children[]=$child->getChildrenAll();
494 public function getChildByKey($key, $grandchildren=true){
495 if( is_null($this->getChildren()) ) return null;
496 foreach ($this->getChildren() as $child){
497 if($child->getKey()==$key) return $child;
499 $childOfChild = $child->getChildByKey($key);
500 if( ! is_null($childOfChild) ) return $childOfChild;
506 public function getChildrenByTag($tag, $grandchildren=true){
508 foreach ($this->getChildren() as $child){
509 if($child->getTag()==$tag) $children[]= $child;
511 $childrenOfChild = $child->getChildrenByTag($tag);
512 if( ! is_null($childrenOfChild) ) {
513 foreach ($childrenOfChild as $c){
514 //echo "ENCONTRADO [".$c->getKey()."] EN [".$child->getKey()."]";
522 public function getChildrenByType($type, $grandchildren=true){
524 foreach ($this->getChildren() as $child){
525 if($child->getType()==$type) $children[]= $child;
527 $childrenOfChild = $child->getChildrenByType($type);
528 if( ! is_null($childrenOfChild) ) {
529 foreach ($childrenOfChild as $c){
530 //echo "ENCONTRADO [".$c->getKey()."] EN [".$child->getKey()."]";
539 public function removeChild($child, $grandchildren=true){
541 foreach ($this->getChildren() as $hijo){
542 //if($hijo->equalsExacts($child)) {
543 if($hijo->equals($child)) {
545 $this->__unset($child);
546 }else{ //RECURSIVIDAD
547 if($grandchildren) $exito = $exito || $hijo->removeChild($child, $grandchildren);
554 public function removeChildrenAll(){
556 foreach ($this->getChildren() as $child){
557 $this->__unset($child);
561 public function removeChildByKey($key, $grandchildren=true){
563 foreach ($this->getChildren() as $child){
564 if($child->getKey()==$key){
566 $this->__unset($child);
567 }else{ //RECURSIVIDAD
568 if($grandchildren) $contador +=$child->removeChildByKey($key, $grandchildren);
575 public function removeChildrenByTag($tag, $grandchildren=true){
577 foreach ($this->getChildren() as $child){
578 if($child->getTag()==$tag){
580 $this->__unset($child);
581 }else{ //RECURSIVIDAD
582 if($grandchildren) $contador +=$child->removeChildrenByTag($tag, $grandchildren);
589 public function removeChildrenByType($type, $grandchildren=true){
591 foreach ($this->getChildren() as $child){
592 if($child->getType()==$type){
594 $this->__unset($child);
595 }else{ //RECURSIVIDAD
596 if($grandchildren) $contador +=$child->removeChildrenByType($type, $grandchildren);
602 //----------------- END: CHILDREN HANDLER ----------
604 //----------------- BEGIN: COMPARATOR --------------
605 /** <p>Compara si otro objeto es igual (comparable no clonable) a este (no si es el mismo); para esto se tienen que cumplir las
606 * siguientes normas: </p>
608 * <li>Que los dos sean instancias de la misma Clase (el mismo tipo de elemento y etiqueta).</li>
609 * <li>Que los dos tengan definidos el mismo numero de atributos y con los mismos valores.</li>
610 * <li>Que los dos tengan definidos el mismo numero de hijos y con los mismos valores.</li>
611 * <li>Tambien que los dos tengan definida la misma clave.</li>
612 * <li>Incluso que los dos contengan el mismo texto como contenido.</li>
614 * @param DOM_element $objDOM Algun objeto instancia de esta Clase
615 * @return boolean **/
616 public function equals($objDOM) {
618 //1º COMPARACION SI NO ES NULO
619 if(is_null($objDOM)) return false;
620 //if(! parent::equals($objDOM->getDOM_attrib())) return false;
621 if(is_null($objDOM->_children)) $objDOM->_children=array();
622 if(is_null($this->_children)) $this->_children=array();
623 //2º COMPARACION SI ES UNA INSTACIA DE ESTA CLASE
624 if( !($objDOM instanceof $this) ) return false; //is_a(), get_class();
625 //if(! is_subclass_of($objAttribs, self::TAG, false) ) return false;
626 //3º COMPARACION VARIABLES
627 //if($equal) $equal = ($this->_key == $objDOM->_key); //SE ADMITE DISTINTA
628 if($equal) $equal = ($this->TAG == $objDOM->TAG);
629 //if($equal) $equal = $equal && ($this->DESC == $objDOM->DESC); //SE ADMITE DISTINTA
630 if($equal) $equal = ($this->OPEN_TAG_LEFT == $objDOM->OPEN_TAG_LEFT);
631 if($equal) $equal = ($this->OPEN_TAG_RIGHT == $objDOM->OPEN_TAG_RIGHT);
632 if($equal) $equal = ($this->CLOSE_TAG_LEFT == $objDOM->CLOSE_TAG_LEFT);
633 if($equal) $equal = ($this->CLOSE_TAG_RIGHT == $objDOM->CLOSE_TAG_RIGHT);
634 if($equal) $equal = ($this->_text == $objDOM->_text);
635 //echo "3º / ".($equal?"TRUE":"FALSE")."<br />";
636 //4º COMPARACION RAPIDA. IGUAL NUMERO DE HIJOS
637 if($equal) $equal = (count($objDOM->_children) == count($this->_children));
638 //echo "4º / ".($equal?"TRUE":"FALSE")."<br />";
639 //5º COMPARACION HIJO A HIJO
642 foreach($objDOM->_children as $clave=>$valor) {
643 foreach($this->_children as $clave2=>$valor2) {
644 if(($clave==$clave2) && ($valor==$valor2)) $contador++;
647 $equal = ( (count($this->_children) == $contador) && (count($objDOM->_children) == $contador) );
648 //echo "5º / ".($equal?"TRUE":"FALSE")."<br />";
650 //6º COMPARACION ATRIBUTO A ATRIBUTO
651 if($equal) $equal = parent::equals($objDOM);
652 //echo "6º / ".($equal?"TRUE":"FALSE")."<br /> - EQUAL=-|"; print_r($equal);echo "|-<br />";
656 public function equalsType($objDOM) {
657 return ( ($objDOM instanceof $this) && ($this->TYPE == $objDOM->TYPE ) );
659 //---------------- END: COMPARATOR ------------------------
661 //---------------- BEGIN: HTML ----------------------------
662 public function toHTML() {
663 $HTML = $this->getOpenTag();
664 if($this->getCloseTag() != "") $HTML .= self::$LINE_BREAK;
665 $HTML .= ($this->TYPE == "textNode") ? $this->getText(true) : ""; //$this->_text;
666 foreach($this->getChildren() as $child){
667 $HTML .= $child->toHTML();
669 $HTML .= $this->getCloseTag() . self::$LINE_BREAK;
670 //if($this->getCloseTag() == "") $HTML .= self::$LINE_BREAK;
672 //return '<a '.parent::__toString().'>'.$this->_key.'</a>';
676 * Metodo para obtener una etiqueta de definicion DTD que especifique el tipo de documento que estamos
677 * tratando. (HTML, XHTML, XML, ...)
678 * @param int $dtd Un entero identificando el tipo de DTD a retornar. Puede ser una de las constantes de
679 * esta clase que comienzan con DTD_
680 * @return string La cadena con el DTD solicitado.
682 public static function getDTD(int $dtd){
683 //<?xml version="1.0" encoding="UTF-8"? >
684 //<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
685 //Copyright © 2014 W3C <sup>®</sup> (<a href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>
686 //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
687 //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
689 //<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
691 //<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
694 //<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
696 //<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
698 //<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
701 //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
703 //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
705 //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
707 //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
709 //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
713 case self::$DTD_DOCTYPE_HTML:
714 return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
715 case self::$DTD_DOCTYPE_XHTML_TRANSITIONAL:
716 return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
717 case self::$DTD_DOCTYPE_XHTML_STRICT:
718 return'<?xml version="1.0" encoding="iso-8859-1"?>
719 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
720 case self::$DTD_XML_1_0:
721 return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
726 //---------------- END: HTML ------------------------------
728 //---------------- BEGIN: JSON ----------------------------
729 public function toJSON($return=true, $base64values=true) {
730 $id =$this->getKey()?('-'.$this->getKey()):'';
731 $id .=$this->getType()?('-'.$this->getType()):'';
732 $id .='-' . rand(5, 1000);
733 //$result ='"'.__CLASS__ . $id .'":{';
734 $result ='{"_base64":"'.($base64values?'true':'false').'",';
737 foreach (get_object_vars($this) as $clave=>$valor){
738 if( !is_array($valor) && !is_object($valor)){
739 //$clave = htmlentities(htmlspecialchars(utf8_encode($clave)));
740 if($clave != "_text"){ //PARA TEXT YA OCURRE EL ESCAPE EN SU PROPIO METODO setText();
741 $clave = addslashes( htmlspecialchars( utf8_encode($clave) ) );
742 $valor = addslashes( htmlspecialchars( utf8_encode($valor) ) );
744 $clave=parent::filtrarStrJSON($clave);
745 $valor=parent::filtrarStrJSON($valor);
747 $array[] = '"'.$clave.'":"'.base64_encode($valor).'"';
749 $array[] = '"'.$clave.'":"'.$valor.'"';
753 $result .= implode(',', $array).',';
754 //$result .='"_children":'.json_encode($this->_children).",";
756 $result .= '"_attribs":'.parent::toJSON($return, $base64values).',';
759 foreach ($this->getChildren() as $key => $value) {
760 if ( is_object($value) ){ //OBJETOS DOM (NO ATTRIBS NI PROPIEDADES)
761 $array[] = $value->toJSON($return,$base64values);
764 $result .= '"_children":['.implode(',', $array).']';
778 public function fromJSON($json) {
779 //DECODIFICAR LA CADENA JSON Y OBTENER EL OBJETO
780 $result = json_decode(utf8_decode(htmlspecialchars_decode(stripslashes($json))));
781 //DETECTAR AUTOMATICAMENTE SI HA SIDO CODIFICADO EN BASE64
782 $base64values = key_exists("_base64", get_object_vars($result))? ($result->_base64=="true") : false;
783 //CONVIERTO EL OBJ-JSON A OBJ-DOM_ELEMENT
784 $object=self::objJSON2DOM_element( $result, true, $base64values );
785 //ASIGNA Y RETORNA THIS COMO EL NUEVO OBJETO...
786 return $this->fromDOM_element($object);
790 * <p>Metodo estatico para construir un objeto DOM a la imagen y semejanza del objeto JSON entregado que deberia representar
791 * otro DOM_element con hijos, atributos, y caracteristicas propias.</p>
792 * <p>NI QUE DECIR TIENE QUE EL OBJETO JSON ENTREGADO DEBE SER UN FIEL REFLEJO DE ALGUN ELEMENTO DE ESTA CLASE,
793 * NORMALMENTE SE OBTENDRA DECODIFICANDO EL RETORNO DE LA FUNCION toJSON(); (json_decode(...->toJSON();))</p>
794 * @param JSON $objectJSON Es un objeto creado con una cadena JSON.
795 * @param boolean $return Expresa si retornar (TRUE) el objeto creado o imprimirlo (FALSE).
796 * @param boolean $base64values Indica si codificar los textos en 'base64' o no.
797 * @return DOM_element El elemento (DOM_element) creado equivalente al objeto entregado o NULL en caso de impresion.
799 public static function objJSON2DOM_element($objectJSON, $return=true, $base64values=true){
800 //$object es un 'Objeto stdClass' convertido de una cadena valida JSON
802 if(is_object($objectJSON)){
803 $object=new DOM_element();
804 foreach (get_object_vars($objectJSON) as $clave=>$valor){
805 if(is_array($valor)){ //OBJECT
806 //$object->setAttribs($valor);
807 //$object->addChildren($valor);
808 foreach ($valor as $key=>$value){
809 $object->addChild( $object->objJSON2DOM_element( $value , $return, $base64values ) );
811 }elseif(is_object($valor)){ //ATTRIBS
812 //$object->setAttribs($valor);
813 foreach (get_object_vars($valor) as $key=>$value){
814 $object->addAttrib($key, ($base64values ? base64_decode( $value ) : $value));
816 }else {//if( !is_array($valor) && !is_object($valor)){ //PARAM
817 if($clave=="_base64") continue;
818 //if($clave=="TYPE") echo "<p>TYPE:".$valor."</p>";
819 $object->$clave = $base64values ? base64_decode( $valor ) : $valor;
820 //if($clave=="TYPE") echo "<p>".$clave.":".$valor." || ".$object->$clave."</p>";
834 //---------------- END: JSON ------------------------------
837 * <p>Metodo para reconstruir este objeto a la imagen y semejanza del objeto DOM_element entregado, con hijos, atributos,
838 * y caracteristicas propias.</p>
839 * @param DOM_element $dom Un objeto de esta clase.
840 * @return DOM_element Este elemento (this) recreado equivalente (pero no el mismo) al objeto entregado.
842 public function fromDOM_element(DOM_element $dom){
843 //$this=new $dom($dom->_key);
844 $this->setReadOnly(false);
845 $this->_Key = $dom->getKey();
846 $this->setConfiguration($dom->getConfiguration());
847 $this->setChildren($dom->getChildren());
848 $this->setAttribs($dom->getAttribs());
849 $this->setReadOnly($dom->getReadOnly());
850 return $this; //DA ERRORES EN PHP 4.0
853 //---------------- BEGIN URL ------------------------------
855 * <p>Retorna una cadena con el formato de las URL's, construida con los Atributos de este Objeto.<br />
856 * Contiene un parametro $encode indicando el tipo de codificacion a aplicar: 'RFC_1738' (espacios=+) o 'RFC_3986' (espacions=%20),
857 * las cuales estan implementadas como cadenas staticas de la clase DOM_attribs.</p>
858 * @param $encode Cadena indicando el tipo de codificacion (alguna de las dos constantes indicadas
859 * {@link DOM_attribs->ENCODE_RFC_1738 RFC_1738} o {@link DOM_attribs#ENCODE_RFC_3986 RFC_3986}).
860 * @return Cadena con formato de codificacion URL.
862 public function attribsToURL($encode = self::ENCODE_RFC_1738){
863 return parent::toURL($encode);
866 * <p>Establece y retorna un array de atributos con sus correspondientes valores extraidos de una cadena con el formato de las URL's,
867 * para construir Atributos de este Objeto.</p>
868 * <p>El parametro es la cadena desde la que se extraeran los atributos y sus valores, esta cadena tendra el formato entregado en
869 * las URL's como parte de su 'queryString' (entre '?' y '#'), Igual a la generada por el metodo toURL().</p>
870 * @param $encode Cadena indicando el tipo de codificacion (alguna de las dos constantes indicadas
871 * {@link DOM_attribs->ENCODE_RFC_1738 RFC_1738} o {@link DOM_attribs#ENCODE_RFC_3986 RFC_3986}).
872 * @return Array de atributos extraidos de la queryString.
874 public function attribsFromURL($strURL){
875 return parent::fromURL($strURL);
877 //----------------- END URL ----------------------------
879 //----------------- BEGIN: CONFIGURACION --------------
880 public function getConfiguration(){
881 /*$conf=array($this->_READ_ONLY, $this->AVISO_GET,
882 $this->TAG, $this->TYPE, $this->DESC, $this->_text,
883 $this->OPEN_TAG_LEFT, $this->OPEN_TAG_RIGHT, $this->CLOSE_TAG_LEFT, $this->CLOSE_TAG_RIGHT );*/
884 $conf=array("_READ_ONLY"=>$this->_READ_ONLY, "AVISO_GET"=>$this->AVISO_GET,
885 "TAG"=>$this->TAG, "TYPE"=>$this->TYPE, "DESC"=>$this->DESC, "_text"=>$this->_text,
886 "OPEN_TAG_LEFT"=>$this->OPEN_TAG_LEFT, "OPEN_TAG_RIGHT"=>$this->OPEN_TAG_RIGHT,
887 "CLOSE_TAG_LEFT"=>$this->CLOSE_TAG_LEFT, "CLOSE_TAG_RIGHT"=>$this->CLOSE_TAG_RIGHT );
891 public function setConfiguration(array $conf){
893 $this->tryingWrite("[".$this->_key."]".$this->TAG);
895 if( ! is_null($conf) ){
896 /*$conf=array($this->_READ_ONLY, $this->AVISO_GET,
897 $this->TAG, $this->TYPE, $this->DESC, $this->_text,
898 $this->OPEN_TAG_LEFT, $this->OPEN_TAG_RIGHT, $this->CLOSE_TAG_LEFT, $this->CLOSE_TAG_RIGHT );
900 foreach ($conf as $clave=>$valor){
901 //echo $clave." = ".$value."<br />";
902 $this->$clave=$valor;
903 //if($clave=="TYPE") echo "<p>TYPE:".$valor."</p>";
904 //echo (is_array($conf)?"true":"false")." :: ".$clave."-".$valor."<br />";
908 }catch(Exception $e){
909 $this->writeLog($e->getMessage(), $e->getTrace());
915 public function importConfINI($confFile=null){
916 // Analizar con secciones
917 $seccIni = parse_ini_file(_PATH_CLASS_DOM_."/"._CONF_INI_FILE_DOM_, true);
918 foreach ($seccIni as $secc=>$items){
919 if($secc==_SECC_CONF_INI_DOM){
921 foreach ($items as $key=>$value){
922 echo $key." = ".$value."<br />";
925 $this->setConfiguration($items);
930 //--------------- END: CONFIGURACION ----------------