Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Eric Barnes | 9a4902a | 2011-12-03 23:46:06 -0500 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Eric Barnes | 9a4902a | 2011-12-03 23:46:06 -0500 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * Pagination Class |
| 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Libraries |
| 35 | * @category Pagination |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/libraries/pagination.html |
| 38 | */ |
| 39 | class CI_Pagination { |
| 40 | |
Eric Barnes | 9a4902a | 2011-12-03 23:46:06 -0500 | [diff] [blame] | 41 | protected $base_url = ''; // The page we are linking to |
| 42 | protected $prefix = ''; // A custom prefix added to the path. |
| 43 | protected $suffix = ''; // A custom suffix added to the path. |
| 44 | protected $total_rows = 0; // Total number of items (database results) |
| 45 | protected $per_page = 10; // Max number of items you want shown per page |
| 46 | protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page |
| 47 | protected $cur_page = 0; // The current page being viewed |
| 48 | protected $use_page_numbers = FALSE; // Use page number for segment instead of offset |
| 49 | protected $first_link = '‹ First'; |
| 50 | protected $next_link = '>'; |
| 51 | protected $prev_link = '<'; |
| 52 | protected $last_link = 'Last ›'; |
| 53 | protected $uri_segment = 3; |
| 54 | protected $full_tag_open = ''; |
| 55 | protected $full_tag_close = ''; |
| 56 | protected $first_tag_open = ''; |
| 57 | protected $first_tag_close = ' '; |
| 58 | protected $last_tag_open = ' '; |
| 59 | protected $last_tag_close = ''; |
| 60 | protected $first_url = ''; // Alternative URL for the First Page. |
| 61 | protected $cur_tag_open = ' <strong>'; |
| 62 | protected $cur_tag_close = '</strong>'; |
| 63 | protected $next_tag_open = ' '; |
| 64 | protected $next_tag_close = ' '; |
| 65 | protected $prev_tag_open = ' '; |
| 66 | protected $prev_tag_close = ''; |
| 67 | protected $num_tag_open = ' '; |
| 68 | protected $num_tag_close = ''; |
| 69 | protected $page_query_string = FALSE; |
| 70 | protected $query_string_segment = 'per_page'; |
| 71 | protected $display_pages = TRUE; |
| 72 | protected $anchor_class = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Constructor |
| 76 | * |
| 77 | * @access public |
| 78 | * @param array initialization parameters |
| 79 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 80 | public function __construct($params = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 81 | { |
Eric Barnes | bce4140 | 2011-12-03 23:47:41 -0500 | [diff] [blame^] | 82 | $this->initialize($params); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 83 | log_message('debug', "Pagination Class Initialized"); |
| 84 | } |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 85 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 86 | // -------------------------------------------------------------------- |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 87 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 88 | /** |
| 89 | * Initialize Preferences |
| 90 | * |
| 91 | * @access public |
| 92 | * @param array initialization parameters |
| 93 | * @return void |
| 94 | */ |
Eric Barnes | 9a4902a | 2011-12-03 23:46:06 -0500 | [diff] [blame] | 95 | public function initialize($params = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 96 | { |
| 97 | if (count($params) > 0) |
| 98 | { |
| 99 | foreach ($params as $key => $val) |
| 100 | { |
| 101 | if (isset($this->$key)) |
| 102 | { |
| 103 | $this->$key = $val; |
| 104 | } |
| 105 | } |
| 106 | } |
Eric Barnes | bce4140 | 2011-12-03 23:47:41 -0500 | [diff] [blame^] | 107 | |
| 108 | if ($this->anchor_class != '') |
| 109 | { |
| 110 | $this->anchor_class = 'class="'.$this->anchor_class.'" '; |
| 111 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 112 | } |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 113 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 114 | // -------------------------------------------------------------------- |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 115 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 116 | /** |
| 117 | * Generate the pagination links |
| 118 | * |
| 119 | * @access public |
| 120 | * @return string |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 121 | */ |
Eric Barnes | 9a4902a | 2011-12-03 23:46:06 -0500 | [diff] [blame] | 122 | public function create_links() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 123 | { |
| 124 | // If our item count or per-page total is zero there is no need to continue. |
| 125 | if ($this->total_rows == 0 OR $this->per_page == 0) |
| 126 | { |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 127 | return ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | // Calculate the total number of pages |
| 131 | $num_pages = ceil($this->total_rows / $this->per_page); |
| 132 | |
| 133 | // Is there only one page? Hm... nothing more to do here then. |
| 134 | if ($num_pages == 1) |
| 135 | { |
| 136 | return ''; |
| 137 | } |
| 138 | |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 139 | // Set the base page index for starting page number |
Aaron Kuzemchak | a5e13f9 | 2011-09-04 16:39:47 -0400 | [diff] [blame] | 140 | $base_page = ($this->use_page_numbers) ? 1 : 0; |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 141 | |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 142 | // Determine the current page number. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | $CI =& get_instance(); |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 144 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 145 | if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) |
| 146 | { |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 147 | if ($CI->input->get($this->query_string_segment) != $base_page) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 148 | { |
| 149 | $this->cur_page = $CI->input->get($this->query_string_segment); |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 150 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 151 | // Prep the current page - no funny business! |
| 152 | $this->cur_page = (int) $this->cur_page; |
| 153 | } |
| 154 | } |
| 155 | else |
| 156 | { |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 157 | if ($CI->uri->segment($this->uri_segment) != $base_page) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 158 | { |
| 159 | $this->cur_page = $CI->uri->segment($this->uri_segment); |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 160 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 161 | // Prep the current page - no funny business! |
| 162 | $this->cur_page = (int) $this->cur_page; |
| 163 | } |
| 164 | } |
Eric Barnes | 9a4902a | 2011-12-03 23:46:06 -0500 | [diff] [blame] | 165 | |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 166 | // Set current page to 1 if using page numbers instead of offset |
| 167 | if ($this->use_page_numbers AND $this->cur_page == 0) |
| 168 | { |
| 169 | $this->cur_page = $base_page; |
| 170 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | |
| 172 | $this->num_links = (int)$this->num_links; |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 173 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 174 | if ($this->num_links < 1) |
| 175 | { |
| 176 | show_error('Your number of links must be a positive number.'); |
| 177 | } |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 178 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 179 | if ( ! is_numeric($this->cur_page)) |
| 180 | { |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 181 | $this->cur_page = $base_page; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | } |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 183 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 184 | // Is the page number beyond the result range? |
| 185 | // If so we show the last page |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 186 | if ($this->use_page_numbers) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 187 | { |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 188 | if ($this->cur_page > $num_pages) |
| 189 | { |
| 190 | $this->cur_page = $num_pages; |
| 191 | } |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | if ($this->cur_page > $this->total_rows) |
| 196 | { |
| 197 | $this->cur_page = ($num_pages - 1) * $this->per_page; |
| 198 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 199 | } |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 200 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 201 | $uri_page_number = $this->cur_page; |
Eric Barnes | 9a4902a | 2011-12-03 23:46:06 -0500 | [diff] [blame] | 202 | |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 203 | if ( ! $this->use_page_numbers) |
| 204 | { |
| 205 | $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); |
| 206 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 207 | |
| 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; |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 211 | $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 213 | // Is pagination being used over GET or POST? If get, add a per_page query |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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) |
| 216 | { |
| 217 | $this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'='; |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | $this->base_url = rtrim($this->base_url, '/') .'/'; |
| 222 | } |
| 223 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 224 | // And here we go... |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | $output = ''; |
| 226 | |
| 227 | // Render the "First" link |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 228 | if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 229 | { |
Robin Sowell | 2a6c1da | 2010-05-24 12:20:03 -0400 | [diff] [blame] | 230 | $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; |
Derek Allard | 96bb75c | 2010-07-05 10:54:30 -0400 | [diff] [blame] | 231 | $output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.'">'.$this->first_link.'</a>'.$this->first_tag_close; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | // Render the "previous" link |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 235 | if ($this->prev_link !== FALSE AND $this->cur_page != 1) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 236 | { |
Aaron Kuzemchak | a5e13f9 | 2011-09-04 16:39:47 -0400 | [diff] [blame] | 237 | $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 238 | |
garthkerr | 48b2301 | 2011-09-21 20:52:50 -0300 | [diff] [blame] | 239 | if (($i == 0 OR ($this->use_page_numbers && $i == 1)) AND $this->first_url != '') |
Robin Sowell | 2a6c1da | 2010-05-24 12:20:03 -0400 | [diff] [blame] | 240 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 241 | $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close; |
Robin Sowell | 2a6c1da | 2010-05-24 12:20:03 -0400 | [diff] [blame] | 242 | } |
| 243 | else |
| 244 | { |
| 245 | $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix; |
Derek Allard | 96bb75c | 2010-07-05 10:54:30 -0400 | [diff] [blame] | 246 | $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close; |
Robin Sowell | 2a6c1da | 2010-05-24 12:20:03 -0400 | [diff] [blame] | 247 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 248 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Derek Allard | e01fd0f | 2010-07-05 11:06:07 -0400 | [diff] [blame] | 251 | // Render the pages |
| 252 | if ($this->display_pages !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 253 | { |
Derek Allard | e01fd0f | 2010-07-05 11:06:07 -0400 | [diff] [blame] | 254 | // Write the digit links |
| 255 | for ($loop = $start -1; $loop <= $end; $loop++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 256 | { |
Aaron Kuzemchak | a5e13f9 | 2011-09-04 16:39:47 -0400 | [diff] [blame] | 257 | $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page; |
Derek Allard | e01fd0f | 2010-07-05 11:06:07 -0400 | [diff] [blame] | 258 | |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 259 | if ($i >= $base_page) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 260 | { |
Derek Allard | e01fd0f | 2010-07-05 11:06:07 -0400 | [diff] [blame] | 261 | if ($this->cur_page == $loop) |
Robin Sowell | 2a6c1da | 2010-05-24 12:20:03 -0400 | [diff] [blame] | 262 | { |
Derek Allard | e01fd0f | 2010-07-05 11:06:07 -0400 | [diff] [blame] | 263 | $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page |
Robin Sowell | 2a6c1da | 2010-05-24 12:20:03 -0400 | [diff] [blame] | 264 | } |
| 265 | else |
| 266 | { |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 267 | $n = ($i == $base_page) ? '' : $i; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 268 | |
Derek Allard | e01fd0f | 2010-07-05 11:06:07 -0400 | [diff] [blame] | 269 | if ($n == '' && $this->first_url != '') |
| 270 | { |
| 271 | $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close; |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 276 | |
Derek Allard | e01fd0f | 2010-07-05 11:06:07 -0400 | [diff] [blame] | 277 | $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close; |
| 278 | } |
Robin Sowell | 2a6c1da | 2010-05-24 12:20:03 -0400 | [diff] [blame] | 279 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | // Render the "next" link |
Derek Allard | 96bb75c | 2010-07-05 10:54:30 -0400 | [diff] [blame] | 285 | if ($this->next_link !== FALSE AND $this->cur_page < $num_pages) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 286 | { |
Aaron Kuzemchak | a5e13f9 | 2011-09-04 16:39:47 -0400 | [diff] [blame] | 287 | $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; |
Aaron Kuzemchak | 11c5f16 | 2011-09-03 20:59:07 -0400 | [diff] [blame] | 288 | |
| 289 | $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; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | // Render the "Last" link |
Derek Allard | 96bb75c | 2010-07-05 10:54:30 -0400 | [diff] [blame] | 293 | if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 294 | { |
Aaron Kuzemchak | a5e13f9 | 2011-09-04 16:39:47 -0400 | [diff] [blame] | 295 | $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; |
Phil Sturgeon | c00a5a0 | 2011-11-22 15:25:32 +0000 | [diff] [blame] | 296 | |
Derek Allard | 96bb75c | 2010-07-05 10:54:30 -0400 | [diff] [blame] | 297 | $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; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Phil Sturgeon | c00a5a0 | 2011-11-22 15:25:32 +0000 | [diff] [blame] | 300 | // Kill double slashes. Note: Sometimes we can end up with a double slash |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 301 | // in the penultimate link so we'll kill all double slashes. |
| 302 | $output = preg_replace("#([^:])//+#", "\\1/", $output); |
| 303 | |
| 304 | // Add the wrapper HTML if exists |
| 305 | $output = $this->full_tag_open.$output.$this->full_tag_close; |
Derek Allard | faac15e | 2009-03-07 17:17:58 +0000 | [diff] [blame] | 306 | |
| 307 | return $output; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | // END Pagination Class |
| 311 | |
| 312 | /* End of file Pagination.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 313 | /* Location: ./system/libraries/Pagination.php */ |