1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5
* An open source application development framework for PHP 5.1.6 or newer
8
* @author ExpressionEngine Dev Team
9
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10
* @license http://codeigniter.com/user_guide/license.html
11
* @link http://codeigniter.com
16
// ------------------------------------------------------------------------
21
* @package CodeIgniter
22
* @subpackage Libraries
23
* @category Pagination
24
* @author ExpressionEngine Dev Team
25
* @link http://codeigniter.com/user_guide/libraries/pagination.html
29
var $base_url = ''; // The page we are linking to
30
var $prefix = ''; // A custom prefix added to the path.
31
var $suffix = ''; // A custom suffix added to the path.
33
var $total_rows = 0; // Total number of items (database results)
34
var $per_page = 10; // Max number of items you want shown per page
35
var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
36
var $cur_page = 0; // The current page being viewed
37
var $use_page_numbers = FALSE; // Use page number for segment instead of offset
38
var $first_link = '‹ First';
39
var $next_link = '>';
40
var $prev_link = '<';
41
var $last_link = 'Last ›';
43
var $full_tag_open = '';
44
var $full_tag_close = '';
45
var $first_tag_open = '';
46
var $first_tag_close = ' ';
47
var $last_tag_open = ' ';
48
var $last_tag_close = '';
49
var $first_url = ''; // Alternative URL for the First Page.
50
var $cur_tag_open = ' <strong>';
51
var $cur_tag_close = '</strong>';
52
var $next_tag_open = ' ';
53
var $next_tag_close = ' ';
54
var $prev_tag_open = ' ';
55
var $prev_tag_close = '';
56
var $num_tag_open = ' ';
57
var $num_tag_close = '';
58
var $page_query_string = FALSE;
59
var $query_string_segment = 'per_page';
60
var $display_pages = TRUE;
61
var $anchor_class = '';
67
* @param array initialization parameters
69
public function __construct($params = array())
71
if (count($params) > 0)
73
$this->initialize($params);
76
if ($this->anchor_class != '')
78
$this->anchor_class = 'class="'.$this->anchor_class.'" ';
81
log_message('debug', "Pagination Class Initialized");
84
// --------------------------------------------------------------------
87
* Initialize Preferences
90
* @param array initialization parameters
93
function initialize($params = array())
95
if (count($params) > 0)
97
foreach ($params as $key => $val)
99
if (isset($this->$key))
107
// --------------------------------------------------------------------
110
* Generate the pagination links
115
function create_links()
117
// If our item count or per-page total is zero there is no need to continue.
118
if ($this->total_rows == 0 OR $this->per_page == 0)
123
// Calculate the total number of pages
124
$num_pages = ceil($this->total_rows / $this->per_page);
126
// Is there only one page? Hm... nothing more to do here then.
132
// Set the base page index for starting page number
133
if ($this->use_page_numbers)
142
// Determine the current page number.
143
$CI =& get_instance();
145
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
147
if ($CI->input->get($this->query_string_segment) != $base_page)
149
$this->cur_page = $CI->input->get($this->query_string_segment);
151
// Prep the current page - no funny business!
152
$this->cur_page = (int) $this->cur_page;
157
if ($CI->uri->segment($this->uri_segment) != $base_page)
159
$this->cur_page = $CI->uri->segment($this->uri_segment);
161
// Prep the current page - no funny business!
162
$this->cur_page = (int) $this->cur_page;
166
// Set current page to 1 if using page numbers instead of offset
167
if ($this->use_page_numbers AND $this->cur_page == 0)
169
$this->cur_page = $base_page;
172
$this->num_links = (int)$this->num_links;
174
if ($this->num_links < 1)
176
show_error('Your number of links must be a positive number.');
179
if ( ! is_numeric($this->cur_page))
181
$this->cur_page = $base_page;
184
// Is the page number beyond the result range?
185
// If so we show the last page
186
if ($this->use_page_numbers)
188
if ($this->cur_page > $num_pages)
190
$this->cur_page = $num_pages;
195
if ($this->cur_page > $this->total_rows)
197
$this->cur_page = ($num_pages - 1) * $this->per_page;
201
$uri_page_number = $this->cur_page;
203
if ( ! $this->use_page_numbers)
205
$this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
208
// Calculate the start and end numbers. These determine
209
// which number to start and end the digit links with
210
$start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;
211
$end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;
213
// Is pagination being used over GET or POST? If get, add a per_page query
214
// string. If post, add a trailing slash to the base URL if needed
215
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
217
$this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'=';
221
$this->base_url = rtrim($this->base_url, '/') .'/';
227
// Render the "First" link
228
if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1))
230
$first_url = ($this->first_url == '') ? $this->base_url : $this->first_url;
231
$output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
234
// Render the "previous" link
235
if ($this->prev_link !== FALSE AND $this->cur_page != 1)
237
if ($this->use_page_numbers)
239
$i = $uri_page_number - 1;
243
$i = $uri_page_number - $this->per_page;
246
if ($i == 0 && $this->first_url != '')
248
$output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
252
$i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix;
253
$output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
259
if ($this->display_pages !== FALSE)
261
// Write the digit links
262
for ($loop = $start -1; $loop <= $end; $loop++)
264
if ($this->use_page_numbers)
270
$i = ($loop * $this->per_page) - $this->per_page;
273
if ($i >= $base_page)
275
if ($this->cur_page == $loop)
277
$output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page
281
$n = ($i == $base_page) ? '' : $i;
283
if ($n == '' && $this->first_url != '')
285
$output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close;
289
$n = ($n == '') ? '' : $this->prefix.$n.$this->suffix;
291
$output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;
298
// Render the "next" link
299
if ($this->next_link !== FALSE AND $this->cur_page < $num_pages)
301
if ($this->use_page_numbers)
303
$i = $this->cur_page + 1;
307
$i = ($this->cur_page * $this->per_page);
310
$output .= $this->next_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.'</a>'.$this->next_tag_close;
313
// Render the "Last" link
314
if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages)
316
if ($this->use_page_numbers)
322
$i = (($num_pages * $this->per_page) - $this->per_page);
324
$output .= $this->last_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.'</a>'.$this->last_tag_close;
327
// Kill double slashes. Note: Sometimes we can end up with a double slash
328
// in the penultimate link so we'll kill all double slashes.
329
$output = preg_replace("#([^:])//+#", "\\1/", $output);
331
// Add the wrapper HTML if exists
332
$output = $this->full_tag_open.$output.$this->full_tag_close;
337
// END Pagination Class
339
/* End of file Pagination.php */
340
/* Location: ./system/libraries/Pagination.php */
b'\\ No newline at end of file'