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