[wp-cvs] wordpress/wp-includes functions.php,1.198,1.199
Ryan Boren
rboren at users.sourceforge.net
Wed Oct 20 21:28:39 UTC 2004
Update of /cvsroot/cafelog/wordpress/wp-includes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14313/wp-includes
Modified Files:
functions.php
Log Message:
Introducing add_query_arg() and remove_query_arg(). Props: Owen Winkler.
Index: functions.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/functions.php,v
retrieving revision 1.198
retrieving revision 1.199
diff -C2 -d -r1.198 -r1.199
*** functions.php 20 Oct 2004 15:07:49 -0000 1.198
--- functions.php 20 Oct 2004 21:28:37 -0000 1.199
***************
*** 2246,2248 ****
--- 2246,2309 ----
}
+ /*
+ add_query_arg: Returns a modified querystring by adding
+ a single key & value or an associative array.
+ Setting a key value to emptystring removes the key.
+ Omitting oldquery_or_uri uses the $_SERVER value.
+
+ Parameters:
+ add_query_arg(newkey, newvalue, oldquery_or_uri) or
+ add_query_arg(associative_array, oldquery_or_uri)
+ */
+ function add_query_arg() {
+ $ret = '';
+ if(is_array(func_get_arg(0))) {
+ $uri = @func_get_arg(1);
+ }
+ else {
+ $uri = @func_get_arg(2);
+ }
+ if ('' == $uri) {
+ $uri = $_SERVER['REQUEST_URI'];
+ }
+ if (strstr($uri, '?')) {
+ $parts = explode('?', $uri, 2);
+ if (1 == count($parts)) {
+ $base = '?';
+ $query = $parts[0];
+ }
+ else {
+ $base = $parts[0] . '?';
+ $query = $parts[1];
+ }
+ }
+ else {
+ $base = $uri . '?';
+ $query = '';
+ }
+ parse_str($query, $qs);
+ if (is_array(func_get_arg(0))) {
+ $kayvees = func_get_arg(0);
+ $qs = array_merge($qs, $kayvees);
+ }
+ else
+ {
+ $qs[func_get_arg(0)] = func_get_arg(1);
+ }
+
+ foreach($qs as $k => $v)
+ {
+ if($v != '')
+ {
+ if($ret != '') $ret .= '&';
+ $ret .= "$k=$v";
+ }
+ }
+ $ret = $base . $ret;
+ return trim($ret, '?');
+ }
+
+ function remove_query_arg($key, $query) {
+ add_query_arg($key, '', $query);
+ }
?>
More information about the cvs
mailing list