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)
31 * @return string The desired hyperlink tag.
36 function create_hyperlink($uri, $text, $target='', $onclick='', $class='', $id='') {
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);
47 return $oTemplate->fetch('hyperlink.tpl');
53 * Generates an image tag
55 * @param string $src The image source path
56 * @param string $alt Alternate link text (OPTIONAL; default
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
66 * @param string $id The ID name (OPTIONAL; default not used)
67 * @param string $onclick The onClick JavaScript handler (OPTIONAL;
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)
84 * @return string The desired hyperlink tag.
89 function create_image($src, $alt='', $width='', $height='',
90 $border='', $class='', $id='', $onclick='',
91 $title='', $align='', $hspace='', $vspace='',
92 $text_alternative='') {
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);
110 return $oTemplate->fetch('image.tpl');
116 * Generates html tags
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
126 function html_tag( $tag, // Tag to output
127 $val = '', // Value between tags
128 $align = '', // Alignment
129 $bgcolor = '', // Back color
130 $xtra = '' ) { // Extra options
132 GLOBAL $languages, $squirrelmail_language;
134 $align = strtolower( $align );
136 $tag = strtolower( $tag );
138 if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
139 $dir = $languages[$squirrelmail_language]['DIR'];
144 if ( $dir == 'ltr' ) {
152 if ( $bgcolor <> '' ) {
153 $bgc = " bgcolor=\"$bgcolor\"";
161 $alg = " align=\"$rgt\"";
164 $alg = " align=\"$lft\"";
167 $alg = " align=\"$align\"";
173 if ( $dir <> 'ltr' ) {
174 $ret .= " dir=\"$dir\"";
183 $ret .= ">$val</$tag>\n";
193 * handy function to set url vars
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
203 function set_url_var($url, $var, $val=0, $link=true) {
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 */
211 $url = str_replace('&','&',$url);
213 // FIXME: why switch is used instead of if () or one preg_match()
215 case (preg_match($pat_a[0],$url,$regs)):
219 case (preg_match($pat_a[1],$url,$regs)):
223 case (preg_match($pat_a[2],$url,$regs)):
227 case (preg_match($pat_a[3],$url,$regs)):
233 if (strpos($url,'?')) {
234 $url .= "&$var=$val";
236 $url .= "?$var=$val";
248 if( substr($v,-1)=='&' ) {
252 $url = preg_replace($pat,$rpl,$url);
255 $url = str_replace('&','&',$url);