(eg. title, onMouseOver, etc.) * * @return string html of pager */ function pager_display($tags = "", $limit = 10, $element = 0, $type = "default", $attributes = array()) { return theme("pager_display_". $type, $tags, $limit, $element, $attributes); } /** @} End of defgroup pager_api **/ /** * @addtogroup themeable * @{ */ /** * DEFAULT PAGER: * When writing themes, you can rewrite this pager function in your * theme. This is the most common pager type, and thus the main one * to re-write in your theme. * * @see pager_display */ function theme_pager_display_default($tags = "", $limit = 10, $element = 0, $attributes = array()) { global $pager_total; if ($pager_total[$element] > $limit) { $output .= "
"; $output .= "
". pager_first(($tags[0] ? $tags[0] : t("first page")), $limit, $element, $attributes) ."
"; $output .= "
". pager_previous(($tags[1] ? $tags[1] : t("previous page")), $limit, $element, 1, $attributes) ."
"; $output .= "
". pager_list($limit, $element, ($tags[2] ? $tags[2] : 9 ), "", $attributes) ."
"; $output .= "
". pager_next(($tags[3] ? $tags[3] : t("next page")), $limit, $element, 1, $attributes) ."
"; $output .= "
". pager_last(($tags[4] ? $tags[4] : t("last page")), $limit, $element, $attributes) ."
"; $output .= "
"; return $output; } } /** * SIMPLE PAGER: * When writing themes, you can rewrite this pager function in your * theme. Keep in mind that the pager it defines is intended to have * a "simple" look, possibly located in a table or block. * * @see pager_display */ function theme_pager_display_simple($tags = "", $limit = 10, $element = 0, $attributes = array()) { /* ** It's left as an exercise to theme writers to create an alternative ** pager for pager_display_simple(). if your theme does not offer a ** replacement, the theme.inc pager_display_default() is used. */ return theme_pager_display_default($tags, $limit, $element, $attributes); } /** * ADMIN PAGER: * When writing themes, you can rewrite this pager function in your * theme. Most themes will probably NOT re-write this function, as * admin pages are not normally themed. * * @see pager_display */ function theme_pager_display_admin($tags = "", $limit = 10, $element = 0, $attributes = array()) { /* ** It's left as an exercise to theme writers to create an alternative ** pager for pager_display_admin(). if your theme does not offer a ** replacement, the pager.inc pager_display_default() is used. */ return theme_pager_display_default($tags, $limit, $element, $attributes); } /** @} End of addtogroup themeable **/ /** * @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. * @{ */ /** * displays a "first-page" link * * @param $text defines the name (or image) of the link * @param $limit how many nodes are displayed per page * @param $element distinguish between multiple pagers on one page * @param $attributes extra html attributes for \ (eg. title, onMouseOver, etc.) * * @return string html of this pager piece */ function pager_first($text, $limit, $element = 0, $attributes = array()) { global $pager_from_array; if ($pager_from_array[$element]) { return "$text"; } else { // we are already at the first page, return nothing return " "; } } /** * displays a "previous-page" link * * @param $text defines the name (or image) of the link * @param $limit how many nodes are displayed per page * @param $element distinguish between multiple pagers on one page * @param $n how many pages we move back (defaults to 1) * @param $attributes extra html attributes for \ (eg. title, onMouseOver, etc.) * * @return string html of this pager piece */ function pager_previous($text, $limit, $element = 0, $n = 1, $attributes = array()) { global $pager_from_array; $from_new = pager_load_array(((int)$pager_from_array[$element] - ((int)$limit * (int)$n)), $element, $pager_from_array); if ($from_new[$element] < 1) { return pager_first($text, $limit, $element, $attributes); } return "$text"; } /** * displays a "next-page" link * * @param $text defines the name (or image) of the link * @param $limit how many nodes are displayed per page * @param $element distinguish between multiple pagers on one page * @param $n how many pages we move back (defaults to 1) * @param $attributes extra html attributes for \ (eg. title, onMouseOver, etc.) * * @return string html of this pager piece */ function pager_next($text, $limit, $element = 0, $n = 1, $attributes = array()) { global $pager_from_array, $pager_total; $from_new = pager_load_array(((int)$pager_from_array[$element] + ((int)$limit * (int)$n)), $element, $pager_from_array); if ($from_new[$element] < $pager_total[$element]) { return "$text"; } return " "; } /** * displays a "last-page" link * * @param $text defines the name (or image) of the link * @param $limit how many nodes are displayed per page * @param $element distinguish between multiple pagers on one page * @param $attributes extra html attributes for \ (eg. title, onMouseOver, etc.) * * @return string html of this pager piece */ function pager_last($text, $limit, $element = 0, $attributes = array()) { global $pager_from_array, $pager_total; $from_new = pager_load_array(($pager_total[$element] - $limit), $element, $pager_from_array); if ($from_new[$element] < ($pager_from_array[$element] + $limit)) { return pager_next($text, $limit, $element, 1, $attributes); } if (($from_new[$element] > $pager_from_array[$element]) && ($from_new[$element] > 0) && $from_new[$element] < $pager_total[$element]) { return "$text"; } return " "; } /** * displays "%d through %d of $d" type detail about the cur page * * @param $limit how many nodes are displayed per page * @param $element distinguish between multiple pagers on one page * @param $format allows you to reword the format string * * @return string html of this pager piece */ function pager_detail($limit, $element = 0, $format = "%d through %d of %d.") { global $pager_from_array, $pager_total; if ($pager_total[$element] > (int)$pager_from_array[$element] + 1) { $output = sprintf($format, (int)$pager_from_array[$element] + 1, ((int)$pager_from_array[$element] + $limit <= $pager_total[$element] ? (int)$pager_from_array[$element] + $limit : $pager_total[$element]), $pager_total[$element]); } return $output; } /** * displays a list of nearby pages with additional nodes * * @param $limit how many nodes are displayed per page * @param $element distinguish between multiple pagers on one page * @param $quantity defines the length of the page list * @param $text optional text to display before the page list * @param $attributes extra html attributes for \ (eg. title, onMouseOver, etc.) * * @return string html of this pager piece */ function pager_list($limit, $element = 0, $quantity = 5, $text = "", $attributes = array()) { global $pager_from_array, $pager_total; // calculate various markers within this pager piece: // middle used to "center" pages around current page $pager_middle = ceil((int)$quantity / 2); // offset adds "offset" second page $pager_offset = (int)$pager_from_array[$element] % (int)$limit; // current is the page we are currently paged to if (($pager_current = (ceil(($pager_from_array[$element] + 1) / $limit))) < 1) { $pager_current = 1; } // first is the first page listed by this pager piece (re quantity) $pager_first = (int)$pager_current - (int)$pager_middle + 1; // last is the last page listed by this pager piece (re quantity) $pager_last = (int)$pager_current + (int)$quantity - (int)$pager_middle; // max is the maximum number of pages content can is devided into if (!$pager_max = (ceil($pager_total[$element] / $limit))) { $pager_max = 1; } if ((int)$pager_offset) { // adjust for offset second page $pager_max++; $pager_current++; } // end of various marker calculations // prepare for generation loop $i = (int)$pager_first; if ($pager_last > $pager_max) { // adjust "center" if at end of query $i = $i + (int)($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 // when there is more than one page, create the pager list if ($i != $pager_max) { $output = "$text"; if ($i > 1) { $output .= "... "; } // finally we're ready to generate the actual pager piece for (; $i <= $pager_last && $i <= $pager_max; $i++) { if ($i < $pager_current) { $output .= pager_previous($i, $limit, $element, ($pager_current - $i), $attributes) ." "; } if ($i == $pager_current) { $output .= "$i "; } if ($i > $pager_current) { $output .= pager_next($i, $limit, $element, ($i - $pager_current), $attributes) ." "; } } if ($i < $pager_max) { $output .= "..."; } } return $output; } /* @} End of member group pager pieces */ function pager_link($from_new, $attributes = array()) { $q = $_GET["q"]; foreach($attributes as $key => $value) { $query[] = "$key=$value"; } if (count($attributes)) { $url = url($q, "from=". $from_new[0] ."&". implode("&", $query)); } else { $url = url($q, "from=". $from_new[0]); } return $url; } 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; } ?>