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