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