From dd32a174c311f33088e696c03a066ac33233065e Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 22 Aug 2005 00:43:27 +0000 Subject: [PATCH] r357: Completed pagination system --- includes/class_pagination.php | 74 +++++++++++++++++++++-------------- includes/settings.php | 8 ++++ templates/pagenav.tpl | 7 ++++ templates/pagenav_bit.tpl | 1 + 4 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 templates/pagenav.tpl create mode 100644 templates/pagenav_bit.tpl diff --git a/includes/class_pagination.php b/includes/class_pagination.php index 30bcb3e..81dee53 100644 --- a/includes/class_pagination.php +++ b/includes/class_pagination.php @@ -46,6 +46,12 @@ class Pagination */ var $pagecount; + /** + * Variable names + * @var array + */ + var $vars; + /** * Constructor: sanitize incoming variables * @@ -60,6 +66,8 @@ class Pagination $this->perpage = intval($bugsys->in["$perpage"]); $this->pagelinks = intval($bugsys->options['pagelinks']); + $this->vars = array('p' => $page, 'pp' => $perpage); + if ($this->page <= 0) { $this->page = 1; @@ -131,10 +139,24 @@ class Pagination * * @access public * + * @param string Base link path + * * @return string Generated HTML page navigator */ - function construct_page_nav() + function construct_page_nav($baselink) { + global $bugsys; + + // handle base link + if (strpos($baselink, '?') === false) + { + $baselink .= '?'; + } + else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink)) + { + $baselink .= '&'; + } + // first page number in page nav $startpage = $this->page - $this->pagelinks; if ($startpage < 1) @@ -164,60 +186,52 @@ class Pagination } // show the prev page - $doprev = true; + $show['prev'] = true; if ($this->page == $startpage) { - $doprev = false; + $show['prev'] = false; } // show the next page - $donext = true; + $show['next'] = true; if ($this->page == $endpage) { - $donext = false; + $show['next'] = false; } // show the first page - $dofirst = false; + $show['first'] = false; if ($startpage > 1) { - $dofirst = true; + $show['first'] = true; } // show the last page - $dolast = false; + $show['last'] = false; if ($endpage < $this->pagecount) { - $dolast = true; - } - - // add the special links - if ($dofirst) - { - $pages[] = 'first'; - } - if ($doprev) - { - $pages[] = 'prev'; + $show['last'] = true; } // construct the page bits for ($i = $startpage; $i <= $endpage; $i++) { - $pages[] = ($i == $this->page ? "$i" : $i); + if ($i == $this->page) + { + $nolink = true; + } + else + { + $nolink = false; + } + eval('$pagebits[] .= "' . $bugsys->template->fetch('pagenav_bit') . '";'); } - // last special links - if ($donext) - { - $pages[] = 'next'; - } - if ($dolast) - { - $pages[] = 'last'; - } + $pagebits = implode(",\n", $pagebits); + + eval('$pagenav = "' . $bugsys->template->fetch('pagenav') . '";'); - return $pages; + return $pagenav; } } diff --git a/includes/settings.php b/includes/settings.php index 6591803..c7f5120 100755 --- a/includes/settings.php +++ b/includes/settings.php @@ -52,6 +52,14 @@ $config['defaultcomment'] = array('reporting', 'defaultcomment', 'textarea', '' // ################################################################### +$define['pagination'] = 'pagination'; + +$config['defaultpp'] = array('pagination', 'defaultpp', 'textbox', 20, false); +$config['maxpp'] = array('pagination', 'maxpp', 'textbox', 100, false); +$config['pagelinks'] = array('pagination', 'pagelinks', 'textbox', 3, false); + +// ################################################################### + $define['untouchables'] = 'untouchables'; $config['trackerversion'] = array('untouchables', 'trackerversion', 'textbox', '', true); diff --git a/templates/pagenav.tpl b/templates/pagenav.tpl new file mode 100644 index 0000000..66b99ad --- /dev/null +++ b/templates/pagenav.tpl @@ -0,0 +1,7 @@ +
+ First ... + Prev ... +$pagebits + ... Next + ... Last +
\ No newline at end of file diff --git a/templates/pagenav_bit.tpl b/templates/pagenav_bit.tpl new file mode 100644 index 0000000..d426aef --- /dev/null +++ b/templates/pagenav_bit.tpl @@ -0,0 +1 @@ + $i$i \ No newline at end of file -- 2.22.5