Minahito
minah****@users*****
2006年 10月 12日 (木) 20:00:35 JST
Index: xoops2jp/html/class/smarty/plugins/function.xoops_pagenavi.php diff -u xoops2jp/html/class/smarty/plugins/function.xoops_pagenavi.php:1.1.2.3 xoops2jp/html/class/smarty/plugins/function.xoops_pagenavi.php:1.1.2.3.2.1 --- xoops2jp/html/class/smarty/plugins/function.xoops_pagenavi.php:1.1.2.3 Fri Jan 27 17:23:38 2006 +++ xoops2jp/html/class/smarty/plugins/function.xoops_pagenavi.php Thu Oct 12 20:00:35 2006 @@ -10,84 +10,70 @@ * Author: minahito * Purpose: the place holder for xoops pagenavi. * Input: pagenavi = - * total = - * current = - * perpage = - * url = * offset = * - * Examples: {xoops_pagenavi total=20 current=3 url="list.php?start="} + * Examples: {xoops_pagenavi pagenavi=$pagenavi} * ------------------------------------------------------------- */ function smarty_function_xoops_pagenavi($params, &$smarty) { - $ret=""; + $ret = ""; - if(isset($params['pagenavi'])&&is_object($params['pagenavi'])) { - $perPage =$params['pagenavi']->getPerpage(); - if ($perPage == 0) { + if (isset($params['pagenavi']) && is_object($params['pagenavi'])) { + + $navi =& $params['pagenavi']; + + $perPage = $navi->getPerpage(); + + $total = $navi->getTotalItems(); + $totalPages = $navi->getTotalPages(); + + if ($totalPages == 0) { return; } - - $total=$params['pagenavi']->getTotal(); - $totalPages = ceil($params['pagenavi']->getTotal() / $perPage); - $url=$params['pagenavi']->getRenderUrl(); - $current=$params['pagenavi']->getStart(); - } - else { - $perPage=isset($params['perpage']) ? intval($params['perpage']) : 20; - if ($perPage == 0) { - return; + + $url = $navi->renderURLForPage(); + $current = $navi->getStart(); + + $offset = isset($params['offset']) ? intval($params['offset']) : 4; + + // + // check prev + // + if($navi->hasPrivPage()) { + $ret .= @sprintf("<a href='%s'>«</a>", $navi->renderURLForPage($navi->getPrivStart())); } - $total=$params['total']; - $totalPages = ceil($total / $perPage); - $url=$params['url']; - $current=$params['current']; - } - - $offset=isset($params['offset']) ? intval($params['offset']) : 4; - - if($totalPages==0) - return; - - // - // check prev - // - $prev=$current-$perPage; - if($prev>=0) - $ret.=@sprintf("<a href='%s%d'>«</a>",$url,$prev); - - - // - // counting - // - $counter=1; - $currentPage=intval(floor(($current+$perPage)/$perPage)); - while($counter<=$totalPages) { - if($counter==$currentPage) { - $ret.=@sprintf("<strong>(%d)</strong> ",$counter); - } - elseif(($counter>$currentPage-$offset && $counter<$currentPage+$offset) || $counter==1 || $counter==$totalPages) { - if($counter==$totalPages && $currentPage<$totalPages-$offset) { - $ret.="... "; + // + // counting + // + $counter=1; + $currentPage = $navi->getCurrentPage(); + while($counter<=$totalPages) { + if($counter==$currentPage) { + $ret.=@sprintf("<strong>(%d)</strong> ",$counter); } - $ret .= @sprintf("<a href='%s%d'>%d</a> ",$url,($counter-1)*$perPage,$counter); - if($counter==1 && $currentPage>1 + $offset) { - $ret.="... "; + elseif(($counter>$currentPage-$offset && $counter<$currentPage+$offset) || $counter==1 || $counter==$totalPages) { + if($counter==$totalPages && $currentPage<$totalPages-$offset) { + $ret.="... "; + } + $ret .= @sprintf("<a href='%s'>%d</a> ",$navi->renderURLForPage(($counter-1)*$perPage),$counter); + if($counter==1 && $currentPage>1 + $offset) { + $ret.="... "; + } } + $counter++; + } + + // + // check next + // + $next=$current + $perPage; + if($navi->hasNextPage()) { + $ret.=@sprintf("<a href='%s'>»</a>",$navi->renderURLForPage($navi->getNextStart())); } - $counter++; } - // - // check next - // - $next=$current + $perPage; - if($total>$next) - $ret.=@sprintf("<a href='%s%d'>»</a>",$url,$next); - - print $ret; }