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 | |
15 | class 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 | |
84d46e4e |
83 | function echoHtml( $usecss=false, $indent='x') { |
84 | if ($indent == 'x') { |
85 | $indent = ''; $indentmore = ''; |
86 | } else { |
87 | $indentmore = $indent . ' '; |
88 | } |
53ef1f99 |
89 | $tag = $this->tag; |
90 | $text = $this->text; |
91 | $class = $this->class; |
92 | $id = $this->id; |
93 | $style = $this->style; |
94 | $javascript = $this->javascript; |
95 | $xtr_prop = $this->xtr_prop; |
96 | if ($xtr_prop) { |
97 | $prop = ''; |
98 | foreach ($xtr_prop as $k => $v) { |
99 | if (is_string($k)) { |
100 | $prop.=' '.$k.'="'.$v.'"'; |
101 | } else { |
102 | $prop.=' '.$v; |
103 | } |
104 | } |
105 | } |
106 | if ($javascript) { |
107 | $js = ''; |
108 | foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */ |
109 | $js.=' '.$k.'="'.$v.'";'; |
110 | } |
111 | } |
6789a914 |
112 | if ($tag) { |
113 | echo $indent . '<' . $tag; |
114 | } else { |
115 | echo $indent; |
116 | } |
53ef1f99 |
117 | if ($class) { |
118 | echo ' class="'.$class.'"'; |
119 | } |
120 | if ($id) { |
121 | echo ' id="'.$id.'"'; |
122 | } |
123 | if ($xtr_prop) { |
124 | echo ' '.$prop; |
125 | } |
4a177858 |
126 | if ($style && !$usecss && !is_array($style)) { |
127 | /* last premisse is to prevent 'style="Array"' in the output */ |
53ef1f99 |
128 | echo ' style="'.$style.'"'; |
129 | } |
130 | if ($javascript) { |
131 | echo ' '.$js; |
132 | } |
6789a914 |
133 | if ($tag) echo '>'; |
c6bed723 |
134 | |
135 | $openstyles = ''; |
136 | $closestyles = ''; |
137 | if ($style && !$usecss) { |
138 | foreach ($style as $k => $v) { |
139 | $openstyles .= '<'.$k.'>'; |
53ef1f99 |
140 | } |
c6bed723 |
141 | foreach ($style as $k => $v) { |
142 | /* if value of key value = true close the tag */ |
143 | if ($v) { |
144 | $closestyles .= '</'.$k.'>'; |
145 | } |
146 | } |
147 | } |
148 | echo $openstyles; |
149 | |
150 | if ($text) { |
151 | echo $text; |
53ef1f99 |
152 | } |
c6bed723 |
153 | |
53ef1f99 |
154 | $cnt = count($this->html_el); |
155 | if ($cnt) { |
156 | echo "\n"; |
53ef1f99 |
157 | for($i = 0;$i<$cnt;$i++) { |
158 | $el = $this->html_el[$i]; |
4a177858 |
159 | $el->echoHtml($usecss,$indentmore); |
53ef1f99 |
160 | } |
c6bed723 |
161 | echo $indent; |
6789a914 |
162 | } |
c6bed723 |
163 | echo $closestyles; |
6789a914 |
164 | if ($tag) { |
c6bed723 |
165 | echo '</'.$tag.'>'."\n"; |
6789a914 |
166 | } else { |
167 | echo "\n"; |
53ef1f99 |
168 | } |
53ef1f99 |
169 | } |
170 | } |
171 | |
172 | |
173 | ?> |