From 11c5f1654d2d13113ad06da46f560628d7e31dd3 Mon Sep 17 00:00:00 2001 From: Aaron Kuzemchak Date: Sat, 3 Sep 2011 20:59:07 -0400 Subject: Enables real page numbers for URI segment in Pagination library --- system/libraries/Pagination.php | 85 +++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 12 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cc62e660b..cdaacf2d4 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -34,6 +34,7 @@ class CI_Pagination { var $per_page = 10; // Max number of items you want shown per page var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page var $cur_page = 0; // The current page being viewed + var $use_page_numbers = FALSE; // Use page number for segment instead of offset var $first_link = '‹ First'; var $next_link = '>'; var $prev_link = '<'; @@ -128,12 +129,22 @@ class CI_Pagination { return ''; } + // Set the base page index for starting page number + if ($this->use_page_numbers) + { + $base_page = 1; + } + else + { + $base_page = 0; + } + // Determine the current page number. $CI =& get_instance(); if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - if ($CI->input->get($this->query_string_segment) != 0) + if ($CI->input->get($this->query_string_segment) != $base_page) { $this->cur_page = $CI->input->get($this->query_string_segment); @@ -143,7 +154,7 @@ class CI_Pagination { } else { - if ($CI->uri->segment($this->uri_segment) != 0) + if ($CI->uri->segment($this->uri_segment) != $base_page) { $this->cur_page = $CI->uri->segment($this->uri_segment); @@ -151,6 +162,12 @@ class CI_Pagination { $this->cur_page = (int) $this->cur_page; } } + + // Set current page to 1 if using page numbers instead of offset + if ($this->use_page_numbers AND $this->cur_page == 0) + { + $this->cur_page = $base_page; + } $this->num_links = (int)$this->num_links; @@ -161,18 +178,32 @@ class CI_Pagination { if ( ! is_numeric($this->cur_page)) { - $this->cur_page = 0; + $this->cur_page = $base_page; } // Is the page number beyond the result range? // If so we show the last page - if ($this->cur_page > $this->total_rows) + if ($this->use_page_numbers) { - $this->cur_page = ($num_pages - 1) * $this->per_page; + if ($this->cur_page > $num_pages) + { + $this->cur_page = $num_pages; + } + } + else + { + if ($this->cur_page > $this->total_rows) + { + $this->cur_page = ($num_pages - 1) * $this->per_page; + } } $uri_page_number = $this->cur_page; - $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); + + if ( ! $this->use_page_numbers) + { + $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); + } // Calculate the start and end numbers. These determine // which number to start and end the digit links with @@ -203,7 +234,14 @@ class CI_Pagination { // Render the "previous" link if ($this->prev_link !== FALSE AND $this->cur_page != 1) { - $i = $uri_page_number - $this->per_page; + if ($this->use_page_numbers) + { + $i = $uri_page_number - 1; + } + else + { + $i = $uri_page_number - $this->per_page; + } if ($i == 0 && $this->first_url != '') { @@ -223,9 +261,16 @@ class CI_Pagination { // Write the digit links for ($loop = $start -1; $loop <= $end; $loop++) { - $i = ($loop * $this->per_page) - $this->per_page; + if ($this->use_page_numbers) + { + $i = $loop; + } + else + { + $i = ($loop * $this->per_page) - $this->per_page; + } - if ($i >= 0) + if ($i >= $base_page) { if ($this->cur_page == $loop) { @@ -233,7 +278,7 @@ class CI_Pagination { } else { - $n = ($i == 0) ? '' : $i; + $n = ($i == $base_page) ? '' : $i; if ($n == '' && $this->first_url != '') { @@ -253,13 +298,29 @@ class CI_Pagination { // Render the "next" link if ($this->next_link !== FALSE AND $this->cur_page < $num_pages) { - $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.($this->cur_page * $this->per_page).$this->suffix.'">'.$this->next_link.''.$this->next_tag_close; + if ($this->use_page_numbers) + { + $i = $this->cur_page + 1; + } + else + { + $i = ($this->cur_page * $this->per_page); + } + + $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.''.$this->next_tag_close; } // Render the "Last" link if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages) { - $i = (($num_pages * $this->per_page) - $this->per_page); + if ($this->use_page_numbers) + { + $i = $num_pages; + } + else + { + $i = (($num_pages * $this->per_page) - $this->per_page); + } $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.''.$this->last_tag_close; } -- cgit v1.2.3-24-g4f1b From a5e13f9bf78e0cf139b905d131075a146430ce0a Mon Sep 17 00:00:00 2001 From: Aaron Kuzemchak Date: Sun, 4 Sep 2011 16:39:47 -0400 Subject: utilizing ternary syntax to clean up some conditionals --- system/libraries/Pagination.php | 46 ++++++----------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cdaacf2d4..f190d55fd 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -130,14 +130,7 @@ class CI_Pagination { } // Set the base page index for starting page number - if ($this->use_page_numbers) - { - $base_page = 1; - } - else - { - $base_page = 0; - } + $base_page = ($this->use_page_numbers) ? 1 : 0; // Determine the current page number. $CI =& get_instance(); @@ -234,14 +227,7 @@ class CI_Pagination { // Render the "previous" link if ($this->prev_link !== FALSE AND $this->cur_page != 1) { - if ($this->use_page_numbers) - { - $i = $uri_page_number - 1; - } - else - { - $i = $uri_page_number - $this->per_page; - } + $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; if ($i == 0 && $this->first_url != '') { @@ -261,14 +247,7 @@ class CI_Pagination { // Write the digit links for ($loop = $start -1; $loop <= $end; $loop++) { - if ($this->use_page_numbers) - { - $i = $loop; - } - else - { - $i = ($loop * $this->per_page) - $this->per_page; - } + $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page; if ($i >= $base_page) { @@ -298,14 +277,7 @@ class CI_Pagination { // Render the "next" link if ($this->next_link !== FALSE AND $this->cur_page < $num_pages) { - if ($this->use_page_numbers) - { - $i = $this->cur_page + 1; - } - else - { - $i = ($this->cur_page * $this->per_page); - } + $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.''.$this->next_tag_close; } @@ -313,14 +285,8 @@ class CI_Pagination { // Render the "Last" link if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages) { - if ($this->use_page_numbers) - { - $i = $num_pages; - } - else - { - $i = (($num_pages * $this->per_page) - $this->per_page); - } + $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; + $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.''.$this->last_tag_close; } -- cgit v1.2.3-24-g4f1b From 48b2301d7e8cc2a4cb164a4bc24c59b656f4f49b Mon Sep 17 00:00:00 2001 From: garthkerr Date: Wed, 21 Sep 2011 20:52:50 -0300 Subject: Added a condition so that the previous link respects use_page_numbers configuration. --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index f190d55fd..eff754a1b 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -229,7 +229,7 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; - if ($i == 0 && $this->first_url != '') + if (($i == 0 OR ($this->use_page_numbers && $i == 1)) AND $this->first_url != '') { $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.''.$this->prev_tag_close; } -- cgit v1.2.3-24-g4f1b From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/libraries/Pagination.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index eff754a1b..7398c292d 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 * @filesource @@ -21,7 +33,7 @@ * @package CodeIgniter * @subpackage Libraries * @category Pagination - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/pagination.html */ class CI_Pagination { -- cgit v1.2.3-24-g4f1b From 9a4902a9708dfe3c99cd5d6d6b765288c23a6977 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sat, 3 Dec 2011 23:46:06 -0500 Subject: Changed visibility of pagination properties and methods. --- system/libraries/Pagination.php | 77 ++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 39 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index f470debeb..600aaa663 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -5,9 +5,9 @@ * An open source application development framework for PHP 5.1.6 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Open Software License version 3.0 - * + * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: @@ -38,39 +38,38 @@ */ class CI_Pagination { - var $base_url = ''; // The page we are linking to - var $prefix = ''; // A custom prefix added to the path. - var $suffix = ''; // A custom suffix added to the path. - - var $total_rows = 0; // Total number of items (database results) - var $per_page = 10; // Max number of items you want shown per page - var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page - var $cur_page = 0; // The current page being viewed - var $use_page_numbers = FALSE; // Use page number for segment instead of offset - var $first_link = '‹ First'; - var $next_link = '>'; - var $prev_link = '<'; - var $last_link = 'Last ›'; - var $uri_segment = 3; - var $full_tag_open = ''; - var $full_tag_close = ''; - var $first_tag_open = ''; - var $first_tag_close = ' '; - var $last_tag_open = ' '; - var $last_tag_close = ''; - var $first_url = ''; // Alternative URL for the First Page. - var $cur_tag_open = ' '; - var $cur_tag_close = ''; - var $next_tag_open = ' '; - var $next_tag_close = ' '; - var $prev_tag_open = ' '; - var $prev_tag_close = ''; - var $num_tag_open = ' '; - var $num_tag_close = ''; - var $page_query_string = FALSE; - var $query_string_segment = 'per_page'; - var $display_pages = TRUE; - var $anchor_class = ''; + protected $base_url = ''; // The page we are linking to + protected $prefix = ''; // A custom prefix added to the path. + protected $suffix = ''; // A custom suffix added to the path. + protected $total_rows = 0; // Total number of items (database results) + protected $per_page = 10; // Max number of items you want shown per page + protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page + protected $cur_page = 0; // The current page being viewed + protected $use_page_numbers = FALSE; // Use page number for segment instead of offset + protected $first_link = '‹ First'; + protected $next_link = '>'; + protected $prev_link = '<'; + protected $last_link = 'Last ›'; + protected $uri_segment = 3; + protected $full_tag_open = ''; + protected $full_tag_close = ''; + protected $first_tag_open = ''; + protected $first_tag_close = ' '; + protected $last_tag_open = ' '; + protected $last_tag_close = ''; + protected $first_url = ''; // Alternative URL for the First Page. + protected $cur_tag_open = ' '; + protected $cur_tag_close = ''; + protected $next_tag_open = ' '; + protected $next_tag_close = ' '; + protected $prev_tag_open = ' '; + protected $prev_tag_close = ''; + protected $num_tag_open = ' '; + protected $num_tag_close = ''; + protected $page_query_string = FALSE; + protected $query_string_segment = 'per_page'; + protected $display_pages = TRUE; + protected $anchor_class = ''; /** * Constructor @@ -102,7 +101,7 @@ class CI_Pagination { * @param array initialization parameters * @return void */ - function initialize($params = array()) + public function initialize($params = array()) { if (count($params) > 0) { @@ -124,7 +123,7 @@ class CI_Pagination { * @access public * @return string */ - function create_links() + public function create_links() { // If our item count or per-page total is zero there is no need to continue. if ($this->total_rows == 0 OR $this->per_page == 0) @@ -167,7 +166,7 @@ class CI_Pagination { $this->cur_page = (int) $this->cur_page; } } - + // Set current page to 1 if using page numbers instead of offset if ($this->use_page_numbers AND $this->cur_page == 0) { @@ -204,7 +203,7 @@ class CI_Pagination { } $uri_page_number = $this->cur_page; - + if ( ! $this->use_page_numbers) { $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); -- cgit v1.2.3-24-g4f1b From bce4140f05f9e8642554eac7aee232023b9a93d9 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sat, 3 Dec 2011 23:47:41 -0500 Subject: Changed pagination construct to call initialize so it sets the anchor class properly. Fixes #737 --- system/libraries/Pagination.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 600aaa663..eea953ae4 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -79,16 +79,7 @@ class CI_Pagination { */ public function __construct($params = array()) { - if (count($params) > 0) - { - $this->initialize($params); - } - - if ($this->anchor_class != '') - { - $this->anchor_class = 'class="'.$this->anchor_class.'" '; - } - + $this->initialize($params); log_message('debug', "Pagination Class Initialized"); } @@ -113,6 +104,11 @@ class CI_Pagination { } } } + + if ($this->anchor_class != '') + { + $this->anchor_class = 'class="'.$this->anchor_class.'" '; + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 8bd8f687827454f83a5512b96bb0f632178a08a6 Mon Sep 17 00:00:00 2001 From: dixy Date: Mon, 19 Dec 2011 22:26:12 +0100 Subject: Prev link and 1 link don't have the same url with use_page_numbers=TRUE --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index eea953ae4..cc73e0d2f 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -236,13 +236,13 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; - if (($i == 0 OR ($this->use_page_numbers && $i == 1)) AND $this->first_url != '') + if ($i == $base_page AND $this->first_url != '') { $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.''.$this->prev_tag_close; } else { - $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix; + $i = ($i == $base_page) ? '' : $this->prefix.$i.$this->suffix; $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.''.$this->prev_tag_close; } -- cgit v1.2.3-24-g4f1b From 33987e6a318eaf853f626f950573601928547f8f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 24 Dec 2011 19:48:45 +0200 Subject: Improve the Pagination library --- system/libraries/Pagination.php | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index eea953ae4..008c15192 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,4 +1,4 @@ -total_rows / $this->per_page); // Is there only one page? Hm... nothing more to do here then. - if ($num_pages == 1) + if ($num_pages === 1) { return ''; } @@ -146,25 +146,16 @@ class CI_Pagination { { if ($CI->input->get($this->query_string_segment) != $base_page) { - $this->cur_page = $CI->input->get($this->query_string_segment); - - // Prep the current page - no funny business! - $this->cur_page = (int) $this->cur_page; + $this->cur_page = (int) $CI->input->get($this->query_string_segment); } } - else + elseif ($CI->uri->segment($this->uri_segment) != $base_page) { - if ($CI->uri->segment($this->uri_segment) != $base_page) - { - $this->cur_page = $CI->uri->segment($this->uri_segment); - - // Prep the current page - no funny business! - $this->cur_page = (int) $this->cur_page; - } + $this->cur_page = (int) $CI->uri->segment($this->uri_segment); } - // Set current page to 1 if using page numbers instead of offset - if ($this->use_page_numbers AND $this->cur_page == 0) + // Set current page to 1 if it's not valid or if using page numbers instead of offset + if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers AND $this->cur_page == 0)) { $this->cur_page = $base_page; } @@ -176,11 +167,6 @@ class CI_Pagination { show_error('Your number of links must be a positive number.'); } - if ( ! is_numeric($this->cur_page)) - { - $this->cur_page = $base_page; - } - // Is the page number beyond the result range? // If so we show the last page if ($this->use_page_numbers) @@ -310,4 +296,4 @@ class CI_Pagination { // END Pagination Class /* End of file Pagination.php */ -/* Location: ./system/libraries/Pagination.php */ \ No newline at end of file +/* Location: ./system/libraries/Pagination.php */ -- cgit v1.2.3-24-g4f1b From 345e7ee1c655c53b8022c3e725a4266e15bd2542 Mon Sep 17 00:00:00 2001 From: Ronald Beilsma Date: Wed, 28 Dec 2011 12:59:04 +0100 Subject: fixed bug in pagination library return value of ceil is of type float --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 008c15192..d10bef3e5 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -131,7 +131,7 @@ class CI_Pagination { $num_pages = ceil($this->total_rows / $this->per_page); // Is there only one page? Hm... nothing more to do here then. - if ($num_pages === 1) + if ($num_pages == 1) { return ''; } -- cgit v1.2.3-24-g4f1b From cfb7021e9f53fa089bfd676978b448b27e4bd996 Mon Sep 17 00:00:00 2001 From: Ronald Beilsma Date: Thu, 29 Dec 2011 09:57:49 +0100 Subject: ceil returned float (line 131), so if statement in line 134 was bound to return false (===, float vs integer) --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d10bef3e5..63b750bdb 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -128,10 +128,10 @@ class CI_Pagination { } // Calculate the total number of pages - $num_pages = ceil($this->total_rows / $this->per_page); + $num_pages = (int) ceil($this->total_rows / $this->per_page); // Is there only one page? Hm... nothing more to do here then. - if ($num_pages == 1) + if ($num_pages === 1) { return ''; } -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 008c15192..23ca549e2 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 8d727f14446f31d919e808e3833d252ef12cf1ae Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Wed, 4 Jan 2012 00:06:36 -0500 Subject: Fixed prefix and suffix in pagination. Fixes #677 --- system/libraries/Pagination.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 23ca549e2..2fe4cf31b 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -142,6 +142,11 @@ class CI_Pagination { // Determine the current page number. $CI =& get_instance(); + if ($this->prefix != '' OR $this->suffix != '') + { + $this->cur_page = str_replace(array($this->prefix, $this->suffix), '', $CI->uri->segment($this->uri_segment)); + } + if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { if ($CI->input->get($this->query_string_segment) != $base_page) -- cgit v1.2.3-24-g4f1b From 3b376595183e0e0db5559ccbfc368c442408dca9 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Wed, 4 Jan 2012 00:28:27 -0500 Subject: Fixed paging with prefix and suffix for real page numbers. Refs #677 Fixes #52 --- system/libraries/Pagination.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 2fe4cf31b..e0cab2128 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -142,9 +142,10 @@ class CI_Pagination { // Determine the current page number. $CI =& get_instance(); + // See if we are using a prefix or suffix on links if ($this->prefix != '' OR $this->suffix != '') { - $this->cur_page = str_replace(array($this->prefix, $this->suffix), '', $CI->uri->segment($this->uri_segment)); + $this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->segment($this->uri_segment)); } if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) @@ -154,7 +155,7 @@ class CI_Pagination { $this->cur_page = (int) $CI->input->get($this->query_string_segment); } } - elseif ($CI->uri->segment($this->uri_segment) != $base_page) + elseif ( ! $this->cur_page AND $CI->uri->segment($this->uri_segment) != $base_page) { $this->cur_page = (int) $CI->uri->segment($this->uri_segment); } @@ -165,7 +166,7 @@ class CI_Pagination { $this->cur_page = $base_page; } - $this->num_links = (int)$this->num_links; + $this->num_links = (int) $this->num_links; if ($this->num_links < 1) { -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 35ac541e8..86b8d79fa 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 796bc95d0b10ea04cb9c9228c22a19c89661eca2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 19:40:40 +0300 Subject: Remove access description lines and cleanup the Pagination library --- system/libraries/Pagination.php | 44 ++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 86b8d79fa..0fe73d69f 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Pagination Class * @@ -74,13 +72,12 @@ class CI_Pagination { /** * Constructor * - * @access public * @param array initialization parameters */ public function __construct($params = array()) { $this->initialize($params); - log_message('debug', "Pagination Class Initialized"); + log_message('debug', 'Pagination Class Initialized'); } // -------------------------------------------------------------------- @@ -88,7 +85,6 @@ class CI_Pagination { /** * Initialize Preferences * - * @access public * @param array initialization parameters * @return void */ @@ -116,7 +112,6 @@ class CI_Pagination { /** * Generate the pagination links * - * @access public * @return string */ public function create_links() @@ -155,13 +150,13 @@ class CI_Pagination { $this->cur_page = (int) $CI->input->get($this->query_string_segment); } } - elseif ( ! $this->cur_page AND $CI->uri->segment($this->uri_segment) != $base_page) + elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) != $base_page) { $this->cur_page = (int) $CI->uri->segment($this->uri_segment); } // Set current page to 1 if it's not valid or if using page numbers instead of offset - if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers AND $this->cur_page == 0)) + if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page == 0)) { $this->cur_page = $base_page; } @@ -182,12 +177,9 @@ class CI_Pagination { $this->cur_page = $num_pages; } } - else + elseif ($this->cur_page > $this->total_rows) { - if ($this->cur_page > $this->total_rows) - { - $this->cur_page = ($num_pages - 1) * $this->per_page; - } + $this->cur_page = ($num_pages - 1) * $this->per_page; } $uri_page_number = $this->cur_page; @@ -199,10 +191,10 @@ class CI_Pagination { // Calculate the start and end numbers. These determine // which number to start and end the digit links with - $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; - $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; + $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; + $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; - // Is pagination being used over GET or POST? If get, add a per_page query + // Is pagination being used over GET or POST? If get, add a per_page query // string. If post, add a trailing slash to the base URL if needed if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { @@ -217,18 +209,18 @@ class CI_Pagination { $output = ''; // Render the "First" link - if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1)) + if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; $output .= $this->first_tag_open.'anchor_class.'href="'.$first_url.'">'.$this->first_link.''.$this->first_tag_close; } // Render the "previous" link - if ($this->prev_link !== FALSE AND $this->cur_page != 1) + if ($this->prev_link !== FALSE && $this->cur_page != 1) { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; - if ($i == $base_page AND $this->first_url != '') + if ($i == $base_page && $this->first_url != '') { $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.''.$this->prev_tag_close; } @@ -274,7 +266,7 @@ class CI_Pagination { } // Render the "next" link - if ($this->next_link !== FALSE AND $this->cur_page < $num_pages) + if ($this->next_link !== FALSE && $this->cur_page < $num_pages) { $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; @@ -282,7 +274,7 @@ class CI_Pagination { } // Render the "Last" link - if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages) + if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links) < $num_pages) { $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; @@ -291,15 +283,13 @@ class CI_Pagination { // Kill double slashes. Note: Sometimes we can end up with a double slash // in the penultimate link so we'll kill all double slashes. - $output = preg_replace("#([^:])//+#", "\\1/", $output); + $output = preg_replace('#([^:])//+#', '\\1/', $output); // Add the wrapper HTML if exists - $output = $this->full_tag_open.$output.$this->full_tag_close; - - return $output; + return $this->full_tag_open.$output.$this->full_tag_close; } + } -// END Pagination Class /* End of file Pagination.php */ -/* Location: ./system/libraries/Pagination.php */ +/* Location: ./system/libraries/Pagination.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1a3885babb73870ef99af24297c722d8251480a1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 2 May 2012 10:23:12 +0300 Subject: Fix pagination anchor_class with multiple initializations --- system/libraries/Pagination.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 0fe73d69f..3d2911813 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -94,17 +94,16 @@ class CI_Pagination { { foreach ($params as $key => $val) { - if (isset($this->$key)) + if ($key === 'anchor_class') + { + $this->anchor_class = ($val != '') ? 'class="'.$val.'" ' : ''; + } + elseif (isset($this->$key)) { $this->$key = $val; } } } - - if ($this->anchor_class != '') - { - $this->anchor_class = 'class="'.$this->anchor_class.'" '; - } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5645479c622eb36cf9869797896dc0921568c4a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 14:32:19 +0300 Subject: Clean up the libraries --- system/libraries/Pagination.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 3d2911813..58f86fa17 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -73,6 +73,7 @@ class CI_Pagination { * Constructor * * @param array initialization parameters + * @return void */ public function __construct($params = array()) { -- cgit v1.2.3-24-g4f1b From d261b1e89c3d4d5191036d5a5660ef6764e593a0 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:16 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/libraries --- system/libraries/Pagination.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 58f86fa17..a91159c98 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -97,7 +97,7 @@ class CI_Pagination { { if ($key === 'anchor_class') { - $this->anchor_class = ($val != '') ? 'class="'.$val.'" ' : ''; + $this->anchor_class = ($val !== '') ? 'class="'.$val.'" ' : ''; } elseif (isset($this->$key)) { @@ -117,7 +117,7 @@ class CI_Pagination { public function create_links() { // If our item count or per-page total is zero there is no need to continue. - if ($this->total_rows == 0 OR $this->per_page == 0) + if ($this->total_rows === 0 OR $this->per_page === 0) { return ''; } @@ -138,25 +138,25 @@ class CI_Pagination { $CI =& get_instance(); // See if we are using a prefix or suffix on links - if ($this->prefix != '' OR $this->suffix != '') + if ($this->prefix !== '' OR $this->suffix !== '') { $this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->segment($this->uri_segment)); } if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - if ($CI->input->get($this->query_string_segment) != $base_page) + if ($CI->input->get($this->query_string_segment) !== $base_page) { $this->cur_page = (int) $CI->input->get($this->query_string_segment); } } - elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) != $base_page) + elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) !== $base_page) { $this->cur_page = (int) $CI->uri->segment($this->uri_segment); } // Set current page to 1 if it's not valid or if using page numbers instead of offset - if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page == 0)) + if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page === 0)) { $this->cur_page = $base_page; } @@ -211,22 +211,22 @@ class CI_Pagination { // Render the "First" link if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { - $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; + $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url; $output .= $this->first_tag_open.'anchor_class.'href="'.$first_url.'">'.$this->first_link.''.$this->first_tag_close; } // Render the "previous" link - if ($this->prev_link !== FALSE && $this->cur_page != 1) + if ($this->prev_link !== FALSE && $this->cur_page !== 1) { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; - if ($i == $base_page && $this->first_url != '') + if ($i === $base_page && $this->first_url !== '') { $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.''.$this->prev_tag_close; } else { - $i = ($i == $base_page) ? '' : $this->prefix.$i.$this->suffix; + $i = ($i === $base_page) ? '' : $this->prefix.$i.$this->suffix; $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.''.$this->prev_tag_close; } @@ -242,21 +242,21 @@ class CI_Pagination { if ($i >= $base_page) { - if ($this->cur_page == $loop) + if ($this->cur_page === $loop) { $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page } else { - $n = ($i == $base_page) ? '' : $i; + $n = ($i === $base_page) ? '' : $i; - if ($n == '' && $this->first_url != '') + if ($n === '' && $this->first_url !== '') { $output .= $this->num_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$loop.''.$this->num_tag_close; } else { - $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; + $n = ($n === '') ? '' : $this->prefix.$n.$this->suffix; $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'">'.$loop.''.$this->num_tag_close; } -- cgit v1.2.3-24-g4f1b From 7eb7ebfaa05b99c12746a7042116afa51d55260e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2012 10:26:27 +0300 Subject: Switch protected properties in Pagination class to public and fix 2 issues from d261b1e89c3d4d5191036d5a5660ef6764e593a0 --- system/libraries/Pagination.php | 68 ++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index a91159c98..ed86b89bc 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -36,38 +36,38 @@ */ class CI_Pagination { - protected $base_url = ''; // The page we are linking to - protected $prefix = ''; // A custom prefix added to the path. - protected $suffix = ''; // A custom suffix added to the path. - protected $total_rows = 0; // Total number of items (database results) - protected $per_page = 10; // Max number of items you want shown per page - protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page - protected $cur_page = 0; // The current page being viewed - protected $use_page_numbers = FALSE; // Use page number for segment instead of offset - protected $first_link = '‹ First'; - protected $next_link = '>'; - protected $prev_link = '<'; - protected $last_link = 'Last ›'; - protected $uri_segment = 3; - protected $full_tag_open = ''; - protected $full_tag_close = ''; - protected $first_tag_open = ''; - protected $first_tag_close = ' '; - protected $last_tag_open = ' '; - protected $last_tag_close = ''; - protected $first_url = ''; // Alternative URL for the First Page. - protected $cur_tag_open = ' '; - protected $cur_tag_close = ''; - protected $next_tag_open = ' '; - protected $next_tag_close = ' '; - protected $prev_tag_open = ' '; - protected $prev_tag_close = ''; - protected $num_tag_open = ' '; - protected $num_tag_close = ''; - protected $page_query_string = FALSE; - protected $query_string_segment = 'per_page'; - protected $display_pages = TRUE; - protected $anchor_class = ''; + public $base_url = ''; // The page we are linking to + public $prefix = ''; // A custom prefix added to the path. + public $suffix = ''; // A custom suffix added to the path. + public $total_rows = 0; // Total number of items (database results) + public $per_page = 10; // Max number of items you want shown per page + public $num_links = 2; // Number of "digit" links to show before/after the currently viewed page + public $cur_page = 0; // The current page being viewed + public $use_page_numbers = FALSE; // Use page number for segment instead of offset + public $first_link = '‹ First'; + public $next_link = '>'; + public $prev_link = '<'; + public $last_link = 'Last ›'; + public $uri_segment = 3; + public $full_tag_open = ''; + public $full_tag_close = ''; + public $first_tag_open = ''; + public $first_tag_close = ' '; + public $last_tag_open = ' '; + public $last_tag_close = ''; + public $first_url = ''; // Alternative URL for the First Page. + public $cur_tag_open = ' '; + public $cur_tag_close = ''; + public $next_tag_open = ' '; + public $next_tag_close = ' '; + public $prev_tag_open = ' '; + public $prev_tag_close = ''; + public $num_tag_open = ' '; + public $num_tag_close = ''; + public $page_query_string = FALSE; + public $query_string_segment = 'per_page'; + public $display_pages = TRUE; + public $anchor_class = ''; /** * Constructor @@ -97,7 +97,7 @@ class CI_Pagination { { if ($key === 'anchor_class') { - $this->anchor_class = ($val !== '') ? 'class="'.$val.'" ' : ''; + $this->anchor_class = ($val) ? 'class="'.$val.'" ' : ''; } elseif (isset($this->$key)) { @@ -145,7 +145,7 @@ class CI_Pagination { if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - if ($CI->input->get($this->query_string_segment) !== $base_page) + if ($CI->input->get($this->query_string_segment) != $base_page) { $this->cur_page = (int) $CI->input->get($this->query_string_segment); } -- cgit v1.2.3-24-g4f1b From 5a1e5e34207b9b30ff42200158074953ca1cabab Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2012 11:28:26 +0300 Subject: Add support for the anchor 'rel' attribute in the Pagination library --- system/libraries/Pagination.php | 44 ++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index ed86b89bc..cdec736ff 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -68,6 +68,7 @@ class CI_Pagination { public $query_string_segment = 'per_page'; public $display_pages = TRUE; public $anchor_class = ''; + public $attr_rel = TRUE; /** * Constructor @@ -212,7 +213,8 @@ class CI_Pagination { if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url; - $output .= $this->first_tag_open.'anchor_class.'href="'.$first_url.'">'.$this->first_link.''.$this->first_tag_close; + $output .= $this->first_tag_open.'anchor_class.'href="'.$first_url.'"'.$this->_attr_rel('start').'>' + .$this->first_link.''.$this->first_tag_close; } // Render the "previous" link @@ -222,12 +224,14 @@ class CI_Pagination { if ($i === $base_page && $this->first_url !== '') { - $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.''.$this->prev_tag_close; + $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'"'.$this->_attr_rel('prev').'>' + .$this->prev_link.''.$this->prev_tag_close; } else { $i = ($i === $base_page) ? '' : $this->prefix.$i.$this->suffix; - $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.''.$this->prev_tag_close; + $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->base_url.$i.'"'.$this->_attr_rel('prev').'>' + .$this->prev_link.''.$this->prev_tag_close; } } @@ -252,13 +256,15 @@ class CI_Pagination { if ($n === '' && $this->first_url !== '') { - $output .= $this->num_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$loop.''.$this->num_tag_close; + $output .= $this->num_tag_open.'anchor_class.'href="'.$this->first_url.'"'.$this->_attr_rel('start').'>' + .$loop.''.$this->num_tag_close; } else { $n = ($n === '') ? '' : $this->prefix.$n.$this->suffix; - $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'">'.$loop.''.$this->num_tag_close; + $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'"'.$this->_attr_rel().'>' + .$loop.''.$this->num_tag_close; } } } @@ -270,7 +276,8 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; - $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.''.$this->next_tag_close; + $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$this->_attr_rel('next').'>' + .$this->next_link.''.$this->next_tag_close; } // Render the "Last" link @@ -278,7 +285,8 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.''.$this->last_tag_close; + $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$this->_attr_rel().'>' + .$this->last_link.''.$this->last_tag_close; } // Kill double slashes. Note: Sometimes we can end up with a double slash @@ -289,6 +297,28 @@ class CI_Pagination { return $this->full_tag_open.$output.$this->full_tag_close; } + // -------------------------------------------------------------------- + + /** + * Add "rel" attribute + * + * @param string + * @return string + */ + protected function _attr_rel($value = '') + { + if (empty($this->attr_rel) OR ($this->attr_rel === TRUE && empty($value))) + { + return ''; + } + elseif ( ! is_bool($this->attr_rel)) + { + $value = $this->attr_rel; + } + + return ' rel="'.$value.'"'; + } + } /* End of file Pagination.php */ -- cgit v1.2.3-24-g4f1b From 88c47278f775413b5a408f48d30bd279e34e601a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 17 Jun 2012 02:32:31 +0300 Subject: Pagination: fixed 'rel' attribute handling, added custom attributes support, deprecated 'anchor_class' setting --- system/libraries/Pagination.php | 86 ++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 27 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cdec736ff..9a5a0bf62 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -67,8 +67,8 @@ class CI_Pagination { public $page_query_string = FALSE; public $query_string_segment = 'per_page'; public $display_pages = TRUE; - public $anchor_class = ''; - public $attr_rel = TRUE; + protected $_attributes = ''; + protected $_link_types = array(); /** * Constructor @@ -92,15 +92,29 @@ class CI_Pagination { */ public function initialize($params = array()) { + $attributes = array(); + + if (isset($params['attributes']) && is_array($params['attributes'])) + { + $attributes = $params['attributes']; + unset($params['attributes']); + } + + // Deprecated legacy support for the anchor_class option + // Should be removed in CI 3.1+ + if (isset($params['anchor_class'])) + { + empty($params['anchor_class']) OR $attributes['class'] = $params['anchor_class']; + unset($params['anchor_class']); + } + + $this->_parse_attributes($attributes); + if (count($params) > 0) { foreach ($params as $key => $val) { - if ($key === 'anchor_class') - { - $this->anchor_class = ($val) ? 'class="'.$val.'" ' : ''; - } - elseif (isset($this->$key)) + if (isset($this->$key)) { $this->$key = $val; } @@ -213,7 +227,7 @@ class CI_Pagination { if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url; - $output .= $this->first_tag_open.'anchor_class.'href="'.$first_url.'"'.$this->_attr_rel('start').'>' + $output .= $this->first_tag_open.'_attributes.$this->_attr_rel('start').'>' .$this->first_link.''.$this->first_tag_close; } @@ -224,13 +238,13 @@ class CI_Pagination { if ($i === $base_page && $this->first_url !== '') { - $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'"'.$this->_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attributes.$this->_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } else { $i = ($i === $base_page) ? '' : $this->prefix.$i.$this->suffix; - $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->base_url.$i.'"'.$this->_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attributes.$this->_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } @@ -243,7 +257,6 @@ class CI_Pagination { for ($loop = $start -1; $loop <= $end; $loop++) { $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page; - if ($i >= $base_page) { if ($this->cur_page === $loop) @@ -253,17 +266,15 @@ class CI_Pagination { else { $n = ($i === $base_page) ? '' : $i; - - if ($n === '' && $this->first_url !== '') + if ($n === '' && ! empty($this->first_url)) { - $output .= $this->num_tag_open.'anchor_class.'href="'.$this->first_url.'"'.$this->_attr_rel('start').'>' + $output .= $this->num_tag_open.'_attributes.$this->_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } else { $n = ($n === '') ? '' : $this->prefix.$n.$this->suffix; - - $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'"'.$this->_attr_rel().'>' + $output .= $this->num_tag_open.'_attributes.$this->_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } } @@ -276,8 +287,8 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; - $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$this->_attr_rel('next').'>' - .$this->next_link.''.$this->next_tag_close; + $output .= $this->next_tag_open.'_attributes + .$this->_attr_rel('next').'>'.$this->next_link.''.$this->next_tag_close; } // Render the "Last" link @@ -285,7 +296,7 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$this->_attr_rel().'>' + $output .= $this->last_tag_open.'_attributes.'>' .$this->last_link.''.$this->last_tag_close; } @@ -299,24 +310,45 @@ class CI_Pagination { // -------------------------------------------------------------------- + /** + * Parse attributes + * + * @param array + * @return void + */ + protected function _parse_attributes($attributes) + { + isset($attributes['rel']) OR $attributes['rel'] = TRUE; + $this->_link_types = ($attributes['rel']) + ? array('start' => 'start', 'prev' => 'prev', 'next' => 'next') + : array(); + unset($attributes['rel']); + + $this->_attributes = ''; + foreach ($attributes as $key => $value) + { + $this->_attributes .= ' '.$key.'="'.$value.'"'; + } + } + + // -------------------------------------------------------------------- + /** * Add "rel" attribute * + * @link http://www.w3.org/TR/html5/links.html#linkTypes * @param string * @return string */ - protected function _attr_rel($value = '') + protected function _attr_rel($type) { - if (empty($this->attr_rel) OR ($this->attr_rel === TRUE && empty($value))) - { - return ''; - } - elseif ( ! is_bool($this->attr_rel)) + if (isset($this->_link_types[$type])) { - $value = $this->attr_rel; + unset($this->_link_types[$type]); + return ' rel="'.$type.'"'; } - return ' rel="'.$value.'"'; + return ''; } } -- cgit v1.2.3-24-g4f1b From 9e5a9b55d6bd3588a35f42d62f76934b4a7582f4 Mon Sep 17 00:00:00 2001 From: Dumk0 Date: Tue, 19 Jun 2012 12:02:27 +0300 Subject: Property values aligned into one vertical line --- system/libraries/Pagination.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 9a5a0bf62..5a4ca8f10 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -36,36 +36,36 @@ */ class CI_Pagination { - public $base_url = ''; // The page we are linking to - public $prefix = ''; // A custom prefix added to the path. - public $suffix = ''; // A custom suffix added to the path. - public $total_rows = 0; // Total number of items (database results) - public $per_page = 10; // Max number of items you want shown per page - public $num_links = 2; // Number of "digit" links to show before/after the currently viewed page - public $cur_page = 0; // The current page being viewed - public $use_page_numbers = FALSE; // Use page number for segment instead of offset - public $first_link = '‹ First'; - public $next_link = '>'; - public $prev_link = '<'; - public $last_link = 'Last ›'; - public $uri_segment = 3; + public $base_url = ''; // The page we are linking to + public $prefix = ''; // A custom prefix added to the path. + public $suffix = ''; // A custom suffix added to the path. + public $total_rows = 0; // Total number of items (database results) + public $per_page = 10; // Max number of items you want shown per page + public $num_links = 2; // Number of "digit" links to show before/after the currently viewed page + public $cur_page = 0; // The current page being viewed + public $use_page_numbers = FALSE; // Use page number for segment instead of offset + public $first_link = '‹ First'; + public $next_link = '>'; + public $prev_link = '<'; + public $last_link = 'Last ›'; + public $uri_segment = 3; public $full_tag_open = ''; public $full_tag_close = ''; public $first_tag_open = ''; public $first_tag_close = ' '; public $last_tag_open = ' '; public $last_tag_close = ''; - public $first_url = ''; // Alternative URL for the First Page. - public $cur_tag_open = ' '; + public $first_url = ''; // Alternative URL for the First Page. + public $cur_tag_open = ' '; public $cur_tag_close = ''; public $next_tag_open = ' '; public $next_tag_close = ' '; public $prev_tag_open = ' '; public $prev_tag_close = ''; - public $num_tag_open = ' '; + public $num_tag_open = ' '; public $num_tag_close = ''; public $page_query_string = FALSE; - public $query_string_segment = 'per_page'; + public $query_string_segment = 'per_page'; public $display_pages = TRUE; protected $_attributes = ''; protected $_link_types = array(); -- cgit v1.2.3-24-g4f1b From f82b92999e8309155df3e665e25a261c26b0e93d Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sat, 23 Jun 2012 15:49:23 +0100 Subject: Added ['reuse_query_string'] to Pagination. This allows automatic repopulation of query string arguments, combined with normal URI segments. --- system/libraries/Pagination.php | 98 ++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 40 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 5a4ca8f10..75745dd48 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -36,39 +36,40 @@ */ class CI_Pagination { - public $base_url = ''; // The page we are linking to - public $prefix = ''; // A custom prefix added to the path. - public $suffix = ''; // A custom suffix added to the path. - public $total_rows = 0; // Total number of items (database results) - public $per_page = 10; // Max number of items you want shown per page - public $num_links = 2; // Number of "digit" links to show before/after the currently viewed page - public $cur_page = 0; // The current page being viewed - public $use_page_numbers = FALSE; // Use page number for segment instead of offset - public $first_link = '‹ First'; - public $next_link = '>'; - public $prev_link = '<'; - public $last_link = 'Last ›'; - public $uri_segment = 3; - public $full_tag_open = ''; - public $full_tag_close = ''; - public $first_tag_open = ''; - public $first_tag_close = ' '; - public $last_tag_open = ' '; - public $last_tag_close = ''; - public $first_url = ''; // Alternative URL for the First Page. - public $cur_tag_open = ' '; - public $cur_tag_close = ''; - public $next_tag_open = ' '; - public $next_tag_close = ' '; - public $prev_tag_open = ' '; - public $prev_tag_close = ''; - public $num_tag_open = ' '; - public $num_tag_close = ''; - public $page_query_string = FALSE; - public $query_string_segment = 'per_page'; - public $display_pages = TRUE; - protected $_attributes = ''; - protected $_link_types = array(); + protected $base_url = ''; // The page we are linking to + protected $prefix = ''; // A custom prefix added to the path. + protected $suffix = ''; // A custom suffix added to the path. + protected $total_rows = 0; // Total number of items (database results) + protected $per_page = 10; // Max number of items you want shown per page + protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page + protected $cur_page = 0; // The current page being viewed + protected $use_page_numbers = FALSE; // Use page number for segment instead of offset + protected $first_link = '‹ First'; + protected $next_link = '>'; + protected $prev_link = '<'; + protected $last_link = 'Last ›'; + protected $uri_segment = 3; + protected $full_tag_open = ''; + protected $full_tag_close = ''; + protected $first_tag_open = ''; + protected $first_tag_close = ' '; + protected $last_tag_open = ' '; + protected $last_tag_close = ''; + protected $first_url = ''; // Alternative URL for the First Page. + protected $cur_tag_open = ' '; + protected $cur_tag_close = ''; + protected $next_tag_open = ' '; + protected $next_tag_close = ' '; + protected $prev_tag_open = ' '; + protected $prev_tag_close = ''; + protected $num_tag_open = ' '; + protected $num_tag_close = ''; + protected $page_query_string = FALSE; + protected $query_string_segment = 'per_page'; + protected $display_pages = TRUE; + protected $_attributes = ''; + protected $_link_types = array(); + protected $reuse_query_string = FALSE; /** * Constructor @@ -222,6 +223,23 @@ class CI_Pagination { // And here we go... $output = ''; + $query_string = ''; + + // Add anything in the query string back to the links + // Note: Nothing to do with query_string_segment or any other query string options + if ($this->reuse_query_string === TRUE) + { + $get = $CI->input->get(); + + // Unset the controll, method, old-school routing options + unset($get['c'], $get['m'], $get[$this->query_string_segment]); + + // Put everything else onto the end + $query_string = (strpos($this->base_url, '&') !== FALSE ? '&' : '?') . http_build_query($get, '', '&'); + + // Add this after the suffix to put it into more links easily + $this->suffix .= $query_string; + } // Render the "First" link if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) @@ -232,19 +250,19 @@ class CI_Pagination { } // Render the "previous" link - if ($this->prev_link !== FALSE && $this->cur_page !== 1) + if ($this->prev_link !== FALSE && $this->cur_page !== 1) { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; if ($i === $base_page && $this->first_url !== '') { - $output .= $this->prev_tag_open.'_attributes.$this->_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attributes.$this->_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } else { - $i = ($i === $base_page) ? '' : $this->prefix.$i.$this->suffix; - $output .= $this->prev_tag_open.'_attributes.$this->_attr_rel('prev').'>' + $append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix; + $output .= $this->prev_tag_open.'_attributes.$this->_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } @@ -268,13 +286,13 @@ class CI_Pagination { $n = ($i === $base_page) ? '' : $i; if ($n === '' && ! empty($this->first_url)) { - $output .= $this->num_tag_open.'_attributes.$this->_attr_rel('start').'>' + $output .= $this->num_tag_open.'_attributes.$this->_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } else { - $n = ($n === '') ? '' : $this->prefix.$n.$this->suffix; - $output .= $this->num_tag_open.'_attributes.$this->_attr_rel('start').'>' + $append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix; + $output .= $this->num_tag_open.'_attributes.$this->_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } } -- cgit v1.2.3-24-g4f1b From a44cf574132ae9332ab68ddbcda8849e3e71c54b Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 12 Jul 2012 11:50:46 +0100 Subject: Added data-ci-pagination-page="x" to pagination output so JS frameworks can hook on. --- system/libraries/Pagination.php | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 75745dd48..ed9964590 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -70,6 +70,7 @@ class CI_Pagination { protected $_attributes = ''; protected $_link_types = array(); protected $reuse_query_string = FALSE; + protected $data_page_attr = 'data-ci-pagination-page'; /** * Constructor @@ -234,6 +235,8 @@ class CI_Pagination { // Unset the controll, method, old-school routing options unset($get['c'], $get['m'], $get[$this->query_string_segment]); + if ( ! $get) $get = array(); + // Put everything else onto the end $query_string = (strpos($this->base_url, '&') !== FALSE ? '&' : '?') . http_build_query($get, '', '&'); @@ -245,7 +248,11 @@ class CI_Pagination { if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url; - $output .= $this->first_tag_open.'_attributes.$this->_attr_rel('start').'>' + + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); + + $output .= $this->first_tag_open.'_attr_rel('start').'>' .$this->first_link.''.$this->first_tag_close; } @@ -254,15 +261,18 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + if ($i === $base_page && $this->first_url !== '') { - $output .= $this->prev_tag_open.'_attributes.$this->_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } else { $append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix; - $output .= $this->prev_tag_open.'_attributes.$this->_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } @@ -275,6 +285,10 @@ class CI_Pagination { for ($loop = $start -1; $loop <= $end; $loop++) { $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page; + + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + if ($i >= $base_page) { if ($this->cur_page === $loop) @@ -286,13 +300,13 @@ class CI_Pagination { $n = ($i === $base_page) ? '' : $i; if ($n === '' && ! empty($this->first_url)) { - $output .= $this->num_tag_open.'_attributes.$this->_attr_rel('start').'>' + $output .= $this->num_tag_open.'_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } else { $append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix; - $output .= $this->num_tag_open.'_attributes.$this->_attr_rel('start').'>' + $output .= $this->num_tag_open.'_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } } @@ -305,7 +319,10 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; - $output .= $this->next_tag_open.'_attributes + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + + $output .= $this->next_tag_open.'_attr_rel('next').'>'.$this->next_link.''.$this->next_tag_close; } @@ -314,7 +331,10 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - $output .= $this->last_tag_open.'_attributes.'>' + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + + $output .= $this->last_tag_open.'' .$this->last_link.''.$this->last_tag_close; } -- cgit v1.2.3-24-g4f1b From 5d50453b501d093419c23b128742a68e830fbe14 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 14 Jul 2012 00:03:56 +0800 Subject: fix issue #1605 covert page number type from float to int Signed-off-by: Bo-Yi Wu --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index ed9964590..df9b0ddd9 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -203,7 +203,7 @@ class CI_Pagination { if ( ! $this->use_page_numbers) { - $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); + $this->cur_page = (int) floor(($this->cur_page/$this->per_page) + 1); } // Calculate the start and end numbers. These determine @@ -392,4 +392,4 @@ class CI_Pagination { } /* End of file Pagination.php */ -/* Location: ./system/libraries/Pagination.php */ \ No newline at end of file +/* Location: ./system/libraries/Pagination.php */ -- cgit v1.2.3-24-g4f1b From 685cdd7a28a8e7ec5a3769e2b0d2cdd40c8f6bf9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 13 Jul 2012 20:11:13 +0300 Subject: Add a changelog entry for issue #1605 (pull #1606) and remove some spaces --- system/libraries/Pagination.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index df9b0ddd9..5573f6407 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -231,7 +231,7 @@ class CI_Pagination { if ($this->reuse_query_string === TRUE) { $get = $CI->input->get(); - + // Unset the controll, method, old-school routing options unset($get['c'], $get['m'], $get[$this->query_string_segment]); @@ -248,9 +248,9 @@ class CI_Pagination { if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url; - + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); $output .= $this->first_tag_open.'_attr_rel('start').'>' .$this->first_link.''.$this->first_tag_close; @@ -392,4 +392,4 @@ class CI_Pagination { } /* End of file Pagination.php */ -/* Location: ./system/libraries/Pagination.php */ +/* Location: ./system/libraries/Pagination.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f7e23b3357c73cc9eb50c59f444181fcfaa2267d Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Fri, 7 Sep 2012 09:52:32 +0100 Subject: Removed the   from the default config variables in the pagination class. Fixes #187 and #208 Signed-off-by: Alex Bilbie --- system/libraries/Pagination.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 5573f6407..4fa605ca9 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -52,20 +52,20 @@ class CI_Pagination { protected $full_tag_open = ''; protected $full_tag_close = ''; protected $first_tag_open = ''; - protected $first_tag_close = ' '; - protected $last_tag_open = ' '; + protected $first_tag_close = ''; + protected $last_tag_open = ''; protected $last_tag_close = ''; protected $first_url = ''; // Alternative URL for the First Page. - protected $cur_tag_open = ' '; + protected $cur_tag_open = ''; protected $cur_tag_close = ''; - protected $next_tag_open = ' '; - protected $next_tag_close = ' '; - protected $prev_tag_open = ' '; + protected $next_tag_open = ''; + protected $next_tag_close = ''; + protected $prev_tag_open = ''; protected $prev_tag_close = ''; - protected $num_tag_open = ' '; + protected $num_tag_open = ''; protected $num_tag_close = ''; protected $page_query_string = FALSE; - protected $query_string_segment = 'per_page'; + protected $query_string_segment = 'per_page'; protected $display_pages = TRUE; protected $_attributes = ''; protected $_link_types = array(); -- cgit v1.2.3-24-g4f1b From 6b4e3624b9a33c144b3ab4aea7904d5919fcc306 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 21 Sep 2012 13:57:24 +0800 Subject: Fixed #1817 Pagination class error Signed-off-by: Bo-Yi Wu --- system/libraries/Pagination.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 4fa605ca9..e1e729bb0 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -215,7 +215,8 @@ class CI_Pagination { // string. If post, add a trailing slash to the base URL if needed if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - $this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'='; + $segment = (strpos($this->base_url, '?')) ? '&' : '?'; + $this->base_url = rtrim($this->base_url).$segment.$this->query_string_segment.'='; } else { -- cgit v1.2.3-24-g4f1b From e66d6243aaf13053631641973a0beff656a94510 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Oct 2012 16:39:12 +0300 Subject: Fix issues #1476, #1909 --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index e1e729bb0..36b57b332 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -157,7 +157,7 @@ class CI_Pagination { // See if we are using a prefix or suffix on links if ($this->prefix !== '' OR $this->suffix !== '') { - $this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->segment($this->uri_segment)); + $this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->rsegment($this->uri_segment)); } if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) @@ -169,7 +169,7 @@ class CI_Pagination { } elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) !== $base_page) { - $this->cur_page = (int) $CI->uri->segment($this->uri_segment); + $this->cur_page = (int) $CI->uri->rsegment($this->uri_segment); } // Set current page to 1 if it's not valid or if using page numbers instead of offset -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/libraries/Pagination.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 36b57b332..4cb72bbfb 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,4 +1,4 @@ - Date: Thu, 1 Nov 2012 23:33:14 +0200 Subject: [ci skip] DocBlocks for Pagination, Session, Trackback, Jquery libraries Partially fixes issue #1295 --- system/libraries/Pagination.php | 295 +++++++++++++++++++++++++++++++++++----- 1 file changed, 259 insertions(+), 36 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 4cb72bbfb..ae8dba072 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -37,46 +37,269 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_Pagination { - protected $base_url = ''; // The page we are linking to - protected $prefix = ''; // A custom prefix added to the path. - protected $suffix = ''; // A custom suffix added to the path. - protected $total_rows = 0; // Total number of items (database results) - protected $per_page = 10; // Max number of items you want shown per page - protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page - protected $cur_page = 0; // The current page being viewed - protected $use_page_numbers = FALSE; // Use page number for segment instead of offset - protected $first_link = '‹ First'; - protected $next_link = '>'; - protected $prev_link = '<'; - protected $last_link = 'Last ›'; - protected $uri_segment = 3; - protected $full_tag_open = ''; - protected $full_tag_close = ''; - protected $first_tag_open = ''; - protected $first_tag_close = ''; - protected $last_tag_open = ''; - protected $last_tag_close = ''; - protected $first_url = ''; // Alternative URL for the First Page. - protected $cur_tag_open = ''; - protected $cur_tag_close = ''; - protected $next_tag_open = ''; - protected $next_tag_close = ''; - protected $prev_tag_open = ''; - protected $prev_tag_close = ''; - protected $num_tag_open = ''; - protected $num_tag_close = ''; + /** + * Base URL + * + * The page that we're linking to + * + * @var string + */ + protected $base_url = ''; + + /** + * Prefix + * + * @var string + */ + protected $prefix = ''; + + /** + * Suffix + * + * @var string + */ + protected $suffix = ''; + + /** + * Total number of items + * + * @var int + */ + protected $total_rows = 0; + + /** + * Items per page + * + * @var int + */ + protected $per_page = 10; + + /** + * Number of links to show + * + * Relates to "digit" type links shown before/after + * the currently viewed page. + * + * @var int + */ + protected $num_links = 2; + + /** + * Current page + * + * @var int + */ + protected $cur_page = 0; + + /** + * Use page numbers flag + * + * Whether to use actual page numbers instead of an offset + * + * @var bool + */ + protected $use_page_numbers = FALSE; + + /** + * First link + * + * @var string + */ + protected $first_link = '‹ First'; + + /** + * Next link + * + * @var string + */ + protected $next_link = '>'; + + /** + * Previous link + * + * @var string + */ + protected $prev_link = '<'; + + /** + * Last link + * + * @var string + */ + protected $last_link = 'Last ›'; + + /** + * URI Segment + * + * @var int + */ + protected $uri_segment = 3; + + /** + * Full tag open + * + * @var string + */ + protected $full_tag_open = ''; + + /** + * Full tag close + * + * @var string + */ + protected $full_tag_close = ''; + + /** + * First tag open + * + * @var string + */ + protected $first_tag_open = ''; + + /** + * First tag close + * + * @var string + */ + protected $first_tag_close = ''; + + /** + * Last tag open + * + * @var string + */ + protected $last_tag_open = ''; + + /** + * Last tag close + * + * @var string + */ + protected $last_tag_close = ''; + + /** + * First URL + * + * An alternative URL for the first page + * + * @var string + */ + protected $first_url = ''; + + /** + * Current tag open + * + * @var string + */ + protected $cur_tag_open = ''; + + /** + * Current tag close + * + * @var string + */ + protected $cur_tag_close = ''; + + /** + * Next tag open + * + * @var string + */ + protected $next_tag_open = ''; + + /** + * Next tag close + * + * @var string + */ + protected $next_tag_close = ''; + + /** + * Previous tag open + * + * @var string + */ + protected $prev_tag_open = ''; + + /** + * Previous tag close + * + * @var string + */ + protected $prev_tag_close = ''; + + /** + * Number tag open + * + * @var string + */ + protected $num_tag_open = ''; + + /** + * Number tag close + * + * @var string + */ + protected $num_tag_close = ''; + + /** + * Page query string flag + * + * @var bool + */ protected $page_query_string = FALSE; + + /** + * Query string segment + * + * @var string + */ protected $query_string_segment = 'per_page'; - protected $display_pages = TRUE; - protected $_attributes = ''; - protected $_link_types = array(); + + /** + * Display pages flag + * + * @var bool + */ + protected $display_pages = TRUE; + + /** + * Attributes + * + * @var string + */ + protected $_attributes = ''; + + /** + * Link types + * + * "rel" attribute + * + * @see CI_Pagination::_attr_rel() + * @var array + */ + protected $_link_types = array(); + + /** + * Reuse query string flag + * + * @var bool + */ protected $reuse_query_string = FALSE; - protected $data_page_attr = 'data-ci-pagination-page'; + + /** + * Data page attribute + * + * @var string + */ + protected $data_page_attr = 'data-ci-pagination-page'; + + // -------------------------------------------------------------------- /** * Constructor * - * @param array initialization parameters + * @param array $params Initialization parameters * @return void */ public function __construct($params = array()) @@ -90,7 +313,7 @@ class CI_Pagination { /** * Initialize Preferences * - * @param array initialization parameters + * @param array $params Initialization parameters * @return void */ public function initialize($params = array()) @@ -353,7 +576,7 @@ class CI_Pagination { /** * Parse attributes * - * @param array + * @param array $attributes * @return void */ protected function _parse_attributes($attributes) @@ -377,7 +600,7 @@ class CI_Pagination { * Add "rel" attribute * * @link http://www.w3.org/TR/html5/links.html#linkTypes - * @param string + * @param string $type * @return string */ protected function _attr_rel($type) -- cgit v1.2.3-24-g4f1b From 2b241399a7b1978ca7992e0a0162599408fabb9b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Nov 2012 13:23:25 +0200 Subject: Manually apply a fix submitted via PR #2012, #2016 --- system/libraries/Pagination.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index ae8dba072..66b341760 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -460,13 +460,15 @@ class CI_Pagination { // Unset the controll, method, old-school routing options unset($get['c'], $get['m'], $get[$this->query_string_segment]); - if ( ! $get) $get = array(); - - // Put everything else onto the end - $query_string = (strpos($this->base_url, '&') !== FALSE ? '&' : '?') . http_build_query($get, '', '&'); + if ( ! empty($get)) + { + // Put everything else onto the end + $query_string = (strpos($this->base_url, '?') !== FALSE ? '&' : '?') + .http_build_query($get, '', '&'); - // Add this after the suffix to put it into more links easily - $this->suffix .= $query_string; + // Add this after the suffix to put it into more links easily + $this->suffix .= $query_string; + } } // Render the "First" link -- cgit v1.2.3-24-g4f1b From 80500afbd188600212ca913a7bac073009feac73 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 1 Jan 2013 08:16:53 +0200 Subject: [ci skip] Happy new year --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 66b341760..d139980d8 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 9f3a590751da2003698546c205a93fcc9c3325f8 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Mon, 28 Jan 2013 04:29:06 -0600 Subject: Multiple pagination bug fixes & optimizations. Signed-off-by: Eric Roberts --- system/libraries/Pagination.php | 190 ++++++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 83 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d139980d8..3a513a7c1 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -133,7 +133,7 @@ class CI_Pagination { * * @var int */ - protected $uri_segment = 3; + protected $uri_segment = 0; /** * Full tag open @@ -318,11 +318,9 @@ class CI_Pagination { */ public function initialize($params = array()) { - $attributes = array(); - if (isset($params['attributes']) && is_array($params['attributes'])) { - $attributes = $params['attributes']; + $this->_parse_attributes($params['attributes']); unset($params['attributes']); } @@ -334,8 +332,6 @@ class CI_Pagination { unset($params['anchor_class']); } - $this->_parse_attributes($attributes); - if (count($params) > 0) { foreach ($params as $key => $val) @@ -372,45 +368,111 @@ class CI_Pagination { return ''; } - // Set the base page index for starting page number - $base_page = ($this->use_page_numbers) ? 1 : 0; + // Check the user defined number of links. + $this->num_links = (int) $this->num_links; + + if ($this->num_links < 1) + { + show_error('Your number of links must be a positive number.'); + } - // Determine the current page number. $CI =& get_instance(); - // See if we are using a prefix or suffix on links - if ($this->prefix !== '' OR $this->suffix !== '') + // Keep any existing query string items. + // Note: Has nothing to do with any other query string option. + $get = array(); + + if ($this->reuse_query_string === TRUE) { - $this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->rsegment($this->uri_segment)); + $get = $CI->input->get(); + + // Unset the controll, method, old-school routing options + unset($get['c'], $get['m'], $get[$this->query_string_segment]); } + // Put together our base and first URLs. + $this->base_url = trim($this->base_url); + + $query_string = ''; + $query_string_sep = (strpos($this->base_url, '?') === FALSE) ? '?' : '&'; + + // Are we using query strings? if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - if ($CI->input->get($this->query_string_segment) != $base_page) + // If a custom first_url hasn't been specified, we'll create one from + // the base_url, but without the page item. + if ($this->first_url === '') { - $this->cur_page = (int) $CI->input->get($this->query_string_segment); + $this->first_url = $this->base_url; + + // If we saved any GET items earlier, make sure they're appended. + if ( ! empty($get)) + { + $this->first_url .= $query_string_sep . http_build_query($get); + } } + + // Add the page segment to the end of the query string, where the + // page number will be appended. + $this->base_url .= $query_string_sep . http_build_query(array_merge($get, array($this->query_string_segment => ''))); } - elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) !== $base_page) + else { - $this->cur_page = (int) $CI->uri->rsegment($this->uri_segment); + // Standard segment mode. + // Generate our saved query string to append later after the page number. + if ( ! empty($get)) + { + $query_string = $query_string_sep . http_build_query($get); + $this->suffix .= $query_string; + } + + // Does the base_url have the query string in it? + // If we're supposed to save it, remove it so we can append it later. + if ($this->reuse_query_string === TRUE && ($base_query_pos = strpos($this->base_url, '?')) !== FALSE) + { + $this->base_url = substr($this->base_url, 0, $base_query_pos); + } + + if ($this->first_url === '') + { + $this->first_url = $this->base_url . $query_string; + } + + $this->base_url = rtrim($this->base_url, '/') . '/'; } - // Set current page to 1 if it's not valid or if using page numbers instead of offset - if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page === 0)) + // Determine the current page number. + $base_page = ($this->use_page_numbers) ? 1 : 0; + + // Are we using query strings? + if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - $this->cur_page = $base_page; + $this->cur_page = (int) $CI->input->get($this->query_string_segment); } + else + { + // Default to the last segment number if one hasn't been defined. + if ($this->uri_segment === 0) + { + $this->uri_segment = count($CI->uri->segment_array()); + } - $this->num_links = (int) $this->num_links; + $this->cur_page = $CI->uri->segment($this->uri_segment); - if ($this->num_links < 1) + // Remove any specified prefix/suffix from the segment. + $this->cur_page = ($this->prefix !== '' OR $this->suffix !== '') + ? (int) str_replace(array($this->prefix, $this->suffix), '', $this->cur_page) + : (int) $this->cur_page; + } + + // If something isn't quite right, back to the default base page. + if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page === 0)) { - show_error('Your number of links must be a positive number.'); + $this->cur_page = $base_page; } // Is the page number beyond the result range? - // If so we show the last page + // If so, we show the last page. if ($this->use_page_numbers) { if ($this->cur_page > $num_pages) @@ -425,80 +487,47 @@ class CI_Pagination { $uri_page_number = $this->cur_page; + // If we're using offset instead of page numbers, convert it + // to a page number, so we can generate the surrounding number links. if ( ! $this->use_page_numbers) { $this->cur_page = (int) floor(($this->cur_page/$this->per_page) + 1); } // Calculate the start and end numbers. These determine - // which number to start and end the digit links with + // which number to start and end the digit links with. $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; - // Is pagination being used over GET or POST? If get, add a per_page query - // string. If post, add a trailing slash to the base URL if needed - if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) - { - $segment = (strpos($this->base_url, '?')) ? '&' : '?'; - $this->base_url = rtrim($this->base_url).$segment.$this->query_string_segment.'='; - } - else - { - $this->base_url = rtrim($this->base_url, '/') .'/'; - } - // And here we go... $output = ''; - $query_string = ''; - - // Add anything in the query string back to the links - // Note: Nothing to do with query_string_segment or any other query string options - if ($this->reuse_query_string === TRUE) - { - $get = $CI->input->get(); - // Unset the controll, method, old-school routing options - unset($get['c'], $get['m'], $get[$this->query_string_segment]); - - if ( ! empty($get)) - { - // Put everything else onto the end - $query_string = (strpos($this->base_url, '?') !== FALSE ? '&' : '?') - .http_build_query($get, '', '&'); - - // Add this after the suffix to put it into more links easily - $this->suffix .= $query_string; - } - } - - // Render the "First" link + // Render the "First" link. if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { - $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url; - - // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); - $output .= $this->first_tag_open.'_attr_rel('start').'>' + $output .= $this->first_tag_open.'_attr_rel('start').'>' .$this->first_link.''.$this->first_tag_close; } - // Render the "previous" link + // Render the "Previous" link. if ($this->prev_link !== FALSE && $this->cur_page !== 1) { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; - // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); - if ($i === $base_page && $this->first_url !== '') + if ($i === $base_page) { - $output .= $this->prev_tag_open.'_attr_rel('prev').'>' + // First page + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } else { - $append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix; + $append = $this->prefix.$i.$this->suffix; $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } @@ -513,29 +542,26 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page; - // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); if ($i >= $base_page) { if ($this->cur_page === $loop) { - $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page + // Current page + $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; + } + elseif ($i === $base_page) + { + // First page + $output .= $this->num_tag_open.'_attr_rel('start').'>' + .$loop.''.$this->num_tag_close; } else { - $n = ($i === $base_page) ? '' : $i; - if ($n === '' && ! empty($this->first_url)) - { - $output .= $this->num_tag_open.'_attr_rel('start').'>' - .$loop.''.$this->num_tag_close; - } - else - { - $append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix; - $output .= $this->num_tag_open.'_attr_rel('start').'>' - .$loop.''.$this->num_tag_close; - } + $append = $this->prefix.$i.$this->suffix; + $output .= $this->num_tag_open.'_attr_rel('start').'>' + .$loop.''.$this->num_tag_close; } } } @@ -546,7 +572,6 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; - // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); $output .= $this->next_tag_open.'use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); $output .= $this->last_tag_open.'' -- cgit v1.2.3-24-g4f1b From 9668d1d56d39187aa26f058495ca666e3544cbe2 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Mon, 28 Jan 2013 17:45:34 -0600 Subject: Remove spaces from concats. Signed-off-by: Eric Roberts --- system/libraries/Pagination.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 3a513a7c1..76754046b 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -408,13 +408,13 @@ class CI_Pagination { // If we saved any GET items earlier, make sure they're appended. if ( ! empty($get)) { - $this->first_url .= $query_string_sep . http_build_query($get); + $this->first_url .= $query_string_sep.http_build_query($get); } } // Add the page segment to the end of the query string, where the // page number will be appended. - $this->base_url .= $query_string_sep . http_build_query(array_merge($get, array($this->query_string_segment => ''))); + $this->base_url .= $query_string_sep.http_build_query(array_merge($get, array($this->query_string_segment => ''))); } else { @@ -422,7 +422,7 @@ class CI_Pagination { // Generate our saved query string to append later after the page number. if ( ! empty($get)) { - $query_string = $query_string_sep . http_build_query($get); + $query_string = $query_string_sep.http_build_query($get); $this->suffix .= $query_string; } @@ -435,10 +435,10 @@ class CI_Pagination { if ($this->first_url === '') { - $this->first_url = $this->base_url . $query_string; + $this->first_url = $this->base_url.$query_string; } - $this->base_url = rtrim($this->base_url, '/') . '/'; + $this->base_url = rtrim($this->base_url, '/').'/'; } // Determine the current page number. -- cgit v1.2.3-24-g4f1b From ba67f3bb595817115a15f6c3249e41e7c85f2ce4 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Mon, 28 Jan 2013 18:01:01 -0600 Subject: Move $get assignment to if/else. Signed-off-by: Eric Roberts --- system/libraries/Pagination.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 76754046b..562a2d3eb 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -380,8 +380,6 @@ class CI_Pagination { // Keep any existing query string items. // Note: Has nothing to do with any other query string option. - $get = array(); - if ($this->reuse_query_string === TRUE) { $get = $CI->input->get(); @@ -389,6 +387,10 @@ class CI_Pagination { // Unset the controll, method, old-school routing options unset($get['c'], $get['m'], $get[$this->query_string_segment]); } + else + { + $get = array(); + } // Put together our base and first URLs. $this->base_url = trim($this->base_url); -- cgit v1.2.3-24-g4f1b From 032af98ab94482cc7c5b10013ec033acfdc34c74 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Mon, 28 Jan 2013 23:25:52 -0600 Subject: Replace is_numeric() with ctype_digit() Signed-off-by: Eric Roberts --- system/libraries/Pagination.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 562a2d3eb..438d6c477 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -449,7 +449,8 @@ class CI_Pagination { // Are we using query strings? if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - $this->cur_page = (int) $CI->input->get($this->query_string_segment); + // Cast as string for use in ctype_digit() later. + $this->cur_page = (string) $CI->input->get($this->query_string_segment); } else { @@ -459,19 +460,25 @@ class CI_Pagination { $this->uri_segment = count($CI->uri->segment_array()); } - $this->cur_page = $CI->uri->segment($this->uri_segment); + $this->cur_page = (string) $CI->uri->segment($this->uri_segment); // Remove any specified prefix/suffix from the segment. - $this->cur_page = ($this->prefix !== '' OR $this->suffix !== '') - ? (int) str_replace(array($this->prefix, $this->suffix), '', $this->cur_page) - : (int) $this->cur_page; + if ($this->prefix !== '' OR $this->suffix !== '') + { + $this->cur_page = str_replace(array($this->prefix, $this->suffix), '', $this->cur_page); + } } // If something isn't quite right, back to the default base page. - if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page === 0)) + if ( ! ctype_digit($this->cur_page) OR ($this->use_page_numbers && (int) $this->cur_page === 0)) { $this->cur_page = $base_page; } + else + { + // Make sure we're using integers for comparisons later. + $this->cur_page = (int) $this->cur_page; + } // Is the page number beyond the result range? // If so, we show the last page. -- cgit v1.2.3-24-g4f1b From 870f11351b6e7a916bf30aa22b4a8c3dd49bf33f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Feb 2013 22:06:00 +0200 Subject: [ci skip] Remove unnecessary string casts in Pagination --- system/libraries/Pagination.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 438d6c477..10fb29dbd 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -449,8 +449,7 @@ class CI_Pagination { // Are we using query strings? if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - // Cast as string for use in ctype_digit() later. - $this->cur_page = (string) $CI->input->get($this->query_string_segment); + $this->cur_page = $CI->input->get($this->query_string_segment); } else { @@ -460,7 +459,7 @@ class CI_Pagination { $this->uri_segment = count($CI->uri->segment_array()); } - $this->cur_page = (string) $CI->uri->segment($this->uri_segment); + $this->cur_page = $CI->uri->segment($this->uri_segment); // Remove any specified prefix/suffix from the segment. if ($this->prefix !== '' OR $this->suffix !== '') -- cgit v1.2.3-24-g4f1b From b367f7ba9302f00926f6b923ca1ca741b351ae96 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 14 Oct 2013 12:27:00 +0300 Subject: Fix #2674 --- system/libraries/Pagination.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 10fb29dbd..c6ffd03d4 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -354,7 +354,8 @@ class CI_Pagination { public function create_links() { // If our item count or per-page total is zero there is no need to continue. - if ($this->total_rows === 0 OR $this->per_page === 0) + // Note: DO NOT change the operator to === here! + if ($this->total_rows == 0 OR $this->per_page == 0) { return ''; } -- cgit v1.2.3-24-g4f1b From 6f6102c805198101fad36024b82692ebce20f2c8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Feb 2014 19:11:40 +0200 Subject: Add method chaining support to Calendar & Pagination libs --- system/libraries/Pagination.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index c6ffd03d4..f67cb47f8 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -314,7 +314,7 @@ class CI_Pagination { * Initialize Preferences * * @param array $params Initialization parameters - * @return void + * @return CI_Pagination */ public function initialize($params = array()) { @@ -342,6 +342,8 @@ class CI_Pagination { } } } + + return $this; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index f67cb47f8..da4b89232 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From aef63e532bcede1d455bc27f0fc6f369ab74f203 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Feb 2014 14:49:55 +0200 Subject: Add language translation support to CI_Pagination (#1589) --- system/libraries/Pagination.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index da4b89232..2f1bcfbad 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -304,6 +304,16 @@ class CI_Pagination { */ public function __construct($params = array()) { + $CI =& get_instance(); + $CI->load->language('paginaton'); + foreach (array('first_link', 'next_link', 'prev_link', 'last_link') as $key) + { + if (($val = $CI->lang->line('pagination_'.$key)) !== FALSE) + { + $this->$key = $val; + } + } + $this->initialize($params); log_message('debug', 'Pagination Class Initialized'); } @@ -316,7 +326,7 @@ class CI_Pagination { * @param array $params Initialization parameters * @return CI_Pagination */ - public function initialize($params = array()) + public function initialize(array $params = array()) { if (isset($params['attributes']) && is_array($params['attributes'])) { @@ -332,14 +342,11 @@ class CI_Pagination { unset($params['anchor_class']); } - if (count($params) > 0) + foreach ($params as $key => $val) { - foreach ($params as $key => $val) + if (property_exists($this, $this->$key)) { - if (isset($this->$key)) - { - $this->$key = $val; - } + $this->$key = $val; } } -- cgit v1.2.3-24-g4f1b From b1616b8c3370d59135275b6945ed1b80cfe99653 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Feb 2014 15:12:43 +0200 Subject: Fix #2364 --- system/libraries/Pagination.php | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 2f1bcfbad..06cc0c378 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -403,30 +403,32 @@ class CI_Pagination { } // Put together our base and first URLs. - $this->base_url = trim($this->base_url); + // Note: DO NOT append to the properties as that would break successive calls + $base_url = trim($this->base_url); + $first_url = $this->first_url; $query_string = ''; - $query_string_sep = (strpos($this->base_url, '?') === FALSE) ? '?' : '&'; + $query_string_sep = (strpos($base_url, '?') === FALSE) ? '?' : '&'; // Are we using query strings? if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { // If a custom first_url hasn't been specified, we'll create one from // the base_url, but without the page item. - if ($this->first_url === '') + if ($first_url === '') { - $this->first_url = $this->base_url; + $first_url = $base_url; // If we saved any GET items earlier, make sure they're appended. if ( ! empty($get)) { - $this->first_url .= $query_string_sep.http_build_query($get); + $first_url .= $query_string_sep.http_build_query($get); } } // Add the page segment to the end of the query string, where the // page number will be appended. - $this->base_url .= $query_string_sep.http_build_query(array_merge($get, array($this->query_string_segment => ''))); + $base_url .= $query_string_sep.http_build_query(array_merge($get, array($this->query_string_segment => ''))); } else { @@ -440,17 +442,17 @@ class CI_Pagination { // Does the base_url have the query string in it? // If we're supposed to save it, remove it so we can append it later. - if ($this->reuse_query_string === TRUE && ($base_query_pos = strpos($this->base_url, '?')) !== FALSE) + if ($this->reuse_query_string === TRUE && ($base_query_pos = strpos($base_url, '?')) !== FALSE) { - $this->base_url = substr($this->base_url, 0, $base_query_pos); + $base_url = substr($base_url, 0, $base_query_pos); } - if ($this->first_url === '') + if ($first_url === '') { - $this->first_url = $this->base_url.$query_string; + $first_url = $base_url.$query_string; } - $this->base_url = rtrim($this->base_url, '/').'/'; + $base_url = rtrim($base_url, '/').'/'; } // Determine the current page number. @@ -526,8 +528,8 @@ class CI_Pagination { // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); - $output .= $this->first_tag_open.'_attr_rel('start').'>' - .$this->first_link.''.$this->first_tag_close; + $output .= $this->first_tag_open.'_attr_rel('start').'>' + .$first_link.''.$this->first_tag_close; } // Render the "Previous" link. @@ -540,13 +542,13 @@ class CI_Pagination { if ($i === $base_page) { // First page - $output .= $this->prev_tag_open.'_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } else { $append = $this->prefix.$i.$this->suffix; - $output .= $this->prev_tag_open.'_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } @@ -572,13 +574,13 @@ class CI_Pagination { elseif ($i === $base_page) { // First page - $output .= $this->num_tag_open.'_attr_rel('start').'>' + $output .= $this->num_tag_open.'_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } else { $append = $this->prefix.$i.$this->suffix; - $output .= $this->num_tag_open.'_attr_rel('start').'>' + $output .= $this->num_tag_open.'_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } } @@ -592,7 +594,7 @@ class CI_Pagination { $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); - $output .= $this->next_tag_open.'next_tag_open.'_attr_rel('next').'>'.$this->next_link.''.$this->next_tag_close; } @@ -603,7 +605,7 @@ class CI_Pagination { $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); - $output .= $this->last_tag_open.'' + $output .= $this->last_tag_open.'' .$this->last_link.''.$this->last_tag_close; } -- cgit v1.2.3-24-g4f1b From 526ded927a607b4dfab0ec00f1d52efa3df0d887 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Feb 2014 16:29:52 +0200 Subject: Fix #2878 --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 06cc0c378..f2d38a852 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -305,7 +305,7 @@ class CI_Pagination { public function __construct($params = array()) { $CI =& get_instance(); - $CI->load->language('paginaton'); + $CI->load->language('pagination'); foreach (array('first_link', 'next_link', 'prev_link', 'last_link') as $key) { if (($val = $CI->lang->line('pagination_'.$key)) !== FALSE) -- cgit v1.2.3-24-g4f1b From e9c8c8988da2e6903b22e5444a2c9ddbe30a39ec Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 17 Feb 2014 17:29:23 +0200 Subject: Fix #2884 --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index f2d38a852..99552ec0d 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -344,7 +344,7 @@ class CI_Pagination { foreach ($params as $key => $val) { - if (property_exists($this, $this->$key)) + if (property_exists($this, $key)) { $this->$key = $val; } -- cgit v1.2.3-24-g4f1b From ffe8aded4d2210759fce3427ed04893e6c655006 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 17 Feb 2014 18:51:48 +0200 Subject: Micro-optimizations --- system/libraries/Pagination.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 99552ec0d..da2fe7400 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -294,6 +294,13 @@ class CI_Pagination { */ protected $data_page_attr = 'data-ci-pagination-page'; + /** + * CI Singleton + * + * @var object + */ + protected $CI; + // -------------------------------------------------------------------- /** @@ -304,11 +311,11 @@ class CI_Pagination { */ public function __construct($params = array()) { - $CI =& get_instance(); - $CI->load->language('pagination'); + $this->CI =& get_instance(); + $this->CI->load->language('pagination'); foreach (array('first_link', 'next_link', 'prev_link', 'last_link') as $key) { - if (($val = $CI->lang->line('pagination_'.$key)) !== FALSE) + if (($val = $this->CI->lang->line('pagination_'.$key)) !== FALSE) { $this->$key = $val; } @@ -350,6 +357,11 @@ class CI_Pagination { } } + if ($this->CI->config->item('enable_query_strings') === TRUE) + { + $this->page_query_string = TRUE; + } + return $this; } @@ -386,13 +398,11 @@ class CI_Pagination { show_error('Your number of links must be a positive number.'); } - $CI =& get_instance(); - // Keep any existing query string items. // Note: Has nothing to do with any other query string option. if ($this->reuse_query_string === TRUE) { - $get = $CI->input->get(); + $get = $this->CI->input->get(); // Unset the controll, method, old-school routing options unset($get['c'], $get['m'], $get[$this->query_string_segment]); @@ -411,7 +421,7 @@ class CI_Pagination { $query_string_sep = (strpos($base_url, '?') === FALSE) ? '?' : '&'; // Are we using query strings? - if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) + if ($this->page_query_string === TRUE) { // If a custom first_url hasn't been specified, we'll create one from // the base_url, but without the page item. @@ -459,19 +469,19 @@ class CI_Pagination { $base_page = ($this->use_page_numbers) ? 1 : 0; // Are we using query strings? - if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) + if ($this->page_query_string === TRUE) { - $this->cur_page = $CI->input->get($this->query_string_segment); + $this->cur_page = $this->CI->input->get($this->query_string_segment); } else { // Default to the last segment number if one hasn't been defined. if ($this->uri_segment === 0) { - $this->uri_segment = count($CI->uri->segment_array()); + $this->uri_segment = count($this->CI->uri->segment_array()); } - $this->cur_page = $CI->uri->segment($this->uri_segment); + $this->cur_page = $this->CI->uri->segment($this->uri_segment); // Remove any specified prefix/suffix from the segment. if ($this->prefix !== '' OR $this->suffix !== '') @@ -629,8 +639,8 @@ class CI_Pagination { { isset($attributes['rel']) OR $attributes['rel'] = TRUE; $this->_link_types = ($attributes['rel']) - ? array('start' => 'start', 'prev' => 'prev', 'next' => 'next') - : array(); + ? array('start' => 'start', 'prev' => 'prev', 'next' => 'next') + : array(); unset($attributes['rel']); $this->_attributes = ''; -- cgit v1.2.3-24-g4f1b From 290f58743179c81c099ca02191910374db89846f Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Tue, 18 Feb 2014 23:10:38 +0200 Subject: Fixed variable scope. --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index da2fe7400..5b9bfcb5d 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -539,7 +539,7 @@ class CI_Pagination { $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); $output .= $this->first_tag_open.'_attr_rel('start').'>' - .$first_link.''.$this->first_tag_close; + .$this->first_link.''.$this->first_tag_close; } // Render the "Previous" link. -- cgit v1.2.3-24-g4f1b From a01924d2cc2d63d2bddbee85a18b423b88a9b19e Mon Sep 17 00:00:00 2001 From: Takayuki Sakai Date: Fri, 13 Jun 2014 02:01:52 +0900 Subject: Make num_links=0 in pagination library possible to configure --- system/libraries/Pagination.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 5b9bfcb5d..d079d835d 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -393,9 +393,9 @@ class CI_Pagination { // Check the user defined number of links. $this->num_links = (int) $this->num_links; - if ($this->num_links < 1) + if ($this->num_links < 0) { - show_error('Your number of links must be a positive number.'); + show_error('Your number of links must be a non-negative number.'); } // Keep any existing query string items. @@ -535,11 +535,14 @@ class CI_Pagination { // Render the "First" link. if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { - // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); + if (($this->num_links === 0 && $this->cur_page < 3) !== true) + { + // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); - $output .= $this->first_tag_open.'_attr_rel('start').'>' + $output .= $this->first_tag_open.'_attr_rel('start').'>' .$this->first_link.''.$this->first_tag_close; + } } // Render the "Previous" link. @@ -611,12 +614,15 @@ class CI_Pagination { // Render the "Last" link if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links) < $num_pages) { - $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; + if (($this->num_links === 0 && ($this->cur_page + 1) >= $num_pages) !== true) + { + $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); - $output .= $this->last_tag_open.'' - .$this->last_link.''.$this->last_tag_close; + $output .= $this->last_tag_open.'' + .$this->last_link.''.$this->last_tag_close; + } } // Kill double slashes. Note: Sometimes we can end up with a double slash -- cgit v1.2.3-24-g4f1b From 1240b6a04ee4e6a200cc882481f09fce6a7eb4fc Mon Sep 17 00:00:00 2001 From: Takayuki Sakai Date: Fri, 13 Jun 2014 18:12:02 +0900 Subject: Revert "Make num_links=0 in pagination library possible to configure" This reverts commit a01924d2cc2d63d2bddbee85a18b423b88a9b19e. --- system/libraries/Pagination.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d079d835d..5b9bfcb5d 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -393,9 +393,9 @@ class CI_Pagination { // Check the user defined number of links. $this->num_links = (int) $this->num_links; - if ($this->num_links < 0) + if ($this->num_links < 1) { - show_error('Your number of links must be a non-negative number.'); + show_error('Your number of links must be a positive number.'); } // Keep any existing query string items. @@ -535,14 +535,11 @@ class CI_Pagination { // Render the "First" link. if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { - if (($this->num_links === 0 && $this->cur_page < 3) !== true) - { - // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); + // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); - $output .= $this->first_tag_open.'_attr_rel('start').'>' + $output .= $this->first_tag_open.'_attr_rel('start').'>' .$this->first_link.''.$this->first_tag_close; - } } // Render the "Previous" link. @@ -614,15 +611,12 @@ class CI_Pagination { // Render the "Last" link if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links) < $num_pages) { - if (($this->num_links === 0 && ($this->cur_page + 1) >= $num_pages) !== true) - { - $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; + $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); - $output .= $this->last_tag_open.'' - .$this->last_link.''.$this->last_tag_close; - } + $output .= $this->last_tag_open.'' + .$this->last_link.''.$this->last_tag_close; } // Kill double slashes. Note: Sometimes we can end up with a double slash -- cgit v1.2.3-24-g4f1b From 8bc5903ce7d4694f50c2cd02036a788c88c134f2 Mon Sep 17 00:00:00 2001 From: Takayuki Sakai Date: Fri, 13 Jun 2014 18:38:05 +0900 Subject: Make 'num_links=0' configuration available in Pagination library Changed conditions when making 'first' and 'last' links --- system/libraries/Pagination.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 5b9bfcb5d..3c8baac36 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -393,9 +393,9 @@ class CI_Pagination { // Check the user defined number of links. $this->num_links = (int) $this->num_links; - if ($this->num_links < 1) + if ($this->num_links < 0) { - show_error('Your number of links must be a positive number.'); + show_error('Your number of links must be a non-negative number.'); } // Keep any existing query string items. @@ -533,7 +533,7 @@ class CI_Pagination { $output = ''; // Render the "First" link. - if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) + if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1 + ! $this->num_links)) { // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); @@ -609,7 +609,7 @@ class CI_Pagination { } // Render the "Last" link - if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links) < $num_pages) + if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links + ! $this->num_links) < $num_pages) { $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; -- cgit v1.2.3-24-g4f1b From 8382157530c57be540492aff686a060b5bff03d8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 1 Aug 2014 12:08:56 +0300 Subject: Make CI_Pagination properties per_page, cur_page public Useful if you want to make calculations based on them. --- system/libraries/Pagination.php | 76 ++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 3c8baac36..b7df06292 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -51,45 +51,45 @@ class CI_Pagination { * * @var string */ - protected $prefix = ''; + protected $prefix = ''; /** * Suffix * * @var string */ - protected $suffix = ''; + protected $suffix = ''; /** * Total number of items * * @var int */ - protected $total_rows = 0; + protected $total_rows = 0; /** - * Items per page + * Number of links to show + * + * Relates to "digit" type links shown before/after + * the currently viewed page. * * @var int */ - protected $per_page = 10; + protected $num_links = 2; /** - * Number of links to show - * - * Relates to "digit" type links shown before/after - * the currently viewed page. + * Items per page * * @var int */ - protected $num_links = 2; + public $per_page = 10; /** * Current page * * @var int */ - protected $cur_page = 0; + public $cur_page = 0; /** * Use page numbers flag @@ -98,84 +98,84 @@ class CI_Pagination { * * @var bool */ - protected $use_page_numbers = FALSE; + protected $use_page_numbers = FALSE; /** * First link * * @var string */ - protected $first_link = '‹ First'; + protected $first_link = '‹ First'; /** * Next link * * @var string */ - protected $next_link = '>'; + protected $next_link = '>'; /** * Previous link * * @var string */ - protected $prev_link = '<'; + protected $prev_link = '<'; /** * Last link * * @var string */ - protected $last_link = 'Last ›'; + protected $last_link = 'Last ›'; /** * URI Segment * * @var int */ - protected $uri_segment = 0; + protected $uri_segment = 0; /** * Full tag open * * @var string */ - protected $full_tag_open = ''; + protected $full_tag_open = ''; /** * Full tag close * * @var string */ - protected $full_tag_close = ''; + protected $full_tag_close = ''; /** * First tag open * * @var string */ - protected $first_tag_open = ''; + protected $first_tag_open = ''; /** * First tag close * * @var string */ - protected $first_tag_close = ''; + protected $first_tag_close = ''; /** * Last tag open * * @var string */ - protected $last_tag_open = ''; + protected $last_tag_open = ''; /** * Last tag close * * @var string */ - protected $last_tag_close = ''; + protected $last_tag_close = ''; /** * First URL @@ -184,70 +184,70 @@ class CI_Pagination { * * @var string */ - protected $first_url = ''; + protected $first_url = ''; /** * Current tag open * * @var string */ - protected $cur_tag_open = ''; + protected $cur_tag_open = ''; /** * Current tag close * * @var string */ - protected $cur_tag_close = ''; + protected $cur_tag_close = ''; /** * Next tag open * * @var string */ - protected $next_tag_open = ''; + protected $next_tag_open = ''; /** * Next tag close * * @var string */ - protected $next_tag_close = ''; + protected $next_tag_close = ''; /** * Previous tag open * * @var string */ - protected $prev_tag_open = ''; + protected $prev_tag_open = ''; /** * Previous tag close * * @var string */ - protected $prev_tag_close = ''; + protected $prev_tag_close = ''; /** * Number tag open * * @var string */ - protected $num_tag_open = ''; + protected $num_tag_open = ''; /** * Number tag close * * @var string */ - protected $num_tag_close = ''; + protected $num_tag_close = ''; /** * Page query string flag * * @var bool */ - protected $page_query_string = FALSE; + protected $page_query_string = FALSE; /** * Query string segment @@ -261,14 +261,14 @@ class CI_Pagination { * * @var bool */ - protected $display_pages = TRUE; + protected $display_pages = TRUE; /** * Attributes * * @var string */ - protected $_attributes = ''; + protected $_attributes = ''; /** * Link types @@ -278,21 +278,21 @@ class CI_Pagination { * @see CI_Pagination::_attr_rel() * @var array */ - protected $_link_types = array(); + protected $_link_types = array(); /** * Reuse query string flag * * @var bool */ - protected $reuse_query_string = FALSE; + protected $reuse_query_string = FALSE; /** * Data page attribute * * @var string */ - protected $data_page_attr = 'data-ci-pagination-page'; + protected $data_page_attr = 'data-ci-pagination-page'; /** * CI Singleton -- cgit v1.2.3-24-g4f1b From bdb96ca1b1dbfc1791172fd169d7751cbc4d7d55 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Oct 2014 00:13:31 +0200 Subject: [ci skip] Switch to MIT license; close #3293 --- system/libraries/Pagination.php | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index b7df06292..0fd7fd9aa 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -4,24 +4,35 @@ * * An open source application development framework for PHP 5.2.4 or newer * - * NOTICE OF LICENSE + * This content is released under the MIT License (MIT) * - * Licensed under the Open Software License version 3.0 + * Copyright (c) 2014, British Columbia Institute of Technology * - * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is - * also available through the world wide web at this URL: - * http://opensource.org/licenses/OSL-3.0 - * If you did not receive a copy of the license and are unable to obtain it - * through the world wide web, please send an email to - * licensing@ellislab.com so we can send you a copy immediately. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * @package CodeIgniter - * @author EllisLab Dev Team + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @package CodeIgniter + * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * @link http://codeigniter.com - * @since Version 1.0 + * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @license http://opensource.org/licenses/MIT MIT License + * @link http://codeigniter.com + * @since Version 1.0.0 * @filesource */ defined('BASEPATH') OR exit('No direct script access allowed'); -- cgit v1.2.3-24-g4f1b From fe9309d22c1b088f5363954d6dac013c8c955894 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Jan 2015 17:48:58 +0200 Subject: Bulk (mostly documentation) update - Remove PHP version from license notices - Bump year number in copyright notices - Recommend PHP 5.4 or newer to be used - Tell Travis-CI to test on PHP 5.3.0 instead of the latest 5.3 version Related: #3450 --- system/libraries/Pagination.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 0fd7fd9aa..1081fbec7 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -2,11 +2,11 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.2.4 or newer + * An open source application development framework for PHP * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014, British Columbia Institute of Technology + * Copyright (c) 2014 - 2015, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From 90726b8c769ea75aec34814ddfa91655d488e6c3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Jan 2015 12:39:22 +0200 Subject: [ci skip] Change some log messages' level 'Class Loaded' type of messages flood log files when log_threshold is set to 2 (debug). They're now logged as 'info' level. This is manually applying PR #1528, which was created to do the same thing, but became outdated. --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 1081fbec7..6c8366435 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -333,7 +333,7 @@ class CI_Pagination { } $this->initialize($params); - log_message('debug', 'Pagination Class Initialized'); + log_message('info', 'Pagination Class Initialized'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 0da50123c196ca0f342cac44b76f889a6f8a96b9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Jan 2015 13:30:05 +0200 Subject: Pagination: Add 'use_global_url_suffix' setting Resolves issue #1887 --- system/libraries/Pagination.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 6c8366435..aa54ec4c1 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -298,6 +298,13 @@ class CI_Pagination { */ protected $reuse_query_string = FALSE; + /** + * Use global URL suffix flag + * + * @var bool + */ + protected $use_global_url_suffix = FALSE; + /** * Data page attribute * @@ -373,6 +380,11 @@ class CI_Pagination { $this->page_query_string = TRUE; } + if ($this->use_global_url_suffix === TRUE) + { + $this->suffix = $this->CI->config->item('url_suffix'); + } + return $this; } -- cgit v1.2.3-24-g4f1b From 4cbe463b4c442e0e2dae2f43565e77f7ac5ecb86 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Wed, 21 Jan 2015 22:56:22 +0100 Subject: Remove closing blocks at end of PHP files --- system/libraries/Pagination.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index aa54ec4c1..d63f61df6 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -694,6 +694,3 @@ class CI_Pagination { } } - -/* End of file Pagination.php */ -/* Location: ./system/libraries/Pagination.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 361750a8eb48c91d4a741b81bcb5572388742fed Mon Sep 17 00:00:00 2001 From: Miguel González Date: Mon, 30 Mar 2015 05:00:21 +0200 Subject: Fixes pagination with relative URL When base_url is a URL based on protocol, like "//www.google.com" the double slash regex kills the first "//". --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d63f61df6..76437f4a5 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -644,7 +644,7 @@ class CI_Pagination { // Kill double slashes. Note: Sometimes we can end up with a double slash // in the penultimate link so we'll kill all double slashes. - $output = preg_replace('#([^:])//+#', '\\1/', $output); + $output = preg_replace('#([^:"])//+#', '\\1/', $output); // Add the wrapper HTML if exists return $this->full_tag_open.$output.$this->full_tag_close; -- cgit v1.2.3-24-g4f1b From d91ed26ebb47bebb86a2021d7f2b57488be72abb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 26 Jul 2015 23:12:16 +0300 Subject: Fix #4000 --- system/libraries/Pagination.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 76437f4a5..5b3aa01f4 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -353,7 +353,8 @@ class CI_Pagination { */ public function initialize(array $params = array()) { - if (isset($params['attributes']) && is_array($params['attributes'])) + isset($params['attributes']) OR $params['attributes'] = array(); + if (is_array($params['attributes'])) { $this->_parse_attributes($params['attributes']); unset($params['attributes']); -- cgit v1.2.3-24-g4f1b From 135b64a30d9746b8d55046ee4c8fded00a1e211a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 16 Sep 2015 14:20:50 +0300 Subject: Fix #4116 Close #4117 --- system/libraries/Pagination.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 5b3aa01f4..4d18998b9 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -571,7 +571,7 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, ($this->cur_page - 1)); if ($i === $base_page) { @@ -592,11 +592,11 @@ class CI_Pagination { if ($this->display_pages !== FALSE) { // Write the digit links - for ($loop = $start -1; $loop <= $end; $loop++) + for ($loop = $start - 1; $loop <= $end; $loop++) { $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page; - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, $loop); if ($i >= $base_page) { @@ -614,7 +614,7 @@ class CI_Pagination { else { $append = $this->prefix.$i.$this->suffix; - $output .= $this->num_tag_open.'_attr_rel('start').'>' + $output .= $this->num_tag_open.'' .$loop.''.$this->num_tag_close; } } @@ -626,7 +626,7 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, $this->cur_page + 1); $output .= $this->next_tag_open.'_attr_rel('next').'>'.$this->next_link.''.$this->next_tag_close; @@ -637,7 +637,7 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, $num_pages); $output .= $this->last_tag_open.'' .$this->last_link.''.$this->last_tag_close; -- cgit v1.2.3-24-g4f1b From 125ef4751080a2118cb203357d77687699e3eb25 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:33:00 +0200 Subject: [ci skip] Bump year to 2016 --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 4d18998b9..3a5e34792 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2015, British Columbia Institute of Technology + * Copyright (c) 2014 - 2016, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From bd202c91b0e9cf0a8c93bcaa71df9574f5909346 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:50:18 +0200 Subject: [ci skip] Update codeigniter.com links to https --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 3a5e34792..9831730e4 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -31,7 +31,7 @@ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License - * @link http://codeigniter.com + * @link https://codeigniter.com * @since Version 1.0.0 * @filesource */ @@ -44,7 +44,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @subpackage Libraries * @category Pagination * @author EllisLab Dev Team - * @link http://codeigniter.com/user_guide/libraries/pagination.html + * @link https://codeigniter.com/user_guide/libraries/pagination.html */ class CI_Pagination { -- cgit v1.2.3-24-g4f1b From 1924e879b165fb119847a49a7a5eab2f28295fa2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:55:34 +0200 Subject: [ci skip] Update ellislab.com links to https too --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 9831730e4..cef98ebf4 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -28,7 +28,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com -- cgit v1.2.3-24-g4f1b From 4e87bd3622b3b9edcb90d7d4792f4374daf46446 Mon Sep 17 00:00:00 2001 From: jekkos Date: Mon, 18 Jan 2016 21:14:06 +0100 Subject: Respect $config['cur_page'] variable for pagination After upgrading to CI3 I noticed that developers are able to determine the current page counter for pagination based on * Explicit query string parameters * URI segment configuration In earlier versions a developer could still set the current page counter in the pagination lib directly which is useful if you want to use pagination with HTTP POST instead of GET. This could be done by passing $config['cur_page'] = '10'; to the pagination function for link generation. Currently this code has changed and will always try to check whether the uri segment is a valid number or not, even if the cur_page variable was passed in the associative array, and fallback to zero if it fails to validate that result. This can be easily resolved by checking whether the counter was already set with a valid number from the $config array before trying to resolve it from the uri segment. This fix give a developer more flexibility and stop CI from overwriting the externally set value with an incorrect one. Signed-off-by: jekkos --- system/libraries/Pagination.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cef98ebf4..9ac9661ad 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -497,7 +497,7 @@ class CI_Pagination { { $this->cur_page = $this->CI->input->get($this->query_string_segment); } - else + elseif (empty($this->cur_page)) { // Default to the last segment number if one hasn't been defined. if ($this->uri_segment === 0) @@ -512,6 +512,10 @@ class CI_Pagination { { $this->cur_page = str_replace(array($this->prefix, $this->suffix), '', $this->cur_page); } + } + else + { + $this->cur_page = (string) $this->cur_page; } // If something isn't quite right, back to the default base page. -- cgit v1.2.3-24-g4f1b From ca26561a987bf0ec6e2736ea4c2eab29c663b94b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 20 Jan 2016 19:36:39 +0200 Subject: [ci skip] Remove a trailing space from latest PR merge --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 9ac9661ad..44f848fe0 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -512,7 +512,7 @@ class CI_Pagination { { $this->cur_page = str_replace(array($this->prefix, $this->suffix), '', $this->cur_page); } - } + } else { $this->cur_page = (string) $this->cur_page; -- cgit v1.2.3-24-g4f1b From da60e9bc66ec90970fbd2dfd08b0a6e66b9f5f5f Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Sat, 31 Dec 2016 08:46:18 -0800 Subject: Update copyright data to 2017 --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 44f848fe0..1df5f9cd5 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2016, British Columbia Institute of Technology + * Copyright (c) 2014 - 2017, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From 71d8f72ffc48a7f46747b3b6b1a554533cc1cbc5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 17 Jan 2017 12:01:00 +0200 Subject: [ci skip] Merge pull request #4986 from ka7/feature/spelling Spelling fixes in comment blocks and docs --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 1df5f9cd5..f26f8a4ed 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -428,7 +428,7 @@ class CI_Pagination { { $get = $this->CI->input->get(); - // Unset the controll, method, old-school routing options + // Unset the control, method, old-school routing options unset($get['c'], $get['m'], $get[$this->query_string_segment]); } else -- cgit v1.2.3-24-g4f1b