From 27d8aef528460e87efc90bc4fffc82c0d1fa87d9 Mon Sep 17 00:00:00 2001 From: Drae Date: Sun, 8 Jul 2012 21:07:28 +0100 Subject: [feature/pagination-as-list] Updates for nils comments Re-remove deprecated functions, change on_page to phpbb_on_page, add null returns, remove globals and pass as params. PHPBB3-10968 --- phpBB/includes/functions.php | 107 +++---------------------------------------- 1 file changed, 7 insertions(+), 100 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 91c2242d4f..8c740edbfd 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1880,102 +1880,11 @@ function tracking_unserialize($string, $max_depth = 3) // Pagination functions -/** -* Pagination routine, generates page number sequence -* To generate pagination which is rendered fully within the template use phpbb_generate_template_pagination -* -* @param string $base_url the base url is prepended to all links generated within the function -* @param int $num_items the total number of items, posts, topics, etc., used to determine the number of pages to produce -* @param int $per_page the number of items, posts, topics, etc. to display per page, used to determine the number of pages to produce -* @param int $start_item the item which should be considered currently active, used to determine the page we're on -* @param bool $add_prevnext_text appends and prepends next and previous links (true) or not (false) -* @param string $tpl_prefix is for using different pagination blocks at one page -*/ -function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = false, $tpl_prefix = '') -{ - global $template, $user; - - // Make sure $per_page is a valid value - $per_page = ($per_page <= 0) ? 1 : $per_page; - - $separator = '' . $user->lang['COMMA_SEPARATOR'] . ''; - $total_pages = ceil($num_items / $per_page); - - if ($total_pages == 1 || !$num_items) - { - return false; - } - - $on_page = floor($start_item / $per_page) + 1; - $url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&'); - - $page_string = ($on_page == 1) ? '1' : '1'; - - if ($total_pages > 5) - { - $start_cnt = min(max(1, $on_page - 4), $total_pages - 5); - $end_cnt = max(min($total_pages, $on_page + 4), 6); - - $page_string .= ($start_cnt > 1) ? ' ... ' : $separator; - - for ($i = $start_cnt + 1; $i < $end_cnt; $i++) - { - $page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . ''; - if ($i < $end_cnt - 1) - { - $page_string .= $separator; - } - } - - $page_string .= ($end_cnt < $total_pages) ? ' ... ' : $separator; - } - else - { - $page_string .= $separator; - - for ($i = 2; $i < $total_pages; $i++) - { - $page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . ''; - if ($i < $total_pages) - { - $page_string .= $separator; - } - } - } - - $page_string .= ($on_page == $total_pages) ? '' . $total_pages . '' : '' . $total_pages . ''; - - if ($add_prevnext_text) - { - if ($on_page != 1) - { - $page_string = '' . $user->lang['PREVIOUS'] . '  ' . $page_string; - } - - if ($on_page != $total_pages) - { - $page_string .= '  ' . $user->lang['NEXT'] . ''; - } - } - - $template->assign_vars(array( - $tpl_prefix . 'BASE_URL' => $base_url, - 'A_' . $tpl_prefix . 'BASE_URL' => addslashes($base_url), - $tpl_prefix . 'PER_PAGE' => $per_page, - - $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page == 1) ? '' : $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page), - $tpl_prefix . 'NEXT_PAGE' => ($on_page == $total_pages) ? '' : $base_url . "{$url_delim}start=" . ($on_page * $per_page), - $tpl_prefix . 'TOTAL_PAGES' => $total_pages, - $tpl_prefix . 'CURRENT_PAGE' => $on_page, - )); - - return $page_string; -} - /** * Generate template rendered pagination * Allows full control of rendering of pagination with the template * +* @param object $template the template object * @param string $base_url is url prepended to all links generated within the function * @param string $block_var_name is the name assigned to the pagination data block within the template (example: ) * @param int $num_items the total number of items, posts, etc., used to determine the number of pages to produce @@ -1983,12 +1892,10 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add * @param int $start_item the item which should be considered currently active, used to determine the page we're on * @param bool $reverse_count determines whether we weight display of the list towards the start (false) or end (true) of the list * @param bool $ignore_on_page decides whether we enable an active (unlinked) item, used primarily for embedded lists -* +* @return null */ -function phpbb_generate_template_pagination($base_url, $block_var_name, $num_items, $per_page, $start_item = 1, $reverse_count = false, $ignore_on_page = false) +function phpbb_generate_template_pagination($template, $base_url, $block_var_name, $num_items, $per_page, $start_item = 1, $reverse_count = false, $ignore_on_page = false) { - global $template; - // Make sure $per_page is a valid value $per_page = ($per_page <= 0) ? 1 : $per_page; $total_pages = ceil($num_items / $per_page); @@ -2098,16 +2005,16 @@ function phpbb_generate_template_pagination($base_url, $block_var_name, $num_ite * Return current page * This function also sets certain specific template variables * +* @param object $template the template object +* @param object $user the user object * @param string $base_url the base url used to call this page, used by Javascript for popup jump to page * @param int $num_items the total number of items, posts, topics, etc. * @param int $per_page the number of items, posts, etc. per page * @param int $start the item which should be considered currently active, used to determine the page we're on -* +* @return null */ -function on_page($base_url, $num_items, $per_page, $start) +function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $start) { - global $template, $user; - // Make sure $per_page is a valid value $per_page = ($per_page <= 0) ? 1 : $per_page; -- cgit v1.2.1