Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.458 diff -u -r1.458 common.inc --- includes/common.inc 20 Jul 2005 10:48:20 -0000 1.458 +++ includes/common.inc 22 Jul 2005 03:08:25 -0000 @@ -509,6 +509,46 @@ } /** + * Recursively construct an equivalent URI string for an array. + * + * This function really shines for tablesorting and/or paging search results + * from a $_POST request. The only coding change involved for developers is to + * use $_REQUEST['edit'] and $_REQUEST['op'] instead of $_POST['edit'] and + * $_POST['op'] within the function callback. + * + * @param $array + * The array (can be multidimensional) to convert into an URI querystring. + * @param $current_key + * Used internally by the function to store the cumulative key values of + * each successive array. + * @return + * A string suitable for passing as an HTTP GET querystring for an URL. + */ +function array2uri($array, $current_key = '') { + $query_string = ''; + + foreach ($array as $key => $value) { + if (is_array($value)) { + $key_param = ($current_key) ? "${current_key}[$key]" : $key; + $query_string .= array2uri($value, $key_param); + } + elseif (is_scalar($value)) { + if ($current_key) { + $key_as_uri = "${current_key}[$key]"; + if (!strstr($query_string, $key_as_uri)) { + $query_string .= '&'. $key_as_uri. '='. urlencode($value); + } + } + else { + $query_string .= '&'. $key. '='. urlencode($value); + } + } + } + + return $query_string; +} + +/** * @} End of "Conversion". */ Index: includes/pager.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/pager.inc,v retrieving revision 1.44 diff -u -r1.44 pager.inc --- includes/pager.inc 25 May 2005 05:42:05 -0000 1.44 +++ includes/pager.inc 22 Jul 2005 03:08:25 -0000 @@ -388,13 +388,10 @@ $q = $_GET['q']; $page = array_key_exists('page', $_GET) ? $_GET['page'] : ''; - foreach ($attributes as $key => $value) { - $query[] = $key .'='. $value; - } - $page_new = pager_load_array($page_new[$element], $element, explode(',', $page)); + $query_string = array2uri($attributes); if (count($attributes)) { - $url = url($q, 'page='. implode($page_new, ',') .'&'. implode('&', $query)); + $url = url($q, 'page='. implode($page_new, ',') . $query_string); } else { $url = url($q, 'page='. implode($page_new, ',')); Index: includes/tablesort.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/tablesort.inc,v retrieving revision 1.34 diff -u -r1.34 tablesort.inc --- includes/tablesort.inc 2 Jul 2005 12:32:09 -0000 1.34 +++ includes/tablesort.inc 22 Jul 2005 03:08:25 -0000 @@ -136,12 +136,8 @@ function tablesort_get_querystring() { $cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST; $query_string = ''; - foreach ($cgi as $key => $val) { - if ($key != 'order' && $key != 'sort' && $key != 'q') { - $query_string .= '&'. $key .'='. $val; - } - } - return $query_string; + unset($cgi['order'], $cgi['sort'], $cgi['q']); + return array2uri($cgi); } /**