summaryrefslogtreecommitdiffstats
path: root/web/lib/aur.inc.php
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2018-08-06 02:02:57 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2018-08-06 06:03:58 +0200
commit3578e77ad4e9258495eed7e786b7dc3aebcf1b63 (patch)
tree6261b4c66435d25ea10583c6a647d645e7182ed7 /web/lib/aur.inc.php
parenta7865ef5aa0309976b5dd2642210632babe106d9 (diff)
downloadaur-3578e77ad4e9258495eed7e786b7dc3aebcf1b63.tar.gz
aur-3578e77ad4e9258495eed7e786b7dc3aebcf1b63.tar.xz
Allow listing all comments from a user
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'web/lib/aur.inc.php')
-rw-r--r--web/lib/aur.inc.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php
index feb4006b..e9530fc0 100644
--- a/web/lib/aur.inc.php
+++ b/web/lib/aur.inc.php
@@ -705,3 +705,56 @@ function aur_location() {
}
return $location;
}
+
+/**
+ * Calculate pagination templates
+ *
+ * @return array The array of pagination templates, per page, and offset values
+ */
+function calculate_pagination($total_comment_count) {
+ /* Sanitize paging variables. */
+ if (isset($_GET["O"])) {
+ $_GET["O"] = max(intval($_GET["O"]), 0);
+ } else {
+ $_GET["O"] = 0;
+ }
+ $offset = $_GET["O"];
+
+ if (isset($_GET["PP"])) {
+ $_GET["PP"] = bound(intval($_GET["PP"]), 1, 250);
+ } else {
+ $_GET["PP"] = 10;
+ }
+ $per_page = $_GET["PP"];
+
+ // Page offsets start at zero, so page 2 has offset 1, which means that we
+ // need to add 1 to the offset to get the current page.
+ $current_page = ceil($offset / $per_page) + 1;
+ $num_pages = ceil($total_comment_count / $per_page);
+ $pagination_templs = array();
+
+ if ($current_page > 1) {
+ $previous_page = $current_page - 1;
+ $previous_offset = ($previous_page - 1) * $per_page;
+ $pagination_templs['&laquo; ' . __('First')] = 0;
+ $pagination_templs['&lsaquo; ' . __('Previous')] = $previous_offset;
+ }
+
+ if ($current_page - 5 > 1) {
+ $pagination_templs["..."] = false;
+ }
+
+ for ($i = max($current_page - 5, 1); $i <= min($num_pages, $current_page + 5); $i++) {
+ $pagination_templs[$i] = ($i - 1) * $per_page;
+ }
+
+ if ($current_page + 5 < $num_pages)
+ $pagination_templs["... "] = false;
+
+ if ($current_page < $num_pages) {
+ $pagination_templs[__('Next') . ' &rsaquo;'] = $current_page * $per_page;
+ $pagination_templs[__('Last') . ' &raquo;'] = ($num_pages - 1) * $per_page;
+ }
+
+ return array($pagination_templs, $per_page, $offset);
+}