1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: class XoopsPageNav
24: {
25: 26: 27: 28: 29:
30: 31: 32:
33: private $total;
34:
35: 36: 37:
38: private $perpage;
39:
40: 41: 42:
43: private $current;
44:
45: 46: 47:
48: private $extra;
49:
50: 51: 52:
53: private $url;
54:
55: 56: 57: 58: 59: 60: 61: 62: 63:
64: public function __construct($total_items, $items_perpage, $current_start, $start_name = "start", $extra_arg = "")
65: {
66: $this->total = (int)($total_items);
67: $this->perpage = (int)($items_perpage);
68: $this->current = (int)($current_start);
69: $this->extra = $extra_arg;
70: if ($extra_arg != '' && (substr($extra_arg, - 5) !== '&' || substr($extra_arg, - 1) !== '&')) {
71: $this->extra = '&' . $extra_arg;
72: }
73: $this->url = $_SERVER['PHP_SELF'] . '?' . trim($start_name) . '=';
74: }
75:
76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86:
87: public function renderNav($offset = 4, $size = "", $align = "right", $prev_text = "«", $next_text = "»")
88: {
89: $xoops = Xoops::getInstance();
90: $ret = '';
91: $nav = array();
92: if ($this->total <= $this->perpage) {
93: return $ret;
94: }
95: if (($this->total != 0) && ($this->perpage != 0)) {
96: $total_pages = ceil($this->total / $this->perpage);
97: if ($total_pages > 1) {
98: $prev = $this->current - $this->perpage;
99: if ($prev >= 0) {
100: $xoops->tpl()->assign('prev_text', $prev_text);
101: $xoops->tpl()->assign('prev_url', $this->url . $prev . $this->extra);
102: }
103: $last = 0;
104: $last_text = '';
105: $last_url = '';
106: $first = 0;
107: $first_text = '';
108: $first_url = '';
109: $counter = 1;
110: $current_page = (int)(floor(($this->current + $this->perpage) / $this->perpage));
111: while ($counter <= $total_pages) {
112: if ($counter == $current_page) {
113: $nav['text'] = $counter;
114: $nav['url'] = '';
115: $nav['active'] = 0;
116: } elseif (($counter > $current_page - $offset && $counter < $current_page + $offset) || $counter == 1 || $counter == $total_pages) {
117: if ($counter == $total_pages && $current_page < $total_pages - $offset) {
118: $nav['text'] = '...';
119: $nav['url'] = '';
120: $nav['active'] = 0;
121: $last = 1;
122: $last_text = $counter;
123: $last_url = $this->url . (($counter - 1) * $this->perpage) . $this->extra;
124: } else {
125: $nav['text'] = $counter;
126: $nav['url'] = $this->url . (($counter - 1) * $this->perpage) . $this->extra;
127: $nav['active'] = 1;
128: }
129: if ($counter == 1 && $current_page > 1 + $offset) {
130: $nav['text'] = '...';
131: $nav['url'] = '';
132: $nav['active'] = 0;
133: $first = 1;
134: $first_text = $counter;
135: $first_url = $this->url . (($counter - 1) * $this->perpage) . $this->extra;
136: }
137: }
138: $xoops->tpl()->appendByRef('xo_nav', $nav);
139: unset($nav);
140: ++$counter;
141: }
142: $xoops->tpl()->assign('last', $last);
143: $xoops->tpl()->assign('last_text', $last_text);
144: $xoops->tpl()->assign('last_url', $last_url);
145: $xoops->tpl()->assign('first', $first);
146: $xoops->tpl()->assign('first_text', $first_text);
147: $xoops->tpl()->assign('first_url', $first_url);
148:
149: $next = $this->current + $this->perpage;
150: if ($this->total > $next) {
151: $xoops->tpl()->assign('next_text', $next_text);
152: $xoops->tpl()->assign('next_url', $this->url . $next . $this->extra);
153: }
154: }
155: }
156: if ($size != '') {
157: $size = ' pagination-' . $size;
158: }
159: $xoops->tpl()->assign('size', $size);
160: $xoops->tpl()->assign('align', ' pagination-' . $align);
161: $xoops->tpl()->assign('pagination_nav', true);
162: $ret = $xoops->tpl()->fetch('module:system/system_pagenav.tpl');
163: $xoops->tpl()->clearAssign('xo_nav');
164: return $ret;
165: }
166:
167: 168: 169: 170: 171: 172: 173:
174: public function renderSelect($align = "right", $showbutton = false)
175: {
176: $xoops = Xoops::getInstance();
177: $ret = '';
178: if ($this->total < $this->perpage) {
179: return $ret;
180: }
181: $total_pages = ceil($this->total / $this->perpage);
182: if ($total_pages > 1) {
183: $counter = 1;
184: $current_page = (int)(floor(($this->current + $this->perpage) / $this->perpage));
185: while ($counter <= $total_pages) {
186: $select['text'] = $counter;
187: $select['value'] = $this->url . (($counter - 1) * $this->perpage) . $this->extra;
188: if ($counter == $current_page) {
189: $select['selected'] = 1;
190: } else {
191: $select['selected'] = 0;
192: }
193: $xoops->tpl()->appendByRef('xo_select', $select);
194: unset($select);
195: ++$counter;
196: }
197: }
198: $xoops->tpl()->assign('onchange', "location=this.options[this.options.selectedIndex].value;");
199: $xoops->tpl()->assign('pagination_select', true);
200: $xoops->tpl()->assign('showbutton', $showbutton);
201: $xoops->tpl()->assign('align', ' pagination-' . $align);
202: $ret = $xoops->tpl()->fetch('module:system/system_pagenav.tpl');
203: $xoops->tpl()->clearAssign('xo_select');
204: return $ret;
205: }
206:
207: 208: 209: 210: 211: 212: 213:
214: public function renderImageNav($offset = 4)
215: {
216: $xoops = Xoops::getInstance();
217: $xoops->deprecated('renderImageNav() is deprecated since 2.6.0. Please use renderNav()');
218: return $this->renderNav($offset);
219: }
220: }
221: