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 | |
30 | function htmlAdd($el) { |
31 | $this->html_el[] = $el; |
32 | } |
33 | |
34 | |
35 | function echoHtml( $usecss=false, $indent='') { |
36 | $tag = $this->tag; |
37 | $text = $this->text; |
38 | $class = $this->class; |
39 | $id = $this->id; |
40 | $style = $this->style; |
41 | $javascript = $this->javascript; |
42 | $xtr_prop = $this->xtr_prop; |
43 | if ($xtr_prop) { |
44 | $prop = ''; |
45 | foreach ($xtr_prop as $k => $v) { |
46 | if (is_string($k)) { |
47 | $prop.=' '.$k.'="'.$v.'"'; |
48 | } else { |
49 | $prop.=' '.$v; |
50 | } |
51 | } |
52 | } |
53 | if ($javascript) { |
54 | $js = ''; |
55 | foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */ |
56 | $js.=' '.$k.'="'.$v.'";'; |
57 | } |
58 | } |
59 | |
60 | echo $indent . '<' . $tag; |
61 | if ($class) { |
62 | echo ' class="'.$class.'"'; |
63 | } |
64 | if ($id) { |
65 | echo ' id="'.$id.'"'; |
66 | } |
67 | if ($xtr_prop) { |
68 | echo ' '.$prop; |
69 | } |
70 | if ($style && !$usecss) { |
71 | echo ' style="'.$style.'"'; |
72 | } |
73 | if ($javascript) { |
74 | echo ' '.$js; |
75 | } |
76 | echo '>'; |
77 | if ($text) { |
78 | if ($style && !$usecss) { /* if use css then fallback to stylesheet for layout */ |
79 | foreach ($style as $k => $v) { |
80 | echo '<'.$k.'>'; |
81 | } |
82 | echo $text; |
83 | foreach ($style as $k => $v) { /* if value of key value = true close the tag */ |
84 | if ($v) { |
85 | echo '</'.$v.'>'; |
86 | } |
87 | } |
88 | } else { |
89 | echo $text; |
90 | } |
91 | } |
92 | $cnt = count($this->html_el); |
93 | if ($cnt) { |
94 | echo "\n"; |
95 | $indent.=' '; |
96 | for($i = 0;$i<$cnt;$i++) { |
97 | $el = $this->html_el[$i]; |
98 | $el->echoHtml($usecss,$indent); |
99 | } |
100 | } |
101 | echo '</'.$tag.'>'."\n"; |
102 | } |
103 | } |
104 | |
105 | |
106 | ?> |