consolidated page browsing code; updates #262
and - fixed page browser display on search results page for last four pages - set max. page count on all other pages to 15 (from 9 or none)
This commit is contained in:
@@ -174,64 +174,20 @@ function get_logpics($purpose, $userid=0, $cacheid=0)
|
||||
}
|
||||
|
||||
|
||||
// set all template variables needed to display log pictures page browser;
|
||||
// Set all template variables needed to display a browsed log pictures page;
|
||||
// all displaying is done in res_logpictures.tpl
|
||||
|
||||
function set_paged_pics($purpose, $userid, $cacheid, $tpl, $url)
|
||||
function set_paged_pics($purpose, $userid, $cacheid, $url)
|
||||
{
|
||||
global $_REQUEST, $opt;
|
||||
global $tpl;
|
||||
|
||||
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat']+0 : 0;
|
||||
|
||||
$pictures = get_logpics($purpose, $userid, $cacheid);
|
||||
$tpl->assign('pictures', array_slice($pictures, $startat, MAX_PICTURES_PER_GALLERY_PAGE));
|
||||
|
||||
$paging = (count($pictures) > MAX_PICTURES_PER_GALLERY_PAGE);
|
||||
$tpl->assign('paging', $paging);
|
||||
if ($paging)
|
||||
{
|
||||
$pages = floor((count($pictures) + MAX_PICTURES_PER_GALLERY_PAGE - 1)/MAX_PICTURES_PER_GALLERY_PAGE);
|
||||
$page = floor($startat/MAX_PICTURES_PER_GALLERY_PAGE) + 1;
|
||||
|
||||
$pl = "";
|
||||
if ($startat > 0)
|
||||
{
|
||||
if ($pages > 2)
|
||||
$pl .= "<a href='" . $url . "&startat=0'><img src='resource2/" . $opt['template']['style'] . "/images/navigation/16x16-browse-first.png' width='16px' height='16px' alt='<<'></a> ";
|
||||
$pl .= "<a href='" . $url . "&startat=" . ($startat - MAX_PICTURES_PER_GALLERY_PAGE) . "'><img src='resource2/" . $opt['template']['style'] . "/images/navigation/16x16-browse-prev.png' width='16px' height='16px' alt='<'></a> ";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($pages > 2)
|
||||
$pl .= "<a href='" . $url . "&startat=0'><img src='resource2/" . $opt['template']['style'] . "/images/navigation/16x16-browse-first-inactive.png' width='16px' height='16px' alt='<<'></a> ";
|
||||
$pl .= "<img src='resource2/" . $opt['template']['style'] . "/images/navigation/16x16-browse-prev-inactive.png' width='16px' height='16px' alt='<'> ";
|
||||
}
|
||||
|
||||
for ($p=1; $p<=$pages; $p++)
|
||||
{
|
||||
if ($pl != "") $pl .= " ";
|
||||
if ($p != $page) $pl .= "<a href='" . $url . "&startat=" . (($p-1)*MAX_PICTURES_PER_GALLERY_PAGE) . "'>";
|
||||
else $pl .= "<strong>";
|
||||
$pl .= $p;
|
||||
if ($p != $page) $pl .= "</a>";
|
||||
else $pl .= "</strong>";
|
||||
}
|
||||
|
||||
if ($startat + MAX_PICTURES_PER_GALLERY_PAGE < count($pictures))
|
||||
{
|
||||
$pl .= " <a href='" . $url . "&startat=" . ($startat + MAX_PICTURES_PER_GALLERY_PAGE) . "'><img src='resource2/" . $opt['template']['style'] . "/images/navigation/16x16-browse-next.png' width='16px' height='16px' alt='>'></a> ";
|
||||
if ($pages > 2)
|
||||
$pl .= " <a href='" . $url . "&startat=" . ($startat + MAX_PICTURES_PER_GALLERY_PAGE) . "'><img src='resource2/" . $opt['template']['style'] . "/images/navigation/16x16-browse-last.png' width='16px' height='16px' alt='>>'></a> ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$pl .= " <img src='resource2/" . $opt['template']['style'] . "/images/navigation/16x16-browse-next-inactive.png' width='16px' height='16px' alt='>'>";
|
||||
if ($pages > 2)
|
||||
$pl .= " <a href='" . $url . "&startat=" . ($startat + MAX_PICTURES_PER_GALLERY_PAGE) . "'><img src='resource2/" . $opt['template']['style'] . "/images/navigation/16x16-browse-last-inactive.png' width='16px' height='16px' alt='>>'></a> ";
|
||||
}
|
||||
|
||||
$tpl->assign('pagelinks', $pl);
|
||||
}
|
||||
$pager = new pager($url . "&startat={offset}");
|
||||
$pager->make_from_offset($startat, count($pictures), MAX_PICTURES_PER_GALLERY_PAGE);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* Set template variables for displaying a page browser control.
|
||||
* Output is formatted by templates2/<style>/res_pager.tpl.
|
||||
***************************************************************************/
|
||||
|
||||
class pager
|
||||
{
|
||||
private $link_url;
|
||||
private $min_pages_shown;
|
||||
private $max_pages_shown;
|
||||
|
||||
|
||||
// Use {page} in link_url als placeholder for the selected page number
|
||||
// and/or {offset} for the 0-based data offset of the selected page number.
|
||||
|
||||
function __construct($link_url, $min_pages_shown=2, $max_pages_shown=15)
|
||||
{
|
||||
global $tpl;
|
||||
|
||||
$this->link_url = $link_url;
|
||||
$this->min_pages_shown = $min_pages_shown;
|
||||
if (($max_pages_shown % 2) == 0)
|
||||
$tpl->error("pager: max pages shown must be odd");
|
||||
$this->max_pages_shown = $max_pages_shown;
|
||||
}
|
||||
|
||||
|
||||
function make_from_pagenr($current_page, $total_pages, $page_size=false)
|
||||
{
|
||||
global $tpl;
|
||||
|
||||
if (mb_strpos($this->link_url,'{offset}') && $page_size === false)
|
||||
{
|
||||
$tpl->error('page size is not set for offset paging');
|
||||
}
|
||||
elseif ($total_pages < $this->min_pages_shown)
|
||||
{
|
||||
// not enough pages - disable pager
|
||||
$tpl->assign('pages_list',false);
|
||||
}
|
||||
else
|
||||
{
|
||||
$first_page = 1;
|
||||
$last_page = $total_pages;
|
||||
$current_page = min(max($current_page,$first_page),$last_page);
|
||||
|
||||
if ($current_page == $first_page)
|
||||
{
|
||||
$tpl->assign('pages_first_link',false);
|
||||
$tpl->assign('pages_prev_link',false);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tpl->assign('pages_first_link', $this->pagelink($first_page,$page_size));
|
||||
$tpl->assign('pages_prev_link', $this->pagelink($current_page-1,$page_size));
|
||||
}
|
||||
|
||||
$pages = array();
|
||||
$lrspan = ($this->max_pages_shown-1) / 2;
|
||||
$from_page = max($first_page, $current_page-$lrspan);
|
||||
$to_page = min($last_page, max($first_page, $current_page-$lrspan) + $this->max_pages_shown-1);
|
||||
$from_page = max($first_page, $to_page - 2*$lrspan);
|
||||
|
||||
for ($page = $from_page; $page <= $to_page; $page++)
|
||||
{
|
||||
if ($page == $current_page)
|
||||
$pages[$page] = false;
|
||||
else
|
||||
$pages[$page] = $this->pagelink($page,$page_size);
|
||||
}
|
||||
$tpl->assign('pages_list', $pages);
|
||||
|
||||
if ($current_page == $last_page)
|
||||
{
|
||||
$tpl->assign('pages_next_link',false);
|
||||
$tpl->assign('pages_last_link',false);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tpl->assign('pages_next_link', $this->pagelink($current_page+1,$page_size));
|
||||
$tpl->assign('pages_last_link', $this->pagelink($last_page,$page_size));
|
||||
}
|
||||
|
||||
if ($last_page-$first_page < 2)
|
||||
{
|
||||
$tpl->assign('pages_first_link',null);
|
||||
$tpl->assign('pages_last_link',null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function make_from_offset($current_offset, $total_items, $page_size)
|
||||
{
|
||||
$this->make_from_pagenr(
|
||||
floor($current_offset/$page_size) + 1,
|
||||
ceil($total_items/$page_size),
|
||||
$page_size);
|
||||
}
|
||||
|
||||
|
||||
private function pagelink($page,$page_size)
|
||||
{
|
||||
return mb_ereg_replace('{page}', $page,
|
||||
mb_ereg_replace('{offset}', ($page-1) * $page_size,
|
||||
$this->link_url));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -110,40 +110,9 @@ function search_output()
|
||||
|
||||
$tpl->assign('caches', $caches);
|
||||
|
||||
// more than one page?
|
||||
if ($resultcount <= $caches_per_page)
|
||||
$pages = '';
|
||||
else
|
||||
{
|
||||
if ($startat > 0) // Ocprop: queryid=([0-9]+)
|
||||
$pages = '<a href="search.php?queryid=' . $options['queryid'] . '&startat=0"><img src="resource2/ocstyle/images/navigation/16x16-browse-first.png" width="16" height="16"></a> <a href="search.php?queryid=' . $options['queryid'] . '&startat=' . ($startat - $caches_per_page) . '"><img src="resource2/ocstyle/images/navigation/16x16-browse-prev.png" width="16" height="16"></a> ';
|
||||
else
|
||||
$pages = ' <img src="resource2/ocstyle/images/navigation/16x16-browse-first-inactive.png" width="16" height="16"> <img src="resource2/ocstyle/images/navigation/16x16-browse-prev-inactive.png" width="16" height="16"> ';
|
||||
$pager = new pager('search.php?queryid=' . $options['queryid'] . '&startat={offset}', 2, 9);
|
||||
$pager->make_from_offset($startat, $resultcount, $caches_per_page);
|
||||
|
||||
$frompage = ($startat / $caches_per_page) - 3;
|
||||
if ($frompage < 1) $frompage = 1;
|
||||
$maxpage = ceil($resultcount / $caches_per_page);
|
||||
$topage = $frompage + 8;
|
||||
if ($topage > $maxpage) $topage = $maxpage;
|
||||
|
||||
for ($i = $frompage; $i <= $topage; $i++)
|
||||
{
|
||||
if (($startat / $caches_per_page + 1) == $i)
|
||||
$pages .= ' <b>' . $i . '</b>';
|
||||
else
|
||||
$pages .= ' <a href="search.php?queryid=' . $options['queryid'] . '&startat=' . (($i - 1) * $caches_per_page) . '">' . $i . '</a>';
|
||||
}
|
||||
|
||||
if ($startat / $caches_per_page < ($maxpage - 1))
|
||||
$pages .= ' <a href="search.php?queryid=' . $options['queryid'] . '&startat=' . ($startat + $caches_per_page) . '"><img src="resource2/ocstyle/images/navigation/16x16-browse-next.png" width="16" height="16"></a> <a href="search.php?queryid=' . $options['queryid'] . '&startat=' . (($maxpage - 1) * $caches_per_page) . '"><img src="resource2/ocstyle/images/navigation/16x16-browse-last.png" width="16" height="16"></a> ';
|
||||
else
|
||||
$pages .= ' <img src="resource2/ocstyle/images/navigation/16x16-browse-next-inactive.png" width="16" height="16"> <img src="resource2/ocstyle/images/navigation/16x16-browse-last-inactive.png" width="16" height="16">';
|
||||
}
|
||||
|
||||
//'<a href="search.php?queryid=' . $options['queryid'] . '&startat=20">20</a> 40 60 80 100';
|
||||
//$caches_per_page
|
||||
//count($caches) - 1
|
||||
$tpl->assign('pages', $pages);
|
||||
$tpl->assign('showonmap', $showonmap);
|
||||
|
||||
// downloads
|
||||
|
||||
Reference in New Issue
Block a user