Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.534 diff -u -F^f -r1.534 common.inc --- includes/common.inc 12 Apr 2006 08:42:47 -0000 1.534 +++ includes/common.inc 12 Apr 2006 19:16:48 -0000 @@ -156,6 +156,43 @@ function drupal_get_headers() { */ /** + * Parse an array into a valid urlencoded query string. + * + * @param $query + * The array to be processed e.g. $_GET + * @param $exclude + * The array filled with keys to be excluded. Use parent[child] to exclude nested items. + * @param $urlencode + * If TRUE, the keys and values are both urlencoded. + * @param $parent + * Should not be passed, only used in recursive calls + * @return + * urlencoded string which can be appended to/as the URL query string + */ +function drupal_query_string_encode($query, $exclude = array(), $parent = '') { + $params = array(); + + foreach ($query as $key => $value) { + if ($parent) { + $key = $parent .'['. $key .']'; + } + + if (in_array($key, $exclude)) { + continue; + } + + if (is_array($value)) { + $params[] = drupal_query_string_encode($value, $exclude, $key); + } + else { + $params[] = urlencode($key) .'='. urlencode($value); + } + } + + return implode('&', $params); +} + +/** * Prepare a destination query string for use in combination with * drupal_goto(). Used to direct the user back to the referring page * after completing a form. By default the current URL is returned. @@ -171,17 +208,11 @@ function drupal_get_destination() { } else { $path = $_GET['q']; - $params = array(); - foreach ($_GET as $key => $value) { - if ($key == 'q') { - continue; - } - $params[] = urlencode($key) .'='. urlencode($value); - } - if (count($params)) { - $path .= '?'; + $query = drupal_query_string_encode($_GET, array('q')); + if ($query != '') { + $path .= '?'. $query; } - return 'destination='. urlencode($path . implode('&', $params)); + return 'destination='. urlencode($path); } } Index: includes/pager.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/pager.inc,v retrieving revision 1.53 diff -u -F^f -r1.53 pager.inc --- includes/pager.inc 15 Jan 2006 16:55:35 -0000 1.53 +++ includes/pager.inc 12 Apr 2006 19:16:49 -0000 @@ -49,7 +49,7 @@ * @ingroup database */ function pager_query($query, $limit = 10, $element = 0, $count_query = NULL) { - global $pager_page_array, $pager_total, $pager_total_items; + global $pager_page_array, $pager_total, $pager_total_items, $pager_url_query; $page = isset($_GET['page']) ? $_GET['page'] : ''; // Substitute in query arguments. @@ -68,6 +68,9 @@ function pager_query($query, $limit = 10 // Convert comma-separated $page to an array, used by other functions. $pager_page_array = explode(',', $page); + // Generate the query to be appended to l() + $pager_url_query[$element] = drupal_query_string_encode($_GET, array('q', 'page')); + // We calculate the total of pages as ceil(items / limit). if (count($args)) { $pager_total_items[$element] = db_result(db_query($count_query, $args)); @@ -179,6 +182,7 @@ function theme_pager_previous($text, $li // If we are anywhere but the first page if ($pager_page_array[$element] > 0) { $page_new = pager_load_array($pager_page_array[$element] - $interval, $element, $pager_page_array); + // If the previous page is the first page, mark the link as such. if ($page_new[$element] == 0) { $output = theme('pager_first', $text, $limit, $element, $parameters); @@ -351,14 +355,18 @@ function theme_pager_list($limit, $eleme * An HTML string that generates the link. */ function theme_pager_link($text, $page_new, $element, $parameters = array(), $attributes = array()) { + global $pager_url_query; + $page = isset($_GET['page']) ? $_GET['page'] : ''; if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) { $parameters['page'] = $new_page; } $query = array(); - foreach ($parameters as $key => $value) { - $query[] = $key .'='. $value; + $query[] = drupal_query_string_encode($parameters, array()); + + if ($pager_url_query[$element] != '') { + $query[] = $pager_url_query[$element]; } // Set each pager link title Index: includes/tablesort.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/tablesort.inc,v retrieving revision 1.37 diff -u -F^f -r1.37 tablesort.inc --- includes/tablesort.inc 10 Dec 2005 19:26:47 -0000 1.37 +++ includes/tablesort.inc 12 Apr 2006 19:16:50 -0000 @@ -135,13 +135,13 @@ function tablesort_cell($cell, $header, */ 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; - } + $query_string = drupal_query_string_encode($cgi, array('q', 'order', 'sort')); + + if ($query_string != '') { + return '&'. $query_string; } - return $query_string; + + return ''; } /**