123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <?php
- class Pager_Sliding extends Pager_Common
- {
-
- public function __construct($options = array())
- {
-
- $this->_delta = 2;
- $this->_prevImg = '«';
- $this->_nextImg = '»';
- $this->_separator = '|';
- $this->_spacesBeforeSeparator = 3;
- $this->_spacesAfterSeparator = 3;
- $this->_curPageSpanPre = '<b>';
- $this->_curPageSpanPost = '</b>';
-
- $err = $this->setOptions($options);
- if ($err !== PAGER_OK) {
- return $this->raiseError($this->errorMessage($err), $err);
- }
- $this->build();
- }
-
-
-
- function getPageIdByOffset($index)
- {
- }
-
-
-
- function getPageRangeByPageId($pageid = null)
- {
- $pageid = isset($pageid) ? (int)$pageid : $this->_currentPage;
- if (!isset($this->_pageData)) {
- $this->_generatePageData();
- }
- if (isset($this->_pageData[$pageid]) || is_null($this->_itemData)) {
- if ($this->_expanded) {
- $min_surplus = ($pageid <= $this->_delta) ? ($this->_delta - $pageid + 1) : 0;
- $max_surplus = ($pageid >= ($this->_totalPages - $this->_delta)) ?
- ($pageid - ($this->_totalPages - $this->_delta)) : 0;
- } else {
- $min_surplus = $max_surplus = 0;
- }
- return array(
- max($pageid - $this->_delta - $max_surplus, 1),
- min($pageid + $this->_delta + $min_surplus, $this->_totalPages)
- );
- }
- return array(0, 0);
- }
-
-
-
- function getLinks($pageID = null, $dummy='')
- {
- if (!is_null($pageID)) {
- $_sav = $this->_currentPage;
- $this->_currentPage = $pageID;
- $this->links = '';
- if ($this->_totalPages > (2 * $this->_delta + 1)) {
- $this->links .= $this->_printFirstPage();
- }
- $this->links .= $this->_getBackLink();
- $this->links .= $this->_getPageLinks();
- $this->links .= $this->_getNextLink();
- if ($this->_totalPages > (2 * $this->_delta + 1)) {
- $this->links .= $this->_printLastPage();
- }
- }
- $back = str_replace(' ', '', $this->_getBackLink());
- $next = str_replace(' ', '', $this->_getNextLink());
- $pages = $this->_getPageLinks();
- $first = $this->_printFirstPage();
- $last = $this->_printLastPage();
- $all = $this->links;
- $linkTags = $this->linkTags;
- $linkTagsRaw = $this->linkTagsRaw;
- if (!is_null($pageID)) {
- $this->_currentPage = $_sav;
- }
- return array(
- $back,
- $pages,
- trim($next),
- $first,
- $last,
- $all,
- $linkTags,
- 'back' => $back,
- 'pages' => $pages,
- 'next' => $next,
- 'first' => $first,
- 'last' => $last,
- 'all' => $all,
- 'linktags' => $linkTags,
- 'linkTagsRaw' => $linkTagsRaw,
- );
- }
-
-
-
- function _getPageLinks($url = '')
- {
-
-
- if (!empty($url)) {
- $this->_path = $url;
- }
-
- if ($this->_clearIfVoid && ($this->_totalPages < 2)) {
- return '';
- }
- $links = '';
- if ($this->_totalPages > (2 * $this->_delta + 1)) {
- if ($this->_expanded) {
- if (($this->_totalPages - $this->_delta) <= $this->_currentPage) {
- $expansion_before = $this->_currentPage - ($this->_totalPages - $this->_delta);
- } else {
- $expansion_before = 0;
- }
- for ($i = $this->_currentPage - $this->_delta - $expansion_before; $expansion_before; $expansion_before--, $i++) {
- $print_separator_flag = ($i != $this->_currentPage + $this->_delta);
- $this->range[$i] = false;
- $this->_linkData[$this->_urlVar] = $i;
- $links .= $this->_renderLink(str_replace('%d', $i, $this->_altPage), $i)
- . $this->_spacesBefore
- . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : '');
- }
- }
- $expansion_after = 0;
- for ($i = $this->_currentPage - $this->_delta; ($i <= $this->_currentPage + $this->_delta) && ($i <= $this->_totalPages); $i++) {
- if ($i < 1) {
- ++$expansion_after;
- continue;
- }
-
- $print_separator_flag = (($i != $this->_currentPage + $this->_delta) && ($i != $this->_totalPages));
- if ($i == $this->_currentPage) {
- $this->range[$i] = true;
- $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
- } else {
- $this->range[$i] = false;
- $this->_linkData[$this->_urlVar] = $i;
- $links .= $this->_renderLink(str_replace('%d', $i, $this->_altPage), $i);
- }
- $links .= $this->_spacesBefore
- . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : '');
- }
- if ($this->_expanded && $expansion_after) {
- $links .= $this->_separator . $this->_spacesAfter;
- for ($i = $this->_currentPage + $this->_delta +1; $expansion_after; $expansion_after--, $i++) {
- $print_separator_flag = ($expansion_after != 1);
- $this->range[$i] = false;
- $this->_linkData[$this->_urlVar] = $i;
- $links .= $this->_renderLink(str_replace('%d', $i, $this->_altPage), $i)
- . $this->_spacesBefore
- . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : '');
- }
- }
- } else {
-
- for ($i=1; $i<=$this->_totalPages; $i++) {
- if ($i != $this->_currentPage) {
- $this->range[$i] = false;
- $this->_linkData[$this->_urlVar] = $i;
- $links .= $this->_renderLink(str_replace('%d', $i, $this->_altPage), $i);
- } else {
- $this->range[$i] = true;
- $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
- }
- $links .= $this->_spacesBefore
- . (($i != $this->_totalPages) ? $this->_separator.$this->_spacesAfter : '');
- }
- }
- return $links;
- }
-
- }
- ?>
|