-
-
class Page {
- private $total;//總數
- private $limit;///傳回mysql的limit語句
- private $pageStart;//開始的數值
- private $pageStop;//結束的數值
- private $pageNumber;//顯示分頁數字的數量
- private $page; //目前頁
- private $pageSize;//每頁顯示的數量
- private $pageToatl;//分頁的總數量
- private $pageParam;//分頁變數
- private $uri;/private $uri;/ /URL參數
- /**
- * 分頁設定樣式不區分大小寫
- * %pageToatl% //總頁數
- * %page%//目前頁
- * %pageSize% //目前頁顯示資料條數
- * %pageStart%//本頁起始條數
- * %pageStop%//本頁結束條數
- * %total%//總資料條數
- * %first%//首頁
- * %ending%//尾頁
- * %up%//上一頁
- * %down%//下一頁
- * %F%//起始頁
- * %E%//結束頁
- * %omitFA%//前省略加跳轉
- * %omitEA%//後省略加跳轉
- * %omitF%//前省略
- * %omitE%//後省略
- * %numberF%//固定數量的數字分頁
- * %numberD%//左右對等的數字分頁
- * %input%//跳轉輸入框
- * %GoTo%//跳轉按鈕
- */ bbs.it-home.org
- private $pageType = '第%page%頁/共%pageToatl%頁 span>%first%%up%%F%%omitFA%%numberF%%omitEA%%E%%down%%ending%';
- //顯示值設定
- private $pageShow = array('first '=>'首頁','ending'=>'尾頁','up'=>'上一頁','down'=>'下一頁','GoTo'=>'GO');
/**
- * 初始化資料,建構方法
- * @access public
- * @param int $total 資料總數
- * @param int $pageSize 每頁顯示條數
- * @param int $ pageNumber 分頁數字顯示數量(使用%numberF%和使用%numberD%會有不同的效果)
- * @param string $pageParam分頁變數
- * @return void
- */
- public function __construct($total,$pageSize=10,$pageNumber=5,$pageParam='p'){
- $this ->total = $total$this->pageSize = $pageSize$this->pageNumber = $pageNumber$this->pageParam = $pageParam;
- $this->calculate();
- }
/**
- * 顯示分頁
- * @access public
- * @return string HTML分頁字串
- */
- public function pageShow(){
- $this->uri();
- if($this->pageToatl>1){
- if($this->page == 1){
- $ first = ''.$this->pageShow['first'].'';
- $up = ''.$this ->pageShow['up'].'';
- }else{
- $first = ''.$this->pageShow['first'].'';
- $up = ''.$this->pageShow['up'].'';
- }
- if($this->page >= $this->pageToatl){
- $ending = ''.$this->pageShow['ending'].' ';
- $down = ''.$this->pageShow['down'].'';
- }else{
- $ending = ' '.$this->pageShow['ending'].' ';
- $down = ''.$this->pageShow['down'].'';
- }
- $input = '';
- $GoTo = ' ' ;
- }else{
- $first = '';$up ='';$ending = '';$down = '';$input = '';$GoTo = '';
- }
- $this->numberF();
- return str_ireplace(array('%pageToatl%','%page%','%pageSize%','%pageStart%','%pageStop%', '%total%','%first%','%ending%','%up%','%down%','%input%','%GoTo%'),array($this-> pageToatl,$this->page,$this->pageStop-$this->pageStart,$this->pageStart,$this->pageStop,$this->total,$first,$ending, $up,$down,$input,$GoTo),$this->pageType);
- }
/**
- *번호 매김
- */
- 비공개 기능 numberF(){
- $pageF = Stripos($this->pageType,'%numberF%');
- $pageD = Stripos($this->pageType,'%numberD%');
- $numberF = '';$numberD = '';$F = '';$E ='';$omitF = '';$omitFA = '';$omitE = '';$omitEA = '';
- if($pageF!==false || $pageD!==false){
- if($pageF!==false){
- $number = $this->pageNumber%2==0 ?$this->pageNumber/2:($this->pageNumber 1)/2;
- $DStart = $this->페이지 - $number<0?$this->페이지 - $number- 1:0;
- if($this->페이지 $number-$DStart > $this->pageToatl){
- $DStop = ($this->페이지 $number-$DStart) - $this->pageToatl;
- $forStop = $this->pageToatl 1;
- }else{
- $DStop = 0;
- $forStop = $this->페이지 $number- $DStart 1;
- }
- $forStart = $this->page-$number-$DStop<1?1:$this->page-$number-$DStop;
- for($ i=$forStart;$i<$forStop; $i){
- if($i==$this->페이지){
- $numberF .= ''.$i.' ';
- }else{
- $numberF .= ''.$i.'';
- }
- }
- }
- if($pageD!==false){
- $number = $this- >pageNumber;
- $forStart = $this->page-$number>0?$this->page-$number:1;
- $forStop = $this->페이지 $number>$ this->pageToatl?$this->pageToatl 1:$this->$number 1페이지;
- for($i=$forStart;$i<$this->page; $i){
- $numberD .= ''.$i.' ';
- }
- $numberD .= ''.$this->페이지.'';
- $ start = $this->1페이지;
- for($i=$start;$i<$forStop; $i){
- $numberD .= ''.$i.'';
- }
- }
- $F = $forStart>1?'1':'' ;
- $E = $forStop<$this->pageToatl 1?''.$this->pageToatl.'':'';
- if($forStart>2){
- $omitF = '< 스팬 클래스="생략">…
';
- $startA = $this->page-$number<1?1:$this->page-$number;
- $ omitFA = '…
- }
- if($forStop<$this->pageToatl){
- $omitE = '…';
- $stopA = $this->$number 페이지>$this->pageToatl?$this->pageToatl:$this->$number 페이지;
- $omitEA = '…';
- }
- }
- $this->pageType = str_ireplace(array('%F%','%E%','%omitFA%','%omitEA%','%omitF%','%omitE%' ,'%numberF%','%numberD%'),array($F,$E,$omitFA,$omitEA,$omitF,$omitE,$numberF,$numberD),$this->pageType);
- }
/**
- *URL 처리 방법
- * @access public
- * @param array $url 관계 배열에 URL을 직접 유지
- * @return string 필터링된 URL 꼬리 매개변수
- */
- 비공개 함수 uri(){
- $url = $_SERVER["REQUEST_URI"];
- $ par = parse_url($url);
- if (isset($par['query'])) {
- parse_str($par['query'],$query);
- if(!is_array( $this->uri)){
- $this->uri = array();
- }
- array_merge($query,$this->uri);
- unset($query [$this->pageParam]);
- while($key = array_search('',$query)){
- unset($query[$key]);
- }
- $this ->uri = $par['path'].'?'.http_build_query($query);
- }else{
- $this->uri = $par['path'].'?' ;
- }
- }
/**
- * 設定limit方法及計算起始條數與結束條數
- */
- 創函數calculate(){
- $this->pageToatl = ceil($this->total/$this ->pageSize) ;
- $this->page = intval($_GET[$this->pageParam]);
- $this->page = $this->page>=1? $this->page>$this->pageToatl?$this->pageToatl:$this->page:1;
- $this->pageStart = ($this->page-1) *$this->pageSize ;
- $this->pageStop = $this->pageStart $this->pageSize;
- $this->pageStop = $this->pageStop>$this ->總計? ->pageStop;
- $this->limit = $this->pageStart.','.$this->pageStop;
- }
/**
- * 設定過濾器
- * /
- public function __set($name,$value){
- switch($name){
- case 'pageType':
- case 'uri':
- $this->$name = $value;
- return;
- case 'pageShow':
- if(is_array($value)){
- $this->pageShow = array_merge($this->pageShow,$value);
- }
- return;
- }
- }
;/**
- * 取值過濾器
- */
- public function __get($name){
- switch ( $name){
- case 'limit':
- case 'pageStart':
- case ' pageStop':
- return $this->$name;
- 預設:
- return;
- }
- }
- }
-
複製程式碼
|