summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc54
-rw-r--r--includes/pager.inc24
-rw-r--r--includes/tablesort.inc23
3 files changed, 68 insertions, 33 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 368aa64fe..263f01ac6 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -156,6 +156,46 @@ 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 .'['. urlencode($key) .']';
+ }
+ else {
+ $key = urlencode($key);
+ }
+
+ if (in_array(urldecode($key), $exclude)) {
+ continue;
+ }
+
+ if (is_array($value)) {
+ $params[] = drupal_query_string_encode($value, $exclude, $key);
+ }
+ else {
+ $params[] = $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 +211,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);
}
}
diff --git a/includes/pager.inc b/includes/pager.inc
index 80d80dd82..9f36f2ab8 100644
--- a/includes/pager.inc
+++ b/includes/pager.inc
@@ -84,6 +84,21 @@ function pager_query($query, $limit = 10, $element = 0, $count_query = NULL) {
}
/**
+ * Compose a query string to append to pager requests.
+ *
+ * @return
+ * A query string that consists of all components of the current page request
+ * except for those pertaining to paging.
+ */
+function pager_get_querystring() {
+ static $string = NULL;
+ if (!isset($string)) {
+ $string = drupal_query_string_encode($_REQUEST, array_merge(array('q', 'page'), array_keys($_COOKIE)));
+ }
+ return $string;
+}
+
+/**
* Format a query pager.
*
* Menu callbacks that display paged query results should call theme('pager') to
@@ -179,6 +194,7 @@ function theme_pager_previous($text, $limit, $element = 0, $interval = 1, $param
// 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);
@@ -357,8 +373,12 @@ function theme_pager_link($text, $page_new, $element, $parameters = array(), $at
}
$query = array();
- foreach ($parameters as $key => $value) {
- $query[] = $key .'='. $value;
+ if (count($parameters)) {
+ $query[] = drupal_query_string_encode($parameters, array());
+ }
+ $querystring = pager_get_querystring();
+ if ($querystring != '') {
+ $query[] = $querystring;
}
// Set each pager link title
diff --git a/includes/tablesort.inc b/includes/tablesort.inc
index 911afe88c..340caf4c0 100644
--- a/includes/tablesort.inc
+++ b/includes/tablesort.inc
@@ -20,18 +20,6 @@ function tablesort_init($header) {
}
/**
- * Fetch pager link arguments.
- *
- * When producing a sortable table that presents paged data, pass the output
- * of this function into theme('pager') to preserve the current sort order.
- */
-function tablesort_pager() {
- $cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST;
- unset($cgi['q'], $cgi['page']);
- return $cgi;
-}
-
-/**
* Create an SQL sort clause.
*
* This function produces the ORDER BY clause to insert in your SQL queries,
@@ -86,7 +74,7 @@ function tablesort_header($cell, $header, $ts) {
$ts['sort'] = 'asc';
$image = '';
}
- $cell['data'] = l($cell['data'] . $image, $_GET['q'], array('title' => $title), 'sort='. $ts['sort'] .'&order='. urlencode($cell['data']). $ts['query_string'], NULL, FALSE, TRUE);
+ $cell['data'] = l($cell['data'] . $image, $_GET['q'], array('title' => $title), 'sort='. $ts['sort'] .'&order='. urlencode($cell['data']) .'&'. $ts['query_string'], NULL, FALSE, TRUE);
unset($cell['field'], $cell['sort']);
}
@@ -134,14 +122,7 @@ function tablesort_cell($cell, $header, $ts, $i) {
* except for those pertaining to table sorting.
*/
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;
+ return drupal_query_string_encode($_REQUEST, array_merge(array('q', 'sort', 'order'), array_keys($_COOKIE)));
}
/**