6 * The idea is to inlcude here some functions to make easier
7 * the right to left implementation by "functionize" some
10 * @copyright © 1999-2006 The SquirrelMail Project Team
11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 * @package squirrelmail
19 * Generates a hyperlink
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;
27 * @param string $class The CSS class name (OPTIONAL; default
29 * @param string $id The ID name (OPTIONAL; default not used)
30 * @param string $name The anchor name (OPTIONAL; default not used)
31 * @param array $aAttribs Any extra attributes: this must be an
32 * associative array, where keys will be
33 * added as the attribute name, and values
34 * (which are optional - should be null if
35 * none should be used) will be placed in
36 * double quotes (pending template implementation)
37 * as the attribute value (OPTIONAL; default empty).
39 * @return string The desired hyperlink tag.
44 function create_hyperlink($uri, $text, $target='', $onclick='',
45 $class='', $id='', $name='', $aAttribs=array()) {
49 $oTemplate->assign('uri', $uri);
50 $oTemplate->assign('text', $text);
51 $oTemplate->assign('target', $target);
52 $oTemplate->assign('onclick', $onclick);
53 $oTemplate->assign('class', $class);
54 $oTemplate->assign('id', $id);
55 $oTemplate->assign('name', $name);
57 $oTemplate->assign('aAttribs', $aAttribs);
59 return $oTemplate->fetch('hyperlink.tpl');
65 * Generates an image tag
67 * @param string $src The image source path
68 * @param string $alt Alternate link text (OPTIONAL; default
70 * @param string $width The width the image should be shown in
71 * (OPTIONAL; default not used)
72 * @param string $height The height the image should be shown in
73 * (OPTIONAL; default not used)
74 * @param string $border The image's border attribute value
75 * (OPTIONAL; default not used)
76 * @param string $class The CSS class name (OPTIONAL; default
78 * @param string $id The ID name (OPTIONAL; default not used)
79 * @param string $onclick The onClick JavaScript handler (OPTIONAL;
81 * @param string $title The image's title attribute value
82 * (OPTIONAL; default not used)
83 * @param string $align The image's alignment attribute value
84 * (OPTIONAL; default not used)
85 * @param string $hspace The image's hspace attribute value
86 * (OPTIONAL; default not used)
87 * @param string $vspace The image's vspace attribute value
88 * (OPTIONAL; default not used)
89 * @param string $text_alternative A text replacement for the entire
90 * image tag, to be used at the
91 * discretion of the template set,
92 * if for some reason the image tag
93 * cannot or should not be produced
94 * (OPTIONAL; default not used)
95 * @param array $aAttribs Any extra attributes: this must be an
96 * associative array, where keys will be
97 * added as the attribute name, and values
98 * (which are optional - should be null if
99 * none should be used) will be placed in
100 * double quotes (pending template implementation)
101 * as the attribute value (OPTIONAL; default empty).
103 * @return string The desired hyperlink tag.
108 function create_image($src, $alt='', $width='', $height='',
109 $border='', $class='', $id='', $onclick='',
110 $title='', $align='', $hspace='', $vspace='',
111 $text_alternative='', $aAttribs=array()) {
115 $oTemplate->assign('src', $src);
116 $oTemplate->assign('alt', $alt);
117 $oTemplate->assign('width', $width);
118 $oTemplate->assign('height', $height);
119 $oTemplate->assign('border', $border);
120 $oTemplate->assign('class', $class);
121 $oTemplate->assign('id', $id);
122 $oTemplate->assign('onclick', $onclick);
123 $oTemplate->assign('title', $title);
124 $oTemplate->assign('align', $align);
125 $oTemplate->assign('hspace', $hspace);
126 $oTemplate->assign('vspace', $vspace);
127 $oTemplate->assign('text_alternative', $text_alternative);
129 $oTemplate->assign('aAttribs', $aAttribs);
131 return $oTemplate->fetch('image.tpl');
137 * Generates a label tag
139 * @param string $value The contents that belong inside the label
140 * @param string $for The ID to which the label applies (OPTIONAL;
142 * @param array $aAttribs Any extra attributes: this must be an
143 * associative array, where keys will be
144 * added as the attribute name, and values
145 * (which are optional - should be null if
146 * none should be used) will be placed in
147 * double quotes (pending template implementation)
148 * as the attribute value (OPTIONAL; default empty).
150 * @return string The desired label tag.
155 function create_label($value, $for='', $aAttribs=array()) {
159 $oTemplate->assign('text', $value);
160 $oTemplate->assign('for', $for);
162 $oTemplate->assign('aAttribs', $aAttribs);
164 return $oTemplate->fetch('label.tpl');
170 * Generates a span tag
172 * @param string $value The contents that belong inside the span
173 * @param string $class The CSS class name (OPTIONAL; default
175 * @param string $id The ID name (OPTIONAL; default not used)
176 * @param array $aAttribs Any extra attributes: this must be an
177 * associative array, where keys will be
178 * added as the attribute name, and values
179 * (which are optional - should be null if
180 * none should be used) will be placed in
181 * double quotes (pending template implementation)
182 * as the attribute value (OPTIONAL; default empty).
184 * @return string The desired span tag.
189 function create_span($value, $class='', $id='', $aAttribs=array()) {
193 $oTemplate->assign('value', $value);
194 $oTemplate->assign('class', $class);
195 $oTemplate->assign('id', $id);
197 $oTemplate->assign('aAttribs', $aAttribs);
199 return $oTemplate->fetch('span.tpl');
205 * Generates html tags
206 //FIXME: this should not be used anywhere in the core, or we should
207 // convert this to use templates. We sould not be assuming HTML output.
209 * @param string $tag Tag to output
210 * @param string $val Value between tags
211 * @param string $align Alignment (left, center, etc)
212 * @param string $bgcolor Back color in hexadecimal
213 * @param string $xtra Extra options
214 * @return string HTML ready for output
217 function html_tag( $tag, // Tag to output
218 $val = '', // Value between tags
219 $align = '', // Alignment
220 $bgcolor = '', // Back color
221 $xtra = '' ) { // Extra options
223 GLOBAL $languages, $squirrelmail_language;
225 $align = strtolower( $align );
227 $tag = strtolower( $tag );
229 if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
230 $dir = $languages[$squirrelmail_language]['DIR'];
235 if ( $dir == 'ltr' ) {
243 if ( $bgcolor <> '' ) {
244 $bgc = " bgcolor=\"$bgcolor\"";
252 $alg = " align=\"$rgt\"";
255 $alg = " align=\"$lft\"";
258 $alg = " align=\"$align\"";
264 if ( $dir <> 'ltr' ) {
265 $ret .= " dir=\"$dir\"";
274 $ret .= ">$val</$tag>\n";
284 * handy function to set url vars
286 * especially useful when $url = $PHP_SELF
287 * @param string $url url that must be modified
288 * @param string $var variable name
289 * @param string $val variable value
290 * @param boolean $link controls sanitizing of ampersand in urls (since 1.3.2)
291 * @return string $url modified url
294 function set_url_var($url, $var, $val=0, $link=true) {
297 '/.+(\\&'.$var.')=(.*)\\&/AU', /* in the middle */
298 '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */
299 '/.+(\\?'.$var.')=(.*)$/AU', /* at front and only var */
300 '/.+(\\&'.$var.')=(.*)$/AU' /* at the end */
302 $url = str_replace('&','&',$url);
304 // FIXME: why switch is used instead of if () or one preg_match()
306 case (preg_match($pat_a[0],$url,$regs)):
310 case (preg_match($pat_a[1],$url,$regs)):
314 case (preg_match($pat_a[2],$url,$regs)):
318 case (preg_match($pat_a[3],$url,$regs)):
324 if (strpos($url,'?')) {
325 $url .= "&$var=$val";
327 $url .= "?$var=$val";
339 if( substr($v,-1)=='&' ) {
343 $url = preg_replace($pat,$rpl,$url);
346 $url = str_replace('&','&',$url);