From 76853641f704914b0db2a7936e199d35d446b3fe Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 25 Nov 2006 07:10:08 +0000 Subject: [PATCH] r1325: Switch from our custom class_pagination.php to ISSO's Pagination framework --- includes/class_pagination.php | 262 ---------------------------------- includes/functions.php | 60 ++++++++ index.php | 13 +- search.php | 13 +- templates/pagenav.tpl | 8 +- templates/pagenav_bit.tpl | 2 +- 6 files changed, 77 insertions(+), 281 deletions(-) delete mode 100644 includes/class_pagination.php diff --git a/includes/class_pagination.php b/includes/class_pagination.php deleted file mode 100644 index 31cfe8f..0000000 --- a/includes/class_pagination.php +++ /dev/null @@ -1,262 +0,0 @@ -page = intval($bugsys->in["$page"]); - $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; - } - - if ($this->perpage <= 0) - { - $this->perpage = $bugsys->options['defaultpp']; - } - if ($this->perpage > $bugsys->options['maxpp']) - { - $this->perpage = $bugsys->options['maxpp']; - } - - $this->perpage = intval($this->perpage); - } - - /** - * Takes the variables and splits up the pages - * - * @access protected - */ - function split_pages() - { - $this->pagecount = ceil($this->total / $this->perpage); - if ($this->pagelinks == 0) - { - $this->pagelinks = $this->pagecount; - } - } - - /** - * Returns the lower limit of the pages - * - * @access public - * - * @param integer Page number - * - * @return integer Lower result limit - */ - function fetch_limit($page = null) - { - if ($page === null) - { - $page = $this->page; - } - - $limit = $page * $this->perpage; - - if ($page < 1) - { - $page = 1; - $limit = 0; - } - else if ($page > $this->pagecount) - { - $page = $this->pagecount - 1; - $limit = $this->total; - } - - if ($limit < 0) - { - return 0; - } - else if ($limit > $this->total) - { - return $this->total; - } - else - { - return $limit; - } - } - - /** - * Constructs the page navigator - * - * @access public - * - * @param string Base link path - * - * @return string Generated HTML page navigator - */ - 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) - { - $startpage = 1; - } - - // last page number in page nav - $endpage = $this->page + $this->pagelinks; - if ($endpage > $this->pagecount) - { - $endpage = $this->pagecount; - } - - // prev page in page nav - $prevpage = $this->page - 1; - if ($prevpage < 1) - { - $prevpage = 1; - } - - // next page in page nav - $nextpage = $this->page + 1; - if ($nextpage > $this->pagecount) - { - $nextpage = $this->pagecount; - } - - // show the prev page - $show['prev'] = true; - if ($this->page == $startpage) - { - $show['prev'] = false; - } - - // show the next page - $show['next'] = true; - if ($this->page == $endpage) - { - $show['next'] = false; - } - - // show the first page - $show['first'] = false; - if ($startpage > 1) - { - $show['first'] = true; - } - - // show the last page - $show['last'] = false; - if ($endpage < $this->pagecount) - { - $show['last'] = true; - } - - // construct the page bits - $pagebits = array(); - for ($i = $startpage; $i <= $endpage; $i++) - { - if ($i == $this->page) - { - $nolink = true; - } - else - { - $nolink = false; - } - eval('$pagebits[] .= "' . $bugsys->template->fetch('pagenav_bit') . '";'); - } - - $pagebits = implode(",\n", $pagebits); - - eval('$pagenav = "' . $bugsys->template->fetch('pagenav') . '";'); - - return $pagenav; - } -} - -/*=====================================================================*\ -|| ################################################################### -|| # $HeadURL$ -|| # $Id$ -|| ################################################################### -\*=====================================================================*/ -?> \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php index 7515f3b..d83ab7d 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -648,6 +648,66 @@ function ProcessBugDataForDisplay($bug, $color = '') return $bug; } +// ################################################################### +/** +* Loads the pagination module and sets all of the appropriate options +* for it +* +* @access public +*/ +function LoadPaginationFramework() +{ + global $bugsys; + + $bugsys->load('pagination', 'pagination', true); + $bugsys->pagination->setDefaultPerPage($bugsys->options['defaultpp']); + $bugsys->pagination->setMaxPerPage($bugsys->options['maxpp']); + $bugsys->pagination->setPageLinks($bugsys->options['pagelinks']); + $bugsys->pagination->setPageVar('p'); + $bugsys->pagination->setPerPageVar('pp'); + $bugsys->pagination->setBitProcessor('PageNavigatorBitCallback'); + $bugsys->pagination->setNavigatorProcessor('PageNavigatorCallback'); + $bugsys->pagination->processIncomingData(); +} + +// ################################################################### +/** +* Callback function for the Pagination->BitProcessor() +* +* @param string Base link +* @param bool Do not show this as a link +* @param integer Page number +* @param object Page navigator framework +* +* @return string Processed HTML +*/ +function PageNavigatorBitCallback($baselink, $nolink, $number, $paginator) +{ + global $bugsys; + eval('$return = "' . $bugsys->template->fetch('pagenav_bit') . '";'); + return $return; +} + +// ################################################################### +/** +* Callback function for the Pagination->NavigatorProcessor() +* +* @param string Base URL +* @param integer Next page number +* @param integer Previous page number +* @param array Show information +* @param string Individual page bits +* @param object Page navigator framework +* +* @return string Processed HTML +*/ +function PageNavigatorCallback($baselink, $nextpage, $prevpage, $show, $pagebits, $paginator) +{ + global $bugsys; + eval('$return = "' . $bugsys->template->fetch('pagenav') . '";'); + return $return; +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/index.php b/index.php index 9b8626a..654b05c 100644 --- a/index.php +++ b/index.php @@ -31,7 +31,6 @@ define('SVN', '$Id$'); $focus['index'] = 'focus'; require_once('./global.php'); -require_once('./includes/class_pagination.php'); require_once('./includes/class_sort.php'); if (!can_perform('canviewbugs')) @@ -40,10 +39,10 @@ if (!can_perform('canviewbugs')) } $sort = new ListSorter('index'); +LoadPaginationFramework(); // ################################################################### -$pagination = new Pagination('p', 'pp'); $count = $db->query_first(" SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "bug @@ -52,10 +51,10 @@ $count = $db->query_first(" AND status NOT IN (" . ($bugsys->userinfo['hidestatuses'] != '' ? $bugsys->userinfo['hidestatuses'] : $bugsys->options['hidestatuses']) . ")" : "") ); -$pagination->total = $count['count']; -$pagination->split_pages(); +$pagination->setTotal($count['count']); +$pagination->splitPages(); -$bugs_fetch = $db->query($sort->fetch_sql_query(null, $pagination->fetch_limit($pagination->page - 1) . ", " . $pagination->perpage)); +$bugs_fetch = $db->query($sort->fetch_sql_query(null, $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage())); while ($bug = $db->fetch_array($bugs_fetch)) { @@ -67,8 +66,8 @@ while ($bug = $db->fetch_array($bugs_fetch)) $db->free_result($bugs_fetch); $order = $sort->fetch_display_array('p=' . $pagination->page . '&pp=' . $pagination->perpage); -$show['pagenav'] = (($pagination->pagecount > 1) ? true : false); -$pagenav = $pagination->construct_page_nav($sort->fetch_sort_link($sort->sortkey)); +$show['pagenav'] = ($pagination->getPageCount() > 1); +$pagenav = $pagination->constructPageNav($sort->fetch_sort_link($sort->sortkey)); eval('$template->flush("' . $template->fetch('trackerhome') . '");'); diff --git a/search.php b/search.php index c90576e..00110db 100644 --- a/search.php +++ b/search.php @@ -33,7 +33,6 @@ $focus['search'] = 'focus'; require_once('./global.php'); require_once('./includes/functions_product.php'); -require_once('./includes/class_pagination.php'); if (!can_perform('cansearch')) { @@ -393,11 +392,11 @@ if ($_REQUEST['do'] == 'results') $hilight = $search['hilight']; } - $pagination = new Pagination('p', 'pp'); - $pagination->total = $search['resultcount']; - $pagination->split_pages(); + LoadPaginationFramework(); + $pagination->setTotal($search['resultcount']); + $pagination->splitPages(); - $search = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($search[ids]) $search[orderby] LIMIT " . $pagination->fetch_limit($pagination->page - 1) . ", " . $pagination->perpage); + $search = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($search[ids]) $search[orderby] LIMIT " . $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage()); while ($bug = $db->fetch_array($search)) { $funct->exec_swap_bg($stylevar['alt_color'], ''); @@ -406,8 +405,8 @@ if ($_REQUEST['do'] == 'results') eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";'); } - $show['pagenav'] = ($pagination->pagecount > 1 ? true : false); - $pagenav = $pagination->construct_page_nav('search.php'); + $show['pagenav'] = ($pagination->getPageCount() > 1); + $pagenav = $pagination->constructPageNav('search.php'); eval('$template->flush("' . $template->fetch('search_results') . '");'); } diff --git a/templates/pagenav.tpl b/templates/pagenav.tpl index 16ec9d3..9146ae9 100644 --- a/templates/pagenav.tpl +++ b/templates/pagenav.tpl @@ -1,7 +1,7 @@
- {@"First"} ... - {@"Prev"} ... + {@"First"} ... + {@"Prev"} ... $pagebits - ... {@"Next"} - ... {@"Last"} + ... {@"Next"} + ... {@"Last"}
\ No newline at end of file diff --git a/templates/pagenav_bit.tpl b/templates/pagenav_bit.tpl index d426aef..5febc85 100644 --- a/templates/pagenav_bit.tpl +++ b/templates/pagenav_bit.tpl @@ -1 +1 @@ - $i$i \ No newline at end of file + $number$number \ No newline at end of file -- 2.22.5