blob: 4fa605ca97e74eaf19049f2bfd3635a98a9fea08 [file] [log] [blame]
Andrey Andreev33987e62011-12-24 19:48:45 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Eric Barnes9a4902a2011-12-03 23:46:06 -05008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Eric Barnes9a4902a2011-12-03 23:46:06 -050010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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 Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * Pagination Class
30 *
31 * @package CodeIgniter
32 * @subpackage Libraries
33 * @category Pagination
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/libraries/pagination.html
36 */
37class CI_Pagination {
38
Phil Sturgeonf82b9292012-06-23 15:49:23 +010039 protected $base_url = ''; // The page we are linking to
40 protected $prefix = ''; // A custom prefix added to the path.
41 protected $suffix = ''; // A custom suffix added to the path.
42 protected $total_rows = 0; // Total number of items (database results)
43 protected $per_page = 10; // Max number of items you want shown per page
44 protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
45 protected $cur_page = 0; // The current page being viewed
46 protected $use_page_numbers = FALSE; // Use page number for segment instead of offset
47 protected $first_link = '&lsaquo; First';
48 protected $next_link = '&gt;';
49 protected $prev_link = '&lt;';
50 protected $last_link = 'Last &rsaquo;';
51 protected $uri_segment = 3;
52 protected $full_tag_open = '';
53 protected $full_tag_close = '';
54 protected $first_tag_open = '';
Alex Bilbief7e23b32012-09-07 09:52:32 +010055 protected $first_tag_close = '';
56 protected $last_tag_open = '';
Phil Sturgeonf82b9292012-06-23 15:49:23 +010057 protected $last_tag_close = '';
58 protected $first_url = ''; // Alternative URL for the First Page.
Alex Bilbief7e23b32012-09-07 09:52:32 +010059 protected $cur_tag_open = '<strong>';
Phil Sturgeonf82b9292012-06-23 15:49:23 +010060 protected $cur_tag_close = '</strong>';
Alex Bilbief7e23b32012-09-07 09:52:32 +010061 protected $next_tag_open = '';
62 protected $next_tag_close = '';
63 protected $prev_tag_open = '';
Phil Sturgeonf82b9292012-06-23 15:49:23 +010064 protected $prev_tag_close = '';
Alex Bilbief7e23b32012-09-07 09:52:32 +010065 protected $num_tag_open = '';
Phil Sturgeonf82b9292012-06-23 15:49:23 +010066 protected $num_tag_close = '';
67 protected $page_query_string = FALSE;
Alex Bilbief7e23b32012-09-07 09:52:32 +010068 protected $query_string_segment = 'per_page';
Phil Sturgeonf82b9292012-06-23 15:49:23 +010069 protected $display_pages = TRUE;
70 protected $_attributes = '';
71 protected $_link_types = array();
72 protected $reuse_query_string = FALSE;
Phil Sturgeona44cf572012-07-12 11:50:46 +010073 protected $data_page_attr = 'data-ci-pagination-page';
Derek Allard2067d1a2008-11-13 22:59:24 +000074
75 /**
76 * Constructor
77 *
Derek Allard2067d1a2008-11-13 22:59:24 +000078 * @param array initialization parameters
Andrey Andreev56454792012-05-17 14:32:19 +030079 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +000080 */
Greg Akera9263282010-11-10 15:26:43 -060081 public function __construct($params = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000082 {
Eric Barnesbce41402011-12-03 23:47:41 -050083 $this->initialize($params);
Andrey Andreev796bc952012-03-26 19:40:40 +030084 log_message('debug', 'Pagination Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000085 }
Derek Allardfaac15e2009-03-07 17:17:58 +000086
Derek Allard2067d1a2008-11-13 22:59:24 +000087 // --------------------------------------------------------------------
Derek Allardfaac15e2009-03-07 17:17:58 +000088
Derek Allard2067d1a2008-11-13 22:59:24 +000089 /**
90 * Initialize Preferences
91 *
Derek Allard2067d1a2008-11-13 22:59:24 +000092 * @param array initialization parameters
93 * @return void
94 */
Eric Barnes9a4902a2011-12-03 23:46:06 -050095 public function initialize($params = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000096 {
Andrey Andreev88c47272012-06-17 02:32:31 +030097 $attributes = array();
98
99 if (isset($params['attributes']) && is_array($params['attributes']))
100 {
101 $attributes = $params['attributes'];
102 unset($params['attributes']);
103 }
104
105 // Deprecated legacy support for the anchor_class option
106 // Should be removed in CI 3.1+
107 if (isset($params['anchor_class']))
108 {
109 empty($params['anchor_class']) OR $attributes['class'] = $params['anchor_class'];
110 unset($params['anchor_class']);
111 }
112
113 $this->_parse_attributes($attributes);
114
Derek Allard2067d1a2008-11-13 22:59:24 +0000115 if (count($params) > 0)
116 {
117 foreach ($params as $key => $val)
118 {
Andrey Andreev88c47272012-06-17 02:32:31 +0300119 if (isset($this->$key))
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 {
121 $this->$key = $val;
122 }
123 }
124 }
125 }
Derek Allardfaac15e2009-03-07 17:17:58 +0000126
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 // --------------------------------------------------------------------
Derek Allardfaac15e2009-03-07 17:17:58 +0000128
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 /**
130 * Generate the pagination links
131 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 * @return string
Derek Allardfaac15e2009-03-07 17:17:58 +0000133 */
Eric Barnes9a4902a2011-12-03 23:46:06 -0500134 public function create_links()
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 {
136 // If our item count or per-page total is zero there is no need to continue.
Alex Bilbied261b1e2012-06-02 11:12:16 +0100137 if ($this->total_rows === 0 OR $this->per_page === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 {
Derek Allardfaac15e2009-03-07 17:17:58 +0000139 return '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 }
141
142 // Calculate the total number of pages
Ronald Beilsmacfb70212011-12-29 09:57:49 +0100143 $num_pages = (int) ceil($this->total_rows / $this->per_page);
Derek Allard2067d1a2008-11-13 22:59:24 +0000144
145 // Is there only one page? Hm... nothing more to do here then.
Ronald Beilsmacfb70212011-12-29 09:57:49 +0100146 if ($num_pages === 1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 {
148 return '';
149 }
150
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400151 // Set the base page index for starting page number
Aaron Kuzemchaka5e13f92011-09-04 16:39:47 -0400152 $base_page = ($this->use_page_numbers) ? 1 : 0;
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400153
Derek Allardfaac15e2009-03-07 17:17:58 +0000154 // Determine the current page number.
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 $CI =& get_instance();
Derek Allardfaac15e2009-03-07 17:17:58 +0000156
Eric Barnes3b376592012-01-04 00:28:27 -0500157 // See if we are using a prefix or suffix on links
Alex Bilbied261b1e2012-06-02 11:12:16 +0100158 if ($this->prefix !== '' OR $this->suffix !== '')
Eric Barnes8d727f12012-01-04 00:06:36 -0500159 {
Eric Barnes3b376592012-01-04 00:28:27 -0500160 $this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->segment($this->uri_segment));
Eric Barnes8d727f12012-01-04 00:06:36 -0500161 }
162
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
164 {
Andrey Andreev7eb7ebf2012-06-12 10:26:27 +0300165 if ($CI->input->get($this->query_string_segment) != $base_page)
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 {
Andrey Andreev33987e62011-12-24 19:48:45 +0200167 $this->cur_page = (int) $CI->input->get($this->query_string_segment);
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 }
169 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100170 elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) !== $base_page)
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 {
Andrey Andreev33987e62011-12-24 19:48:45 +0200172 $this->cur_page = (int) $CI->uri->segment($this->uri_segment);
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 }
Eric Barnes9a4902a2011-12-03 23:46:06 -0500174
Andrey Andreev33987e62011-12-24 19:48:45 +0200175 // Set current page to 1 if it's not valid or if using page numbers instead of offset
Alex Bilbied261b1e2012-06-02 11:12:16 +0100176 if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page === 0))
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400177 {
178 $this->cur_page = $base_page;
179 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000180
Eric Barnes3b376592012-01-04 00:28:27 -0500181 $this->num_links = (int) $this->num_links;
Derek Allardfaac15e2009-03-07 17:17:58 +0000182
Derek Allard2067d1a2008-11-13 22:59:24 +0000183 if ($this->num_links < 1)
184 {
185 show_error('Your number of links must be a positive number.');
186 }
Derek Allardfaac15e2009-03-07 17:17:58 +0000187
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 // Is the page number beyond the result range?
189 // If so we show the last page
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400190 if ($this->use_page_numbers)
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 {
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400192 if ($this->cur_page > $num_pages)
193 {
194 $this->cur_page = $num_pages;
195 }
196 }
Andrey Andreev796bc952012-03-26 19:40:40 +0300197 elseif ($this->cur_page > $this->total_rows)
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400198 {
Andrey Andreev796bc952012-03-26 19:40:40 +0300199 $this->cur_page = ($num_pages - 1) * $this->per_page;
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 }
Derek Allardfaac15e2009-03-07 17:17:58 +0000201
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 $uri_page_number = $this->cur_page;
Eric Barnes9a4902a2011-12-03 23:46:06 -0500203
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400204 if ( ! $this->use_page_numbers)
205 {
Bo-Yi Wu5d504532012-07-14 00:03:56 +0800206 $this->cur_page = (int) floor(($this->cur_page/$this->per_page) + 1);
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400207 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000208
209 // Calculate the start and end numbers. These determine
210 // which number to start and end the digit links with
Andrey Andreev796bc952012-03-26 19:40:40 +0300211 $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;
212 $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;
Derek Allard2067d1a2008-11-13 22:59:24 +0000213
Andrey Andreev796bc952012-03-26 19:40:40 +0300214 // Is pagination being used over GET or POST? If get, add a per_page query
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 // string. If post, add a trailing slash to the base URL if needed
216 if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
217 {
218 $this->base_url = rtrim($this->base_url).'&amp;'.$this->query_string_segment.'=';
219 }
220 else
221 {
222 $this->base_url = rtrim($this->base_url, '/') .'/';
223 }
224
Barry Mienydd671972010-10-04 16:33:58 +0200225 // And here we go...
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 $output = '';
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100227 $query_string = '';
228
229 // Add anything in the query string back to the links
230 // Note: Nothing to do with query_string_segment or any other query string options
231 if ($this->reuse_query_string === TRUE)
232 {
233 $get = $CI->input->get();
Andrey Andreev685cdd72012-07-13 20:11:13 +0300234
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100235 // Unset the controll, method, old-school routing options
236 unset($get['c'], $get['m'], $get[$this->query_string_segment]);
237
Phil Sturgeona44cf572012-07-12 11:50:46 +0100238 if ( ! $get) $get = array();
239
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100240 // Put everything else onto the end
241 $query_string = (strpos($this->base_url, '&amp;') !== FALSE ? '&amp;' : '?') . http_build_query($get, '', '&amp;');
242
243 // Add this after the suffix to put it into more links easily
244 $this->suffix .= $query_string;
245 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000246
247 // Render the "First" link
Andrey Andreev796bc952012-03-26 19:40:40 +0300248 if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1))
Derek Allard2067d1a2008-11-13 22:59:24 +0000249 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100250 $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url;
Andrey Andreev685cdd72012-07-13 20:11:13 +0300251
Phil Sturgeona44cf572012-07-12 11:50:46 +0100252 // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
Andrey Andreev685cdd72012-07-13 20:11:13 +0300253 $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1);
Phil Sturgeona44cf572012-07-12 11:50:46 +0100254
255 $output .= $this->first_tag_open.'<a href="'.$first_url.'"'.$attributes.$this->_attr_rel('start').'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300256 .$this->first_link.'</a>'.$this->first_tag_close;
Derek Allard2067d1a2008-11-13 22:59:24 +0000257 }
258
259 // Render the "previous" link
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100260 if ($this->prev_link !== FALSE && $this->cur_page !== 1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000261 {
Aaron Kuzemchaka5e13f92011-09-04 16:39:47 -0400262 $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page;
Barry Mienydd671972010-10-04 16:33:58 +0200263
Phil Sturgeona44cf572012-07-12 11:50:46 +0100264 // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
265 $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
266
Alex Bilbied261b1e2012-06-02 11:12:16 +0100267 if ($i === $base_page && $this->first_url !== '')
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400268 {
Phil Sturgeona44cf572012-07-12 11:50:46 +0100269 $output .= $this->prev_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$attributes.$this->_attr_rel('prev').'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300270 .$this->prev_link.'</a>'.$this->prev_tag_close;
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400271 }
272 else
273 {
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100274 $append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix;
Phil Sturgeona44cf572012-07-12 11:50:46 +0100275 $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$append.'"'.$attributes.$this->_attr_rel('prev').'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300276 .$this->prev_link.'</a>'.$this->prev_tag_close;
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400277 }
Barry Mienydd671972010-10-04 16:33:58 +0200278
Derek Allard2067d1a2008-11-13 22:59:24 +0000279 }
280
Derek Allarde01fd0f2010-07-05 11:06:07 -0400281 // Render the pages
282 if ($this->display_pages !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 {
Derek Allarde01fd0f2010-07-05 11:06:07 -0400284 // Write the digit links
285 for ($loop = $start -1; $loop <= $end; $loop++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000286 {
Aaron Kuzemchaka5e13f92011-09-04 16:39:47 -0400287 $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page;
Phil Sturgeona44cf572012-07-12 11:50:46 +0100288
289 // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
290 $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
291
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400292 if ($i >= $base_page)
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100294 if ($this->cur_page === $loop)
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400295 {
Derek Allarde01fd0f2010-07-05 11:06:07 -0400296 $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400297 }
298 else
299 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100300 $n = ($i === $base_page) ? '' : $i;
Andrey Andreev88c47272012-06-17 02:32:31 +0300301 if ($n === '' && ! empty($this->first_url))
Derek Allarde01fd0f2010-07-05 11:06:07 -0400302 {
Phil Sturgeona44cf572012-07-12 11:50:46 +0100303 $output .= $this->num_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$attributes.$this->_attr_rel('start').'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300304 .$loop.'</a>'.$this->num_tag_close;
Derek Allarde01fd0f2010-07-05 11:06:07 -0400305 }
306 else
307 {
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100308 $append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix;
Phil Sturgeona44cf572012-07-12 11:50:46 +0100309 $output .= $this->num_tag_open.'<a href="'.$this->base_url.$append.'"'.$attributes.$this->_attr_rel('start').'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300310 .$loop.'</a>'.$this->num_tag_close;
Derek Allarde01fd0f2010-07-05 11:06:07 -0400311 }
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400312 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000313 }
314 }
315 }
316
317 // Render the "next" link
Andrey Andreev796bc952012-03-26 19:40:40 +0300318 if ($this->next_link !== FALSE && $this->cur_page < $num_pages)
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 {
Aaron Kuzemchaka5e13f92011-09-04 16:39:47 -0400320 $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page;
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400321
Phil Sturgeona44cf572012-07-12 11:50:46 +0100322 // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
323 $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
324
325 $output .= $this->next_tag_open.'<a href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$attributes
Andrey Andreev88c47272012-06-17 02:32:31 +0300326 .$this->_attr_rel('next').'>'.$this->next_link.'</a>'.$this->next_tag_close;
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 }
328
329 // Render the "Last" link
Andrey Andreev796bc952012-03-26 19:40:40 +0300330 if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links) < $num_pages)
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 {
Aaron Kuzemchaka5e13f92011-09-04 16:39:47 -0400332 $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page;
Phil Sturgeonc00a5a02011-11-22 15:25:32 +0000333
Phil Sturgeona44cf572012-07-12 11:50:46 +0100334 // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
335 $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
336
337 $output .= $this->last_tag_open.'<a href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$attributes.'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300338 .$this->last_link.'</a>'.$this->last_tag_close;
Derek Allard2067d1a2008-11-13 22:59:24 +0000339 }
340
Phil Sturgeonc00a5a02011-11-22 15:25:32 +0000341 // Kill double slashes. Note: Sometimes we can end up with a double slash
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 // in the penultimate link so we'll kill all double slashes.
Andrey Andreev796bc952012-03-26 19:40:40 +0300343 $output = preg_replace('#([^:])//+#', '\\1/', $output);
Derek Allard2067d1a2008-11-13 22:59:24 +0000344
345 // Add the wrapper HTML if exists
Andrey Andreev796bc952012-03-26 19:40:40 +0300346 return $this->full_tag_open.$output.$this->full_tag_close;
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 }
Andrey Andreev796bc952012-03-26 19:40:40 +0300348
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300349 // --------------------------------------------------------------------
350
351 /**
Andrey Andreev88c47272012-06-17 02:32:31 +0300352 * Parse attributes
353 *
354 * @param array
355 * @return void
356 */
357 protected function _parse_attributes($attributes)
358 {
359 isset($attributes['rel']) OR $attributes['rel'] = TRUE;
360 $this->_link_types = ($attributes['rel'])
361 ? array('start' => 'start', 'prev' => 'prev', 'next' => 'next')
362 : array();
363 unset($attributes['rel']);
364
365 $this->_attributes = '';
366 foreach ($attributes as $key => $value)
367 {
368 $this->_attributes .= ' '.$key.'="'.$value.'"';
369 }
370 }
371
372 // --------------------------------------------------------------------
373
374 /**
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300375 * Add "rel" attribute
376 *
Andrey Andreev88c47272012-06-17 02:32:31 +0300377 * @link http://www.w3.org/TR/html5/links.html#linkTypes
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300378 * @param string
379 * @return string
380 */
Andrey Andreev88c47272012-06-17 02:32:31 +0300381 protected function _attr_rel($type)
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300382 {
Andrey Andreev88c47272012-06-17 02:32:31 +0300383 if (isset($this->_link_types[$type]))
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300384 {
Andrey Andreev88c47272012-06-17 02:32:31 +0300385 unset($this->_link_types[$type]);
386 return ' rel="'.$type.'"';
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300387 }
388
Andrey Andreev88c47272012-06-17 02:32:31 +0300389 return '';
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300390 }
391
Derek Allard2067d1a2008-11-13 22:59:24 +0000392}
Derek Allard2067d1a2008-11-13 22:59:24 +0000393
394/* End of file Pagination.php */
Andrey Andreev685cdd72012-07-13 20:11:13 +0300395/* Location: ./system/libraries/Pagination.php */