From 02725e0b9db8578b1b3389a2fb823106d603bc9c Mon Sep 17 00:00:00 2001 From: stekkel Date: Fri, 5 Jul 2002 10:40:30 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3032 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/html.php | 61 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/functions/html.php b/functions/html.php index 6666cd64..40799d2d 100644 --- a/functions/html.php +++ b/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 ); } -?> \ No newline at end of file + /* 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 "$pat , $rpl
"; + $url = preg_replace($pat,$rpl,$url); + } else { + $pat = "/$k=$v/"; + $url = preg_replace($pat,'',$url); + } + } + return preg_replace('/&/','&',$url); + } + +?> -- 2.25.1