$pager_max) { // Adjust "center" if at end of query. $i = $i + ($pager_max - $pager_last); $pager_last = $pager_max; } if ($i <= 0) { // Adjust "center" if at start of query. $pager_last = $pager_last + (1 - $i); $i = 1; } // End of generation loop preparation. $li_first = theme('pager_first', (isset($tags[0]) ? $tags[0] : t('« first')), $limit, $element, $parameters); $li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹ previous')), $limit, $element, 1, $parameters); $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('next ›')), $limit, $element, 1, $parameters); $li_last = theme('pager_last', (isset($tags[4]) ? $tags[4] : t('last »')), $limit, $element, $parameters); if ($pager_total[$element] > 1) { if ($li_first) { $items[] = array( 'class' => 'pager-first', 'data' => $li_first, ); } if ($li_previous) { $items[] = array( 'class' => 'pager-previous', 'data' => $li_previous, ); } // When there is more than one page, create the pager list. if ($i != $pager_max) { if ($i > 1) { $items[] = array( 'class' => 'pager-ellipsis', 'data' => '…', ); } // Now generate the actual pager piece. for (; $i <= $pager_last && $i <= $pager_max; $i++) { if ($i < $pager_current) { $items[] = array( 'class' => 'pager-item', 'data' => theme('pager_previous', $i, $limit, $element, ($pager_current - $i), $parameters), ); } if ($i == $pager_current) { $items[] = array( 'class' => 'pager-current', 'data' => $i, ); } if ($i > $pager_current) { $items[] = array( 'class' => 'pager-item', 'data' => theme('pager_next', $i, $limit, $element, ($i - $pager_current), $parameters), ); } } if ($i < $pager_max) { $items[] = array( 'class' => 'pager-ellipsis', 'data' => '…', ); } } // End generation. if ($li_next) { $items[] = array( 'class' => 'pager-next', 'data' => $li_next, ); } if ($li_last) { $items[] = array( 'class' => 'pager-last', 'data' => $li_last, ); } return theme('item_list', $items, NULL, 'ul', array('class' => 'pager')); } } /** * @name Pager pieces * @{ * Use these pieces to construct your own custom pagers in your theme. Note that * you should NOT modify this file to customize your pager. */ /** * Format a "first page" link. * * @param $text * The name (or image) of the link. * @param $limit * The number of query results to display per page. * @param $element * An optional integer to distinguish between multiple pagers on one page. * @param $parameters * An associative array of query string parameters to append to the pager links. * @return * An HTML string that generates this piece of the query pager. * * @ingroup themeable */ function theme_pager_first($text, $limit, $element = 0, $parameters = array()) { global $pager_page_array; $output = ''; // If we are anywhere but the first page if ($pager_page_array[$element] > 0) { $output = theme('pager_link', $text, pager_load_array(0, $element, $pager_page_array), $element, $parameters); } return $output; } /** * Format a "previous page" link. * * @param $text * The name (or image) of the link. * @param $limit * The number of query results to display per page. * @param $element * An optional integer to distinguish between multiple pagers on one page. * @param $interval * The number of pages to move backward when the link is clicked. * @param $parameters * An associative array of query string parameters to append to the pager links. * @return * An HTML string that generates this piece of the query pager. * * @ingroup themeable */ function theme_pager_previous($text, $limit, $element = 0, $interval = 1, $parameters = array()) { global $pager_page_array; $output = ''; // If we are anywhere but the first page if ($pager_page_array[$element] > 0) { $page_new = pager_load_array($pager_page_array[$element] - $interval, $element, $pager_page_array); // If the previous page is the first page, mark the link as such. if ($page_new[$element] == 0) { $output = theme('pager_first', $text, $limit, $element, $parameters); } // The previous page is not the first page. else { $output = theme('pager_link', $text, $page_new, $element, $parameters); } } return $output; } /** * Format a "next page" link. * * @param $text * The name (or image) of the link. * @param $limit * The number of query results to display per page. * @param $element * An optional integer to distinguish between multiple pagers on one page. * @param $interval * The number of pages to move forward when the link is clicked. * @param $parameters * An associative array of query string parameters to append to the pager links. * @return * An HTML string that generates this piece of the query pager. * * @ingroup themeable */ function theme_pager_next($text, $limit, $element = 0, $interval = 1, $parameters = array()) { global $pager_page_array, $pager_total; $output = ''; // If we are anywhere but the last page if ($pager_page_array[$element] < ($pager_total[$element] - 1)) { $page_new = pager_load_array($pager_page_array[$element] + $interval, $element, $pager_page_array); // If the next page is the last page, mark the link as such. if ($page_new[$element] == ($pager_total[$element] - 1)) { $output = theme('pager_last', $text, $limit, $element, $parameters); } // The next page is not the last page. else { $output = theme('pager_link', $text, $page_new, $element, $parameters); } } return $output; } /** * Format a "last page" link. * * @param $text * The name (or image) of the link. * @param $limit * The number of query results to display per page. * @param $element * An optional integer to distinguish between multiple pagers on one page. * @param $parameters * An associative array of query string parameters to append to the pager links. * @return * An HTML string that generates this piece of the query pager. * * @ingroup themeable */ function theme_pager_last($text, $limit, $element = 0, $parameters = array()) { global $pager_page_array, $pager_total; $output = ''; // If we are anywhere but the last page if ($pager_page_array[$element] < ($pager_total[$element] - 1)) { $output = theme('pager_link', $text, pager_load_array($pager_total[$element] - 1, $element, $pager_page_array), $element, $parameters); } return $output; } /** * Format a link to a specific query result page. * * @param $page_new * The first result to display on the linked page. * @param $element * An optional integer to distinguish between multiple pagers on one page. * @param $parameters * An associative array of query string parameters to append to the pager link. * @param $attributes * An associative array of HTML attributes to apply to a pager anchor tag. * @return * An HTML string that generates the link. * * @ingroup themeable */ function theme_pager_link($text, $page_new, $element, $parameters = array(), $attributes = array()) { $page = isset($_GET['page']) ? $_GET['page'] : ''; if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) { $parameters['page'] = $new_page; } $query = array(); if (count($parameters)) { $query[] = drupal_query_string_encode($parameters, array()); } $querystring = pager_get_querystring(); if ($querystring != '') { $query[] = $querystring; } // Set each pager link title if (!isset($attributes['title'])) { static $titles = NULL; if (!isset($titles)) { $titles = array( t('« first') => t('Go to first page'), t('‹ previous') => t('Go to previous page'), t('next ›') => t('Go to next page'), t('last »') => t('Go to last page'), ); } if (isset($titles[$text])) { $attributes['title'] = $titles[$text]; } else if (is_numeric($text)) { $attributes['title'] = t('Go to page @number', array('@number' => $text)); } } return l($text, $_GET['q'], array('attributes' => $attributes, 'query' => count($query) ? implode('&', $query) : NULL)); } /** * @} End of "Pager pieces". */ /** * Helper function * * Copies $old_array to $new_array and sets $new_array[$element] = $value * Fills in $new_array[0 .. $element - 1] = 0 */ function pager_load_array($value, $element, $old_array) { $new_array = $old_array; // Look for empty elements. for ($i = 0; $i < $element; $i++) { if (!$new_array[$i]) { // Load found empty element with 0. $new_array[$i] = 0; } } // Update the changed element. $new_array[$element] = (int)$value; return $new_array; }