blob: 4cb72bbfb964e1f87f8d23552b112f5dbf3f0b20 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * Pagination Class
31 *
32 * @package CodeIgniter
33 * @subpackage Libraries
34 * @category Pagination
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @link http://codeigniter.com/user_guide/libraries/pagination.html
37 */
38class CI_Pagination {
39
Phil Sturgeonf82b9292012-06-23 15:49:23 +010040 protected $base_url = ''; // The page we are linking to
41 protected $prefix = ''; // A custom prefix added to the path.
42 protected $suffix = ''; // A custom suffix added to the path.
43 protected $total_rows = 0; // Total number of items (database results)
44 protected $per_page = 10; // Max number of items you want shown per page
45 protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
46 protected $cur_page = 0; // The current page being viewed
47 protected $use_page_numbers = FALSE; // Use page number for segment instead of offset
48 protected $first_link = '&lsaquo; First';
49 protected $next_link = '&gt;';
50 protected $prev_link = '&lt;';
51 protected $last_link = 'Last &rsaquo;';
52 protected $uri_segment = 3;
53 protected $full_tag_open = '';
54 protected $full_tag_close = '';
55 protected $first_tag_open = '';
Alex Bilbief7e23b32012-09-07 09:52:32 +010056 protected $first_tag_close = '';
57 protected $last_tag_open = '';
Phil Sturgeonf82b9292012-06-23 15:49:23 +010058 protected $last_tag_close = '';
59 protected $first_url = ''; // Alternative URL for the First Page.
Alex Bilbief7e23b32012-09-07 09:52:32 +010060 protected $cur_tag_open = '<strong>';
Phil Sturgeonf82b9292012-06-23 15:49:23 +010061 protected $cur_tag_close = '</strong>';
Alex Bilbief7e23b32012-09-07 09:52:32 +010062 protected $next_tag_open = '';
63 protected $next_tag_close = '';
64 protected $prev_tag_open = '';
Phil Sturgeonf82b9292012-06-23 15:49:23 +010065 protected $prev_tag_close = '';
Alex Bilbief7e23b32012-09-07 09:52:32 +010066 protected $num_tag_open = '';
Phil Sturgeonf82b9292012-06-23 15:49:23 +010067 protected $num_tag_close = '';
68 protected $page_query_string = FALSE;
Alex Bilbief7e23b32012-09-07 09:52:32 +010069 protected $query_string_segment = 'per_page';
Phil Sturgeonf82b9292012-06-23 15:49:23 +010070 protected $display_pages = TRUE;
71 protected $_attributes = '';
72 protected $_link_types = array();
73 protected $reuse_query_string = FALSE;
Phil Sturgeona44cf572012-07-12 11:50:46 +010074 protected $data_page_attr = 'data-ci-pagination-page';
Derek Allard2067d1a2008-11-13 22:59:24 +000075
76 /**
77 * Constructor
78 *
Derek Allard2067d1a2008-11-13 22:59:24 +000079 * @param array initialization parameters
Andrey Andreev56454792012-05-17 14:32:19 +030080 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +000081 */
Greg Akera9263282010-11-10 15:26:43 -060082 public function __construct($params = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000083 {
Eric Barnesbce41402011-12-03 23:47:41 -050084 $this->initialize($params);
Andrey Andreev796bc952012-03-26 19:40:40 +030085 log_message('debug', 'Pagination Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000086 }
Derek Allardfaac15e2009-03-07 17:17:58 +000087
Derek Allard2067d1a2008-11-13 22:59:24 +000088 // --------------------------------------------------------------------
Derek Allardfaac15e2009-03-07 17:17:58 +000089
Derek Allard2067d1a2008-11-13 22:59:24 +000090 /**
91 * Initialize Preferences
92 *
Derek Allard2067d1a2008-11-13 22:59:24 +000093 * @param array initialization parameters
94 * @return void
95 */
Eric Barnes9a4902a2011-12-03 23:46:06 -050096 public function initialize($params = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000097 {
Andrey Andreev88c47272012-06-17 02:32:31 +030098 $attributes = array();
99
100 if (isset($params['attributes']) && is_array($params['attributes']))
101 {
102 $attributes = $params['attributes'];
103 unset($params['attributes']);
104 }
105
106 // Deprecated legacy support for the anchor_class option
107 // Should be removed in CI 3.1+
108 if (isset($params['anchor_class']))
109 {
110 empty($params['anchor_class']) OR $attributes['class'] = $params['anchor_class'];
111 unset($params['anchor_class']);
112 }
113
114 $this->_parse_attributes($attributes);
115
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 if (count($params) > 0)
117 {
118 foreach ($params as $key => $val)
119 {
Andrey Andreev88c47272012-06-17 02:32:31 +0300120 if (isset($this->$key))
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 {
122 $this->$key = $val;
123 }
124 }
125 }
126 }
Derek Allardfaac15e2009-03-07 17:17:58 +0000127
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 // --------------------------------------------------------------------
Derek Allardfaac15e2009-03-07 17:17:58 +0000129
Derek Allard2067d1a2008-11-13 22:59:24 +0000130 /**
131 * Generate the pagination links
132 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 * @return string
Derek Allardfaac15e2009-03-07 17:17:58 +0000134 */
Eric Barnes9a4902a2011-12-03 23:46:06 -0500135 public function create_links()
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 {
137 // If our item count or per-page total is zero there is no need to continue.
Alex Bilbied261b1e2012-06-02 11:12:16 +0100138 if ($this->total_rows === 0 OR $this->per_page === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 {
Derek Allardfaac15e2009-03-07 17:17:58 +0000140 return '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000141 }
142
143 // Calculate the total number of pages
Ronald Beilsmacfb70212011-12-29 09:57:49 +0100144 $num_pages = (int) ceil($this->total_rows / $this->per_page);
Derek Allard2067d1a2008-11-13 22:59:24 +0000145
146 // Is there only one page? Hm... nothing more to do here then.
Ronald Beilsmacfb70212011-12-29 09:57:49 +0100147 if ($num_pages === 1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 {
149 return '';
150 }
151
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400152 // Set the base page index for starting page number
Aaron Kuzemchaka5e13f92011-09-04 16:39:47 -0400153 $base_page = ($this->use_page_numbers) ? 1 : 0;
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400154
Derek Allardfaac15e2009-03-07 17:17:58 +0000155 // Determine the current page number.
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 $CI =& get_instance();
Derek Allardfaac15e2009-03-07 17:17:58 +0000157
Eric Barnes3b376592012-01-04 00:28:27 -0500158 // See if we are using a prefix or suffix on links
Alex Bilbied261b1e2012-06-02 11:12:16 +0100159 if ($this->prefix !== '' OR $this->suffix !== '')
Eric Barnes8d727f12012-01-04 00:06:36 -0500160 {
Andrey Andreeve66d6242012-10-22 16:39:12 +0300161 $this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->rsegment($this->uri_segment));
Eric Barnes8d727f12012-01-04 00:06:36 -0500162 }
163
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
165 {
Andrey Andreev7eb7ebf2012-06-12 10:26:27 +0300166 if ($CI->input->get($this->query_string_segment) != $base_page)
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 {
Andrey Andreev33987e62011-12-24 19:48:45 +0200168 $this->cur_page = (int) $CI->input->get($this->query_string_segment);
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 }
170 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100171 elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) !== $base_page)
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 {
Andrey Andreeve66d6242012-10-22 16:39:12 +0300173 $this->cur_page = (int) $CI->uri->rsegment($this->uri_segment);
Derek Allard2067d1a2008-11-13 22:59:24 +0000174 }
Eric Barnes9a4902a2011-12-03 23:46:06 -0500175
Andrey Andreev33987e62011-12-24 19:48:45 +0200176 // 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 +0100177 if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page === 0))
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400178 {
179 $this->cur_page = $base_page;
180 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000181
Eric Barnes3b376592012-01-04 00:28:27 -0500182 $this->num_links = (int) $this->num_links;
Derek Allardfaac15e2009-03-07 17:17:58 +0000183
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 if ($this->num_links < 1)
185 {
186 show_error('Your number of links must be a positive number.');
187 }
Derek Allardfaac15e2009-03-07 17:17:58 +0000188
Derek Allard2067d1a2008-11-13 22:59:24 +0000189 // Is the page number beyond the result range?
190 // If so we show the last page
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400191 if ($this->use_page_numbers)
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 {
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400193 if ($this->cur_page > $num_pages)
194 {
195 $this->cur_page = $num_pages;
196 }
197 }
Andrey Andreev796bc952012-03-26 19:40:40 +0300198 elseif ($this->cur_page > $this->total_rows)
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400199 {
Andrey Andreev796bc952012-03-26 19:40:40 +0300200 $this->cur_page = ($num_pages - 1) * $this->per_page;
Derek Allard2067d1a2008-11-13 22:59:24 +0000201 }
Derek Allardfaac15e2009-03-07 17:17:58 +0000202
Derek Allard2067d1a2008-11-13 22:59:24 +0000203 $uri_page_number = $this->cur_page;
Eric Barnes9a4902a2011-12-03 23:46:06 -0500204
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400205 if ( ! $this->use_page_numbers)
206 {
Bo-Yi Wu5d504532012-07-14 00:03:56 +0800207 $this->cur_page = (int) floor(($this->cur_page/$this->per_page) + 1);
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400208 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000209
210 // Calculate the start and end numbers. These determine
211 // which number to start and end the digit links with
Andrey Andreev796bc952012-03-26 19:40:40 +0300212 $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;
213 $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;
Derek Allard2067d1a2008-11-13 22:59:24 +0000214
Andrey Andreev796bc952012-03-26 19:40:40 +0300215 // Is pagination being used over GET or POST? If get, add a per_page query
Derek Allard2067d1a2008-11-13 22:59:24 +0000216 // string. If post, add a trailing slash to the base URL if needed
217 if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
218 {
Bo-Yi Wu6b4e3622012-09-21 13:57:24 +0800219 $segment = (strpos($this->base_url, '?')) ? '&amp;' : '?';
220 $this->base_url = rtrim($this->base_url).$segment.$this->query_string_segment.'=';
Derek Allard2067d1a2008-11-13 22:59:24 +0000221 }
222 else
223 {
224 $this->base_url = rtrim($this->base_url, '/') .'/';
225 }
226
Barry Mienydd671972010-10-04 16:33:58 +0200227 // And here we go...
Derek Allard2067d1a2008-11-13 22:59:24 +0000228 $output = '';
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100229 $query_string = '';
230
231 // Add anything in the query string back to the links
232 // Note: Nothing to do with query_string_segment or any other query string options
233 if ($this->reuse_query_string === TRUE)
234 {
235 $get = $CI->input->get();
Andrey Andreev685cdd72012-07-13 20:11:13 +0300236
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100237 // Unset the controll, method, old-school routing options
238 unset($get['c'], $get['m'], $get[$this->query_string_segment]);
239
Phil Sturgeona44cf572012-07-12 11:50:46 +0100240 if ( ! $get) $get = array();
241
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100242 // Put everything else onto the end
243 $query_string = (strpos($this->base_url, '&amp;') !== FALSE ? '&amp;' : '?') . http_build_query($get, '', '&amp;');
244
245 // Add this after the suffix to put it into more links easily
246 $this->suffix .= $query_string;
247 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000248
249 // Render the "First" link
Andrey Andreev796bc952012-03-26 19:40:40 +0300250 if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1))
Derek Allard2067d1a2008-11-13 22:59:24 +0000251 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100252 $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url;
Andrey Andreev685cdd72012-07-13 20:11:13 +0300253
Phil Sturgeona44cf572012-07-12 11:50:46 +0100254 // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
Andrey Andreev685cdd72012-07-13 20:11:13 +0300255 $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1);
Phil Sturgeona44cf572012-07-12 11:50:46 +0100256
257 $output .= $this->first_tag_open.'<a href="'.$first_url.'"'.$attributes.$this->_attr_rel('start').'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300258 .$this->first_link.'</a>'.$this->first_tag_close;
Derek Allard2067d1a2008-11-13 22:59:24 +0000259 }
260
261 // Render the "previous" link
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100262 if ($this->prev_link !== FALSE && $this->cur_page !== 1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000263 {
Aaron Kuzemchaka5e13f92011-09-04 16:39:47 -0400264 $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page;
Barry Mienydd671972010-10-04 16:33:58 +0200265
Phil Sturgeona44cf572012-07-12 11:50:46 +0100266 // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
267 $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
268
Alex Bilbied261b1e2012-06-02 11:12:16 +0100269 if ($i === $base_page && $this->first_url !== '')
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400270 {
Phil Sturgeona44cf572012-07-12 11:50:46 +0100271 $output .= $this->prev_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$attributes.$this->_attr_rel('prev').'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300272 .$this->prev_link.'</a>'.$this->prev_tag_close;
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400273 }
274 else
275 {
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100276 $append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix;
Phil Sturgeona44cf572012-07-12 11:50:46 +0100277 $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$append.'"'.$attributes.$this->_attr_rel('prev').'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300278 .$this->prev_link.'</a>'.$this->prev_tag_close;
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400279 }
Barry Mienydd671972010-10-04 16:33:58 +0200280
Derek Allard2067d1a2008-11-13 22:59:24 +0000281 }
282
Derek Allarde01fd0f2010-07-05 11:06:07 -0400283 // Render the pages
284 if ($this->display_pages !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 {
Derek Allarde01fd0f2010-07-05 11:06:07 -0400286 // Write the digit links
287 for ($loop = $start -1; $loop <= $end; $loop++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 {
Aaron Kuzemchaka5e13f92011-09-04 16:39:47 -0400289 $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page;
Phil Sturgeona44cf572012-07-12 11:50:46 +0100290
291 // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
292 $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
293
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400294 if ($i >= $base_page)
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100296 if ($this->cur_page === $loop)
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400297 {
Derek Allarde01fd0f2010-07-05 11:06:07 -0400298 $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400299 }
300 else
301 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100302 $n = ($i === $base_page) ? '' : $i;
Andrey Andreev88c47272012-06-17 02:32:31 +0300303 if ($n === '' && ! empty($this->first_url))
Derek Allarde01fd0f2010-07-05 11:06:07 -0400304 {
Phil Sturgeona44cf572012-07-12 11:50:46 +0100305 $output .= $this->num_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$attributes.$this->_attr_rel('start').'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300306 .$loop.'</a>'.$this->num_tag_close;
Derek Allarde01fd0f2010-07-05 11:06:07 -0400307 }
308 else
309 {
Phil Sturgeonf82b9292012-06-23 15:49:23 +0100310 $append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix;
Phil Sturgeona44cf572012-07-12 11:50:46 +0100311 $output .= $this->num_tag_open.'<a href="'.$this->base_url.$append.'"'.$attributes.$this->_attr_rel('start').'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300312 .$loop.'</a>'.$this->num_tag_close;
Derek Allarde01fd0f2010-07-05 11:06:07 -0400313 }
Robin Sowell2a6c1da2010-05-24 12:20:03 -0400314 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 }
316 }
317 }
318
319 // Render the "next" link
Andrey Andreev796bc952012-03-26 19:40:40 +0300320 if ($this->next_link !== FALSE && $this->cur_page < $num_pages)
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 {
Aaron Kuzemchaka5e13f92011-09-04 16:39:47 -0400322 $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page;
Aaron Kuzemchak11c5f162011-09-03 20:59:07 -0400323
Phil Sturgeona44cf572012-07-12 11:50:46 +0100324 // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
325 $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
326
327 $output .= $this->next_tag_open.'<a href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$attributes
Andrey Andreev88c47272012-06-17 02:32:31 +0300328 .$this->_attr_rel('next').'>'.$this->next_link.'</a>'.$this->next_tag_close;
Derek Allard2067d1a2008-11-13 22:59:24 +0000329 }
330
331 // Render the "Last" link
Andrey Andreev796bc952012-03-26 19:40:40 +0300332 if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links) < $num_pages)
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 {
Aaron Kuzemchaka5e13f92011-09-04 16:39:47 -0400334 $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page;
Phil Sturgeonc00a5a02011-11-22 15:25:32 +0000335
Phil Sturgeona44cf572012-07-12 11:50:46 +0100336 // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's
337 $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i);
338
339 $output .= $this->last_tag_open.'<a href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$attributes.'>'
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300340 .$this->last_link.'</a>'.$this->last_tag_close;
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 }
342
Phil Sturgeonc00a5a02011-11-22 15:25:32 +0000343 // Kill double slashes. Note: Sometimes we can end up with a double slash
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 // in the penultimate link so we'll kill all double slashes.
Andrey Andreev796bc952012-03-26 19:40:40 +0300345 $output = preg_replace('#([^:])//+#', '\\1/', $output);
Derek Allard2067d1a2008-11-13 22:59:24 +0000346
347 // Add the wrapper HTML if exists
Andrey Andreev796bc952012-03-26 19:40:40 +0300348 return $this->full_tag_open.$output.$this->full_tag_close;
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 }
Andrey Andreev796bc952012-03-26 19:40:40 +0300350
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300351 // --------------------------------------------------------------------
352
353 /**
Andrey Andreev88c47272012-06-17 02:32:31 +0300354 * Parse attributes
355 *
356 * @param array
357 * @return void
358 */
359 protected function _parse_attributes($attributes)
360 {
361 isset($attributes['rel']) OR $attributes['rel'] = TRUE;
362 $this->_link_types = ($attributes['rel'])
363 ? array('start' => 'start', 'prev' => 'prev', 'next' => 'next')
364 : array();
365 unset($attributes['rel']);
366
367 $this->_attributes = '';
368 foreach ($attributes as $key => $value)
369 {
370 $this->_attributes .= ' '.$key.'="'.$value.'"';
371 }
372 }
373
374 // --------------------------------------------------------------------
375
376 /**
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300377 * Add "rel" attribute
378 *
Andrey Andreev88c47272012-06-17 02:32:31 +0300379 * @link http://www.w3.org/TR/html5/links.html#linkTypes
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300380 * @param string
381 * @return string
382 */
Andrey Andreev88c47272012-06-17 02:32:31 +0300383 protected function _attr_rel($type)
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300384 {
Andrey Andreev88c47272012-06-17 02:32:31 +0300385 if (isset($this->_link_types[$type]))
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300386 {
Andrey Andreev88c47272012-06-17 02:32:31 +0300387 unset($this->_link_types[$type]);
388 return ' rel="'.$type.'"';
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300389 }
390
Andrey Andreev88c47272012-06-17 02:32:31 +0300391 return '';
Andrey Andreev5a1e5e32012-06-12 11:28:26 +0300392 }
393
Derek Allard2067d1a2008-11-13 22:59:24 +0000394}
Derek Allard2067d1a2008-11-13 22:59:24 +0000395
396/* End of file Pagination.php */
Andrey Andreev685cdd72012-07-13 20:11:13 +0300397/* Location: ./system/libraries/Pagination.php */