diff options
author | Gerhard Killesreiter <killes_www_drop_org@227.no-reply.drupal.org> | 2006-04-13 08:25:27 +0000 |
---|---|---|
committer | Gerhard Killesreiter <killes_www_drop_org@227.no-reply.drupal.org> | 2006-04-13 08:25:27 +0000 |
commit | d6a164c4008395e323ef8888a3c8867188f40d6b (patch) | |
tree | 490ba9b27d1241a595edc4ff055d77fdfced2420 /includes/common.inc | |
parent | bfb407601b73ccd6fbe79481dcc49517fcbdbe67 (diff) | |
download | brdo-d6a164c4008395e323ef8888a3c8867188f40d6b.tar.gz brdo-d6a164c4008395e323ef8888a3c8867188f40d6b.tar.bz2 |
#5371, drupal_get_destination, pager and tablesort array handling, patch by Steven
Diffstat (limited to 'includes/common.inc')
-rw-r--r-- | includes/common.inc | 54 |
1 files changed, 44 insertions, 10 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); } } |