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 | * |
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 { |
33 | echo 'JOPPPEEE'; |
34 | $new_html_el = array(); |
35 | $new_html_el[] = $el; |
36 | foreach ($this->html_el as $html_el) { |
37 | $new_html_el[] = $html_el; |
38 | } |
39 | $this->html_el = $new_html_el; |
40 | } |
53ef1f99 |
41 | } |
42 | |
6789a914 |
43 | function AddChild($tag='', $text='', $style ='', $class='', $id='', |
44 | $xtr_prop = '', $javascript = '') { |
45 | $el = new html ($tag, $text, $style, $class, $id, $xtr_prop, $javascript); |
46 | $this->htmlAdd($el); |
47 | } |
48 | |
49 | function FindId($id) { |
50 | $cnt = count($this->html_el); |
51 | $el = false; |
52 | if ($cnt) { |
53 | for ($i = 0 ; $i < $cnt; $i++) { |
54 | if ($this->html_el[$i]->id == $id) { |
55 | $ret = $this->html_el[$i]; |
56 | return $ret; |
57 | } else if (count($this->html_el[$i]->html_el)) { |
58 | $el = $this->html_el[$i]->FindId($id); |
59 | } |
60 | if ($el) return $el; |
61 | } |
62 | } |
63 | return $el; |
64 | } |
65 | |
66 | function InsToId( $el, $id, $last=true) { |
67 | $html_el = &$this->FindId($id); |
68 | if ($html_el) { |
69 | $html_el->htmlAdd($el, $last); |
70 | } |
71 | } |
72 | |
73 | function scriptAdd($script) { |
74 | $s = "\n".'<!--'."\n". |
75 | $script . |
76 | "\n".'// -->'."\n"; |
77 | $el = new html ('script',$s,''.''.''.array('language' => 'JavaScript', |
78 | 'type' => 'text/javascript')); |
79 | $this->htmlAdd($el); |
80 | } |
53ef1f99 |
81 | |
84d46e4e |
82 | function echoHtml( $usecss=false, $indent='x') { |
83 | if ($indent == 'x') { |
84 | $indent = ''; $indentmore = ''; |
85 | } else { |
86 | $indentmore = $indent . ' '; |
87 | } |
53ef1f99 |
88 | $tag = $this->tag; |
89 | $text = $this->text; |
90 | $class = $this->class; |
91 | $id = $this->id; |
92 | $style = $this->style; |
93 | $javascript = $this->javascript; |
94 | $xtr_prop = $this->xtr_prop; |
95 | if ($xtr_prop) { |
96 | $prop = ''; |
97 | foreach ($xtr_prop as $k => $v) { |
98 | if (is_string($k)) { |
99 | $prop.=' '.$k.'="'.$v.'"'; |
100 | } else { |
101 | $prop.=' '.$v; |
102 | } |
103 | } |
104 | } |
105 | if ($javascript) { |
106 | $js = ''; |
107 | foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */ |
108 | $js.=' '.$k.'="'.$v.'";'; |
109 | } |
110 | } |
6789a914 |
111 | if ($tag) { |
112 | echo $indent . '<' . $tag; |
113 | } else { |
114 | echo $indent; |
115 | } |
53ef1f99 |
116 | if ($class) { |
117 | echo ' class="'.$class.'"'; |
118 | } |
119 | if ($id) { |
120 | echo ' id="'.$id.'"'; |
121 | } |
122 | if ($xtr_prop) { |
123 | echo ' '.$prop; |
124 | } |
4a177858 |
125 | if ($style && !$usecss && !is_array($style)) { |
126 | /* last premisse is to prevent 'style="Array"' in the output */ |
53ef1f99 |
127 | echo ' style="'.$style.'"'; |
128 | } |
129 | if ($javascript) { |
130 | echo ' '.$js; |
131 | } |
6789a914 |
132 | if ($tag) echo '>'; |
c6bed723 |
133 | |
134 | $openstyles = ''; |
135 | $closestyles = ''; |
136 | if ($style && !$usecss) { |
137 | foreach ($style as $k => $v) { |
138 | $openstyles .= '<'.$k.'>'; |
53ef1f99 |
139 | } |
c6bed723 |
140 | foreach ($style as $k => $v) { |
141 | /* if value of key value = true close the tag */ |
142 | if ($v) { |
143 | $closestyles .= '</'.$k.'>'; |
144 | } |
145 | } |
146 | } |
147 | echo $openstyles; |
148 | |
149 | if ($text) { |
150 | echo $text; |
53ef1f99 |
151 | } |
c6bed723 |
152 | |
53ef1f99 |
153 | $cnt = count($this->html_el); |
154 | if ($cnt) { |
155 | echo "\n"; |
53ef1f99 |
156 | for($i = 0;$i<$cnt;$i++) { |
157 | $el = $this->html_el[$i]; |
4a177858 |
158 | $el->echoHtml($usecss,$indentmore); |
53ef1f99 |
159 | } |
c6bed723 |
160 | echo $indent; |
6789a914 |
161 | } |
c6bed723 |
162 | echo $closestyles; |
6789a914 |
163 | if ($tag) { |
c6bed723 |
164 | echo '</'.$tag.'>'."\n"; |
6789a914 |
165 | } else { |
166 | echo "\n"; |
53ef1f99 |
167 | } |
53ef1f99 |
168 | } |
169 | } |
170 | |
171 | |
172 | ?> |