9cd67a0a |
1 | <?php |
2 | |
3 | /** |
8008456a |
4 | * html.php |
9cd67a0a |
5 | * |
9cd67a0a |
6 | * The idea is to inlcude here some functions to make easier |
7 | * the right to left implementation by "functionize" some |
8 | * html outputs. |
9 | * |
47ccfad4 |
10 | * @copyright © 1999-2006 The SquirrelMail Project Team |
4b4abf93 |
11 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
31841a9e |
12 | * @version $Id$ |
d6c32258 |
13 | * @package squirrelmail |
792f911e |
14 | * @since 1.3.0 |
9cd67a0a |
15 | */ |
16 | |
769a819d |
17 | |
18 | /** |
19 | * Generates a hyperlink |
20 | * |
21 | * @param string $uri The target link location |
22 | * @param string $text The link text |
23 | * @param string $target The location where the link should |
24 | * be opened (OPTIONAL; default not used) |
25 | * @param string $onclick The onClick JavaScript handler (OPTIONAL; |
26 | * default not used) |
27 | * @param string $class The CSS class name (OPTIONAL; default |
28 | * not used) |
29 | * @param string $id The ID name (OPTIONAL; default not used) |
ca11c6f1 |
30 | * @param string $name The anchor name (OPTIONAL; default not used) |
769a819d |
31 | * |
32 | * @return string The desired hyperlink tag. |
33 | * |
34 | * @since 1.5.2 |
35 | * |
36 | */ |
ca11c6f1 |
37 | function create_hyperlink($uri, $text, $target='', $onclick='', |
38 | $class='', $id='', $name='') { |
769a819d |
39 | |
40 | global $oTemplate; |
41 | |
42 | $oTemplate->assign('uri', $uri); |
43 | $oTemplate->assign('text', $text); |
44 | $oTemplate->assign('target', $target); |
45 | $oTemplate->assign('onclick', $onclick); |
46 | $oTemplate->assign('class', $class); |
47 | $oTemplate->assign('id', $id); |
ca11c6f1 |
48 | $oTemplate->assign('name', $name); |
769a819d |
49 | |
50 | return $oTemplate->fetch('hyperlink.tpl'); |
51 | |
52 | } |
53 | |
54 | |
0173ad29 |
55 | /** |
56 | * Generates an image tag |
57 | * |
58 | * @param string $src The image source path |
59 | * @param string $alt Alternate link text (OPTIONAL; default |
60 | * not used) |
61 | * @param string $width The width the image should be shown in |
62 | * (OPTIONAL; default not used) |
63 | * @param string $height The height the image should be shown in |
64 | * (OPTIONAL; default not used) |
65 | * @param string $border The image's border attribute value |
66 | * (OPTIONAL; default not used) |
67 | * @param string $class The CSS class name (OPTIONAL; default |
68 | * not used) |
69 | * @param string $id The ID name (OPTIONAL; default not used) |
70 | * @param string $onclick The onClick JavaScript handler (OPTIONAL; |
71 | * default not used) |
72 | * @param string $title The image's title attribute value |
73 | * (OPTIONAL; default not used) |
74 | * @param string $align The image's alignment attribute value |
75 | * (OPTIONAL; default not used) |
76 | * @param string $hspace The image's hspace attribute value |
77 | * (OPTIONAL; default not used) |
78 | * @param string $vspace The image's vspace attribute value |
79 | * (OPTIONAL; default not used) |
bcc55e4b |
80 | * @param string $text_alternative A text replacement for the entire |
81 | * image tag, to be used at the |
82 | * discretion of the template set, |
83 | * if for some reason the image tag |
84 | * cannot or should not be produced |
85 | * (OPTIONAL; default not used) |
0173ad29 |
86 | * |
87 | * @return string The desired hyperlink tag. |
88 | * |
89 | * @since 1.5.2 |
90 | * |
91 | */ |
92 | function create_image($src, $alt='', $width='', $height='', |
93 | $border='', $class='', $id='', $onclick='', |
bcc55e4b |
94 | $title='', $align='', $hspace='', $vspace='', |
95 | $text_alternative='') { |
0173ad29 |
96 | |
97 | global $oTemplate; |
98 | |
99 | $oTemplate->assign('src', $src); |
100 | $oTemplate->assign('alt', $alt); |
101 | $oTemplate->assign('width', $width); |
102 | $oTemplate->assign('height', $height); |
103 | $oTemplate->assign('border', $border); |
104 | $oTemplate->assign('class', $class); |
105 | $oTemplate->assign('id', $id); |
106 | $oTemplate->assign('onclick', $onclick); |
107 | $oTemplate->assign('title', $title); |
108 | $oTemplate->assign('align', $align); |
109 | $oTemplate->assign('hspace', $hspace); |
110 | $oTemplate->assign('vspace', $vspace); |
bcc55e4b |
111 | $oTemplate->assign('text_alternative', $text_alternative); |
0173ad29 |
112 | |
113 | return $oTemplate->fetch('image.tpl'); |
114 | |
115 | } |
116 | |
117 | |
b0215f91 |
118 | /** |
119 | * Generates a span tag |
120 | * |
121 | * @param string $value The contents that belong inside the span |
122 | * @param string $class The CSS class name (OPTIONAL; default |
123 | * not used) |
124 | * @param string $id The ID name (OPTIONAL; default not used) |
125 | * |
126 | * @return string The desired span tag. |
127 | * |
128 | * @since 1.5.2 |
129 | * |
130 | */ |
131 | function create_span($value, $class='', $id='') { |
132 | |
133 | global $oTemplate; |
134 | |
135 | $oTemplate->assign('value', $value); |
136 | $oTemplate->assign('class', $class); |
137 | $oTemplate->assign('id', $id); |
138 | |
139 | return $oTemplate->fetch('span.tpl'); |
140 | |
141 | } |
142 | |
143 | |
d6c32258 |
144 | /** |
792f911e |
145 | * Generates html tags |
b0215f91 |
146 | //FIXME: this should not be used anywhere in the core, or we should |
147 | // convert this to use templates. We sould not be assuming HTML output. |
d6c32258 |
148 | * |
149 | * @param string $tag Tag to output |
150 | * @param string $val Value between tags |
151 | * @param string $align Alignment (left, center, etc) |
152 | * @param string $bgcolor Back color in hexadecimal |
153 | * @param string $xtra Extra options |
154 | * @return string HTML ready for output |
792f911e |
155 | * @since 1.3.0 |
d6c32258 |
156 | */ |
157 | function html_tag( $tag, // Tag to output |
d68323ff |
158 | $val = '', // Value between tags |
8008456a |
159 | $align = '', // Alignment |
160 | $bgcolor = '', // Back color |
161 | $xtra = '' ) { // Extra options |
892b98c9 |
162 | |
792f911e |
163 | GLOBAL $languages, $squirrelmail_language; |
892b98c9 |
164 | |
792f911e |
165 | $align = strtolower( $align ); |
166 | $bgc = ''; |
167 | $tag = strtolower( $tag ); |
892b98c9 |
168 | |
792f911e |
169 | if ( isset( $languages[$squirrelmail_language]['DIR']) ) { |
170 | $dir = $languages[$squirrelmail_language]['DIR']; |
171 | } else { |
172 | $dir = 'ltr'; |
173 | } |
892b98c9 |
174 | |
792f911e |
175 | if ( $dir == 'ltr' ) { |
176 | $rgt = 'right'; |
177 | $lft = 'left'; |
178 | } else { |
179 | $rgt = 'left'; |
180 | $lft = 'right'; |
181 | } |
892b98c9 |
182 | |
792f911e |
183 | if ( $bgcolor <> '' ) { |
184 | $bgc = " bgcolor=\"$bgcolor\""; |
185 | } |
892b98c9 |
186 | |
792f911e |
187 | switch ( $align ) { |
188 | case '': |
189 | $alg = ''; |
190 | break; |
191 | case 'right': |
192 | $alg = " align=\"$rgt\""; |
193 | break; |
194 | case 'left': |
195 | $alg = " align=\"$lft\""; |
196 | break; |
197 | default: |
198 | $alg = " align=\"$align\""; |
199 | break; |
200 | } |
892b98c9 |
201 | |
792f911e |
202 | $ret = "<$tag"; |
892b98c9 |
203 | |
792f911e |
204 | if ( $dir <> 'ltr' ) { |
205 | $ret .= " dir=\"$dir\""; |
206 | } |
207 | $ret .= $bgc . $alg; |
892b98c9 |
208 | |
792f911e |
209 | if ( $xtra <> '' ) { |
210 | $ret .= " $xtra"; |
211 | } |
892b98c9 |
212 | |
792f911e |
213 | if ( $val <> '' ) { |
214 | $ret .= ">$val</$tag>\n"; |
215 | } else { |
216 | $ret .= '>'. "\n"; |
94ac35c6 |
217 | } |
218 | |
792f911e |
219 | return( $ret ); |
220 | } |
892b98c9 |
221 | |
769a819d |
222 | |
792f911e |
223 | /** |
224 | * handy function to set url vars |
225 | * |
226 | * especially useful when $url = $PHP_SELF |
227 | * @param string $url url that must be modified |
228 | * @param string $var variable name |
229 | * @param string $val variable value |
230 | * @param boolean $link controls sanitizing of ampersand in urls (since 1.3.2) |
231 | * @return string $url modified url |
232 | * @since 1.3.0 |
233 | */ |
234 | function set_url_var($url, $var, $val=0, $link=true) { |
235 | $k = ''; |
236 | $pat_a = array ( |
237 | '/.+(\\&'.$var.')=(.*)\\&/AU', /* in the middle */ |
238 | '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */ |
239 | '/.+(\\?'.$var.')=(.*)$/AU', /* at front and only var */ |
240 | '/.+(\\&'.$var.')=(.*)$/AU' /* at the end */ |
241 | ); |
4f113ce5 |
242 | $url = str_replace('&','&',$url); |
792f911e |
243 | |
244 | // FIXME: why switch is used instead of if () or one preg_match() |
245 | switch (true) { |
246 | case (preg_match($pat_a[0],$url,$regs)): |
247 | $k = $regs[1]; |
248 | $v = $regs[2]; |
249 | break; |
250 | case (preg_match($pat_a[1],$url,$regs)): |
251 | $k = $regs[1]; |
252 | $v = $regs[2]; |
253 | break; |
254 | case (preg_match($pat_a[2],$url,$regs)): |
255 | $k = $regs[1]; |
256 | $v = $regs[2]; |
257 | break; |
258 | case (preg_match($pat_a[3],$url,$regs)): |
259 | $k = $regs[1]; |
260 | $v = $regs[2]; |
261 | break; |
262 | default: |
263 | if ($val) { |
264 | if (strpos($url,'?')) { |
265 | $url .= "&$var=$val"; |
892b98c9 |
266 | } else { |
792f911e |
267 | $url .= "?$var=$val"; |
892b98c9 |
268 | } |
792f911e |
269 | } |
270 | break; |
271 | } |
272 | |
273 | if ($k) { |
274 | if ($val) { |
275 | $rpl = "$k=$val"; |
792f911e |
276 | } else { |
277 | $rpl = ''; |
278 | } |
279 | if( substr($v,-1)=='&' ) { |
280 | $rpl .= '&'; |
02725e0b |
281 | } |
792f911e |
282 | $pat = "/$k=$v/"; |
283 | $url = preg_replace($pat,$rpl,$url); |
892b98c9 |
284 | } |
4f113ce5 |
285 | if ($link) { |
286 | $url = str_replace('&','&',$url); |
287 | } |
792f911e |
288 | return $url; |
289 | } |
769a819d |
290 | |
291 | |