XOOPS  2.6.0
pagenav.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
24 {
33  private $total;
34 
38  private $perpage;
39 
43  private $current;
44 
48  private $extra;
49 
53  private $url;
54 
64  public function __construct($total_items, $items_perpage, $current_start, $start_name = "start", $extra_arg = "")
65  {
66  $this->total = intval($total_items);
67  $this->perpage = intval($items_perpage);
68  $this->current = intval($current_start);
69  $this->extra = $extra_arg;
70  if ($extra_arg != '' && (substr($extra_arg, - 5) != '&amp;' || substr($extra_arg, - 1) != '&')) {
71  $this->extra = '&amp;' . $extra_arg;
72  }
73  $this->url = $_SERVER['PHP_SELF'] . '?' . trim($start_name) . '=';
74  }
75 
87  public function renderNav($offset = 4, $size = "", $align = "right", $prev_text = "&laquo;", $next_text = "&raquo;")
88  {
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 = intval(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 
174  public function renderSelect($align = "right", $showbutton = false)
175  {
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 = intval(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 
214  public function renderImageNav($offset = 4)
215  {
217  $xoops->deprecated('renderImageNav() is deprecated since 2.6.0. Please use renderNav()');
218  return $this->renderNav($offset);
219  }
220 }
renderSelect($align="right", $showbutton=false)
Definition: pagenav.php:174
static getInstance()
Definition: Xoops.php:160
renderImageNav($offset=4)
Definition: pagenav.php:214
$_SERVER['REQUEST_URI']
$xoops
Definition: admin.php:25
renderNav($offset=4, $size="", $align="right", $prev_text="&laquo;", $next_text="&raquo;")
Definition: pagenav.php:87
__construct($total_items, $items_perpage, $current_start, $start_name="start", $extra_arg="")
Definition: pagenav.php:64