summaryrefslogtreecommitdiff
path: root/lib/partials.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-12-10 15:09:47 +0500
committerilotterytea <iltsu@alright.party>2025-12-10 15:09:47 +0500
commit78ccc7e7db5fca5a1ff9bb63ef64b015f3afb1f3 (patch)
tree1954381e4fcdfc4c1ae02674524bdd8892dc1a38 /lib/partials.php
parent23da921c43b1c925710b55f93b87fef92dedd179 (diff)
feat: new pagination
Diffstat (limited to 'lib/partials.php')
-rw-r--r--lib/partials.php58
1 files changed, 47 insertions, 11 deletions
diff --git a/lib/partials.php b/lib/partials.php
index 2d6cd44..12aa23d 100644
--- a/lib/partials.php
+++ b/lib/partials.php
@@ -162,23 +162,59 @@ function html_navigation_search()
function html_pagination(int $total_pages, int $current_page, string $redirect)
{
+ if ($total_pages < 1) {
+ return;
+ }
+
if (str_contains($redirect, "?")) {
$redirect .= "&p=";
} else {
$redirect .= "?p=";
}
- if ($total_pages > 1) {
- echo '' ?>
- <div class="pagination">
- <?php if ($current_page > 1): ?>
- <a href="<?= $redirect . ($current_page - 1) ?>">[ prev ]</a>
- <?php endif; ?>
- <?php if ($current_page < $total_pages): ?>
- <a href="<?= $redirect . ($current_page + 1) ?>">[ next ]</a>
- <?php endif; ?>
+ echo '<div class="pagination">';
- </div>
- <?php ;
+ if ($current_page > 1) {
+ echo '<a href="' . $redirect . ($current_page - 1) . '">&lt;</a>';
+ }
+
+ echo "<a href='{$redirect}1'>" . ($current_page == 1 ? "<b>1</b>" : 1) . '</a>';
+
+ $max = 5;
+ $range = 2;
+
+ $start = max(2, $current_page - $range);
+ $end = min($total_pages - 1, $current_page + $range);
+
+ if ($current_page <= $range) {
+ $start = 2;
+ $end = min($total_pages - 1, $max);
+ }
+
+ if ($current_page > $total_pages - $range) {
+ $start = max(2, $total_pages - $max);
+ $end = $total_pages - 1;
+ }
+
+ if ($start > 2) {
+ echo '...';
}
+
+ for ($i = $start; $i <= $end; $i++) {
+ echo "<a href='{$redirect}$i'>";
+ echo $i == $current_page ? "<b>$i</b>" : $i;
+ echo '</a>';
+ }
+
+ if ($end < $total_pages - 1) {
+ echo '...';
+ }
+
+ echo "<a href='{$redirect}$total_pages'>" . ($current_page == $total_pages ? "<b>$total_pages</b>" : $total_pages) . '</a>';
+
+ if ($current_page < $total_pages) {
+ echo '<a href="' . $redirect . ($current_page + 1) . '">&gt;</a>';
+ }
+
+ echo '</div>';
} \ No newline at end of file