瀏覽代碼

added function for setting the uri vars ([&\?] something=value.

By using $PHP_SELF and the specified var and value we no longer need to set
all the vars by hand. Just use this function and it only alters / remove the
specified var.
stekkel 23 年之前
父節點
當前提交
262e060dda
共有 1 個文件被更改,包括 59 次插入2 次删除
  1. 59 2
      functions/html.php

+ 59 - 2
functions/html.php

@@ -22,7 +22,7 @@
     	GLOBAL $languages, $squirrelmail_language;
     	
     	$align = strtolower( $align );
-    	$dir   = strtolower( $dir );
+    	$bgc = '';
     	$tag = strtoupper( $tag );
     	
     	if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
@@ -77,4 +77,61 @@
         return( $ret );
     }
 
-?>
+    /* handy function to set url vars */
+    /* especially usefull when $url = $PHP_SELF */
+    function set_url_var($url, $var, $val=0) {
+      $k = '';
+      $ret = '';
+      $url = trim(preg_replace('/&/','&',$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 */
+		     );
+      switch (true) {
+        case (preg_match($pat_a[0],$url,$regs)):
+          $k = $regs[1];
+          $v = $regs[2];
+	  break;
+        case (preg_match($pat_a[1],$url,$regs)):
+          $k = $regs[1];
+          $v = $regs[2];
+	  break;
+	case (preg_match($pat_a[2],$url,$regs)): 
+          $k = $regs[1];
+          $v = $regs[2];
+	  break;
+        case (preg_match($pat_a[3],$url,$regs)):
+          $k = $regs[1];
+          $v = $regs[2];
+	  break;
+	default:
+          if ($val) {
+            if (strpos($url,'?')) {
+           
+    $url .= "&$var=$val";
+	    } else {
+           
+   $url .= "?$var=$val";
+	    }   
+          }
+	  break;
+      }
+
+      if ($k) {
+        if ($val) {
+           $pat = "/$k=$v/";
+	   $rpl = "$k=$val";
+	   echo "<B>$pat , $rpl </b><BR>";
+           $url = preg_replace($pat,$rpl,$url);
+        } else {
+           $pat = "/$k=$v/";
+           $url = preg_replace($pat,'',$url);
+        }
+      }	
+      return  preg_replace('/&/','&amp;',$url);
+    } 
+
+?>