1: <?php
2: /*
3: itemsCount: Total number of items in the current list
4: pageSize: Number of items in each page
5: offset: Index of the 1st item currently displayed
6: linksCount: Number of direct links to show (default to 5)
7: url: URL mask used to generate links (%s will be replaced by offset)
8: itemsCount=$items_count pageSize=$module_config.perpage offset=$offset
9: url="viewcat.php?cid=`$entity.cid`&orderby=`$sort_order`&offset=%s"
10: */
11:
12: /**
13: * @param $params
14: * @param $smarty
15: *
16: * @return string
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: //TODO Remove this hardocded strings
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: