mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Merge remote-tracking branch 'nickvergessen/feature/pagination-class' into develop
# By Joas Schilling # Via Joas Schilling * nickvergessen/feature/pagination-class: [ticket/11849] Fix more function calls [ticket/11849] Update more MCP calls to pagination class [ticket/11849] Update some ACP modules with new pagination [ticket/11849] Update rest of the UCP modules [ticket/11849] Update UCP notifications and pm folder [ticket/11849] Update search and memberlist [ticket/11849] Update pagination in viewonline.php [ticket/11849] Remove old pagination test [ticket/11849] Update pagination code in viewtopic.php [ticket/11849] Replace pagination in viewforum.php with class [ticket/11849] Add service definition [ticket/11849] Remove pagination functions [ticket/11849] Test validate_start and on_page [ticket/11849] Move pagination code to class
This commit is contained in:
commit
f9c7f0fc19
30 changed files with 680 additions and 449 deletions
|
@ -255,6 +255,12 @@ services:
|
|||
- %tables.notifications%
|
||||
- %tables.user_notifications%
|
||||
|
||||
pagination:
|
||||
class: phpbb\pagination
|
||||
arguments:
|
||||
- @template
|
||||
- @user
|
||||
|
||||
path_helper:
|
||||
class: phpbb\path_helper
|
||||
arguments:
|
||||
|
|
|
@ -25,7 +25,7 @@ class acp_attachments
|
|||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $db, $user, $auth, $template, $cache;
|
||||
global $db, $user, $auth, $template, $cache, $phpbb_container;
|
||||
global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
|
||||
|
||||
$user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
|
||||
|
@ -1166,10 +1166,9 @@ class acp_attachments
|
|||
}
|
||||
|
||||
// Make sure $start is set to the last page if it exceeds the amount
|
||||
if ($start < 0 || $start > $num_files)
|
||||
{
|
||||
$start = ($start < 0) ? 0 : floor(($num_files - 1) / $attachments_per_page) * $attachments_per_page;
|
||||
}
|
||||
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
$start = $pagination->validate_start($start, $attachments_per_page, $num_files);
|
||||
|
||||
// If the user is trying to reach the second half of the attachments list, fetch it starting from the end
|
||||
$store_reverse = false;
|
||||
|
@ -1179,15 +1178,11 @@ class acp_attachments
|
|||
{
|
||||
$store_reverse = true;
|
||||
|
||||
if ($start + $attachments_per_page > $num_files)
|
||||
{
|
||||
$sql_limit = min($attachments_per_page, max(1, $num_files - $start));
|
||||
}
|
||||
|
||||
// Select the sort order. Add time sort anchor for non-time sorting cases
|
||||
$sql_sort_anchor = ($sort_key != 't') ? ', a.filetime ' . (($sort_dir == 'd') ? 'ASC' : 'DESC') : '';
|
||||
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC') . $sql_sort_anchor;
|
||||
$sql_start = max(0, $num_files - $sql_limit - $start);
|
||||
$sql_limit = $pagination->reverse_limit($start, $sql_limit, $num_files);
|
||||
$sql_start = $pagination->reverse_start($start, $sql_limit, $num_files);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1195,7 +1190,6 @@ class acp_attachments
|
|||
$sql_sort_anchor = ($sort_key != 't') ? ', a.filetime ' . (($sort_dir == 'd') ? 'DESC' : 'ASC') : '';
|
||||
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC') . $sql_sort_anchor;
|
||||
$sql_start = $start;
|
||||
|
||||
}
|
||||
|
||||
$attachments_list = array();
|
||||
|
@ -1222,13 +1216,13 @@ class acp_attachments
|
|||
$db->sql_freeresult($result);
|
||||
|
||||
$base_url = $this->u_action . "&$u_sort_param";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $num_files, $attachments_per_page, $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_files, $attachments_per_page, $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'TOTAL_FILES' => $num_files,
|
||||
'TOTAL_SIZE' => get_formatted_filesize($total_size),
|
||||
|
||||
'S_ON_PAGE' => phpbb_on_page($template, $user, $base_url, $num_files, $attachments_per_page, $start),
|
||||
'S_ON_PAGE' => $pagination->on_page($base_url, $num_files, $attachments_per_page, $start),
|
||||
'S_LIMIT_DAYS' => $s_limit_days,
|
||||
'S_SORT_KEY' => $s_sort_key,
|
||||
'S_SORT_DIR' => $s_sort_dir)
|
||||
|
|
|
@ -676,6 +676,7 @@ class acp_groups
|
|||
}
|
||||
|
||||
$this->page_title = 'GROUP_MEMBERS';
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
// Grab the leaders - always, on every page...
|
||||
$sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_colour, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
|
||||
|
@ -719,14 +720,14 @@ class acp_groups
|
|||
}
|
||||
|
||||
$base_url = $this->u_action . "&action=$action&g=$group_id";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total_members, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_members, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_LIST' => true,
|
||||
'S_GROUP_SPECIAL' => ($group_row['group_type'] == GROUP_SPECIAL) ? true : false,
|
||||
'S_ACTION_OPTIONS' => $s_action_options,
|
||||
|
||||
'S_ON_PAGE' => phpbb_on_page($template, $user, $base_url, $total_members, $config['topics_per_page'], $start),
|
||||
'S_ON_PAGE' => $pagination->on_page($base_url, $total_members, $config['topics_per_page'], $start),
|
||||
'GROUP_NAME' => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
|
||||
|
||||
'U_ACTION' => $this->u_action . "&g=$group_id",
|
||||
|
|
|
@ -27,7 +27,7 @@ class acp_icons
|
|||
{
|
||||
global $db, $user, $auth, $template, $cache;
|
||||
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
||||
global $request;
|
||||
global $request, $phpbb_container;
|
||||
|
||||
$user->add_lang('acp/posting');
|
||||
|
||||
|
@ -893,6 +893,7 @@ class acp_icons
|
|||
);
|
||||
|
||||
$spacer = false;
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
$pagination_start = request_var('start', 0);
|
||||
|
||||
$item_count = $this->item_count($table);
|
||||
|
@ -927,7 +928,7 @@ class acp_icons
|
|||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
phpbb_generate_template_pagination($template, $this->u_action, 'pagination', 'start', $item_count, $config['smilies_per_page'], $pagination_start);
|
||||
$pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $item_count, $config['smilies_per_page'], $pagination_start);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ class acp_inactive
|
|||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $config, $db, $user, $auth, $template;
|
||||
global $config, $db, $user, $auth, $template, $phpbb_container;
|
||||
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
|
||||
|
||||
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
|
||||
|
@ -49,6 +49,7 @@ class acp_inactive
|
|||
|
||||
$form_key = 'acp_inactive';
|
||||
add_form_key($form_key);
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
// We build the sort key and per page settings here, because they may be needed later
|
||||
|
||||
|
@ -285,7 +286,7 @@ class acp_inactive
|
|||
}
|
||||
|
||||
$base_url = $this->u_action . "&$u_sort_param&users_per_page=$per_page";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $inactive_count, $per_page, $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $inactive_count, $per_page, $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_INACTIVE_USERS' => true,
|
||||
|
@ -294,7 +295,7 @@ class acp_inactive
|
|||
'S_LIMIT_DAYS' => $s_limit_days,
|
||||
'S_SORT_KEY' => $s_sort_key,
|
||||
'S_SORT_DIR' => $s_sort_dir,
|
||||
'S_ON_PAGE' => phpbb_on_page($template, $user, $base_url, $inactive_count, $per_page, $start),
|
||||
'S_ON_PAGE' => $pagination->on_page($base_url, $inactive_count, $per_page, $start),
|
||||
'USERS_PER_PAGE' => $per_page,
|
||||
|
||||
'U_ACTION' => $this->u_action . "&$u_sort_param&users_per_page=$per_page&start=$start",
|
||||
|
|
|
@ -24,7 +24,7 @@ class acp_logs
|
|||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $db, $user, $auth, $template, $cache;
|
||||
global $db, $user, $auth, $template, $cache, $phpbb_container;
|
||||
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
||||
global $request;
|
||||
|
||||
|
@ -46,6 +46,7 @@ class acp_logs
|
|||
|
||||
$this->tpl_name = 'acp_logs';
|
||||
$this->log_type = constant('LOG_' . strtoupper($mode));
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
// Delete entries if requested and able
|
||||
if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
|
||||
|
@ -130,14 +131,14 @@ class acp_logs
|
|||
$start = view_log($mode, $log_data, $log_count, $config['topics_per_page'], $start, $forum_id, 0, 0, $sql_where, $sql_sort, $keywords);
|
||||
|
||||
$base_url = $this->u_action . "&$u_sort_param$keywords_param";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'L_TITLE' => $l_title,
|
||||
'L_EXPLAIN' => $l_title_explain,
|
||||
'U_ACTION' => $this->u_action . "&$u_sort_param$keywords_param&start=$start",
|
||||
|
||||
'S_ON_PAGE' => phpbb_on_page($template, $user, $base_url, $log_count, $config['topics_per_page'], $start),
|
||||
'S_ON_PAGE' => $pagination->on_page($base_url, $log_count, $config['topics_per_page'], $start),
|
||||
|
||||
'S_LIMIT_DAYS' => $s_limit_days,
|
||||
'S_SORT_KEY' => $s_sort_key,
|
||||
|
|
|
@ -1096,6 +1096,7 @@ class acp_users
|
|||
$deleteall = (isset($_POST['delall'])) ? true : false;
|
||||
$marked = request_var('mark', array(0));
|
||||
$message = utf8_normalize_nfc(request_var('message', '', true));
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
// Sort keys
|
||||
$sort_days = request_var('st', 0);
|
||||
|
@ -1166,11 +1167,11 @@ class acp_users
|
|||
$start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
|
||||
|
||||
$base_url = $this->u_action . "&u=$user_id&$u_sort_param";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_FEEDBACK' => true,
|
||||
'S_ON_PAGE' => phpbb_on_page($template, $user, $base_url, $log_count, $config['topics_per_page'], $start),
|
||||
'S_ON_PAGE' => $pagination->on_page($base_url, $log_count, $config['topics_per_page'], $start),
|
||||
|
||||
'S_LIMIT_DAYS' => $s_limit_days,
|
||||
'S_SORT_KEY' => $s_sort_key,
|
||||
|
@ -1998,6 +1999,7 @@ class acp_users
|
|||
$start = request_var('start', 0);
|
||||
$deletemark = (isset($_POST['delmarked'])) ? true : false;
|
||||
$marked = request_var('mark', array(0));
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
// Sort keys
|
||||
$sort_key = request_var('sk', 'a');
|
||||
|
@ -2134,11 +2136,11 @@ class acp_users
|
|||
$db->sql_freeresult($result);
|
||||
|
||||
$base_url = $this->u_action . "&u=$user_id&sk=$sort_key&sd=$sort_dir";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_ATTACHMENTS' => true,
|
||||
'S_ON_PAGE' => phpbb_on_page($template, $user, $base_url, $num_attachments, $config['topics_per_page'], $start),
|
||||
'S_ON_PAGE' => $pagination->on_page($base_url, $num_attachments, $config['topics_per_page'], $start),
|
||||
'S_SORT_KEY' => $s_sort_key,
|
||||
'S_SORT_DIR' => $s_sort_dir,
|
||||
));
|
||||
|
|
|
@ -2205,225 +2205,6 @@ function tracking_unserialize($string, $max_depth = 3)
|
|||
return $level;
|
||||
}
|
||||
|
||||
// Pagination functions
|
||||
/**
|
||||
* Generate a pagination link based on the url and the page information
|
||||
*
|
||||
* @param string $base_url is url prepended to all links generated within the function
|
||||
* If you use page numbers inside your controller route, base_url should contains a placeholder (%d)
|
||||
* for the page. Also be sure to specify the pagination path information into the start_name argument
|
||||
* @param string $on_page is the page for which we want to generate the link
|
||||
* @param string $start_name is the name of the parameter containing the first item of the given page (example: start=20)
|
||||
* If you use page numbers inside your controller route, start name should be the string
|
||||
* that should be removed for the first page (example: /page/%d)
|
||||
* @param int $per_page the number of items, posts, etc. to display per page, used to determine the number of pages to produce
|
||||
* @return URL for the requested page
|
||||
*/
|
||||
function phpbb_generate_page_link($base_url, $on_page, $start_name, $per_page)
|
||||
{
|
||||
|
||||
if (strpos($start_name, '%d') !== false)
|
||||
{
|
||||
return ($on_page > 1) ? sprintf($base_url, (int) $on_page) : str_replace($start_name, '', $base_url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&');
|
||||
return ($on_page > 1) ? $base_url . $url_delim . $start_name . '=' . (($on_page - 1) * $per_page) : $base_url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* If you use page numbers inside your controller route, base_url should contains a placeholder (%d)
|
||||
* for the page. Also be sure to specify the pagination path information into the start_name argument
|
||||
* @param string $block_var_name is the name assigned to the pagination data block within the template (example: <!-- BEGIN pagination -->)
|
||||
* @param string $start_name is the name of the parameter containing the first item of the given page (example: start=20)
|
||||
* If you use page numbers inside your controller route, start name should be the string
|
||||
* that should be removed for the first page (example: /page/%d)
|
||||
* @param int $num_items the total number of items, posts, etc., used to determine the number of pages to produce
|
||||
* @param int $per_page the number of items, posts, 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 $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($template, $base_url, $block_var_name, $start_name, $num_items, $per_page, $start_item = 1, $reverse_count = false, $ignore_on_page = false)
|
||||
{
|
||||
// Make sure $per_page is a valid value
|
||||
$per_page = ($per_page <= 0) ? 1 : $per_page;
|
||||
$total_pages = ceil($num_items / $per_page);
|
||||
|
||||
if ($total_pages == 1 || !$num_items)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$on_page = floor($start_item / $per_page) + 1;
|
||||
|
||||
if ($reverse_count)
|
||||
{
|
||||
$start_page = ($total_pages > 5) ? $total_pages - 4 : 1;
|
||||
$end_page = $total_pages;
|
||||
}
|
||||
else
|
||||
{
|
||||
// What we're doing here is calculating what the "start" and "end" pages should be. We
|
||||
// do this by assuming pagination is "centered" around the currently active page with
|
||||
// the three previous and three next page links displayed. Anything more than that and
|
||||
// we display the ellipsis, likewise anything less.
|
||||
//
|
||||
// $start_page is the page at which we start creating the list. When we have five or less
|
||||
// pages we start at page 1 since there will be no ellipsis displayed. Anymore than that
|
||||
// and we calculate the start based on the active page. This is the min/max calculation.
|
||||
// First (max) would we end up starting on a page less than 1? Next (min) would we end
|
||||
// up starting so close to the end that we'd not display our minimum number of pages.
|
||||
//
|
||||
// $end_page is the last page in the list to display. Like $start_page we use a min/max to
|
||||
// determine this number. Again at most five pages? Then just display them all. More than
|
||||
// five and we first (min) determine whether we'd end up listing more pages than exist.
|
||||
// We then (max) ensure we're displaying the minimum number of pages.
|
||||
$start_page = ($total_pages > 5) ? min(max(1, $on_page - 3), $total_pages - 4) : 1;
|
||||
$end_page = ($total_pages > 5) ? max(min($total_pages, $on_page + 3), 5) : $total_pages;
|
||||
}
|
||||
|
||||
$u_previous_page = $u_next_page = '';
|
||||
if ($on_page != 1)
|
||||
{
|
||||
$u_previous_page = phpbb_generate_page_link($base_url, $on_page - 1, $start_name, $per_page);
|
||||
|
||||
$template->assign_block_vars($block_var_name, array(
|
||||
'PAGE_NUMBER' => '',
|
||||
'PAGE_URL' => $u_previous_page,
|
||||
'S_IS_CURRENT' => false,
|
||||
'S_IS_PREV' => true,
|
||||
'S_IS_NEXT' => false,
|
||||
'S_IS_ELLIPSIS' => false,
|
||||
));
|
||||
}
|
||||
|
||||
// This do...while exists purely to negate the need for start and end assign_block_vars, i.e.
|
||||
// to display the first and last page in the list plus any ellipsis. We use this loop to jump
|
||||
// around a little within the list depending on where we're starting (and ending).
|
||||
$at_page = 1;
|
||||
do
|
||||
{
|
||||
// We decide whether to display the ellipsis during the loop. The ellipsis is always
|
||||
// displayed as either the second or penultimate item in the list. So are we at either
|
||||
// of those points and of course do we even need to display it, i.e. is the list starting
|
||||
// on at least page 3 and ending three pages before the final item.
|
||||
$template->assign_block_vars($block_var_name, array(
|
||||
'PAGE_NUMBER' => $at_page,
|
||||
'PAGE_URL' => phpbb_generate_page_link($base_url, $at_page, $start_name, $per_page),
|
||||
'S_IS_CURRENT' => (!$ignore_on_page && $at_page == $on_page),
|
||||
'S_IS_NEXT' => false,
|
||||
'S_IS_PREV' => false,
|
||||
'S_IS_ELLIPSIS' => ($at_page == 2 && $start_page > 2) || ($at_page == $total_pages - 1 && $end_page < $total_pages - 1),
|
||||
));
|
||||
|
||||
// We may need to jump around in the list depending on whether we have or need to display
|
||||
// the ellipsis. Are we on page 2 and are we more than one page away from the start
|
||||
// of the list? Yes? Then we jump to the start of the list. Likewise are we at the end of
|
||||
// the list and are there more than two pages left in total? Yes? Then jump to the penultimate
|
||||
// page (so we can display the ellipsis next pass). Else, increment the counter and keep
|
||||
// going
|
||||
if ($at_page == 2 && $at_page < $start_page - 1)
|
||||
{
|
||||
$at_page = $start_page;
|
||||
}
|
||||
else if ($at_page == $end_page && $end_page < $total_pages - 1)
|
||||
{
|
||||
$at_page = $total_pages - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$at_page++;
|
||||
}
|
||||
}
|
||||
while ($at_page <= $total_pages);
|
||||
|
||||
if ($on_page != $total_pages)
|
||||
{
|
||||
$u_next_page = phpbb_generate_page_link($base_url, $on_page + 1, $start_name, $per_page);
|
||||
|
||||
$template->assign_block_vars($block_var_name, array(
|
||||
'PAGE_NUMBER' => '',
|
||||
'PAGE_URL' => $u_next_page,
|
||||
'S_IS_CURRENT' => false,
|
||||
'S_IS_PREV' => false,
|
||||
'S_IS_NEXT' => true,
|
||||
'S_IS_ELLIPSIS' => false,
|
||||
));
|
||||
}
|
||||
|
||||
// If the block_var_name is a nested block, we will use the last (most
|
||||
// inner) block as a prefix for the template variables. If the last block
|
||||
// name is pagination, the prefix is empty. If the rest of the
|
||||
// block_var_name is not empty, we will modify the last row of that block
|
||||
// and add our pagination items.
|
||||
$tpl_block_name = $tpl_prefix = '';
|
||||
if (strrpos($block_var_name, '.') !== false)
|
||||
{
|
||||
$tpl_block_name = substr($block_var_name, 0, strrpos($block_var_name, '.'));
|
||||
$tpl_prefix = strtoupper(substr($block_var_name, strrpos($block_var_name, '.') + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
$tpl_prefix = strtoupper($block_var_name);
|
||||
}
|
||||
$tpl_prefix = ($tpl_prefix == 'PAGINATION') ? '' : $tpl_prefix . '_';
|
||||
|
||||
$template_array = array(
|
||||
$tpl_prefix . 'BASE_URL' => $base_url,
|
||||
$tpl_prefix . 'PER_PAGE' => $per_page,
|
||||
'U_' . $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page != 1) ? $u_previous_page : '',
|
||||
'U_' . $tpl_prefix . 'NEXT_PAGE' => ($on_page != $total_pages) ? $u_next_page : '',
|
||||
$tpl_prefix . 'TOTAL_PAGES' => $total_pages,
|
||||
$tpl_prefix . 'CURRENT_PAGE' => $on_page,
|
||||
);
|
||||
|
||||
if ($tpl_block_name)
|
||||
{
|
||||
$template->alter_block_array($tpl_block_name, $template_array, true, 'change');
|
||||
}
|
||||
else
|
||||
{
|
||||
$template->assign_vars($template_array);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $start)
|
||||
{
|
||||
// Make sure $per_page is a valid value
|
||||
$per_page = ($per_page <= 0) ? 1 : $per_page;
|
||||
|
||||
$on_page = floor($start / $per_page) + 1;
|
||||
|
||||
$template->assign_vars(array(
|
||||
'PER_PAGE' => $per_page,
|
||||
'ON_PAGE' => $on_page,
|
||||
'BASE_URL' => $base_url,
|
||||
));
|
||||
|
||||
return sprintf($user->lang['PAGE_OF'], $on_page, max(ceil($num_items / $per_page), 1));
|
||||
}
|
||||
|
||||
// Server functions (building urls, redirecting...)
|
||||
|
||||
/**
|
||||
|
|
|
@ -73,6 +73,8 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
|
|||
break;
|
||||
}
|
||||
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
$selected_ids = '';
|
||||
if (sizeof($post_id_list) && $action != 'merge_topics')
|
||||
{
|
||||
|
@ -102,7 +104,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
|
|||
$limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
|
||||
|
||||
$base_url = $url . "&i=$id&action=$action&mode=$mode&sd=$sort_dir&sk=$sort_key&st=$sort_days" . (($merge_select) ? $selected_ids : '');
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $forum_topics, $topics_per_page, $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $forum_topics, $topics_per_page, $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'ACTION' => $action,
|
||||
|
@ -133,7 +135,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
|
|||
|
||||
'S_MCP_ACTION' => $url . "&i=$id&forum_action=$action&mode=$mode&start=$start" . (($merge_select) ? $selected_ids : ''),
|
||||
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $forum_topics, $topics_per_page, $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $forum_topics, $topics_per_page, $start),
|
||||
'TOTAL_TOPICS' => $user->lang('VIEW_FORUM_TOPICS', (int) $forum_topics),
|
||||
));
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class mcp_logs
|
|||
function main($id, $mode)
|
||||
{
|
||||
global $auth, $db, $user, $template;
|
||||
global $config, $phpbb_root_path, $phpEx;
|
||||
global $config, $phpbb_root_path, $phpEx, $phpbb_container;
|
||||
|
||||
$user->add_lang('acp/common');
|
||||
|
||||
|
@ -62,6 +62,8 @@ class mcp_logs
|
|||
$this->tpl_name = 'mcp_logs';
|
||||
$this->page_title = 'MCP_LOGS';
|
||||
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
$forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
|
||||
$forum_list[] = 0;
|
||||
|
||||
|
@ -172,10 +174,10 @@ class mcp_logs
|
|||
$start = view_log('mod', $log_data, $log_count, $config['topics_per_page'], $start, $forum_list, $topic_id, 0, $sql_where, $sql_sort, $keywords);
|
||||
|
||||
$base_url = $this->u_action . "&$u_sort_param$keywords_param";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $log_count, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $log_count, $config['topics_per_page'], $start),
|
||||
'TOTAL' => $user->lang('TOTAL_LOGS', (int) $log_count),
|
||||
|
||||
'L_TITLE' => $user->lang['MCP_LOGS'],
|
||||
|
|
|
@ -72,7 +72,7 @@ class mcp_notes
|
|||
function mcp_notes_user_view($action)
|
||||
{
|
||||
global $phpEx, $phpbb_root_path, $config;
|
||||
global $template, $db, $user, $auth;
|
||||
global $template, $db, $user, $auth, $phpbb_container;
|
||||
|
||||
$user_id = request_var('u', 0);
|
||||
$username = request_var('username', '', true);
|
||||
|
@ -80,6 +80,7 @@ class mcp_notes
|
|||
$st = request_var('st', 0);
|
||||
$sk = request_var('sk', 'b');
|
||||
$sd = request_var('sd', 'd');
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
add_form_key('mcp_notes');
|
||||
|
||||
|
@ -216,7 +217,7 @@ class mcp_notes
|
|||
}
|
||||
|
||||
$base_url = $this->u_action . "&$u_sort_param$keywords_param";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'U_POST_ACTION' => $this->u_action,
|
||||
|
@ -228,7 +229,7 @@ class mcp_notes
|
|||
|
||||
'L_TITLE' => $user->lang['MCP_NOTES_USER'],
|
||||
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $log_count, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $log_count, $config['topics_per_page'], $start),
|
||||
'TOTAL_REPORTS' => $user->lang('LIST_REPORTS', (int) $log_count),
|
||||
|
||||
'RANK_TITLE' => $rank_title,
|
||||
|
|
|
@ -39,6 +39,7 @@ class mcp_pm_reports
|
|||
include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
|
||||
|
||||
$start = request_var('start', 0);
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
$this->page_title = 'MCP_PM_REPORTS';
|
||||
|
||||
|
@ -297,7 +298,7 @@ class mcp_pm_reports
|
|||
}
|
||||
|
||||
$base_url = $this->u_action . "&st=$sort_days&sk=$sort_key&sd=$sort_dir";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
|
||||
|
||||
// Now display the page
|
||||
$template->assign_vars(array(
|
||||
|
@ -308,7 +309,7 @@ class mcp_pm_reports
|
|||
'S_MCP_ACTION' => $this->u_action,
|
||||
'S_CLOSED' => ($mode == 'pm_reports_closed') ? true : false,
|
||||
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $total, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $total, $config['topics_per_page'], $start),
|
||||
'TOTAL' => $total,
|
||||
'TOTAL_REPORTS' => $user->lang('LIST_REPORTS', (int) $total),
|
||||
)
|
||||
|
|
|
@ -337,6 +337,7 @@ class mcp_queue
|
|||
|
||||
$topic_id = $request->variable('t', 0);
|
||||
$forum_info = array();
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
if ($topic_id)
|
||||
{
|
||||
|
@ -532,7 +533,7 @@ class mcp_queue
|
|||
unset($rowset, $forum_names);
|
||||
|
||||
$base_url = $this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
|
||||
|
||||
// Now display the page
|
||||
$template->assign_vars(array(
|
||||
|
@ -546,7 +547,7 @@ class mcp_queue
|
|||
'S_TOPICS' => $is_topics,
|
||||
'S_RESTORE' => $is_restore,
|
||||
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $total, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $total, $config['topics_per_page'], $start),
|
||||
'TOPIC_ID' => $topic_id,
|
||||
'TOTAL' => $user->lang(((!$is_topics) ? 'VIEW_TOPIC_POSTS' : 'VIEW_FORUM_TOPICS'), (int) $total),
|
||||
));
|
||||
|
|
|
@ -315,6 +315,7 @@ class mcp_reports
|
|||
|
||||
$forum_list[] = 0;
|
||||
$forum_data = array();
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
$forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
|
||||
foreach ($forum_list_reports as $row)
|
||||
|
@ -410,7 +411,7 @@ class mcp_reports
|
|||
}
|
||||
|
||||
$base_url = $this->u_action . "&f=$forum_id&t=$topic_id&st=$sort_days&sk=$sort_key&sd=$sort_dir";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
|
||||
|
||||
// Now display the page
|
||||
$template->assign_vars(array(
|
||||
|
@ -422,7 +423,7 @@ class mcp_reports
|
|||
'S_FORUM_OPTIONS' => $forum_options,
|
||||
'S_CLOSED' => ($mode == 'reports_closed') ? true : false,
|
||||
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $total, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $total, $config['topics_per_page'], $start),
|
||||
'TOPIC_ID' => $topic_id,
|
||||
'TOTAL' => $total,
|
||||
'TOTAL_REPORTS' => $user->lang('LIST_REPORTS', (int) $total),
|
||||
|
|
|
@ -26,6 +26,7 @@ function mcp_topic_view($id, $mode, $action)
|
|||
$url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url());
|
||||
|
||||
$user->add_lang('viewtopic');
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
$topic_id = request_var('t', 0);
|
||||
$topic_info = get_topic_data(array($topic_id), false, true);
|
||||
|
@ -129,12 +130,7 @@ function mcp_topic_view($id, $mode, $action)
|
|||
{
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
// Make sure $start is set to the last page if it exceeds the amount
|
||||
if ($start < 0 || $start >= $total)
|
||||
{
|
||||
$start = ($start < 0) ? 0 : floor(($total - 1) / $posts_per_page) * $posts_per_page;
|
||||
}
|
||||
$start = $pagination->validate_start($start, $posts_per_page, $total);
|
||||
|
||||
$sql = 'SELECT u.username, u.username_clean, u.user_colour, p.*
|
||||
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
|
||||
|
@ -304,7 +300,7 @@ function mcp_topic_view($id, $mode, $action)
|
|||
$base_url = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&t={$topic_info['topic_id']}&mode=$mode&action=$action&to_topic_id=$to_topic_id&posts_per_page=$posts_per_page&st=$sort_days&sk=$sort_key&sd=$sort_dir");
|
||||
if ($posts_per_page)
|
||||
{
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $posts_per_page, $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $posts_per_page, $start);
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
|
@ -347,7 +343,7 @@ function mcp_topic_view($id, $mode, $action)
|
|||
'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_info['forum_id']}&t={$topic_info['topic_id']}&start=$start") . '">', '</a>'),
|
||||
'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f={$topic_info['forum_id']}&start=$start") . '">', '</a>'),
|
||||
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $total, $posts_per_page, $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $total, $posts_per_page, $start),
|
||||
'TOTAL_POSTS' => $user->lang('VIEW_TOPIC_POSTS', (int) $total),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -134,10 +134,11 @@ class mcp_warn
|
|||
*/
|
||||
function mcp_warn_list_view($action)
|
||||
{
|
||||
global $phpEx, $phpbb_root_path, $config;
|
||||
global $phpEx, $phpbb_root_path, $config, $phpbb_container;
|
||||
global $template, $db, $user, $auth;
|
||||
|
||||
$user->add_lang('memberlist');
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
$start = request_var('start', 0);
|
||||
$st = request_var('st', 0);
|
||||
|
@ -176,7 +177,7 @@ class mcp_warn
|
|||
}
|
||||
|
||||
$base_url = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=warn&mode=list&st=$st&sk=$sk&sd=$sd");
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $user_count, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $user_count, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'U_POST_ACTION' => $this->u_action,
|
||||
|
@ -185,7 +186,7 @@ class mcp_warn
|
|||
'S_SELECT_SORT_KEY' => $s_sort_key,
|
||||
'S_SELECT_SORT_DAYS' => $s_limit_days,
|
||||
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $user_count, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $user_count, $config['topics_per_page'], $start),
|
||||
'TOTAL_USERS' => $user->lang('LIST_USERS', (int) $user_count),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class ucp_attachments
|
|||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $template, $user, $db, $config, $phpEx, $phpbb_root_path;
|
||||
global $template, $user, $db, $config, $phpEx, $phpbb_root_path, $phpbb_container;
|
||||
|
||||
$start = request_var('start', 0);
|
||||
$sort_key = request_var('sk', 'a');
|
||||
|
@ -119,6 +119,10 @@ class ucp_attachments
|
|||
$num_attachments = $db->sql_fetchfield('num_attachments');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
// Ensure start is a valid value
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
$start = $pagination->validate_start($start, $config['topics_per_page'], $num_attachments);
|
||||
|
||||
$sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
|
||||
FROM ' . ATTACHMENTS_TABLE . ' a
|
||||
LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id AND a.in_message = 0)
|
||||
|
@ -171,10 +175,10 @@ class ucp_attachments
|
|||
$db->sql_freeresult($result);
|
||||
|
||||
$base_url = $this->u_action . "&sk=$sort_key&sd=$sort_dir";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $num_attachments, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $num_attachments, $config['topics_per_page'], $start),
|
||||
'TOTAL_ATTACHMENTS' => $num_attachments,
|
||||
|
||||
'L_TITLE' => $user->lang['UCP_ATTACHMENTS'],
|
||||
|
|
|
@ -813,13 +813,15 @@ class ucp_groups
|
|||
$s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
|
||||
}
|
||||
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
$base_url = $this->u_action . "&action=$action&g=$group_id";
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total_members, $config['topics_per_page'], $start);
|
||||
$start = $pagination->validate_start($start, $config['topics_per_page'], $total_members);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_members, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_LIST' => true,
|
||||
'S_ACTION_OPTIONS' => $s_action_options,
|
||||
'S_ON_PAGE' => phpbb_on_page($template, $user, $base_url, $total_members, $config['topics_per_page'], $start),
|
||||
'S_ON_PAGE' => $pagination->on_page($template, $user, $base_url, $total_members, $config['topics_per_page'], $start),
|
||||
|
||||
'U_ACTION' => $this->u_action . "&g=$group_id",
|
||||
'S_UCP_ACTION' => $this->u_action . "&g=$group_id",
|
||||
|
|
|
@ -646,6 +646,7 @@ class ucp_main
|
|||
|
||||
$table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE;
|
||||
$start = request_var('start', 0);
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
// Grab icons
|
||||
$icons = $cache->obtain_icons();
|
||||
|
@ -669,10 +670,11 @@ class ucp_main
|
|||
|
||||
if ($topics_count)
|
||||
{
|
||||
phpbb_generate_template_pagination($template, $this->u_action, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start);
|
||||
$start = $pagination->validate_start($start, $config['topics_per_page'], $topics_count);
|
||||
$pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $this->u_action, $topics_count, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($this->u_action, $topics_count, $config['topics_per_page'], $start),
|
||||
'TOTAL_TOPICS' => $user->lang('VIEW_FORUM_TOPICS', (int) $topics_count),
|
||||
));
|
||||
}
|
||||
|
@ -839,7 +841,7 @@ class ucp_main
|
|||
'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
|
||||
));
|
||||
|
||||
phpbb_generate_template_pagination($template, append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . "&t=$topic_id"), 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true);
|
||||
$pagination->generate_template_pagination(append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . "&t=$topic_id"), 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ class ucp_notifications
|
|||
$form_time = ($form_time <= 0 || $form_time > time()) ? time() : $form_time;
|
||||
|
||||
$phpbb_notifications = $phpbb_container->get('notification_manager');
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
|
@ -137,10 +138,11 @@ class ucp_notifications
|
|||
}
|
||||
|
||||
$base_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=ucp_notifications&mode=notification_list");
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $notifications['total_count'], $config['topics_per_page'], $start);
|
||||
$start = $pagination->validate_start($start, $config['topics_per_page'], $notifications['total_count']);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $notifications['total_count'], $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $notifications['total_count'], $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $notifications['total_count'], $config['topics_per_page'], $start),
|
||||
'TOTAL_COUNT' => $notifications['total_count'],
|
||||
'U_MARK_ALL' => $base_url . '&mark=all&token=' . generate_link_hash('mark_all_notifications_read'),
|
||||
));
|
||||
|
|
|
@ -393,7 +393,7 @@ function view_folder($id, $mode, $folder_id, $folder)
|
|||
*/
|
||||
function get_pm_from($folder_id, $folder, $user_id)
|
||||
{
|
||||
global $user, $db, $template, $config, $auth, $phpbb_root_path, $phpEx;
|
||||
global $user, $db, $template, $config, $auth, $phpbb_container, $phpbb_root_path, $phpEx;
|
||||
|
||||
$start = request_var('start', 0);
|
||||
|
||||
|
@ -402,6 +402,8 @@ function get_pm_from($folder_id, $folder, $user_id)
|
|||
$sort_key = request_var('sk', 't');
|
||||
$sort_dir = request_var('sd', 'd');
|
||||
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
// PM ordering options
|
||||
$limit_days = array(0 => $user->lang['ALL_MESSAGES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
|
||||
|
||||
|
@ -452,10 +454,11 @@ function get_pm_from($folder_id, $folder, $user_id)
|
|||
}
|
||||
|
||||
$base_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&action=view_folder&f=$folder_id&$u_sort_param");
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $pm_count, $config['topics_per_page'], $start);
|
||||
$start = $pagination->validate_start($start, $config['topics_per_page'], $pm_count);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $pm_count, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $pm_count, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $pm_count, $config['topics_per_page'], $start),
|
||||
'TOTAL_MESSAGES' => $user->lang('VIEW_PM_MESSAGES', (int) $pm_count),
|
||||
|
||||
'POST_IMG' => (!$auth->acl_get('u_sendpm')) ? $user->img('button_topic_locked', 'POST_PM_LOCKED') : $user->img('button_pm_new', 'POST_NEW_PM'),
|
||||
|
@ -481,14 +484,10 @@ function get_pm_from($folder_id, $folder, $user_id)
|
|||
{
|
||||
$store_reverse = true;
|
||||
|
||||
if ($start + $config['topics_per_page'] > $pm_count)
|
||||
{
|
||||
$sql_limit = min($config['topics_per_page'], max(1, $pm_count - $start));
|
||||
}
|
||||
|
||||
// Select the sort order
|
||||
$direction = ($sort_dir == 'd') ? 'ASC' : 'DESC';
|
||||
$sql_start = max(0, $pm_count - $sql_limit - $start);
|
||||
$sql_limit = $pagination->reverse_limit($start, $sql_limit, $pm_count);
|
||||
$sql_start = $pagination->reverse_start($start, $sql_limit, $pm_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -998,6 +998,7 @@ switch ($mode)
|
|||
// The basic memberlist
|
||||
$page_title = $user->lang['MEMBERLIST'];
|
||||
$template_html = 'memberlist_body.html';
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
// Sorting
|
||||
$sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_LOCATION'], 'c' => $user->lang['SORT_JOINED'], 'd' => $user->lang['SORT_POST_COUNT'], 'f' => $user->lang['WEBSITE'], 'g' => $user->lang['ICQ'], 'h' => $user->lang['AIM'], 'i' => $user->lang['MSNM'], 'j' => $user->lang['YIM'], 'k' => $user->lang['JABBER']);
|
||||
|
@ -1487,6 +1488,8 @@ switch ($mode)
|
|||
);
|
||||
}
|
||||
|
||||
$start = $pagination->validate_start($start, $config['topics_per_page'], $config['num_users']);
|
||||
|
||||
// Get us some users :D
|
||||
$sql = "SELECT u.user_id
|
||||
FROM " . USERS_TABLE . " u
|
||||
|
@ -1607,11 +1610,11 @@ switch ($mode)
|
|||
}
|
||||
}
|
||||
|
||||
phpbb_generate_template_pagination($template, $pagination_url, 'pagination', 'start', $total_users, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_users, $config['topics_per_page'], $start);
|
||||
|
||||
// Generate page
|
||||
$template->assign_vars(array(
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $pagination_url, $total_users, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($pagination_url, $total_users, $config['topics_per_page'], $start),
|
||||
'TOTAL_USERS' => $user->lang('LIST_USERS', (int) $total_users),
|
||||
|
||||
'PROFILE_IMG' => $user->img('icon_user_profile', $user->lang['PROFILE']),
|
||||
|
|
306
phpBB/phpbb/pagination.php
Normal file
306
phpBB/phpbb/pagination.php
Normal file
|
@ -0,0 +1,306 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpbb
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb;
|
||||
|
||||
class pagination
|
||||
{
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\template\template $template
|
||||
* @param \phpbb\user $user
|
||||
*/
|
||||
public function __construct(\phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a pagination link based on the url and the page information
|
||||
*
|
||||
* @param string $base_url is url prepended to all links generated within the function
|
||||
* If you use page numbers inside your controller route, base_url should contains a placeholder (%d)
|
||||
* for the page. Also be sure to specify the pagination path information into the start_name argument
|
||||
* @param string $on_page is the page for which we want to generate the link
|
||||
* @param string $start_name is the name of the parameter containing the first item of the given page (example: start=20)
|
||||
* If you use page numbers inside your controller route, start name should be the string
|
||||
* that should be removed for the first page (example: /page/%d)
|
||||
* @param int $per_page the number of items, posts, etc. to display per page, used to determine the number of pages to produce
|
||||
* @return URL for the requested page
|
||||
*/
|
||||
protected function generate_page_link($base_url, $on_page, $start_name, $per_page)
|
||||
{
|
||||
if (strpos($start_name, '%d') !== false)
|
||||
{
|
||||
return ($on_page > 1) ? sprintf($base_url, (int) $on_page) : str_replace($start_name, '', $base_url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&');
|
||||
return ($on_page > 1) ? $base_url . $url_delim . $start_name . '=' . (($on_page - 1) * $per_page) : $base_url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate template rendered pagination
|
||||
* Allows full control of rendering of pagination with the template
|
||||
*
|
||||
* @param string $base_url is url prepended to all links generated within the function
|
||||
* If you use page numbers inside your controller route, base_url should contains a placeholder (%d)
|
||||
* for the page. Also be sure to specify the pagination path information into the start_name argument
|
||||
* @param string $block_var_name is the name assigned to the pagination data block within the template (example: <!-- BEGIN pagination -->)
|
||||
* @param string $start_name is the name of the parameter containing the first item of the given page (example: start=20)
|
||||
* If you use page numbers inside your controller route, start name should be the string
|
||||
* that should be removed for the first page (example: /page/%d)
|
||||
* @param int $num_items the total number of items, posts, etc., used to determine the number of pages to produce
|
||||
* @param int $per_page the number of items, posts, etc. to display per page, used to determine the number of pages to produce
|
||||
* @param int $start 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
|
||||
*/
|
||||
public function generate_template_pagination($base_url, $block_var_name, $start_name, $num_items, $per_page, $start = 1, $reverse_count = false, $ignore_on_page = false)
|
||||
{
|
||||
$total_pages = ceil($num_items / $per_page);
|
||||
|
||||
if ($total_pages == 1 || !$num_items)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$on_page = $this->get_on_page($per_page, $start);
|
||||
|
||||
if ($reverse_count)
|
||||
{
|
||||
$start_page = ($total_pages > 5) ? $total_pages - 4 : 1;
|
||||
$end_page = $total_pages;
|
||||
}
|
||||
else
|
||||
{
|
||||
// What we're doing here is calculating what the "start" and "end" pages should be. We
|
||||
// do this by assuming pagination is "centered" around the currently active page with
|
||||
// the three previous and three next page links displayed. Anything more than that and
|
||||
// we display the ellipsis, likewise anything less.
|
||||
//
|
||||
// $start_page is the page at which we start creating the list. When we have five or less
|
||||
// pages we start at page 1 since there will be no ellipsis displayed. Anymore than that
|
||||
// and we calculate the start based on the active page. This is the min/max calculation.
|
||||
// First (max) would we end up starting on a page less than 1? Next (min) would we end
|
||||
// up starting so close to the end that we'd not display our minimum number of pages.
|
||||
//
|
||||
// $end_page is the last page in the list to display. Like $start_page we use a min/max to
|
||||
// determine this number. Again at most five pages? Then just display them all. More than
|
||||
// five and we first (min) determine whether we'd end up listing more pages than exist.
|
||||
// We then (max) ensure we're displaying the minimum number of pages.
|
||||
$start_page = ($total_pages > 5) ? min(max(1, $on_page - 3), $total_pages - 4) : 1;
|
||||
$end_page = ($total_pages > 5) ? max(min($total_pages, $on_page + 3), 5) : $total_pages;
|
||||
}
|
||||
|
||||
$u_previous_page = $u_next_page = '';
|
||||
if ($on_page != 1)
|
||||
{
|
||||
$u_previous_page = $this->generate_page_link($base_url, $on_page - 1, $start_name, $per_page);
|
||||
|
||||
$this->template->assign_block_vars($block_var_name, array(
|
||||
'PAGE_NUMBER' => '',
|
||||
'PAGE_URL' => $u_previous_page,
|
||||
'S_IS_CURRENT' => false,
|
||||
'S_IS_PREV' => true,
|
||||
'S_IS_NEXT' => false,
|
||||
'S_IS_ELLIPSIS' => false,
|
||||
));
|
||||
}
|
||||
|
||||
// This do...while exists purely to negate the need for start and end assign_block_vars, i.e.
|
||||
// to display the first and last page in the list plus any ellipsis. We use this loop to jump
|
||||
// around a little within the list depending on where we're starting (and ending).
|
||||
$at_page = 1;
|
||||
do
|
||||
{
|
||||
// We decide whether to display the ellipsis during the loop. The ellipsis is always
|
||||
// displayed as either the second or penultimate item in the list. So are we at either
|
||||
// of those points and of course do we even need to display it, i.e. is the list starting
|
||||
// on at least page 3 and ending three pages before the final item.
|
||||
$this->template->assign_block_vars($block_var_name, array(
|
||||
'PAGE_NUMBER' => $at_page,
|
||||
'PAGE_URL' => $this->generate_page_link($base_url, $at_page, $start_name, $per_page),
|
||||
'S_IS_CURRENT' => (!$ignore_on_page && $at_page == $on_page),
|
||||
'S_IS_NEXT' => false,
|
||||
'S_IS_PREV' => false,
|
||||
'S_IS_ELLIPSIS' => ($at_page == 2 && $start_page > 2) || ($at_page == $total_pages - 1 && $end_page < $total_pages - 1),
|
||||
));
|
||||
|
||||
// We may need to jump around in the list depending on whether we have or need to display
|
||||
// the ellipsis. Are we on page 2 and are we more than one page away from the start
|
||||
// of the list? Yes? Then we jump to the start of the list. Likewise are we at the end of
|
||||
// the list and are there more than two pages left in total? Yes? Then jump to the penultimate
|
||||
// page (so we can display the ellipsis next pass). Else, increment the counter and keep
|
||||
// going
|
||||
if ($at_page == 2 && $at_page < $start_page - 1)
|
||||
{
|
||||
$at_page = $start_page;
|
||||
}
|
||||
else if ($at_page == $end_page && $end_page < $total_pages - 1)
|
||||
{
|
||||
$at_page = $total_pages - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$at_page++;
|
||||
}
|
||||
}
|
||||
while ($at_page <= $total_pages);
|
||||
|
||||
if ($on_page != $total_pages)
|
||||
{
|
||||
$u_next_page = $this->generate_page_link($base_url, $on_page + 1, $start_name, $per_page);
|
||||
|
||||
$this->template->assign_block_vars($block_var_name, array(
|
||||
'PAGE_NUMBER' => '',
|
||||
'PAGE_URL' => $u_next_page,
|
||||
'S_IS_CURRENT' => false,
|
||||
'S_IS_PREV' => false,
|
||||
'S_IS_NEXT' => true,
|
||||
'S_IS_ELLIPSIS' => false,
|
||||
));
|
||||
}
|
||||
|
||||
// If the block_var_name is a nested block, we will use the last (most
|
||||
// inner) block as a prefix for the template variables. If the last block
|
||||
// name is pagination, the prefix is empty. If the rest of the
|
||||
// block_var_name is not empty, we will modify the last row of that block
|
||||
// and add our pagination items.
|
||||
$tpl_block_name = $tpl_prefix = '';
|
||||
if (strrpos($block_var_name, '.') !== false)
|
||||
{
|
||||
$tpl_block_name = substr($block_var_name, 0, strrpos($block_var_name, '.'));
|
||||
$tpl_prefix = strtoupper(substr($block_var_name, strrpos($block_var_name, '.') + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
$tpl_prefix = strtoupper($block_var_name);
|
||||
}
|
||||
$tpl_prefix = ($tpl_prefix == 'PAGINATION') ? '' : $tpl_prefix . '_';
|
||||
|
||||
$template_array = array(
|
||||
$tpl_prefix . 'BASE_URL' => $base_url,
|
||||
$tpl_prefix . 'PER_PAGE' => $per_page,
|
||||
'U_' . $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page != 1) ? $u_previous_page : '',
|
||||
'U_' . $tpl_prefix . 'NEXT_PAGE' => ($on_page != $total_pages) ? $u_next_page : '',
|
||||
$tpl_prefix . 'TOTAL_PAGES' => $total_pages,
|
||||
$tpl_prefix . 'CURRENT_PAGE' => $on_page,
|
||||
);
|
||||
|
||||
if ($tpl_block_name)
|
||||
{
|
||||
$this->template->alter_block_array($tpl_block_name, $template_array, true, 'change');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->template->assign_vars($template_array);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current page number
|
||||
*
|
||||
* @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 int Current page number
|
||||
*/
|
||||
public function get_on_page($per_page, $start)
|
||||
{
|
||||
return floor($start / $per_page) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current page
|
||||
* This function also sets certain specific template variables
|
||||
*
|
||||
* @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 string Descriptive pagination string (e.g. "page 1 of 10")
|
||||
*/
|
||||
public function on_page($base_url, $num_items, $per_page, $start)
|
||||
{
|
||||
$on_page = $this->get_on_page($per_page, $start);
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'PER_PAGE' => $per_page,
|
||||
'ON_PAGE' => $on_page,
|
||||
'BASE_URL' => $base_url,
|
||||
));
|
||||
|
||||
return $this->user->lang('PAGE_OF', $on_page, max(ceil($num_items / $per_page), 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current page number
|
||||
*
|
||||
* @param int $start the item which should be considered currently active, used to determine the page we're on
|
||||
* @param int $per_page the number of items, posts, etc. per page
|
||||
* @param int $num_items the total number of items, posts, topics, etc.
|
||||
* @return int Current page number
|
||||
*/
|
||||
public function validate_start($start, $per_page, $num_items)
|
||||
{
|
||||
if ($start < 0 || $start >= $num_items)
|
||||
{
|
||||
return ($start < 0) ? 0 : floor(($num_items - 1) / $per_page) * $per_page;
|
||||
}
|
||||
|
||||
return $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get new start when searching from the end
|
||||
*
|
||||
* If the user is trying to reach late pages, start searching from the end.
|
||||
*
|
||||
* @param int $start the item which should be considered currently active, used to determine the page we're on
|
||||
* @param int $limit the number of items, posts, etc. to display
|
||||
* @param int $num_items the total number of items, posts, topics, etc.
|
||||
* @return int Current page number
|
||||
*/
|
||||
public function reverse_start($start, $limit, $num_items)
|
||||
{
|
||||
return max(0, $num_items - $limit - $start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get new item limit when searching from the end
|
||||
*
|
||||
* If the user is trying to reach late pages, start searching from the end.
|
||||
* In this case the items to display might be lower then the actual per_page setting.
|
||||
*
|
||||
* @param int $start the item which should be considered currently active, used to determine the page we're on
|
||||
* @param int $per_page the number of items, posts, etc. per page
|
||||
* @param int $num_items the total number of items, posts, topics, etc.
|
||||
* @return int Current page number
|
||||
*/
|
||||
public function reverse_limit($start, $per_page, $num_items)
|
||||
{
|
||||
if ($start + $per_page > $num_items)
|
||||
{
|
||||
return min($per_page, max(1, $num_items - $start));
|
||||
}
|
||||
|
||||
return $per_page;
|
||||
}
|
||||
}
|
|
@ -120,6 +120,7 @@ $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
|
|||
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
|
||||
|
||||
$phpbb_content_visibility = $phpbb_container->get('content.visibility');
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
if ($keywords || $author || $author_id || $search_id || $submit)
|
||||
{
|
||||
|
@ -501,14 +502,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
|||
}
|
||||
|
||||
// Make sure $start is set to the last page if it exceeds the amount
|
||||
if ($start < 0)
|
||||
{
|
||||
$start = 0;
|
||||
}
|
||||
else if ($start >= $total_match_count)
|
||||
{
|
||||
$start = floor(($total_match_count - 1) / $per_page) * $per_page;
|
||||
}
|
||||
$start = $pagination->validate_start($start, $per_page, $total_match_count);
|
||||
|
||||
$id_ary = array_slice($id_ary, $start, $per_page);
|
||||
}
|
||||
|
@ -600,7 +594,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
|||
$phrase_search_disabled = $search->supports_phrase_search() ? false : true;
|
||||
}
|
||||
|
||||
phpbb_generate_template_pagination($template, $u_search, 'pagination', 'start', $total_match_count, $per_page, $start);
|
||||
$pagination->generate_template_pagination($u_search, 'pagination', 'start', $total_match_count, $per_page, $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'SEARCH_TITLE' => $l_search_title,
|
||||
|
@ -608,7 +602,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
|||
'SEARCH_WORDS' => $keywords,
|
||||
'SEARCHED_QUERY' => $search->get_search_query(),
|
||||
'IGNORED_WORDS' => (sizeof($common_words)) ? implode(' ', $common_words) : '',
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $u_search, $total_match_count, $per_page, $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($u_search, $total_match_count, $per_page, $start),
|
||||
|
||||
'PHRASE_SEARCH_DISABLED' => $phrase_search_disabled,
|
||||
|
||||
|
@ -1025,7 +1019,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
|||
|
||||
if ($show_results == 'topics')
|
||||
{
|
||||
phpbb_generate_template_pagination($template, $view_topic_url, 'searchresults.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true);
|
||||
$pagination->generate_template_pagination($view_topic_url, 'searchresults.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ $sort_days = request_var('st', $default_sort_days);
|
|||
$sort_key = request_var('sk', $default_sort_key);
|
||||
$sort_dir = request_var('sd', $default_sort_dir);
|
||||
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
// Check if the user has actually sent a forum ID with his/her request
|
||||
// If not give them a nice error page.
|
||||
if (!$forum_id)
|
||||
|
@ -140,8 +142,13 @@ else
|
|||
}
|
||||
}
|
||||
|
||||
$phpbb_content_visibility = $phpbb_container->get('content.visibility');
|
||||
|
||||
// Dump out the page header and load viewforum template
|
||||
page_header($forum_data['forum_name'] . ($start ? ' - ' . sprintf($user->lang['PAGE_TITLE_NUMBER'], floor($start / $config['topics_per_page']) + 1) : ''), true, $forum_id);
|
||||
$topics_count = $phpbb_content_visibility->get_count('forum_topics', $forum_data, $forum_id);
|
||||
$start = $pagination->validate_start($start, $config['topics_per_page'], $topics_count);
|
||||
|
||||
page_header($forum_data['forum_name'] . ($start ? ' - ' . $user->lang('PAGE_TITLE_NUMBER', $pagination->get_on_page($config['topics_per_page'], $start)) : ''), true, $forum_id);
|
||||
|
||||
$template->set_filenames(array(
|
||||
'body' => 'viewforum_body.html')
|
||||
|
@ -246,8 +253,6 @@ $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_po
|
|||
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
|
||||
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir);
|
||||
|
||||
$phpbb_content_visibility = $phpbb_container->get('content.visibility');
|
||||
|
||||
// Limit topics to certain time frame, obtain correct topic count
|
||||
if ($sort_days)
|
||||
{
|
||||
|
@ -275,16 +280,9 @@ if ($sort_days)
|
|||
}
|
||||
else
|
||||
{
|
||||
$topics_count = $phpbb_content_visibility->get_count('forum_topics', $forum_data, $forum_id);
|
||||
$sql_limit_time = '';
|
||||
}
|
||||
|
||||
// Make sure $start is set to the last page if it exceeds the amount
|
||||
if ($start < 0 || $start > $topics_count)
|
||||
{
|
||||
$start = ($start < 0) ? 0 : floor(($topics_count - 1) / $config['topics_per_page']) * $config['topics_per_page'];
|
||||
}
|
||||
|
||||
// Basic pagewide vars
|
||||
$post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC'];
|
||||
|
||||
|
@ -480,14 +478,11 @@ if ($start > $topics_count / 2)
|
|||
{
|
||||
$store_reverse = true;
|
||||
|
||||
if ($start + $config['topics_per_page'] > $topics_count)
|
||||
{
|
||||
$sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start));
|
||||
}
|
||||
|
||||
// Select the sort order
|
||||
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
|
||||
$sql_start = max(0, $topics_count - $sql_limit - $start);
|
||||
|
||||
$sql_limit = $pagination->reverse_limit($start, $sql_limit, $topics_count);
|
||||
$sql_start = $pagination->reverse_start($start, $sql_limit, $topics_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -631,10 +626,10 @@ if ($s_display_active)
|
|||
$total_topic_count = $topics_count - sizeof($global_announce_forums);
|
||||
|
||||
$base_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : ''));
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $topics_count, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $topics_count, $config['topics_per_page'], $start),
|
||||
'TOTAL_TOPICS' => ($s_display_active) ? false : $user->lang('VIEW_FORUM_TOPICS', (int) $total_topic_count),
|
||||
));
|
||||
|
||||
|
@ -802,7 +797,7 @@ if (sizeof($topic_list))
|
|||
|
||||
$template->assign_block_vars('topicrow', $topic_row);
|
||||
|
||||
phpbb_generate_template_pagination($template, $view_topic_url, 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true);
|
||||
$pagination->generate_template_pagination($view_topic_url, 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true);
|
||||
|
||||
$s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
|
|||
login_box('', $user->lang['LOGIN_EXPLAIN_VIEWONLINE']);
|
||||
}
|
||||
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
$sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_JOINED'], 'c' => $user->lang['SORT_LOCATION']);
|
||||
$sort_key_sql = array('a' => 'u.username_clean', 'b' => 's.session_time', 'c' => 's.session_page');
|
||||
|
||||
|
@ -419,15 +421,16 @@ $db->sql_freeresult($result);
|
|||
// Refreshing the page every 60 seconds...
|
||||
meta_refresh(60, append_sid("{$phpbb_root_path}viewonline.$phpEx", "sg=$show_guests&sk=$sort_key&sd=$sort_dir&start=$start"));
|
||||
|
||||
$start = $pagination->validate_start($start, $config['topics_per_page'], $counter);
|
||||
$base_url = append_sid("{$phpbb_root_path}viewonline.$phpEx", "sg=$show_guests&sk=$sort_key&sd=$sort_dir");
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $counter, $config['topics_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $counter, $config['topics_per_page'], $start);
|
||||
|
||||
// Send data to template
|
||||
$template->assign_vars(array(
|
||||
'TOTAL_REGISTERED_USERS_ONLINE' => $user->lang('REG_USERS_ONLINE', (int) $logged_visible_online, $user->lang('HIDDEN_USERS_ONLINE', (int) $logged_hidden_online)),
|
||||
'TOTAL_GUEST_USERS_ONLINE' => $user->lang('GUEST_USERS_ONLINE', (int) $guest_counter),
|
||||
'LEGEND' => $legend,
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $counter, $config['topics_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $counter, $config['topics_per_page'], $start),
|
||||
|
||||
'U_SORT_USERNAME' => append_sid("{$phpbb_root_path}viewonline.$phpEx", 'sk=a&sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a') . '&sg=' . ((int) $show_guests)),
|
||||
'U_SORT_UPDATED' => append_sid("{$phpbb_root_path}viewonline.$phpEx", 'sk=b&sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a') . '&sg=' . ((int) $show_guests)),
|
||||
|
|
|
@ -43,6 +43,8 @@ $sort_dir = request_var('sd', $default_sort_dir);
|
|||
|
||||
$update = request_var('update', false);
|
||||
|
||||
$pagination = $phpbb_container->get('pagination');
|
||||
|
||||
$s_can_vote = false;
|
||||
/**
|
||||
* @todo normalize?
|
||||
|
@ -434,10 +436,7 @@ if ($hilit_words)
|
|||
}
|
||||
|
||||
// Make sure $start is set to the last page if it exceeds the amount
|
||||
if ($start < 0 || $start >= $total_posts)
|
||||
{
|
||||
$start = ($start < 0) ? 0 : floor(($total_posts - 1) / $config['posts_per_page']) * $config['posts_per_page'];
|
||||
}
|
||||
$start = $pagination->validate_start($start, $config['posts_per_page'], $total_posts);
|
||||
|
||||
// General Viewtopic URL for return links
|
||||
$viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id" . (($start == 0) ? '' : "&start=$start") . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($highlight_match) ? "&hilit=$highlight" : ''));
|
||||
|
@ -591,7 +590,7 @@ if (!empty($_EXTRA_URL))
|
|||
|
||||
// If we've got a hightlight set pass it on to pagination.
|
||||
$base_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($highlight_match) ? "&hilit=$highlight" : ''));
|
||||
phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total_posts, $config['posts_per_page'], $start);
|
||||
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_posts, $config['posts_per_page'], $start);
|
||||
|
||||
// Send vars to template
|
||||
$template->assign_vars(array(
|
||||
|
@ -606,7 +605,7 @@ $template->assign_vars(array(
|
|||
'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
|
||||
'TOPIC_AUTHOR' => get_username_string('username', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
|
||||
|
||||
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $total_posts, $config['posts_per_page'], $start),
|
||||
'PAGE_NUMBER' => $pagination->on_page($base_url, $total_posts, $config['posts_per_page'], $start),
|
||||
'TOTAL_POSTS' => $user->lang('VIEW_TOPIC_POSTS', (int) $total_posts),
|
||||
'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&mode=topic_view&f=$forum_id&t=$topic_id" . (($start == 0) ? '' : "&start=$start") . ((strlen($u_sort_param)) ? "&$u_sort_param" : ''), true, $user->session_id) : '',
|
||||
'MODERATORS' => (isset($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id])) ? implode($user->lang['COMMA_SEPARATOR'], $forum_moderators[$forum_id]) : '',
|
||||
|
@ -910,14 +909,11 @@ if ($start > $total_posts / 2)
|
|||
{
|
||||
$store_reverse = true;
|
||||
|
||||
if ($start + $config['posts_per_page'] > $total_posts)
|
||||
{
|
||||
$sql_limit = min($config['posts_per_page'], max(1, $total_posts - $start));
|
||||
}
|
||||
|
||||
// Select the sort order
|
||||
$direction = (($sort_dir == 'd') ? 'ASC' : 'DESC');
|
||||
$sql_start = max(0, $total_posts - $sql_limit - $start);
|
||||
|
||||
$sql_limit = $pagination->reverse_limit($start, $sql_limit, $total_posts);
|
||||
$sql_start = $pagination->reverse_start($start, $sql_limit, $total_posts);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1909,7 +1905,7 @@ if (!request_var('t', 0) && !empty($topic_id))
|
|||
$request->overwrite('t', $topic_id);
|
||||
}
|
||||
|
||||
$page_title = $topic_data['topic_title'] . ($start ? ' - ' . sprintf($user->lang['PAGE_TITLE_NUMBER'], floor($start / $config['posts_per_page']) + 1) : '');
|
||||
$page_title = $topic_data['topic_title'] . ($start ? ' - ' . sprintf($user->lang['PAGE_TITLE_NUMBER'], $pagination->get_on_page($config['topics_per_page'], $start)) : '');
|
||||
|
||||
/**
|
||||
* You can use this event to modify the page title of the viewtopic page
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../template/template_test_case.php';
|
||||
|
||||
class phpbb_pagination_generate_template_test extends phpbb_template_template_test_case
|
||||
{
|
||||
protected $test_path = 'tests/pagination';
|
||||
|
||||
public function phpbb_generate_template_pagination_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'page.php',
|
||||
'start',
|
||||
95,
|
||||
10,
|
||||
10,
|
||||
'pagination
|
||||
:previous::page.php
|
||||
:else:1:page.php
|
||||
:current:2:page.php?start=10
|
||||
:else:3:page.php?start=20
|
||||
:else:4:page.php?start=30
|
||||
:else:5:page.php?start=40
|
||||
:ellipsis:9:page.php?start=80
|
||||
:else:10:page.php?start=90
|
||||
:next::page.php?start=20
|
||||
:u_prev:page.php
|
||||
:u_next:page.php?start=20',
|
||||
),
|
||||
array(
|
||||
'page.php',
|
||||
'start',
|
||||
95,
|
||||
10,
|
||||
20,
|
||||
'pagination
|
||||
:previous::page.php?start=10
|
||||
:else:1:page.php
|
||||
:else:2:page.php?start=10
|
||||
:current:3:page.php?start=20
|
||||
:else:4:page.php?start=30
|
||||
:else:5:page.php?start=40
|
||||
:else:6:page.php?start=50
|
||||
:ellipsis:9:page.php?start=80
|
||||
:else:10:page.php?start=90
|
||||
:next::page.php?start=30
|
||||
:u_prev:page.php?start=10
|
||||
:u_next:page.php?start=30',
|
||||
),
|
||||
array(
|
||||
'test/page/%d',
|
||||
'/page/%d',
|
||||
95,
|
||||
10,
|
||||
10,
|
||||
'pagination
|
||||
:previous::test
|
||||
:else:1:test
|
||||
:current:2:test/page/2
|
||||
:else:3:test/page/3
|
||||
:else:4:test/page/4
|
||||
:else:5:test/page/5
|
||||
:ellipsis:9:test/page/9
|
||||
:else:10:test/page/10
|
||||
:next::test/page/3
|
||||
:u_prev:test
|
||||
:u_next:test/page/3',
|
||||
),
|
||||
array(
|
||||
'test/page/%d',
|
||||
'/page/%d',
|
||||
95,
|
||||
10,
|
||||
20,
|
||||
'pagination
|
||||
:previous::test/page/2
|
||||
:else:1:test
|
||||
:else:2:test/page/2
|
||||
:current:3:test/page/3
|
||||
:else:4:test/page/4
|
||||
:else:5:test/page/5
|
||||
:else:6:test/page/6
|
||||
:ellipsis:9:test/page/9
|
||||
:else:10:test/page/10
|
||||
:next::test/page/4
|
||||
:u_prev:test/page/2
|
||||
:u_next:test/page/4',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider phpbb_generate_template_pagination_data
|
||||
*/
|
||||
public function test_phpbb_generate_template_pagination($base_url, $start_name, $num_items, $per_page, $start_item, $expect)
|
||||
{
|
||||
phpbb_generate_template_pagination($this->template, $base_url, 'pagination', $start_name, $num_items, $per_page, $start_item);
|
||||
$this->template->set_filenames(array('test' => 'pagination.html'));
|
||||
|
||||
$this->assertEquals(str_replace("\t", '', $expect), $this->display('test'));
|
||||
}
|
||||
}
|
240
tests/pagination/pagination_test.php
Normal file
240
tests/pagination/pagination_test.php
Normal file
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../template/template_test_case.php';
|
||||
|
||||
class phpbb_pagination_pagination_test extends phpbb_template_template_test_case
|
||||
{
|
||||
protected $test_path = 'tests/pagination';
|
||||
|
||||
public function return_callback_implode()
|
||||
{
|
||||
return implode('-', func_get_args());
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$user = $this->getMock('\phpbb\user');
|
||||
$user->expects($this->any())
|
||||
->method('lang')
|
||||
->will($this->returnCallback(array($this, 'return_callback_implode')));
|
||||
$this->pagination = new \phpbb\pagination($this->template, $user);
|
||||
}
|
||||
|
||||
public function generate_template_pagination_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'page.php',
|
||||
'start',
|
||||
95,
|
||||
10,
|
||||
10,
|
||||
'pagination
|
||||
:previous::page.php
|
||||
:else:1:page.php
|
||||
:current:2:page.php?start=10
|
||||
:else:3:page.php?start=20
|
||||
:else:4:page.php?start=30
|
||||
:else:5:page.php?start=40
|
||||
:ellipsis:9:page.php?start=80
|
||||
:else:10:page.php?start=90
|
||||
:next::page.php?start=20
|
||||
:u_prev:page.php
|
||||
:u_next:page.php?start=20',
|
||||
),
|
||||
array(
|
||||
'page.php',
|
||||
'start',
|
||||
95,
|
||||
10,
|
||||
20,
|
||||
'pagination
|
||||
:previous::page.php?start=10
|
||||
:else:1:page.php
|
||||
:else:2:page.php?start=10
|
||||
:current:3:page.php?start=20
|
||||
:else:4:page.php?start=30
|
||||
:else:5:page.php?start=40
|
||||
:else:6:page.php?start=50
|
||||
:ellipsis:9:page.php?start=80
|
||||
:else:10:page.php?start=90
|
||||
:next::page.php?start=30
|
||||
:u_prev:page.php?start=10
|
||||
:u_next:page.php?start=30',
|
||||
),
|
||||
array(
|
||||
'test/page/%d',
|
||||
'/page/%d',
|
||||
95,
|
||||
10,
|
||||
10,
|
||||
'pagination
|
||||
:previous::test
|
||||
:else:1:test
|
||||
:current:2:test/page/2
|
||||
:else:3:test/page/3
|
||||
:else:4:test/page/4
|
||||
:else:5:test/page/5
|
||||
:ellipsis:9:test/page/9
|
||||
:else:10:test/page/10
|
||||
:next::test/page/3
|
||||
:u_prev:test
|
||||
:u_next:test/page/3',
|
||||
),
|
||||
array(
|
||||
'test/page/%d',
|
||||
'/page/%d',
|
||||
95,
|
||||
10,
|
||||
20,
|
||||
'pagination
|
||||
:previous::test/page/2
|
||||
:else:1:test
|
||||
:else:2:test/page/2
|
||||
:current:3:test/page/3
|
||||
:else:4:test/page/4
|
||||
:else:5:test/page/5
|
||||
:else:6:test/page/6
|
||||
:ellipsis:9:test/page/9
|
||||
:else:10:test/page/10
|
||||
:next::test/page/4
|
||||
:u_prev:test/page/2
|
||||
:u_next:test/page/4',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generate_template_pagination_data
|
||||
*/
|
||||
public function test_generate_template_pagination($base_url, $start_name, $num_items, $per_page, $start_item, $expect)
|
||||
{
|
||||
$this->pagination->generate_template_pagination($base_url, 'pagination', $start_name, $num_items, $per_page, $start_item);
|
||||
$this->template->set_filenames(array('test' => 'pagination.html'));
|
||||
|
||||
$this->assertEquals(str_replace("\t", '', $expect), $this->display('test'));
|
||||
}
|
||||
|
||||
public function on_page_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'page.php',
|
||||
10,
|
||||
10,
|
||||
0,
|
||||
'PAGE_OF-1-1',
|
||||
'on_page
|
||||
per_page:10
|
||||
on_page:1
|
||||
base_url:page.php',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider on_page_data
|
||||
*/
|
||||
public function test_on_page($base_url, $num_items, $per_page, $start_item, $expect_return, $expect)
|
||||
{
|
||||
$this->assertEquals($expect_return, $this->pagination->on_page($base_url, $num_items, $per_page, $start_item));
|
||||
|
||||
$this->template->set_filenames(array('test' => 'on_page.html'));
|
||||
|
||||
$this->assertEquals(str_replace("\t", '', $expect), $this->display('test'));
|
||||
}
|
||||
|
||||
public function validate_start_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
-1,
|
||||
0,
|
||||
),
|
||||
array(
|
||||
0,
|
||||
0,
|
||||
),
|
||||
array(
|
||||
10,
|
||||
10,
|
||||
),
|
||||
array(
|
||||
20,
|
||||
10,
|
||||
),
|
||||
array(
|
||||
30,
|
||||
10,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validate_start_data
|
||||
*/
|
||||
public function test_validate_start($start, $expect)
|
||||
{
|
||||
$this->assertEquals($expect, $this->pagination->validate_start($start, 10, 20));
|
||||
}
|
||||
|
||||
public function reverse_start_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
10,
|
||||
5,
|
||||
15,
|
||||
0,
|
||||
),
|
||||
array(
|
||||
10,
|
||||
10,
|
||||
25,
|
||||
5,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider reverse_start_data
|
||||
*/
|
||||
public function test_reverse_start($start, $limit, $num_items, $expect)
|
||||
{
|
||||
$this->assertEquals($expect, $this->pagination->reverse_start($start, $limit, $num_items));
|
||||
}
|
||||
|
||||
public function reverse_limit_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
10,
|
||||
10,
|
||||
15,
|
||||
5,
|
||||
),
|
||||
array(
|
||||
20,
|
||||
10,
|
||||
15,
|
||||
1,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider reverse_limit_data
|
||||
*/
|
||||
public function test_reverse_limit($start, $per_page, $num_items, $expect)
|
||||
{
|
||||
$this->assertEquals($expect, $this->pagination->reverse_limit($start, $per_page, $num_items));
|
||||
}
|
||||
}
|
4
tests/pagination/templates/on_page.html
Normal file
4
tests/pagination/templates/on_page.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
on_page
|
||||
per_page:{PER_PAGE}
|
||||
on_page:{ON_PAGE}
|
||||
base_url:{BASE_URL}
|
Loading…
Add table
Reference in a new issue