Location: PHPKode > scripts > PageLite > pagelite/pagelightTiny.php
<?php
 class Page_Lite { protected $_totalItems = null; protected $_pagiUrl = null; protected $_perPage = 10; protected $_range = 5; protected $_rewrite = false; protected $_pageJump = true; protected $_jumpCount = 5; protected $_jumpCalcFoward = 1.15; protected $_jumpCalcBackward = 1.25; protected $_pageIdentifer = 'page'; protected $_useAutoIdentifier = true; public $totalPages = null; public static $styleArray = array( 'start' => '', 'end' => '', 'first_start' => '', 'first_end' => '', 'last_start' => '', 'last_end' => '', 'current_start' => '', 'current_end' => '', 'link_start' => '', 'link_end' => '', 'next_start' => '', 'next_end' => '', 'prev_start' => '', 'prev_end' => '' ); public $currentPage = null; protected $_displayLinkFirst = true; protected $_displayLinkPrev = true; protected $_displayLinkLast = true; protected $_displayLinkNext = true; public $linkPageOne = '[&laquo;]'; public $linkPagePrev = '&laquo;'; public $linkPageLast = '[&raquo;]'; public $linkPageNext = '&raquo;'; public function __construct($totalItems, $pagiUrl) { $this->setTotalItems($totalItems); $this->setPageUrl($pagiUrl); } public function setDisplayLinkFirst($flag) { $this->_displayLinkFirst = $flag; } public function setDisplayLinkPrev($str) { $this->_displayLinkPrev = $str; } public function setDisplayLinkLast($flag) { $this->_displayLinkLast = $flag; } public function setDisplayLinkNext($str) { $this->_displayLinkNext = $flag; } public function setLinkFirst($str) { $this->linkPageOne = $str; } public function setLinkNext($str) { $this->linkPageNext = $str; } public function setLinkLast($str) { $this->linkPageLast = $str; } public function setLinkPrev($str) { $this->linkPagePrev = $str; } public function setIdentifier($str) { $this->_pageIdentifer = $str; } public function setCurrentPage($int) { $this->currentPage = $int; } public function setAutoIdentifier($flag) { $this->_useAutoIdentifier = $flag; } public function setStyleArray($style) { $this->styleArray = $style; } public function getCurrentPage() { if ( $this->_useAutoIdentifier == false ) { return $this->currentPage; } else { if ($_GET[$this->_pageIdentifer]) { $this->currentPage = (int) $_GET[$this->_pageIdentifer]; return (int) $_GET[$this->_pageIdentifer]; } else { $this->currentPage = 1; return 1; } } } public function setRange($count) { $this->_range = $count; } public function setPageJumpCount($count) { $this->_jumpCount = $count; } public function setPageJump($flag) { $this->_pageJump = $flag; } public function setRewrite($flag) { $this->_rewrite = $flag; } public function setTotalItems($int) { $this->_totalItems = $int; } public function setJumpCalForward($int) { $this->_jumpCalcFoward = $int; } public function setJumpCalBackward($int) { $this->_jumpCalcBackward = $int; } public function setPageUrl($url) { $this->_pagiUrl = $url; } public function setPerPage($int) { $this->_perPage = $int; } public function getPerPage() { return $this->_perPage; } public function getStart() {  return ($this->getCurrentPage() == 1) ? 0 : $this->getCurrentPage() * $this->getPerPage(); } public function calculatePageTotal() { return $this->totalPages = floor( ($this->_totalItems) / ($this->_perPage) ); } public function getTotalPages() { return $this->calculatePageTotal(); } public function build() { $return = ''; $back = ''; $totalPages = $this->getTotalPages(); $range = ceil($this->_range / 2); $jumpRange = ceil($this->_jumpCount / 2); $return .= $this->styleArray['start']; $currentPage = $this->getCurrentPage(); if ($this->_rewrite == true) { $append = '/'; } elseif ( strpos($this->_pagiUrl, '?') === false ) { $append = '?'.$this->_pageIdentifer.'='; } else { $append = '&'.$this->_pageIdentifer.'='; } if ($currentPage != 1 && $this->_displayLinkFirst == true) { $return .= $this->styleArray['first_start'].' <a href="'.$this->_pagiUrl.$append.'1" title="Go to page 1  of '.$totalPages.'">'.$this->linkPageOne.'</a>'.$this->styleArray['first_end']; } if ($currentPage > 1 && $this->_displayLinkPrev == true) { $prev = ($currentPage - 1); $return .= $this->styleArray['prev_start'].'  <a href="'.$this->_pagiUrl.$append.$prev.'" title="Go to page '.$prev.' of '.$totalPages.'">'.$this->linkPagePrev.'</a>  '.$this->styleArray['prev_end']; } for ($i = 1; $i <= $range; $i++) { $p = $currentPage - $i; if ($p > 0) { $back .= $p.','; } } $lastBack = $currentPage - $range - 1; if ($lastBack > 2 && $this->_pageJump == true) { for ($i = 1; $i <= $jumpRange; $i++) { $lastBack = floor($lastBack / $this->_jumpCalcBackward); if ($lastBack >= 2) { $back .= $lastBack . ','; } } } $back = strrev($back); $backJump = explode(',', $back); foreach ($backJump as $rev) { if ($rev != null) { $rev = strrev($rev); $return .= $this->styleArray['link_start'].'  <a href="'.$this->_pagiUrl.$append.$rev.'" title="Go to page '.$rev.' of '.$totalPages.'">'.$rev.'</a> '.$this->styleArray['link_end']; } } $return .= $this->styleArray['current_start'].''.$currentPage.'</span> '.$this->styleArray['current_end']; for ($i = 1; $i <= $range; $i++) { $p = $currentPage + $i; if($p <= $totalPages) { $return .= $this->styleArray['link_start'].' <a href="'.$this->_pagiUrl.$append.$p.'" title="Go to page '.$p.' of '.$totalPages.'">'.$p.'</a> '.$this->styleArray['link_end']; } } $lastPage = $currentPage + $range; if ($this->_pageJump == true) { for ($i = 1; $i <= $jumpRange; $i++) { $lastPage = ceil($lastPage * $this->_jumpCalcFoward); if ($lastPage <= $totalPages) { $return .= $this->styleArray['link_start'].' <a href="'.$this->_pagiUrl.$append.$lastPage.'" title="Go to page '.$lastPage.' of '.$totalPages.'">'.$lastPage.'</a> '.$this->styleArray['link_end']; } } } if ($currentPage < $totalPages && $totalPages != '0' && $this->_displayLinkNext == true) { $next = $currentPage + 1; $return .= $this->styleArray['next_start'].' <a href="'.$this->_pagiUrl.$append.$next.'" title="Go to page '.$next.' of '.$totalPages.'">'.$this->linkPageNext.'</a> '.$this->styleArray['next_end']; } if ($currentPage != $totalPages && $totalPages != '0' && $this->_displayLinkLast == true) { $return .= $this->styleArray['last_start'].'<a href="'.$this->_pagiUrl.$append.$totalPages.'" title="Go to page '.$totalPages.' of '.$totalPages.'">'.$this->linkPageLast.'</a>'.$this->styleArray['last_end']; } $return .= $this->styleArray['end']; return $return; } } ?>
Return current item: PageLite