An event to alter pagination links would be very handy in \phpbb\pagination\generate_page_link
This could be handled like in append_sid with something like :
Code: Select all
/**
* 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 string URL for the requested page
*/
protected function generate_page_link($base_url, $on_page, $start_name, $per_page)
{
global $phpbb_dispatcher;
$page_link_overwrite = false;
/**
* This event can override the generate_page_link() function
*
* To override this function, the event must set $page_link_overwrite to
* the new URL value, which will be returned following the event
*
* @event core.pagination_generate_page_link
* @param string $base_url
* @param string $on_page
* @param string $start_name
* @param int $per_page
* @var bool|string page_link_overwrite Overwrite function (string URL) or not (false)
* @since 3.1.0-RC3
*/
$vars = array('base_url', 'on_page', 'start_name', 'per_page', 'page_link_overwrite');
extract($phpbb_dispatcher->trigger_event('core.pagination_generate_page_link', compact($vars)));
if ($page_link_overwrite)
{
return $page_link_overwrite;
}
if (!is_string($base_url))
{
if (is_array($base_url['routes']))
{
$route = ($on_page > 1) ? $base_url['routes'][1] : $base_url['routes'][0];
}
else
{
$route = $base_url['routes'];
}
$params = (isset($base_url['params'])) ? $base_url['params'] : array();
$is_amp = (isset($base_url['is_amp'])) ? $base_url['is_amp'] : true;
$session_id = (isset($base_url['session_id'])) ? $base_url['session_id'] : false;
if ($on_page > 1 || !is_array($base_url['routes']))
{
$params[$start_name] = (int) $on_page;
}
return $this->helper->route($route, $params, $is_amp, $session_id);
}
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;
}
}
Providing the event with all param from generate_page_link is the simple option, we could imagine to use two event for route/base_url'd cases, but I don't think it would be that wise.