6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * The idea is to inlcude here some functions to make easier
10 * the right to left implementation by "functionize" some
14 * @package squirrelmail
20 * @param string $tag Tag to output
21 * @param string $val Value between tags
22 * @param string $align Alignment (left, center, etc)
23 * @param string $bgcolor Back color in hexadecimal
24 * @param string $xtra Extra options
25 * @return string HTML ready for output
27 function html_tag( $tag, // Tag to output
28 $val = '', // Value between tags
29 $align = '', // Alignment
30 $bgcolor = '', // Back color
31 $xtra = '' ) { // Extra options
33 GLOBAL $languages, $squirrelmail_language;
35 $align = strtolower( $align );
37 $tag = strtolower( $tag );
39 if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
40 $dir = $languages[$squirrelmail_language]['DIR'];
45 if ( $dir == 'ltr' ) {
53 if ( $bgcolor <> '' ) {
54 $bgc = " bgcolor=\"$bgcolor\"";
62 $alg = " align=\"$rgt\"";
65 $alg = " align=\"$lft\"";
68 $alg = " align=\"$align\"";
74 if ( $dir <> 'ltr' ) {
75 $ret .= " dir=\"$dir\"";
84 $ret .= ">$val</$tag>\n";
92 /* handy function to set url vars */
93 /* especially usefull when $url = $PHP_SELF */
94 function set_url_var($url, $var, $val=0, $link=true) {
97 '/.+(\\&'.$var.')=(.*)\\&/AU', /* in the middle */
98 '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */
99 '/.+(\\?'.$var.')=(.*)$/AU', /* at front and only var */
100 '/.+(\\&'.$var.')=(.*)$/AU' /* at the end */
102 preg_replace('/&/','&',$url);
104 case (preg_match($pat_a[0],$url,$regs)):
108 case (preg_match($pat_a[1],$url,$regs)):
112 case (preg_match($pat_a[2],$url,$regs)):
116 case (preg_match($pat_a[3],$url,$regs)):
122 if (strpos($url,'?')) {
123 $url .= "&$var=$val";
125 $url .= "?$var=$val";
135 $rpl = preg_replace('/&/','&',$rpl);
140 if( substr($v,-1)=='&' ) {
144 $url = preg_replace($pat,$rpl,$url);
149 /* Temporary test function to proces template vars with formatting.
150 * I use it for viewing the message_header (view_header.php) with
151 * a sort of template.
153 function echo_template_var($var, $format_ar = array() ) {
154 $frm_last = count($format_ar) -1;
156 if (isset($format_ar[0])) echo $format_ar[0];
160 case (is_string($var)):
163 case (is_array($var)):
164 $frm_a = array_slice($format_ar,1,$frm_last-1);
165 foreach ($var as $a_el) {
166 if (is_array($a_el)) {
167 echo_template_var($a_el,$frm_a);
170 if (isset($format_ar[$i])) {
180 if (isset($format_ar[$frm_last]) && $frm_last>$i ) {
181 echo $format_ar[$frm_last];