aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-02-05 03:20:27 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-02-05 03:20:27 +0000
commit2cd3ef9e9b25a9166b6c816d622f593a41256898 (patch)
treee1b9b947662080d6953513f6714e8a6abfd186f0
parente53bf6cc34137cee9bec69cbe5c35c3851567fe9 (diff)
downloadelgg-2cd3ef9e9b25a9166b6c816d622f593a41256898.tar.gz
elgg-2cd3ef9e9b25a9166b6c816d622f593a41256898.tar.bz2
Fixes #1481: Applie Mike's patch and created function elgg_http_add_url_query_elements() to handle what the pagination view was trying to do.
git-svn-id: http://code.elgg.org/elgg/trunk@3903 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--CHANGES.txt1
-rw-r--r--engine/lib/elgglib.php38
-rw-r--r--views/default/navigation/pagination.php29
-rw-r--r--views/default/river/item/list.php15
4 files changed, 43 insertions, 40 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index ca59f83f5..af93f9913 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -43,6 +43,7 @@ http://code.elgg.org/elgg/.....
* delete_relationship() triggers the hook delete:relationship and passes the relationship object. #1213
* added ElggEntity::removeRelationship(). #1376.
* get_entity_dates() supports order by. #1406.
+ * added elgg_http_add_url_query_elements().
Services API:
* Separated user and api authenticate processing
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 357141baa..76f8430b7 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -2576,12 +2576,12 @@ function elgg_validate_action_url($link) {
* @return string
*/
function elgg_http_remove_url_query_element($url, $element) {
- $url = parse_url($url);
+ $url_array = parse_url($url);
- if (isset($url['query'])) {
- parse_str($url['query'], $query);
+ if (isset($url_array['query'])) {
+ parse_str($url_array['query'], $query);
} else {
- // nothing to remove.
+ // nothing to remove. Return original URL.
return $url;
}
@@ -2589,13 +2589,39 @@ function elgg_http_remove_url_query_element($url, $element) {
unset($query[$element]);
}
- $url['query'] = http_build_query($query);
- $string = elgg_http_build_url($url);
+ $url_array['query'] = http_build_query($query);
+ $string = elgg_http_build_url($url_array);
return $string;
}
/**
+ * Adds get params to $url
+ *
+ * @param str $url
+ * @param array $elements k/v pairs.
+ * @return str
+ */
+function elgg_http_add_url_query_elements($url, array $elements) {
+ $url_array = parse_url($url);
+
+ if (isset($url_array['query'])) {
+ parse_str($url_array['query'], $query);
+ } else {
+ $query = array();
+ }
+
+ foreach ($elements as $k => $v) {
+ $query[$k] = $v;
+ }
+
+ $url_array['query'] = http_build_query($query);
+ $string = elgg_http_build_url($url_array);
+
+ 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 4e0682367..0512aada1 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 = elgg_http_remove_url_query_element($vars['baseurl'], $word);
+//$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') {
@@ -51,17 +51,13 @@ if (($count > $limit || $offset > 0) && get_context() != 'widget') {
if ($offset > 0) {
$prevoffset = $offset - $limit;
- if ($prevoffset < 0) $prevoffset = 0;
-
- $prevurl = $baseurl;
- if (substr_count($baseurl,'?')) {
- $prevurl .= "&{$word}=" . $prevoffset;
- } else {
- $prevurl .= "?{$word}=" . $prevoffset;
+ if ($prevoffset < 0) {
+ $prevoffset = 0;
}
- echo "<a href=\"{$prevurl}\" class=\"pagination_previous\">&laquo; ". elgg_echo("previous") ."</a> ";
+ $prevurl = elgg_http_add_url_query_elements($baseurl, array($word => $prevoffset));
+ echo "<a href=\"{$prevurl}\" class=\"pagination_previous\">&laquo; ". elgg_echo("previous") ."</a> ";
}
if ($offset > 0 || $offset < ($count - $limit)) {
@@ -98,13 +94,9 @@ if (($count > $limit || $offset > 0) && get_context() != 'widget') {
echo "<span class=\"pagination_more\">...</span>";
}
- $counturl = $baseurl;
$curoffset = (($i - 1) * $limit);
- if (substr_count($baseurl,'?')) {
- $counturl .= "&{$word}=" . $curoffset;
- } else {
- $counturl .= "?{$word}=" . $curoffset;
- }
+ $counturl = elgg_http_add_url_query_elements($base_url, array($word => $curoffset));
+
if ($curoffset != $offset) {
echo " <a href=\"{$counturl}\" class=\"pagination_number\">{$i}</a> ";
} else {
@@ -122,12 +114,7 @@ if (($count > $limit || $offset > 0) && get_context() != 'widget') {
$nextoffset--;
}
- $nexturl = $baseurl;
- if (substr_count($baseurl,'?')) {
- $nexturl .= "&{$word}=" . $nextoffset;
- } else {
- $nexturl .= "?{$word}=" . $nextoffset;
- }
+ $nexturl = elgg_http_add_url_query_elements($baseurl, array($word => $nextoffset));
echo " <a href=\"{$nexturl}\" class=\"pagination_next\">" . elgg_echo("next") . " &raquo;</a>";
diff --git a/views/default/river/item/list.php b/views/default/river/item/list.php
index f9d8dd283..8fcc84bea 100644
--- a/views/default/river/item/list.php
+++ b/views/default/river/item/list.php
@@ -26,18 +26,12 @@
if ($vars['pagination'] !== false) {
$baseurl = $_SERVER['REQUEST_URI'];
- $baseurl = elgg_http_remove_url_query_element($baseurl, 'offset');
$nav = '';
if (sizeof($vars['items']) > $vars['limit']) {
$newoffset = $vars['offset'] + $vars['limit'];
- $urladdition = 'offset='.$newoffset;
- if (substr_count($baseurl,'?')) {
- $nexturl = $baseurl . '&' . $urladdition;
- } else {
- $nexturl=$baseurl . '?' . $urladdition;
- }
+ $nexturl = elgg_http_add_url_query_elements($baseurl, array('offset' => $newoffset));
$nav .= '<a class="back" href="'.$nexturl.'">&laquo; ' . elgg_echo('previous') . '</a> ';
}
@@ -47,12 +41,7 @@
if ($newoffset < 0) {
$newoffset = 0;
}
- $urladdition = 'offset='.$newoffset;
- if (substr_count($baseurl,'?')) {
- $prevurl=$baseurl . '&' . $urladdition;
- } else {
- $prevurl=$baseurl . '?' . $urladdition;
- }
+ $prevurl = elgg_http_add_url_query_elements($baseurl, array('offset' => $newoffset));
$nav .= '<a class="forward" href="'.$prevurl.'">' . elgg_echo('next') . ' &raquo;</a> ';
}