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