diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-01-31 00:00:43 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-01-31 00:00:43 +0000 |
commit | e3d22584664b28d31aa138f7b82554694254aae2 (patch) | |
tree | 2b300cceed68ad9a4bb4bb78bf029f393b8512b3 /engine | |
parent | f5f185ddd307d218cbfab4dd53ec540caf54205e (diff) | |
download | elgg-e3d22584664b28d31aa138f7b82554694254aae2.tar.gz elgg-e3d22584664b28d31aa138f7b82554694254aae2.tar.bz2 |
Fixes #959: Added elgg_http_remove_url_query_element() to remove a GET element instead of using faulty regexp.
git-svn-id: http://code.elgg.org/elgg/trunk@3866 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/elgglib.php | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 5c0f9aa2d..698a34b93 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -2462,15 +2462,23 @@ interface Friendable { } /** - * Rebuilds the parsed URL + * Rebuilds a parsed (partial) URL * * @param array $parts Associative array of URL components like parse_url() returns * @return str Full URL * @since 1.7 */ function elgg_http_build_url(array $parts) { - $port = (array_key_exists('port', $parts)) ? ":{$parts['port']}" : ''; - return "{$parts['scheme']}://{$parts['host']}{$port}{$parts['path']}?{$parts['query']}"; + // build only what's given to us. + $scheme = isset($parts['scheme']) ? "{$parts['scheme']}://" : ''; + $host = isset($parts['host']) ? "{$parts['host']}" : ''; + $port = isset($parts['port']) ? "{$parts['port']}" : ''; + $path = isset($parts['path']) ? "{$parts['path']}" : ''; + $query = isset($parts['query']) ? "?{$parts['query']}" : ''; + + $string = $scheme . $host . $port . $path . $query; + + return $string; } /** @@ -2503,6 +2511,33 @@ function elgg_validate_action_url($link) { } /** + * Removes a single elementry from a (partial) url query. + * + * @param string $url + * @param string $element + * @return string + */ +function elgg_http_remove_url_query_element($url, $element) { + $url = parse_url($url); + + if (isset($url['query'])) { + parse_str($url['query'], $query); + } else { + // nothing to remove. + return $url; + } + + if (array_key_exists($element, $query)) { + unset($query[$element]); + } + + $url['query'] = http_build_query($query); + $string = elgg_http_build_url($url); + return $string; +} + + +/** * Returns the PHP INI setting in bytes * * @param str $setting |