Source code for file /joomla/html/pagination.php
Documentation is available at pagination.php
* @version $Id: pagination.php 6674 2007-02-19 05:52:03Z Jinx $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* Pagination Class. Provides a common interface for content pagination for the
* @package Joomla.Framework
* The record number to start dislpaying from
* Number of rows to display per page
* Base URL for pagination output
function __construct($total, $limitstart, $limit, $link =
null)
$this->total = (int)
$total;
// Set the total pages and current page values
// Set the pagination iteration loop values
$this->set( 'pages.start', (floor(($this->get('pages.current') -
1) /
$displayedPages)) *
$displayedPages +
1);
if ($this->get('pages.start') +
$displayedPages -
1 <
$this->get('pages.total')) {
$this->set( 'pages.stop', $this->get('pages.start') +
$displayedPages -
1);
$this->set( 'pages.stop', $this->get('pages.total'));
// Set the base link for the object
if ($config->getValue('config.sef') &&
!$mainframe->isAdmin())
$this->_link =
'index.php?';
$this->_link .=
'&option='.
$get['option'];
foreach ($get as $k =>
$v)
if ($k !=
'option' &&
$k !=
'Itemid') {
$this->_link .=
'&'.
$k.
'='.
$v;
$this->_link .=
'&Itemid='.
$get['Itemid'];
$this->_link .=
'index.php?';
// Strip out limit and limitstart variables from base link
// If we are viewing all records set the view all flag to true
* Return the rationalised offset for a row with a given index.
* @param int $index The row index
* @return int Rationalised offset for a row with a given index
* Return the pagination data object, only creating it if it doesn't already exist
* @return object Pagination data object
* Create and return the pagination pages counter string, ie. Page 2 of 4
* @return string Pagination pages counter string
if ($this->get('pages.total') >
0) {
$html .=
JText::_('Page').
" ".
$this->get('pages.current').
" ".
JText::_('of').
" ".
$this->get('pages.total');
* Create and return the pagination result set counter string, ie. Results 1-10 of 42
* @return string Pagination result set counter string
// If the limit is reached before the end of the list
$toResult =
$this->total;
// If there are results found
$html .=
"\n".
JText::_('No records found');
* Create and return the pagination page list string, ie. Previous, Next, 1 2 3 ... x
* @return string Pagination page list string
// Build the page navigation list
$chromePath =
JPATH_BASE.
'/templates/'.
$mainframe->getTemplate().
'/html/pagination.php';
require_once ($chromePath);
if ($data->all->base !==
null) {
$list['all']['active'] =
true;
$list['all']['data'] =
($itemOverride) ?
pagination_item_active($data->all) :
$this->_item_active($data->all);
$list['all']['active'] =
false;
$list['all']['data'] =
($itemOverride) ?
pagination_item_inactive($data->all) :
$this->_item_inactive($data->all);
if ($data->start->base !==
null) {
$list['start']['active'] =
true;
$list['start']['data'] =
($itemOverride) ?
pagination_item_active($data->start) :
$this->_item_active($data->start);
$list['start']['active'] =
false;
$list['start']['data'] =
($itemOverride) ?
pagination_item_inactive($data->start) :
$this->_item_inactive($data->start);
if ($data->previous->base !==
null) {
$list['previous']['active'] =
true;
$list['previous']['data'] =
($itemOverride) ?
pagination_item_active($data->previous) :
$this->_item_active($data->previous);
$list['previous']['active'] =
false;
$list['previous']['data'] =
($itemOverride) ?
pagination_item_inactive($data->previous) :
$this->_item_inactive($data->previous);
$list['pages'] =
array(); //make sure it exists
foreach ($data->pages as $i =>
$page)
if ($page->base !==
null) {
$list['pages'][$i]['active'] =
true;
$list['pages'][$i]['data'] =
($itemOverride) ?
pagination_item_active($page) :
$this->_item_active($page);
$list['pages'][$i]['active'] =
false;
$list['pages'][$i]['data'] =
($itemOverride) ?
pagination_item_inactive($page) :
$this->_item_inactive($page);
if ($data->next->base !==
null) {
$list['next']['active'] =
true;
$list['next']['data'] =
($itemOverride) ?
pagination_item_active($data->next) :
$this->_item_active($data->next);
$list['next']['active'] =
false;
$list['next']['data'] =
($itemOverride) ?
pagination_item_inactive($data->next) :
$this->_item_inactive($data->next);
if ($data->end->base !==
null) {
$list['end']['active'] =
true;
$list['end']['data'] =
($itemOverride) ?
pagination_item_active($data->end) :
$this->_item_active($data->end);
$list['end']['active'] =
false;
$list['end']['data'] =
($itemOverride) ?
pagination_item_inactive($data->end) :
$this->_item_inactive($data->end);
return ($listOverride) ?
pagination_list_render($list) :
$this->_list_render($list);
* Return the pagination footer
* @return string Pagination footer
$list['limit'] =
$this->limit;
$list['total'] =
$this->total;
$chromePath =
JPATH_BASE.
'/templates/'.
$mainframe->getTemplate().
'/html/pagination.php';
require_once ($chromePath);
return ($listOverride) ?
pagination_list_footer($list) :
$this->_list_footer($list);
* Creates a dropdown box for selecting how many records to show per page
* @return string The html for the limit # input box
for ($i =
5; $i <=
30; $i +=
5) {
if ($mainframe->isAdmin()) {
$html =
JHTMLSelect::genericList($limits, 'limit', 'class="inputbox" size="1" onchange="submitform();"', 'value', 'text', $this->limit);
$html =
JHTMLSelect::genericList($limits, 'limit', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', $this->limit);
* Return the icon to move an item UP
* @param int $i The row index
* @param boolean $condition True to show the icon
* @param string $task The task to fire
* @param string $alt The image alternate text string
* @return string Either the icon to move an item up or a space
function orderUpIcon($i, $condition =
true, $task =
'orderup', $alt =
'Move Up', $enabled =
true)
if (($i >
0 ||
($i +
$this->limitstart >
0)) &&
$condition)
$html =
'<a href="#reorder" onclick="return listItemTask(\'cb'.
$i.
'\',\''.
$task.
'\')" title="'.
$alt.
'">';
$html .=
' <img src="images/uparrow.png" width="16" height="16" border="0" alt="'.
$alt.
'" />';
$html =
'<img src="images/uparrow0.png" width="16" height="16" border="0" alt="'.
$alt.
'" />';
* Return the icon to move an item DOWN
* @param int $i The row index
* @param int $n The number of items in the list
* @param boolean $condition True to show the icon
* @param string $task The task to fire
* @param string $alt The image alternate text string
* @return string Either the icon to move an item down or a space
function orderDownIcon($i, $n, $condition =
true, $task =
'orderdown', $alt =
'Move Down', $enabled =
true)
if (($i <
$n -
1 ||
$i +
$this->limitstart <
$this->total -
1) &&
$condition)
$html =
'<a href="#reorder" onclick="return listItemTask(\'cb'.
$i.
'\',\''.
$task.
'\')" title="'.
$alt.
'">';
$html .=
' <img src="images/downarrow.png" width="16" height="16" border="0" alt="'.
$alt.
'" />';
$html =
'<img src="images/downarrow0.png" width="16" height="16" border="0" alt="'.
$alt.
'" />';
* Return the icon to move an item UP
* @param int $id The row index
* @param int $order The ordering value for the item
* @param boolean $condition [Does Not Appear To Be Used]
* @param string $task The task to fire
* @param string $alt The image alternate text string
* @return string Either the icon to move an item up or a space
function orderUpIcon2($id, $order, $condition =
true, $task =
'orderup', $alt =
'#')
// handling of default value
$output =
'<a href="javascript:void listItemTask(\'cb'.
$id.
'\',\'orderup\')" title="'.
$alt.
'">';
$output .=
'<img src="images/'.
$img.
'" width="16" height="16" border="0" alt="'.
$alt.
'" title="'.
$alt.
'" /></a>';
* Return the icon to move an item DOWN
* @param int $id The row index
* @param int $order The ordering value for the item
* @param boolean $condition [Does Not Appear To Be Used]
* @param string $task The task to fire
* @param string $alt The image alternate text string
* @return string Either the icon to move an item down or a space
function orderDownIcon2($id, $order, $condition =
true, $task =
'orderdown', $alt =
'#')
// handling of default value
$img =
'downarrow-1.png';
$output =
'<a href="javascript:void listItemTask(\'cb'.
$id.
'\',\'orderdown\')" title="'.
$alt.
'">';
$output .=
'<img src="images/'.
$img.
'" width="16" height="16" border="0" alt="'.
$alt.
'" title="'.
$alt.
'" /></a>';
$html =
"<div class=\"list-footer\">\n";
$html .=
"\n<div class=\"counter\">".
$list['pagescounter'].
"</div>";
$html .=
$list['pageslinks'];
$html .=
"\n<div class=\"limit\">".
JText::_('Display Num').
$list['limitfield'].
"</div>";
$html .=
"\n<div class=\"limit\">".
JText::_('Display Num').
$list['limitfield'].
"</div>";
$html .=
$list['pageslinks'];
$html .=
"\n<div class=\"counter\">".
$list['pagescounter'].
"</div>";
$html .=
"\n<input type=\"hidden\" name=\"limitstart\" value=\"".
$list['limitstart'].
"\" />";
// Reverse output rendering for right-to-left display
$html .=
$list['previous']['data'];
$html .=
$list['start']['data'];
foreach( $list['pages'] as $page ) {
$html .=
$list['end']['data'];
$html .=
$list['next']['data'];
$html .=
$list['start']['data'];
$html .=
$list['previous']['data'];
foreach( $list['pages'] as $page ) {
$html .=
' '.
$page['data'];
$html .=
' '.
$list['next']['data'];
$html .=
' '.
$list['end']['data'];
if ($mainframe->isAdmin()) {
return "<a title=\"".
$item->text.
"\" onclick=\"javascript: document.adminForm.limitstart.value=".
$item->base.
"; submitform();return false;\">".
$item->text.
"</a>";
return "<a title=\"".
$item->text.
"\" href=\"".
$item->link.
"\" class=\"pagenav\">".
$item->text.
"</a>";
if ($mainframe->isAdmin()) {
return "<span>".
$item->text.
"</span>";
return "<span class=\"pagenav\">".
$item->text.
"</span>";
* Create and return the pagination data object
* @return object Pagination data object
$data->all->link =
JRoute::_($base.
"&limitstart=0");
// Set the start and previous data objects
if ($this->get('pages.current') >
1)
$page =
($this->get('pages.current') -
2) *
$this->limit;
$data->start->base =
'0';
$data->start->link =
JRoute::_($link.
"&limitstart=0");
$data->previous->base =
$page;
$data->previous->link =
JRoute::_($link.
"&limitstart=".
$page);
// Set the next and end data objects
if ($this->get('pages.current') <
$this->get('pages.total'))
$page =
$this->get('pages.current') *
$this->limit;
$endPage =
($this->get('pages.total') -
1) *
$this->limit;
$data->next->base =
$page;
$data->next->link =
JRoute::_($link.
"&limitstart=".
$page);
$data->end->base =
$endPage;
$data->end->link =
JRoute::_($link.
"&limitstart=".
$endPage);
$stop =
$this->get('pages.stop');
for ($i =
$this->get('pages.start'); $i <=
$stop; $i ++
)
$offset =
($i -
1) *
$this->limit;
if ($i !=
$this->get('pages.current') ||
$this->_viewall)
$data->pages[$i]->base =
$offset;
$data->pages[$i]->link =
JRoute::_($link.
"&limitstart=".
$offset);
* Pagination object representing a particular item in the pagination lists
* @package Joomla.Framework