cfd0652a0d4b30f4ca93e4e7e85a967563c60eb1
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)
32 * @return string The desired hyperlink tag.
37 function create_hyperlink($uri, $text, $target='', $onclick='',
38 $class='', $id='', $name='') {
42 $oTemplate->assign('uri', $uri);
43 $oTemplate->assign('text', $text);
44 $oTemplate->assign('target', $target);
45 $oTemplate->assign('onclick', $onclick);
46 $oTemplate->assign('class', $class);
47 $oTemplate->assign('id', $id);
48 $oTemplate->assign('name', $name);
50 return $oTemplate->fetch('hyperlink.tpl');
56 * Generates an image tag
58 * @param string $src The image source path
59 * @param string $alt Alternate link text (OPTIONAL; default
61 * @param string $width The width the image should be shown in
62 * (OPTIONAL; default not used)
63 * @param string $height The height the image should be shown in
64 * (OPTIONAL; default not used)
65 * @param string $border The image's border attribute value
66 * (OPTIONAL; default not used)
67 * @param string $class The CSS class name (OPTIONAL; default
69 * @param string $id The ID name (OPTIONAL; default not used)
70 * @param string $onclick The onClick JavaScript handler (OPTIONAL;
72 * @param string $title The image's title attribute value
73 * (OPTIONAL; default not used)
74 * @param string $align The image's alignment attribute value
75 * (OPTIONAL; default not used)
76 * @param string $hspace The image's hspace attribute value
77 * (OPTIONAL; default not used)
78 * @param string $vspace The image's vspace attribute value
79 * (OPTIONAL; default not used)
80 * @param string $text_alternative A text replacement for the entire
81 * image tag, to be used at the
82 * discretion of the template set,
83 * if for some reason the image tag
84 * cannot or should not be produced
85 * (OPTIONAL; default not used)
87 * @return string The desired hyperlink tag.
92 function create_image($src, $alt='', $width='', $height='',
93 $border='', $class='', $id='', $onclick='',
94 $title='', $align='', $hspace='', $vspace='',
95 $text_alternative='') {
99 $oTemplate->assign('src', $src);
100 $oTemplate->assign('alt', $alt);
101 $oTemplate->assign('width', $width);
102 $oTemplate->assign('height', $height);
103 $oTemplate->assign('border', $border);
104 $oTemplate->assign('class', $class);
105 $oTemplate->assign('id', $id);
106 $oTemplate->assign('onclick', $onclick);
107 $oTemplate->assign('title', $title);
108 $oTemplate->assign('align', $align);
109 $oTemplate->assign('hspace', $hspace);
110 $oTemplate->assign('vspace', $vspace);
111 $oTemplate->assign('text_alternative', $text_alternative);
113 return $oTemplate->fetch('image.tpl');
119 * Generates a span tag
121 * @param string $value The contents that belong inside the span
122 * @param string $class The CSS class name (OPTIONAL; default
124 * @param string $id The ID name (OPTIONAL; default not used)
126 * @return string The desired span tag.
131 function create_span($value, $class='', $id='') {
135 $oTemplate->assign('value', $value);
136 $oTemplate->assign('class', $class);
137 $oTemplate->assign('id', $id);
139 return $oTemplate->fetch('span.tpl');
145 * Generates html tags
146 //FIXME: this should not be used anywhere in the core, or we should
147 // convert this to use templates. We sould not be assuming HTML output.
149 * @param string $tag Tag to output
150 * @param string $val Value between tags
151 * @param string $align Alignment (left, center, etc)
152 * @param string $bgcolor Back color in hexadecimal
153 * @param string $xtra Extra options
154 * @return string HTML ready for output
157 function html_tag( $tag, // Tag to output
158 $val = '', // Value between tags
159 $align = '', // Alignment
160 $bgcolor = '', // Back color
161 $xtra = '' ) { // Extra options
163 GLOBAL $languages, $squirrelmail_language;
165 $align = strtolower( $align );
167 $tag = strtolower( $tag );
169 if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
170 $dir = $languages[$squirrelmail_language]['DIR'];
175 if ( $dir == 'ltr' ) {
183 if ( $bgcolor <> '' ) {
184 $bgc = " bgcolor=\"$bgcolor\"";
192 $alg = " align=\"$rgt\"";
195 $alg = " align=\"$lft\"";
198 $alg = " align=\"$align\"";
204 if ( $dir <> 'ltr' ) {
205 $ret .= " dir=\"$dir\"";
214 $ret .= ">$val</$tag>\n";
224 * handy function to set url vars
226 * especially useful when $url = $PHP_SELF
227 * @param string $url url that must be modified
228 * @param string $var variable name
229 * @param string $val variable value
230 * @param boolean $link controls sanitizing of ampersand in urls (since 1.3.2)
231 * @return string $url modified url
234 function set_url_var($url, $var, $val=0, $link=true) {
237 '/.+(\\&'.$var.')=(.*)\\&/AU', /* in the middle */
238 '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */
239 '/.+(\\?'.$var.')=(.*)$/AU', /* at front and only var */
240 '/.+(\\&'.$var.')=(.*)$/AU' /* at the end */
242 $url = str_replace('&','&',$url);
244 // FIXME: why switch is used instead of if () or one preg_match()
246 case (preg_match($pat_a[0],$url,$regs)):
250 case (preg_match($pat_a[1],$url,$regs)):
254 case (preg_match($pat_a[2],$url,$regs)):
258 case (preg_match($pat_a[3],$url,$regs)):
264 if (strpos($url,'?')) {
265 $url .= "&$var=$val";
267 $url .= "?$var=$val";
279 if( substr($v,-1)=='&' ) {
283 $url = preg_replace($pat,$rpl,$url);
286 $url = str_replace('&','&',$url);