OSDN Git Service

Creación y administración de documentos basados en DOM mediante PHP
[dombasic/DOMbasic.git] / examples / example1.php
1 <?php 
2 /*
3  * File containing the Example1.php, 
4  * PACKAGE DOMBasic - Generation PHP FILE for demostration purpose
5 *
6 * @package DOMBasic
7 * @version 1.0
8 * @copyright Copyright (C) 2014-2020 Juan Jose Guerra Haba. All rights reserved.
9 * @license http://www.jumla-droid.com/licenses/new_bsd New BSD License
10 */
11
12   $language="es-ES";
13         //$ruta=realpath( dirname(realpath( dirname(__FILE__) ) ) )."/../DOM_element.php";
14         $ruta="../DOM_element.php";
15         //echo $ruta;
16         require($ruta);
17
18         $document=new DOM_element('document');
19         $document->setTag('');
20         $conf=array( "TYPE"=>"document", "DESC"=>"document DOM",
21                         "OPEN_TAG_LEFT"=>"", "OPEN_TAG_RIGHT"=>"", "CLOSE_TAG_LEFT"=>"", "CLOSE_TAG_RIGHT"=>"" );
22         $document->setConfiguration($conf);
23
24                 $doctype=new DOM_element("doctype");
25                 $doctype->setTag("DOCTYPE");
26                 $conf=array( "TYPE"=>"doctype", "DESC"=>"Tipo de Documento (DTD)",
27                                                                          "OPEN_TAG_LEFT"=>"<!", "OPEN_TAG_RIGHT"=>">", "CLOSE_TAG_LEFT"=>"", "CLOSE_TAG_RIGHT"=>"" );
28                 $doctype->setConfiguration($conf);
29                 //IGUALAR UNA CLAVE A NULL SIGNIFICA UNA CLAVE SIN VALOR
30                 $doctype->html=null;
31                 $doctype->addAttrib('PUBLIC',null); //$doctype->PUBLIC=null;
32                 //COMENZAR UNA CLAVE POR '_null' significa un atributo sin clave (doctype) (SOLO VALOR)
33                 $doctype->addAttrib("_null1", "-//W3C//DTD XHTML 1.0 Transitional//EN");
34                 $doctype->_null2="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
35                 
36                 $html=new DOM_element('html');
37                 $html->setTag("html");
38                 $html->xmlns="http://www.w3.org/1999/xhtml";
39                 $html->addAttrib("xml:lang", $language);
40                 $html->lang=$language;
41                 
42                         $head=new DOM_element('head');
43                         $head->setTag("head");
44                         
45                                 $meta1=new DOM_element("meta1");
46                                 $meta1->setTag("meta");
47                                 $conf=array( "TYPE"=>"meta", "DESC"=>"meta-tag HTML",
48                                                 "OPEN_TAG_LEFT"=>"<", "OPEN_TAG_RIGHT"=>" />", "CLOSE_TAG_LEFT"=>"", "CLOSE_TAG_RIGHT"=>"" );
49                                 $meta1->setConfiguration($conf);
50                                 $meta1->addAttrib("http-equiv", "Content-Type")->addAttrib("content", 'text/html; charset=utf-8');
51                                 
52                                 $title=new DOM_element('title');
53                                 $title->setTag('title')->setText("ARCHIVO DE PRUEBAS PARA POO-PHP");
54                                 
55                                 $link1=new DOM_element("link1");
56                                 $link1->setTag("link");
57                                 $conf=array( "TYPE"=>"link", "DESC"=>"link-resource HTML",
58                                                 "OPEN_TAG_LEFT"=>"<", "OPEN_TAG_RIGHT"=>" />", "CLOSE_TAG_LEFT"=>"", "CLOSE_TAG_RIGHT"=>"" );
59                                 $link1->setConfiguration($conf);
60                                 $link1->addAttrib("type", "image/x-icon")->addAttrib("rel", "shortcut icon")->addAttrib("href", "favicon.png");
61                                 
62                                 $link2=new DOM_element("link2");
63                                 $link2->setTag("link");
64                                 $conf=array( "TYPE"=>"link", "DESC"=>"link-resource HTML",
65                                                 "OPEN_TAG_LEFT"=>"<", "OPEN_TAG_RIGHT"=>" />", "CLOSE_TAG_LEFT"=>"", "CLOSE_TAG_RIGHT"=>"" );
66                                 $link2->setConfiguration($conf);
67                                 $link2->addAttrib("type", "text/css")->addAttrib("rel", "stylesheet");
68                                 $link2->addAttrib("href", "http://ajax.googleapis.com/ajax/libs/mootools/1.2.2/mootools-yui-compressed.css");
69                                 
70                                 $style1=new DOM_element("style1");
71                                 $style1->setTag("style")->type="text/css";
72                                 $style1->setText(
73                                                                                                         "#container{
74                                                                                                                 padding:10px;
75                                                                                                                 margin:10px;
76                                                                                                         }
77                                                                                                         #container2{
78                                                                                                           background:lightGray;
79                                                                                                           border: 1px ridge coral;
80                                                                                                                 border-radius:8px;
81                                                                                                                 padding:10px;
82                                                                                                                 max-width:250px;
83                                                                                                                 margin:auto;
84                                                                                                         }
85                                                                                                         img{
86                                                                                                           border: 1px solid gray;
87                                                                                                                 border-radius:6px;
88                                                                                                                 box-shadow:4px 6px 8px;
89                                                                                                                 width:85%;
90                                                                                                                 margin:10px;
91                                                                                                                 cursor:pointer;
92                                                                                                         }
93                                                                                                         img:hover{ width:84%;}"
94                                                                                                 );
95
96                                 $script1=new DOM_element("script1");
97                                 $script1->setTag("script")->type="text/javascript";
98                                 $conf=array( "TYPE"=>"link", "DESC"=>"link-resource HTML",
99                                                 "OPEN_TAG_LEFT"=>"<", "OPEN_TAG_RIGHT"=>">", "CLOSE_TAG_LEFT"=>"</", "CLOSE_TAG_RIGHT"=>">" );
100                                 $script1->setConfiguration($conf);
101                                 $script1->src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.2/mootools-yui-compressed.js";
102                                 
103                                 $script2=new DOM_element("script2");
104                                 $script2->setTag("script")->type="text/javascript";
105                                 $script2->setText("
106                                                                                                                 window.addEvent(\"domready\", function() {
107                                                                                                                   $(\"container\").highlight(\"#AAAA00\");
108                                                                                                                 });"
109                                                                                                         );
110
111                         $head->setChildren(array($meta1, $title, $link1, $link2, $style1, $script1, $script2));
112                         
113                         $body=new DOM_element('body');
114                         $body->setTag("body");
115                         
116                                 $h1=new DOM_element('h1_1');
117                                 $h1->setTag("h1");
118                                 $h1->setText('EXAMPLE1 :: Paquete DOMBasic <br /><small style="color:#666666;">- Generaci&oacute;n de archivo HTML para prop&oacute;sitos de demostraci&oacute;n <br /><small><a href="mailto:dinertron@gmail.com">guerraTron - 2014</a></small></small>');
119                                                                                          
120                                 $div1=new DOM_element('div1');
121                                 $div1->setTag("div")->id="container";
122                                 $div1->setText('<hr />"El fondo de este DIV resaltará dinámicamente mediante Javascript [Mootools]"<hr />');
123                                 
124                                 $div2=new DOM_element('div2');
125                                 $div2->setTag("div")->id="container2";
126                                 $div2->setText('Pulsar en la primera im&aacute;gen de Lego<br />');
127                                 
128                                         $img1=new DOM_element('img1');
129                                                 $conf=array( "TYPE"=>"img", "DESC"=>"image-resource HTML",
130                                                 "OPEN_TAG_LEFT"=>"<", "OPEN_TAG_RIGHT"=>"/>", "CLOSE_TAG_LEFT"=>"", "CLOSE_TAG_RIGHT"=>"" );
131                                         $img1->setConfiguration($conf);
132                                         $img1->setTag("img")->addAttribs(array("src"=>"./img1.png", 
133                                                                                                                                                                                          "alt"=>"img1.png - Legotron 1", 
134                                                                                                                                                                                          "title"=>"Legotron 1",
135                                                                                                                                                                                          "onclick"=>"javascript: alert('LegoTron 1');"));
136
137                                         $img2=new DOM_element('img2');
138                                                 $conf=array( "TYPE"=>"img", "DESC"=>"image-resource HTML",
139                                                 "OPEN_TAG_LEFT"=>"<", "OPEN_TAG_RIGHT"=>"/>", "CLOSE_TAG_LEFT"=>"", "CLOSE_TAG_RIGHT"=>"" );
140                                         $img2->setConfiguration($conf);
141                                         $img2->setTag("img")->addAttribs(array("src"=>"./img2.png", 
142                                                                                                                                                                                          "alt"=>"img2.png - Legotron 2", 
143                                                                                                                                                                                          "title"=>"Legotron 2"));
144                                 $div2->addChildren(array($img1, $img2));
145                         $body->setChildren(array( $h1, $div1, $div2 ));
146                         
147                 $html->setChildren(array($head, $body));
148                 
149         $document->addChild($doctype)->addChild($html);
150
151
152         //SALIDA
153         echo $document->toHTML();
154         //DEPURACION
155         /*
156         echo "<pre>";
157                 print_r($document);
158         echo "</pre>";
159         */
160 ?>