9cd67a0a |
1 | <?php |
2 | |
3 | /** |
4 | * imap.php |
5 | * |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * The idea is to inlcude here some functions to make easier |
10 | * the right to left implementation by "functionize" some |
11 | * html outputs. |
12 | * |
13 | * $Id$ |
14 | */ |
15 | |
16 | function html_tag( $tag, |
17 | $align = '', |
94ac35c6 |
18 | $bgcolor = '', |
9cd67a0a |
19 | $xtra = '' ) { |
20 | |
94ac35c6 |
21 | GLOBAL $languages, $language; |
22 | |
23 | $align = strtolower( $align ); |
24 | $dir = strtolower( $dir ); |
25 | |
26 | if ( isset( $languages[$language]['DIR']) ) { |
27 | $dir = $languages[$language]['DIR']; |
28 | } else { |
29 | $dir = 'ltr'; |
30 | } |
31 | |
32 | if ( $dir == 'ltr' ) { |
33 | $rgt = 'right'; |
34 | $lft = 'left'; |
35 | } else { |
36 | $rgt = 'left'; |
37 | $lft = 'right'; |
38 | } |
39 | |
40 | if ( $bgcolor <> '' ) { |
41 | $bgc = " BGCOLOR=\"$bgcolor\""; |
42 | } |
43 | |
44 | switch ( $align ) { |
45 | case '': |
46 | $alg = ''; |
47 | break; |
48 | case 'right': |
49 | $alg = " ALIGN=\"$rgt\""; |
50 | break; |
51 | default: |
52 | $alg = " ALIGN=\"$lft\""; |
53 | } |
9cd67a0a |
54 | |
94ac35c6 |
55 | return( "<$tag DIR=\"$dir\"$bgc$alg $xtra>" ); |
56 | } |
57 | |
58 | /* |
59 | * Zookeeper |
60 | * Copyright (c) 2001 Partridge |
61 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
62 | * |
63 | * $Id$ |
64 | */ |
65 | |
66 | /** |
67 | * ZkSvc_html |
68 | * |
69 | * The ZkSvc_html class manages html output. |
70 | */ |
71 | class ZkSvc_html { |
72 | |
73 | /* Constants */ |
74 | var $name = 'html'; // Module name |
75 | var $ver = '$Id$'; |
76 | |
77 | /* Properties */ |
78 | var $buffer; // Buffered output |
79 | var $htmlmod; // Module handler |
80 | var $title; // Page title |
81 | var $head_extras; // Extra header tags |
82 | var $bgcolor; // Background color |
83 | var $text; // Text color |
84 | var $link; // Link color |
85 | var $vlink; // Visited link color |
86 | var $alink; // Active link color |
87 | var $onload; // Onload event |
88 | var $onunload; // OnUnload event |
89 | var $dir; // Text direction |
90 | |
91 | var $tag_options; // Array of tag options array |
92 | |
93 | /** CONSTRUCTOR |
94 | */ |
95 | |
96 | function ZkSvc_html() { |
97 | |
98 | GLOBAL $languages, $language; |
99 | |
100 | $this->spool = FALSE; |
101 | $this->buffer = ''; |
102 | $this->title = 'Default zkHTML Title'; |
103 | $this->head_extras = ''; |
104 | $this->bgcolor = '#FFFFFF'; |
105 | $this->text = '#000000'; |
106 | $this->link = '#3300CC'; |
107 | $this->vlink = '#993333'; |
108 | $this->alink = '#993333'; |
109 | $this->onload = ''; |
110 | $this->onunload = ''; |
111 | |
112 | /* To know if a tag exists we check that it has got a place in the following array */ |
113 | $this->tag_options = array( 'table' => array( 'tag_name' => 'table', |
114 | 'tag_closed' => TRUE ), |
115 | 'tr' => array( 'tag_name' => 'tr', |
116 | 'tag_closed' => TRUE ), |
117 | 'th' => array( 'tag_name' => 'th', |
118 | 'tag_closed' => TRUE ), |
119 | 'td' => array( 'tag_name' => 'td', |
120 | 'tag_closed' => TRUE ), |
121 | 'li' => array( 'tag_name' => 'li', |
122 | 'tag_closed' => TRUE ), |
123 | 'ol' => array( 'tag_name' => 'ol', |
124 | 'tag_closed' => TRUE ), |
125 | 'form' => array( 'tag_name' => 'form', |
126 | 'tag_closed' => TRUE ), |
127 | 'input' => array( 'tag_name' => 'input', |
128 | 'tag_closed' => FALSE ), |
129 | 'br' => array( 'tag_name' => 'br', |
130 | 'tag_closed' => FALSE ), |
131 | 'textarea' => array( 'tag_name' => 'textarea', |
132 | 'tag_closed' => TRUE ), |
133 | 'p' => array( 'tag_name' => 'p', |
134 | 'tag_closed' => TRUE ), |
135 | 'a' => array( 'tag_name' => 'a', |
136 | 'tag_closed' => TRUE ), |
137 | 'center' => array( 'name' => 'center', |
138 | 'tag_closed' => TRUE ), |
139 | 'img' => array( 'name' => 'img', |
140 | 'tag_closed' => FALSE ), |
141 | 'font' => array( 'tag_closed' => TRUE ), |
142 | 'blockquote' => array( 'tag_name' => 'blockquote', |
143 | 'tag_closed' => TRUE ) |
144 | ); |
145 | |
146 | if ( isset( $languages[$language]['DIR']) ) { |
147 | $this->dir = strtolower( $languages[$language]['DIR'] ); |
148 | } else { |
149 | $this->dir = 'ltr'; |
150 | } |
151 | |
152 | } |
153 | |
154 | /** |
155 | * Return the name of this service. |
156 | * |
157 | * @return string the name of this service |
158 | */ |
159 | function getServiceName() { |
160 | return( $this->name ); |
161 | } |
162 | |
163 | /** |
164 | * Replace the Zookeeper html module loaded for this service. (no modules yet) |
165 | * |
166 | */ |
167 | function loadModule(&$module) { |
168 | $this->htmlmod = &$module; |
169 | } |
170 | |
171 | /** |
172 | * Outputs the buffer and re-initialize it. |
173 | * |
174 | */ |
175 | function flush( $string = '' ) { |
176 | echo $this->buffer . $string; |
177 | flush(); |
178 | $this->buffer = ''; |
179 | } |
180 | |
181 | /** |
182 | * Builds a header string |
183 | * |
184 | */ |
185 | function header( $string = '' ) { |
186 | |
187 | // It initializes the buffer. |
188 | $this->buffer = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">' . |
189 | "\n<HTML>\n"; |
190 | |
191 | if( $this->head_extras <> '' || $this->title <> '' ) { |
192 | |
193 | $this->buffer .= "<HEAD>\n"; |
194 | |
195 | if( $this->title <> '' ) |
196 | $this->buffer .= "<TITLE>$this->title</TITLE>\n"; |
197 | |
198 | $this->buffer .= "$this->head_extras</HEAD>\n"; |
199 | } |
200 | $xtra = ''; |
201 | if ( $this->onload <> '' ) { |
202 | $xtra .= ' onload="' . $this->onload . '" '; |
203 | } |
204 | if ( $this->onunload <> '' ) { |
205 | $xtra .= ' onunload="' . $this->onunload . '" '; |
206 | } |
207 | $this->buffer .= "<BODY TEXT=\"$this->text\" BGCOLOR=\"$this->bgcolor\" LINK=\"$this->link\" VLINK=\"$this->vlink\" ALINK=\"$this->alink\" $xtra>\n"; |
208 | |
209 | /* See if we're asking for a closed strcuture */ |
210 | if( $string == '' ) { |
211 | $this->flush(); |
212 | } else { |
213 | $this->buffer .= $string . '</BODY></HTML>'; |
214 | } |
215 | |
216 | } |
217 | |
218 | /** |
219 | * Builds a footer string |
220 | * |
221 | */ |
222 | function footer() { |
223 | |
224 | $this->buffer .= "\n</body>\n</html>\n"; |
225 | $this->flush(); |
226 | |
227 | } |
228 | |
229 | /** |
230 | * Builds a tag string |
231 | * |
232 | */ |
233 | function tag( $tag, $string = '', $options = '' ) { |
234 | |
235 | $ret = ''; |
236 | if( $this->tag_options[$tag] <> NULL ) { |
237 | if( $options == '' ) { |
238 | $options = $this->tag_options[$tag]; |
239 | } |
240 | switch( strtolower( $tag ) ) { |
241 | case 'td': |
242 | case 'th': |
243 | if ( $this->dir == 'rtl' && isset( $options['align'] ) ) { |
244 | |
245 | } |
246 | case 'table': |
247 | if ( $this->dir <> '' ) { |
248 | $options['DIR'] = $this->dir; |
249 | } |
250 | break; |
251 | } |
252 | $ret = zkTag_html( $tag, $string, $options, $this->tag_options[$tag]['tag_closed'] ); |
253 | } |
254 | return( $ret ); |
255 | |
256 | } |
257 | |
258 | /** |
259 | * Builds a header string |
260 | * |
261 | */ |
262 | function h( $string, $level = '1' ) { |
263 | |
264 | $buffer = "<h$level>"; |
265 | |
266 | /* See if we're asking for a closed strcuture */ |
267 | if( $string == '' ) { |
268 | $this->$buffer .= $buffer; |
269 | } else { |
270 | $buffer .= $string . "</h$level>"; |
271 | } |
272 | return( $buffer ); |
273 | |
274 | } |
275 | |
276 | } |
277 | |
278 | /** |
279 | * Converts an array into a parameters tag list. |
280 | * |
281 | */ |
282 | function zkGetParms_html( $parms ) { |
283 | |
284 | $buffer = ''; |
285 | foreach( $parms as $key => $opt ) { |
286 | if( substr( $key, 0, 3 ) <> 'tag' ) { |
287 | $buffer .= " $key"; |
288 | if ($opt <> '' ) { |
289 | $buffer .= "=\"$opt\""; |
290 | } |
291 | } |
292 | } |
293 | return( $buffer ); |
294 | } |
295 | |
296 | /** |
297 | * Composes a tag string with all its parameters. |
298 | * |
299 | */ |
300 | function zkTag_html( $tag, $string, $options, $closed ) { |
301 | |
302 | /* |
303 | We must check direction tag in case we have table, td or th |
304 | */ |
305 | |
306 | $ret = "<$tag" . |
307 | zkGetParms_html( $options ) . |
308 | '>' . |
309 | $string; |
310 | |
311 | if ( $closed ) { |
312 | $ret .= "</$tag>"; |
313 | } |
314 | |
315 | return( $ret ); |
316 | } |
317 | |
318 | function optionize( $name, $opts, $default, $xtra = '' ) { |
319 | |
320 | $ret = "<select name=\"$name\" $xtra>\n"; |
321 | |
322 | foreach( $opts as $key => $opt ) { |
323 | if( $opt == $default ) { |
324 | $chk = ' SELECTED'; |
325 | } else { |
326 | $chk = ''; |
327 | } |
328 | $ret .= "<option value=\"$opt\"$chk>$opt</option>\n"; |
9cd67a0a |
329 | } |
330 | |
94ac35c6 |
331 | $ret .= "</select>\n"; |
332 | return( $ret ); |
333 | } |
9cd67a0a |
334 | |
94ac35c6 |
335 | ?> |