Doc update... needs to be finished
[squirrelmail.git] / functions / html.php
CommitLineData
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 &copy; 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)
30 *
31 * @return string The desired hyperlink tag.
32 *
33 * @since 1.5.2
34 *
35 */
36function create_hyperlink($uri, $text, $target='', $onclick='', $class='', $id='') {
37
38 global $oTemplate;
39
40 $oTemplate->assign('uri', $uri);
41 $oTemplate->assign('text', $text);
42 $oTemplate->assign('target', $target);
43 $oTemplate->assign('onclick', $onclick);
44 $oTemplate->assign('class', $class);
45 $oTemplate->assign('id', $id);
46
47 return $oTemplate->fetch('hyperlink.tpl');
48
49}
50
51
d6c32258 52/**
0173ad29 53 * Generates an image tag
54 *
55 * @param string $src The image source path
56 * @param string $alt Alternate link text (OPTIONAL; default
57 * not used)
58 * @param string $width The width the image should be shown in
59 * (OPTIONAL; default not used)
60 * @param string $height The height the image should be shown in
61 * (OPTIONAL; default not used)
62 * @param string $border The image's border attribute value
63 * (OPTIONAL; default not used)
64 * @param string $class The CSS class name (OPTIONAL; default
65 * not used)
66 * @param string $id The ID name (OPTIONAL; default not used)
67 * @param string $onclick The onClick JavaScript handler (OPTIONAL;
68 * default not used)
69 * @param string $title The image's title attribute value
70 * (OPTIONAL; default not used)
71 * @param string $align The image's alignment attribute value
72 * (OPTIONAL; default not used)
73 * @param string $hspace The image's hspace attribute value
74 * (OPTIONAL; default not used)
75 * @param string $vspace The image's vspace attribute value
76 * (OPTIONAL; default not used)
bcc55e4b 77 * @param string $text_alternative A text replacement for the entire
78 * image tag, to be used at the
79 * discretion of the template set,
80 * if for some reason the image tag
81 * cannot or should not be produced
82 * (OPTIONAL; default not used)
0173ad29 83 *
84 * @return string The desired hyperlink tag.
85 *
86 * @since 1.5.2
87 *
88 */
89function create_image($src, $alt='', $width='', $height='',
90 $border='', $class='', $id='', $onclick='',
bcc55e4b 91 $title='', $align='', $hspace='', $vspace='',
92 $text_alternative='') {
0173ad29 93
94 global $oTemplate;
95
96 $oTemplate->assign('src', $src);
97 $oTemplate->assign('alt', $alt);
98 $oTemplate->assign('width', $width);
99 $oTemplate->assign('height', $height);
100 $oTemplate->assign('border', $border);
101 $oTemplate->assign('class', $class);
102 $oTemplate->assign('id', $id);
103 $oTemplate->assign('onclick', $onclick);
104 $oTemplate->assign('title', $title);
105 $oTemplate->assign('align', $align);
106 $oTemplate->assign('hspace', $hspace);
107 $oTemplate->assign('vspace', $vspace);
bcc55e4b 108 $oTemplate->assign('text_alternative', $text_alternative);
0173ad29 109
110 return $oTemplate->fetch('image.tpl');
111
112}
113
114
115/**
792f911e 116 * Generates html tags
d6c32258 117 *
118 * @param string $tag Tag to output
119 * @param string $val Value between tags
120 * @param string $align Alignment (left, center, etc)
121 * @param string $bgcolor Back color in hexadecimal
122 * @param string $xtra Extra options
123 * @return string HTML ready for output
792f911e 124 * @since 1.3.0
d6c32258 125 */
126function html_tag( $tag, // Tag to output
d68323ff 127 $val = '', // Value between tags
8008456a 128 $align = '', // Alignment
129 $bgcolor = '', // Back color
130 $xtra = '' ) { // Extra options
892b98c9 131
792f911e 132 GLOBAL $languages, $squirrelmail_language;
892b98c9 133
792f911e 134 $align = strtolower( $align );
135 $bgc = '';
136 $tag = strtolower( $tag );
892b98c9 137
792f911e 138 if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
139 $dir = $languages[$squirrelmail_language]['DIR'];
140 } else {
141 $dir = 'ltr';
142 }
892b98c9 143
792f911e 144 if ( $dir == 'ltr' ) {
145 $rgt = 'right';
146 $lft = 'left';
147 } else {
148 $rgt = 'left';
149 $lft = 'right';
150 }
892b98c9 151
792f911e 152 if ( $bgcolor <> '' ) {
153 $bgc = " bgcolor=\"$bgcolor\"";
154 }
892b98c9 155
792f911e 156 switch ( $align ) {
157 case '':
158 $alg = '';
159 break;
160 case 'right':
161 $alg = " align=\"$rgt\"";
162 break;
163 case 'left':
164 $alg = " align=\"$lft\"";
165 break;
166 default:
167 $alg = " align=\"$align\"";
168 break;
169 }
892b98c9 170
792f911e 171 $ret = "<$tag";
892b98c9 172
792f911e 173 if ( $dir <> 'ltr' ) {
174 $ret .= " dir=\"$dir\"";
175 }
176 $ret .= $bgc . $alg;
892b98c9 177
792f911e 178 if ( $xtra <> '' ) {
179 $ret .= " $xtra";
180 }
892b98c9 181
792f911e 182 if ( $val <> '' ) {
183 $ret .= ">$val</$tag>\n";
184 } else {
185 $ret .= '>'. "\n";
94ac35c6 186 }
187
792f911e 188 return( $ret );
189}
892b98c9 190
769a819d 191
792f911e 192/**
193 * handy function to set url vars
194 *
195 * especially useful when $url = $PHP_SELF
196 * @param string $url url that must be modified
197 * @param string $var variable name
198 * @param string $val variable value
199 * @param boolean $link controls sanitizing of ampersand in urls (since 1.3.2)
200 * @return string $url modified url
201 * @since 1.3.0
202 */
203function set_url_var($url, $var, $val=0, $link=true) {
204 $k = '';
205 $pat_a = array (
206 '/.+(\\&'.$var.')=(.*)\\&/AU', /* in the middle */
207 '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */
208 '/.+(\\?'.$var.')=(.*)$/AU', /* at front and only var */
209 '/.+(\\&'.$var.')=(.*)$/AU' /* at the end */
210 );
4f113ce5 211 $url = str_replace('&amp;','&',$url);
792f911e 212
213 // FIXME: why switch is used instead of if () or one preg_match()
214 switch (true) {
215 case (preg_match($pat_a[0],$url,$regs)):
216 $k = $regs[1];
217 $v = $regs[2];
218 break;
219 case (preg_match($pat_a[1],$url,$regs)):
220 $k = $regs[1];
221 $v = $regs[2];
222 break;
223 case (preg_match($pat_a[2],$url,$regs)):
224 $k = $regs[1];
225 $v = $regs[2];
226 break;
227 case (preg_match($pat_a[3],$url,$regs)):
228 $k = $regs[1];
229 $v = $regs[2];
230 break;
231 default:
232 if ($val) {
233 if (strpos($url,'?')) {
234 $url .= "&$var=$val";
892b98c9 235 } else {
792f911e 236 $url .= "?$var=$val";
892b98c9 237 }
792f911e 238 }
239 break;
240 }
241
242 if ($k) {
243 if ($val) {
244 $rpl = "$k=$val";
792f911e 245 } else {
246 $rpl = '';
247 }
248 if( substr($v,-1)=='&' ) {
249 $rpl .= '&';
02725e0b 250 }
792f911e 251 $pat = "/$k=$v/";
252 $url = preg_replace($pat,$rpl,$url);
892b98c9 253 }
4f113ce5 254 if ($link) {
255 $url = str_replace('&','&amp;',$url);
256 }
792f911e 257 return $url;
258}
769a819d 259
260