Remove span tags from core
[squirrelmail.git] / functions / html.php
1 <?php
2
3 /**
4 * html.php
5 *
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 *
10 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @version $Id$
13 * @package squirrelmail
14 * @since 1.3.0
15 */
16
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 */
36 function 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
52 /**
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)
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)
83 *
84 * @return string The desired hyperlink tag.
85 *
86 * @since 1.5.2
87 *
88 */
89 function create_image($src, $alt='', $width='', $height='',
90 $border='', $class='', $id='', $onclick='',
91 $title='', $align='', $hspace='', $vspace='',
92 $text_alternative='') {
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);
108 $oTemplate->assign('text_alternative', $text_alternative);
109
110 return $oTemplate->fetch('image.tpl');
111
112 }
113
114
115 /**
116 * Generates a span tag
117 *
118 * @param string $value The contents that belong inside the span
119 * @param string $class The CSS class name (OPTIONAL; default
120 * not used)
121 * @param string $id The ID name (OPTIONAL; default not used)
122 *
123 * @return string The desired span tag.
124 *
125 * @since 1.5.2
126 *
127 */
128 function create_span($value, $class='', $id='') {
129
130 global $oTemplate;
131
132 $oTemplate->assign('value', $value);
133 $oTemplate->assign('class', $class);
134 $oTemplate->assign('id', $id);
135
136 return $oTemplate->fetch('span.tpl');
137
138 }
139
140
141 /**
142 * Generates html tags
143 //FIXME: this should not be used anywhere in the core, or we should
144 // convert this to use templates. We sould not be assuming HTML output.
145 *
146 * @param string $tag Tag to output
147 * @param string $val Value between tags
148 * @param string $align Alignment (left, center, etc)
149 * @param string $bgcolor Back color in hexadecimal
150 * @param string $xtra Extra options
151 * @return string HTML ready for output
152 * @since 1.3.0
153 */
154 function html_tag( $tag, // Tag to output
155 $val = '', // Value between tags
156 $align = '', // Alignment
157 $bgcolor = '', // Back color
158 $xtra = '' ) { // Extra options
159
160 GLOBAL $languages, $squirrelmail_language;
161
162 $align = strtolower( $align );
163 $bgc = '';
164 $tag = strtolower( $tag );
165
166 if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
167 $dir = $languages[$squirrelmail_language]['DIR'];
168 } else {
169 $dir = 'ltr';
170 }
171
172 if ( $dir == 'ltr' ) {
173 $rgt = 'right';
174 $lft = 'left';
175 } else {
176 $rgt = 'left';
177 $lft = 'right';
178 }
179
180 if ( $bgcolor <> '' ) {
181 $bgc = " bgcolor=\"$bgcolor\"";
182 }
183
184 switch ( $align ) {
185 case '':
186 $alg = '';
187 break;
188 case 'right':
189 $alg = " align=\"$rgt\"";
190 break;
191 case 'left':
192 $alg = " align=\"$lft\"";
193 break;
194 default:
195 $alg = " align=\"$align\"";
196 break;
197 }
198
199 $ret = "<$tag";
200
201 if ( $dir <> 'ltr' ) {
202 $ret .= " dir=\"$dir\"";
203 }
204 $ret .= $bgc . $alg;
205
206 if ( $xtra <> '' ) {
207 $ret .= " $xtra";
208 }
209
210 if ( $val <> '' ) {
211 $ret .= ">$val</$tag>\n";
212 } else {
213 $ret .= '>'. "\n";
214 }
215
216 return( $ret );
217 }
218
219
220 /**
221 * handy function to set url vars
222 *
223 * especially useful when $url = $PHP_SELF
224 * @param string $url url that must be modified
225 * @param string $var variable name
226 * @param string $val variable value
227 * @param boolean $link controls sanitizing of ampersand in urls (since 1.3.2)
228 * @return string $url modified url
229 * @since 1.3.0
230 */
231 function set_url_var($url, $var, $val=0, $link=true) {
232 $k = '';
233 $pat_a = array (
234 '/.+(\\&'.$var.')=(.*)\\&/AU', /* in the middle */
235 '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */
236 '/.+(\\?'.$var.')=(.*)$/AU', /* at front and only var */
237 '/.+(\\&'.$var.')=(.*)$/AU' /* at the end */
238 );
239 $url = str_replace('&amp;','&',$url);
240
241 // FIXME: why switch is used instead of if () or one preg_match()
242 switch (true) {
243 case (preg_match($pat_a[0],$url,$regs)):
244 $k = $regs[1];
245 $v = $regs[2];
246 break;
247 case (preg_match($pat_a[1],$url,$regs)):
248 $k = $regs[1];
249 $v = $regs[2];
250 break;
251 case (preg_match($pat_a[2],$url,$regs)):
252 $k = $regs[1];
253 $v = $regs[2];
254 break;
255 case (preg_match($pat_a[3],$url,$regs)):
256 $k = $regs[1];
257 $v = $regs[2];
258 break;
259 default:
260 if ($val) {
261 if (strpos($url,'?')) {
262 $url .= "&$var=$val";
263 } else {
264 $url .= "?$var=$val";
265 }
266 }
267 break;
268 }
269
270 if ($k) {
271 if ($val) {
272 $rpl = "$k=$val";
273 } else {
274 $rpl = '';
275 }
276 if( substr($v,-1)=='&' ) {
277 $rpl .= '&';
278 }
279 $pat = "/$k=$v/";
280 $url = preg_replace($pat,$rpl,$url);
281 }
282 if ($link) {
283 $url = str_replace('&','&amp;',$url);
284 }
285 return $url;
286 }
287
288