Replacing tabs with spaces, trimming white space at EOL and newline at EOF
[squirrelmail.git] / functions / html.php
index d49617344cb85cee6cab339d66a93e941069c592..747d68ede2c347859388d01c56cbd45242efb329 100644 (file)
@@ -3,18 +3,29 @@
 /**
  * html.php
  *
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Copyright (c) 1999-2004 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * The idea is to inlcude here some functions to make easier
  * the right to left implementation by "functionize" some
  * html outputs.
  *
- * $Id$
+ * @version $Id$
+ * @package squirrelmail
  */
 
-    function html_tag( $tag,                // Tag to output
-                       $val = '',           // Value between tags (if empty only start tag is issued)
+/**
+ * Generate html tags
+ *
+ * @param string $tag Tag to output
+ * @param string $val Value between tags
+ * @param string $align Alignment (left, center, etc)
+ * @param string $bgcolor Back color in hexadecimal
+ * @param string $xtra Extra options
+ * @return string HTML ready for output
+ */
+function html_tag( $tag,                // Tag to output
+                       $val = '',           // Value between tags
                        $align = '',         // Alignment
                        $bgcolor = '',       // Back color
                        $xtra = '' ) {       // Extra options
 
         $align = strtolower( $align );
         $bgc = '';
-        $tag = strtoupper( $tag );
+        $tag = strtolower( $tag );
 
         if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
-        $dir = $languages[$squirrelmail_language]['DIR'];
+            $dir = $languages[$squirrelmail_language]['DIR'];
         } else {
             $dir = 'ltr';
         }
@@ -40,7 +51,7 @@
         }
 
         if ( $bgcolor <> '' ) {
-            $bgc = " BGCOLOR=\"$bgcolor\""; 
+            $bgc = " bgcolor=\"$bgcolor\"";
         }
 
         switch ( $align ) {
                 $alg = '';
                 break;
             case 'right':
-                $alg = " ALIGN=\"$rgt\"";
+                $alg = " align=\"$rgt\"";
                 break;
             case 'left':
-                $alg = " ALIGN=\"$lft\"";
+                $alg = " align=\"$lft\"";
                 break;
             default:
-                $alg = " ALIGN=\"$align\"";
+                $alg = " align=\"$align\"";
                 break;
         }
 
         $ret = "<$tag";
 
         if ( $dir <> 'ltr' ) {
-            $ret .= " DIR=\"$dir\"";
+            $ret .= " dir=\"$dir\"";
         }
-        $ret .= "$bgc$alg";
+        $ret .= $bgc . $alg;
 
         if ( $xtra <> '' ) {
             $ret .= " $xtra";
         }
-        $ret .= '>';
 
         if ( $val <> '' ) {
-            $ret .= "$val</$tag>";
+            $ret .= ">$val</$tag>";
+        } else {
+            $ret .= '>';
         }
 
         return( $ret );
 
     /* handy function to set url vars */
     /* especially usefull when $url = $PHP_SELF */
-    function set_url_var($url, $var, $val=0) {
+    function set_url_var($url, $var, $val=0, $link=true) {
         $k = '';
-        $ret = '';
-        $url = trim(preg_replace('/&amp;/','&',$url));
-
         $pat_a = array (
                        '/.+(\\&'.$var.')=(.*)\\&/AU',   /* in the middle */
                        '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */
                        '/.+(\\?'.$var.')=(.*)$/AU',     /* at front and only var */
                        '/.+(\\&'.$var.')=(.*)$/AU'      /* at the end */
                      );
+        preg_replace('/&amp;/','&',$url);
         switch (true) {
             case (preg_match($pat_a[0],$url,$regs)):
                 $k = $regs[1];
         if ($k) {
             if ($val) {
                 $rpl = "$k=$val";
+                if ($link) {
+                    $rpl = preg_replace('/&/','&amp;',$rpl);
+                }
             } else {
                 $rpl = '';
             }
             $pat = "/$k=$v/";
             $url = preg_replace($pat,$rpl,$url);
         }
-        return  preg_replace('/&/','&amp;',$url);
+        return $url;
     }
 
     /* Temporary test function to proces template vars with formatting.
     function echo_template_var($var, $format_ar = array() ) {
         $frm_last = count($format_ar) -1;
 
-        if (isset($format_ar[0])) echo $format_ar[0]; 
+        if (isset($format_ar[0])) echo $format_ar[0];
             $i = 1;
 
         switch (true) {
             echo $format_ar[$frm_last];
         }
     }
-?>
+?>
\ No newline at end of file