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.php112
1 files changed, 71 insertions, 41 deletions
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index a91159c98..cdec736ff 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -36,38 +36,39 @@
*/
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 = '&nbsp;<strong>';
- protected $cur_tag_close = '</strong>';
- protected $next_tag_open = '&nbsp;';
- protected $next_tag_close = '&nbsp;';
- protected $prev_tag_open = '&nbsp;';
- protected $prev_tag_close = '';
- protected $num_tag_open = '&nbsp;';
- 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 = '&lsaquo; First';
+ public $next_link = '&gt;';
+ public $prev_link = '&lt;';
+ public $last_link = 'Last &rsaquo;';
+ public $uri_segment = 3;
+ public $full_tag_open = '';
+ public $full_tag_close = '';
+ public $first_tag_open = '';
+ public $first_tag_close = '&nbsp;';
+ public $last_tag_open = '&nbsp;';
+ public $last_tag_close = '';
+ public $first_url = ''; // Alternative URL for the First Page.
+ public $cur_tag_open = '&nbsp;<strong>';
+ public $cur_tag_close = '</strong>';
+ public $next_tag_open = '&nbsp;';
+ public $next_tag_close = '&nbsp;';
+ public $prev_tag_open = '&nbsp;';
+ public $prev_tag_close = '';
+ public $num_tag_open = '&nbsp;';
+ public $num_tag_close = '';
+ public $page_query_string = FALSE;
+ public $query_string_segment = 'per_page';
+ public $display_pages = TRUE;
+ public $anchor_class = '';
+ public $attr_rel = TRUE;
/**
* Constructor
@@ -97,7 +98,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 +146,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);
}
@@ -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.'<a '.$this->anchor_class.'href="'.$first_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
+ $output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.'"'.$this->_attr_rel('start').'>'
+ .$this->first_link.'</a>'.$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.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
+ $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'"'.$this->_attr_rel('prev').'>'
+ .$this->prev_link.'</a>'.$this->prev_tag_close;
}
else
{
$i = ($i === $base_page) ? '' : $this->prefix.$i.$this->suffix;
- $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
+ $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$i.'"'.$this->_attr_rel('prev').'>'
+ .$this->prev_link.'</a>'.$this->prev_tag_close;
}
}
@@ -252,13 +256,15 @@ class CI_Pagination {
if ($n === '' && $this->first_url !== '')
{
- $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close;
+ $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'"'.$this->_attr_rel('start').'>'
+ .$loop.'</a>'.$this->num_tag_close;
}
else
{
$n = ($n === '') ? '' : $this->prefix.$n.$this->suffix;
- $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;
+ $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$n.'"'.$this->_attr_rel().'>'
+ .$loop.'</a>'.$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.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.'</a>'.$this->next_tag_close;
+ $output .= $this->next_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$this->_attr_rel('next').'>'
+ .$this->next_link.'</a>'.$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.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.'</a>'.$this->last_tag_close;
+ $output .= $this->last_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$this->_attr_rel().'>'
+ .$this->last_link.'</a>'.$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 */