summaryrefslogtreecommitdiffstats
path: root/system/libraries/Pagination.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Pagination.php')
-rw-r--r--system/libraries/Pagination.php57
1 files changed, 39 insertions, 18 deletions
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 75745dd48..e1e729bb0 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -52,24 +52,25 @@ 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 = '&nbsp;<strong>';
+ protected $cur_tag_open = '<strong>';
protected $cur_tag_close = '</strong>';
- protected $next_tag_open = '&nbsp;';
- protected $next_tag_close = '&nbsp;';
- protected $prev_tag_open = '&nbsp;';
+ protected $next_tag_open = '';
+ protected $next_tag_close = '';
+ protected $prev_tag_open = '';
protected $prev_tag_close = '';
- protected $num_tag_open = '&nbsp;';
+ 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();
protected $reuse_query_string = FALSE;
+ protected $data_page_attr = 'data-ci-pagination-page';
/**
* Constructor
@@ -202,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
@@ -214,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).'&amp;'.$this->query_string_segment.'=';
+ $segment = (strpos($this->base_url, '?')) ? '&amp;' : '?';
+ $this->base_url = rtrim($this->base_url).$segment.$this->query_string_segment.'=';
}
else
{
@@ -230,10 +232,12 @@ 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]);
+ if ( ! $get) $get = array();
+
// Put everything else onto the end
$query_string = (strpos($this->base_url, '&amp;') !== FALSE ? '&amp;' : '?') . http_build_query($get, '', '&amp;');
@@ -245,7 +249,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.'<a href="'.$first_url.'"'.$this->_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.'<a href="'.$first_url.'"'.$attributes.$this->_attr_rel('start').'>'
.$this->first_link.'</a>'.$this->first_tag_close;
}
@@ -254,15 +262,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.'<a href="'.$this->first_url.$query_string.'"'.$this->_attributes.$this->_attr_rel('prev').'>'
+ $output .= $this->prev_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$attributes.$this->_attr_rel('prev').'>'
.$this->prev_link.'</a>'.$this->prev_tag_close;
}
else
{
$append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix;
- $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$append.'"'.$this->_attributes.$this->_attr_rel('prev').'>'
+ $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$append.'"'.$attributes.$this->_attr_rel('prev').'>'
.$this->prev_link.'</a>'.$this->prev_tag_close;
}
@@ -275,6 +286,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 +301,13 @@ class CI_Pagination {
$n = ($i === $base_page) ? '' : $i;
if ($n === '' && ! empty($this->first_url))
{
- $output .= $this->num_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$this->_attributes.$this->_attr_rel('start').'>'
+ $output .= $this->num_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$attributes.$this->_attr_rel('start').'>'
.$loop.'</a>'.$this->num_tag_close;
}
else
{
$append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix;
- $output .= $this->num_tag_open.'<a href="'.$this->base_url.$append.'"'.$this->_attributes.$this->_attr_rel('start').'>'
+ $output .= $this->num_tag_open.'<a href="'.$this->base_url.$append.'"'.$attributes.$this->_attr_rel('start').'>'
.$loop.'</a>'.$this->num_tag_close;
}
}
@@ -305,7 +320,10 @@ class CI_Pagination {
{
$i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page;
- $output .= $this->next_tag_open.'<a href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$this->_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.'<a href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$attributes
.$this->_attr_rel('next').'>'.$this->next_link.'</a>'.$this->next_tag_close;
}
@@ -314,7 +332,10 @@ class CI_Pagination {
{
$i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page;
- $output .= $this->last_tag_open.'<a href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$this->_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.'<a href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$attributes.'>'
.$this->last_link.'</a>'.$this->last_tag_close;
}