aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/elgglib.php41
-rw-r--r--views/default/navigation/pagination.php2
-rw-r--r--views/default/navigation/viewtype.php2
-rw-r--r--views/default/river/item/list.php2
4 files changed, 41 insertions, 6 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
diff --git a/views/default/navigation/pagination.php b/views/default/navigation/pagination.php
index aec005eaf..4e0682367 100644
--- a/views/default/navigation/pagination.php
+++ b/views/default/navigation/pagination.php
@@ -38,7 +38,7 @@ if (isset($vars['nonefound'])) {
$totalpages = ceil($count / $limit);
$currentpage = ceil($offset / $limit) + 1;
-$baseurl = preg_replace('/[\&\?]'.$word.'\=[0-9]*/',"",$vars['baseurl']);
+$baseurl = elgg_http_remove_url_query_element($vars['baseurl'], $word);
//only display if there is content to paginate through or if we already have an offset
if (($count > $limit || $offset > 0) && get_context() != 'widget') {
diff --git a/views/default/navigation/viewtype.php b/views/default/navigation/viewtype.php
index fcea39b61..6366ebc04 100644
--- a/views/default/navigation/viewtype.php
+++ b/views/default/navigation/viewtype.php
@@ -8,7 +8,7 @@
* @link http://elgg.org/
*/
-$baseurl = preg_replace('/[\&\?]search\_viewtype\=[A-Za-z0-9]*/',"",$vars['baseurl']);
+$baseurl = elgg_http_remove_url_query_element($vars['baseurl'], 'search_viewtype');
if ($vars['viewtype'] == "list") {
$viewtype = "gallery";
diff --git a/views/default/river/item/list.php b/views/default/river/item/list.php
index 9508a0da6..f9d8dd283 100644
--- a/views/default/river/item/list.php
+++ b/views/default/river/item/list.php
@@ -26,7 +26,7 @@
if ($vars['pagination'] !== false) {
$baseurl = $_SERVER['REQUEST_URI'];
- $baseurl = $baseurl = preg_replace('/[\&\?]offset\=[0-9]*/',"",$baseurl);
+ $baseurl = elgg_http_remove_url_query_element($baseurl, 'offset');
$nav = '';