Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.460 diff -u -r1.460 common.inc --- includes/common.inc 25 Jul 2005 20:40:35 -0000 1.460 +++ includes/common.inc 26 Jul 2005 16:56:04 -0000 @@ -153,7 +153,7 @@ $destination[] = "$param=". $_GET[$param]; } } - return 'destination='. urlencode(implode('&', $destination)); + return 'destination='. array2uri($destination); } } @@ -509,6 +509,44 @@ } /** + * Recursively construct an URI string from an array. + * + * The main purpose of this function was to allow search results to be paged + * and tablesorted. The only coding change involved for developers is to + * use $_REQUEST['edit'] and $_REQUEST['op'] instead of $_POST['edit'] and + * $_POST['op'] within your controller function. + * + * @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) && !$current_key) { + $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]"; + $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 26 Jul 2005 16:56:04 -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.35 diff -u -r1.35 tablesort.inc --- includes/tablesort.inc 25 Jul 2005 20:38:30 -0000 1.35 +++ includes/tablesort.inc 26 Jul 2005 16:56:04 -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); } /**