Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.466 diff -u -r1.466 common.inc --- includes/common.inc 11 Aug 2005 12:57:41 -0000 1.466 +++ includes/common.inc 13 Aug 2005 18:28:12 -0000 @@ -143,17 +143,17 @@ */ function drupal_get_destination() { if ($_REQUEST['destination']) { - return 'destination='. urlencode($_REQUEST['destination']); + return array2uri(array('destination' => $_REQUEST['destination'])); } else { $destination[] = $_GET['q']; $params = array('page', 'sort', 'order'); foreach ($params as $param) { if (isset($_GET[$param])) { - $destination[] = "$param=". $_GET[$param]; + $destination[$param] = $_GET[$param]; } } - return 'destination='. urlencode(implode('&', $destination)); + return array2uri(array('destination' => $destination)); } } @@ -509,6 +509,49 @@ } /** + * 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 $to_uri + * A string or array to convert into an URI querystring. The array can be + * multidimensional. + * @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($to_uri, $current_key = '') { + $query_string = ''; + + if (!is_array($to_uri)) { + return (isset($to_uri) ? '&'. $to_uri : NULL); + } + + foreach ($to_uri 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.46 diff -u -r1.46 pager.inc --- includes/pager.inc 10 Aug 2005 20:50:14 -0000 1.46 +++ includes/pager.inc 13 Aug 2005 18:28:12 -0000 @@ -359,17 +359,9 @@ $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)); - if (count($attributes)) { - $url = url($q, 'page='. implode(',', $page_new) .'&'. implode('&', $query)); - } - else { - $url = url($q, 'page='. implode(',', $page_new)); - } + $query_string = array2uri($attributes); + $url = url($q, 'page='. implode($page_new, ',') . $query_string); return ''. check_plain($text) .''; } 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 13 Aug 2005 18:28:12 -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); } /**