1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18:
19: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
20:
21: 22: 23:
24: class XoopsPageNav
25: {
26: 27: 28: 29: 30:
31: public $total;
32: public $perpage;
33: public $current;
34: public $url;
35: 36: 37:
38:
39: 40: 41: 42: 43: 44: 45: 46: 47:
48: public function __construct($total_items, $items_perpage, $current_start, $start_name = 'start', $extra_arg = '')
49: {
50: $this->total = (int)$total_items;
51: $this->perpage = (int)$items_perpage;
52: $this->current = (int)$current_start;
53: $this->extra = $extra_arg;
54: if ($extra_arg != '' && (substr($extra_arg, -5) !== '&' || substr($extra_arg, -1) !== '&')) {
55: $this->extra = '&' . $extra_arg;
56: }
57: $this->url = $_SERVER['PHP_SELF'] . '?' . trim($start_name) . '=';
58: }
59:
60: 61: 62: 63: 64: 65:
66: public function renderNav($offset = 4)
67: {
68: $ret = '';
69: if ($this->total <= $this->perpage) {
70: return $ret;
71: }
72: if (($this->total != 0) && ($this->perpage != 0)) {
73: $total_pages = ceil($this->total / $this->perpage);
74: if ($total_pages > 1) {
75: $ret .= '<div id="xo-pagenav">';
76: $prev = $this->current - $this->perpage;
77: if ($prev >= 0) {
78: $ret .= '<a class="xo-pagarrow" href="' . $this->url . $prev . $this->extra . '"><u>«</u></a> ';
79: }
80: $counter = 1;
81: $current_page = (int)floor(($this->current + $this->perpage) / $this->perpage);
82: while ($counter <= $total_pages) {
83: if ($counter == $current_page) {
84: $ret .= '<strong class="xo-pagact" >(' . $counter . ')</strong> ';
85: } elseif (($counter > $current_page - $offset && $counter < $current_page + $offset) || $counter == 1 || $counter == $total_pages) {
86: if ($counter == $total_pages && $current_page < $total_pages - $offset) {
87: $ret .= '... ';
88: }
89: $ret .= '<a class="xo-counterpage" href="' . $this->url . (($counter - 1) * $this->perpage) . $this->extra . '">' . $counter . '</a> ';
90: if ($counter == 1 && $current_page > 1 + $offset) {
91: $ret .= '... ';
92: }
93: }
94: ++$counter;
95: }
96: $next = $this->current + $this->perpage;
97: if ($this->total > $next) {
98: $ret .= '<a class="xo-pagarrow" href="' . $this->url . $next . $this->extra . '"><u>»</u></a> ';
99: }
100: $ret .= '</div> ';
101: }
102: }
103:
104: return $ret;
105: }
106:
107: 108: 109: 110: 111: 112:
113: public function renderSelect($showbutton = false)
114: {
115: if ($this->total < $this->perpage) {
116: return null;
117: }
118: $total_pages = ceil($this->total / $this->perpage);
119: $ret = '';
120: if ($total_pages > 1) {
121: $ret = '<form name="pagenavform">';
122: $ret .= '<select name="pagenavselect" onchange="location=this.options[this.options.selectedIndex].value;">';
123: $counter = 1;
124: $current_page = (int)floor(($this->current + $this->perpage) / $this->perpage);
125: while ($counter <= $total_pages) {
126: if ($counter == $current_page) {
127: $ret .= '<option value="' . $this->url . (($counter - 1) * $this->perpage) . $this->extra . '" selected>' . $counter . '</option>';
128: } else {
129: $ret .= '<option value="' . $this->url . (($counter - 1) * $this->perpage) . $this->extra . '">' . $counter . '</option>';
130: }
131: ++$counter;
132: }
133: $ret .= '</select>';
134: if ($showbutton) {
135: $ret .= ' <input type="submit" value="' . _GO . '" />';
136: }
137: $ret .= '</form>';
138: }
139:
140: return $ret;
141: }
142:
143: 144: 145: 146: 147: 148:
149: public function renderImageNav($offset = 4)
150: {
151: if ($this->total < $this->perpage) {
152: return null;
153: }
154: $total_pages = ceil($this->total / $this->perpage);
155: $ret = '';
156: if ($total_pages > 1) {
157: $ret = '<table><tr>';
158: $prev = $this->current - $this->perpage;
159: if ($prev >= 0) {
160: $ret .= '<td class="pagneutral"><a href="' . $this->url . $prev . $this->extra . '"><</a></td><td><img src="' . XOOPS_URL . '/images/blank.gif" width="6" alt="" /></td>';
161: } else {
162: $ret .= '<td class="pagno"></a></td><td><img src="' . XOOPS_URL . '/images/blank.gif" width="6" alt="" /></td>';
163: }
164: $counter = 1;
165: $current_page = (int)floor(($this->current + $this->perpage) / $this->perpage);
166: while ($counter <= $total_pages) {
167: if ($counter == $current_page) {
168: $ret .= '<td class="pagact"><strong>' . $counter . '</strong></td>';
169: } elseif (($counter > $current_page - $offset && $counter < $current_page + $offset) || $counter == 1 || $counter == $total_pages) {
170: if ($counter == $total_pages && $current_page < $total_pages - $offset) {
171: $ret .= '<td class="paginact">...</td>';
172: }
173: $ret .= '<td class="paginact"><a href="' . $this->url . (($counter - 1) * $this->perpage) . $this->extra . '">' . $counter . '</a></td>';
174: if ($counter == 1 && $current_page > 1 + $offset) {
175: $ret .= '<td class="paginact">...</td>';
176: }
177: }
178: ++$counter;
179: }
180: $next = $this->current + $this->perpage;
181: if ($this->total > $next) {
182: $ret .= '<td><img src="' . XOOPS_URL . '/images/blank.gif" width="6" alt="" /></td><td class="pagneutral"><a href="' . $this->url . $next . $this->extra . '">></a></td>';
183: } else {
184: $ret .= '<td><img src="' . XOOPS_URL . '/images/blank.gif" width="6" alt="" /></td><td class="pagno"></td>';
185: }
186: $ret .= '</tr></table>';
187: }
188:
189: return $ret;
190: }
191: }
192: