Skip to content

Instantly share code, notes, and snippets.

@pjbeardsley
Created July 11, 2012 14:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pjbeardsley/3090580 to your computer and use it in GitHub Desktop.
fPagination.php.patch
Index: fPagination.php
===================================================================
--- fPagination.php (revision 71)
+++ fPagination.php (working copy)
@@ -373,23 +373,44 @@
);
}
+ $size = self::$templates[$template]['size'];
if (self::$templates[$template]['type'] == 'without_first_last') {
- $start_page = max(1, $page - self::$templates[$template]['size']);
- $end_page = min($total_pages, $page + self::$templates[$template]['size']);
+ $start_page = max(1, $page - $size);
+ $end_page = min($total_pages, $page + $size);
} else {
$start_separator = TRUE;
- $start_page = $page - (self::$templates[$template]['size'] - 2);
+ $start_page = $page - ($size - 2);
if ($start_page <= 2) {
$start_separator = FALSE;
$start_page = 1;
}
+ $extra_end_pages = 0;
+ if ($page <= $size) {
+ $extra_end_pages = $size - $page + 1;
+ }
+
$end_separator = TRUE;
- $end_page = $page + (self::$templates[$template]['size'] - 2);
+ $end_page = $page + ($size - 2);
if ($end_page >= $total_pages - 1) {
$end_separator = FALSE;
$end_page = $total_pages;
}
+ $extra_start_pages = 0;
+ if ($page > $total_pages - $size) {
+ $extra_start_pages = $size - ($total_pages - $page);
+ }
+
+ $start_page -= $extra_start_pages;
+ if ($start_page <= 3) {
+ $start_separator = FALSE;
+ $start_page = 1;
+ }
+ $end_page += $extra_end_pages;
+ if ($end_page >= $total_pages - 2) {
+ $end_separator = FALSE;
+ $end_page = $total_pages;
+ }
}
if (self::$templates[$template]['type'] == 'with_first_last' && $start_separator) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment