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 a span tag
118 * @param string $value The contents that belong inside the span
119 * @param string $class The CSS class name (OPTIONAL; default
121 * @param string $id The ID name (OPTIONAL; default not used)
123 * @return string The desired span tag.
128 function create_span($value, $class='', $id='') {
132 $oTemplate->assign('value', $value);
133 $oTemplate->assign('class', $class);
134 $oTemplate->assign('id', $id);
136 return $oTemplate->fetch('span.tpl');
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.
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
154 function html_tag( $tag, // Tag to output
155 $val = '', // Value between tags
156 $align = '', // Alignment
157 $bgcolor = '', // Back color
158 $xtra = '' ) { // Extra options
160 GLOBAL $languages, $squirrelmail_language;
162 $align = strtolower( $align );
164 $tag = strtolower( $tag );
166 if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
167 $dir = $languages[$squirrelmail_language]['DIR'];
172 if ( $dir == 'ltr' ) {
180 if ( $bgcolor <> '' ) {
181 $bgc = " bgcolor=\"$bgcolor\"";
189 $alg = " align=\"$rgt\"";
192 $alg = " align=\"$lft\"";
195 $alg = " align=\"$align\"";
201 if ( $dir <> 'ltr' ) {
202 $ret .= " dir=\"$dir\"";
211 $ret .= ">$val</$tag>\n";
221 * handy function to set url vars
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
231 function set_url_var($url, $var, $val=0, $link=true) {
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 */
239 $url = str_replace('&','&',$url);
241 // FIXME: why switch is used instead of if () or one preg_match()
243 case (preg_match($pat_a[0],$url,$regs)):
247 case (preg_match($pat_a[1],$url,$regs)):
251 case (preg_match($pat_a[2],$url,$regs)):
255 case (preg_match($pat_a[3],$url,$regs)):
261 if (strpos($url,'?')) {
262 $url .= "&$var=$val";
264 $url .= "?$var=$val";
276 if( substr($v,-1)=='&' ) {
280 $url = preg_replace($pat,$rpl,$url);
283 $url = str_replace('&','&',$url);