<HTML> tag placement fix
[squirrelmail.git] / class / html.class
CommitLineData
53ef1f99 1<?php
2/**
3 * html.class
4 *
5 * Copyright (c) 2002 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 *
9 * This contains functions needed to generate html output.
10 *
11 * $Id$
12 */
13
14
15class html {
16 var $tag, $text, $style, $class,
17 $id, $html_el = array(), $javascript, $xtr_prop;
18
19 function html($tag='', $text='', $style ='', $class='', $id='',
20 $xtr_prop = '', $javascript = '') {
21 $this->tag = $tag;
22 $this->text = $text;
23 $this->style = $style;
24 $this->class = $class;
25 $this->id = $id;
26 $this->xtr_prop = $xtr_prop;
27 $this->javascript = $javascript;
28 }
29
6789a914 30 function htmlAdd($el, $last=true) {
31 if ($last) {
32 $this->html_el[] = $el;
33 } else {
34 echo 'JOPPPEEE';
35 $new_html_el = array();
36 $new_html_el[] = $el;
37 foreach ($this->html_el as $html_el) {
38 $new_html_el[] = $html_el;
39 }
40 $this->html_el = $new_html_el;
41 }
53ef1f99 42 }
43
6789a914 44 function AddChild($tag='', $text='', $style ='', $class='', $id='',
45 $xtr_prop = '', $javascript = '') {
46 $el = new html ($tag, $text, $style, $class, $id, $xtr_prop, $javascript);
47 $this->htmlAdd($el);
48 }
49
50 function FindId($id) {
51 $cnt = count($this->html_el);
52 $el = false;
53 if ($cnt) {
54 for ($i = 0 ; $i < $cnt; $i++) {
55 if ($this->html_el[$i]->id == $id) {
56 $ret = $this->html_el[$i];
57 return $ret;
58 } else if (count($this->html_el[$i]->html_el)) {
59 $el = $this->html_el[$i]->FindId($id);
60 }
61 if ($el) return $el;
62 }
63 }
64 return $el;
65 }
66
67 function InsToId( $el, $id, $last=true) {
68 $html_el = &$this->FindId($id);
69 if ($html_el) {
70 $html_el->htmlAdd($el, $last);
71 }
72 }
73
74 function scriptAdd($script) {
75 $s = "\n".'<!--'."\n".
76 $script .
77 "\n".'// -->'."\n";
78 $el = new html ('script',$s,''.''.''.array('language' => 'JavaScript',
79 'type' => 'text/javascript'));
80 $this->htmlAdd($el);
81 }
53ef1f99 82
83 function echoHtml( $usecss=false, $indent='') {
84 $tag = $this->tag;
85 $text = $this->text;
86 $class = $this->class;
87 $id = $this->id;
88 $style = $this->style;
89 $javascript = $this->javascript;
90 $xtr_prop = $this->xtr_prop;
91 if ($xtr_prop) {
92 $prop = '';
93 foreach ($xtr_prop as $k => $v) {
94 if (is_string($k)) {
95 $prop.=' '.$k.'="'.$v.'"';
96 } else {
97 $prop.=' '.$v;
98 }
99 }
100 }
101 if ($javascript) {
102 $js = '';
103 foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */
104 $js.=' '.$k.'="'.$v.'";';
105 }
106 }
6789a914 107 if ($tag) {
108 echo $indent . '<' . $tag;
109 } else {
110 echo $indent;
111 }
53ef1f99 112 if ($class) {
113 echo ' class="'.$class.'"';
114 }
115 if ($id) {
116 echo ' id="'.$id.'"';
117 }
118 if ($xtr_prop) {
119 echo ' '.$prop;
120 }
4a177858 121 if ($style && !$usecss && !is_array($style)) {
122 /* last premisse is to prevent 'style="Array"' in the output */
53ef1f99 123 echo ' style="'.$style.'"';
124 }
125 if ($javascript) {
126 echo ' '.$js;
127 }
6789a914 128 if ($tag) echo '>';
53ef1f99 129 if ($text) {
130 if ($style && !$usecss) { /* if use css then fallback to stylesheet for layout */
131 foreach ($style as $k => $v) {
132 echo '<'.$k.'>';
133 }
134 echo $text;
135 foreach ($style as $k => $v) { /* if value of key value = true close the tag */
136 if ($v) {
4a177858 137 echo '</'.$k.'>';
53ef1f99 138 }
139 }
140 } else {
141 echo $text;
142 }
143 }
144 $cnt = count($this->html_el);
145 if ($cnt) {
6789a914 146 if ($style && !$usecss) {
147 foreach ($style as $k => $v) {
148 echo '<'.$k.'>';
149 }
150 }
53ef1f99 151 echo "\n";
4a177858 152 $indentmore = $indent . ' ';
53ef1f99 153 for($i = 0;$i<$cnt;$i++) {
154 $el = $this->html_el[$i];
4a177858 155 $el->echoHtml($usecss,$indentmore);
53ef1f99 156 }
6789a914 157 if ($style && !$usecss) {
158 foreach ($style as $k => $v) { /* if value of key value = true close the tag */
159 if ($v) {
4a177858 160 echo '</'.$k.'>';
6789a914 161 }
162 }
163 }
164 }
165 if ($tag) {
166 echo '</'.$tag.'>'."\n";
167 } else {
168 echo "\n";
53ef1f99 169 }
53ef1f99 170 }
171}
172
173
174?>