1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: function smarty_function_xoPageNav($params, &$smarty)
13: {
14: $xoops = Xoops::getInstance();
15:
16: extract($params);
17: if ($pageSize < 1) {
18: $pageSize = 10;
19: }
20: $pagesCount = (int)($itemsCount / $pageSize);
21: if ($itemsCount <= $pageSize || $pagesCount < 2) {
22: return '';
23: }
24: $str = '';
25: $currentPage = (int)($offset / $pageSize) + 1;
26: $lastPage = (int)($itemsCount / $pageSize) + 1;
27:
28: $minPage = min(1, ceil($currentPage - $linksCount / 2));
29: $maxPage = max($lastPage, floor($currentPage + $linksCount / 2));
30:
31:
32: if ($currentPage > 1) {
33: $str .= '<a href="' . $xoops->url(str_replace( '%s', $offset - $pageSize, $url)) . '">Previous</a>';
34: }
35: for ($i = $minPage; $i <= $maxPage; ++$i) {
36: $tgt = htmlspecialchars($xoops->url(str_replace('%s', ($i - 1) * $pageSize, $url)), ENT_QUOTES);
37: $str .= "<a href='$tgt'>$i</a>";
38: }
39: if ($currentPage < $lastPage) {
40: $str .= '<a href="' . $xoops->url(str_replace('%s', $offset + $pageSize, $url)) . '">Next</a>';
41: }
42: $class = @!empty($class) ? htmlspecialchars($class, ENT_QUOTES) : 'pagenav';
43:
44: $str = "<div class='{$class}'>{$str}</div>";
45: return $str;
46:
47: }
48: