class Page {
private $total;//合計数量
private $limit;//mysql
privateのlimit文を返す$pageStart;//開始値
private $pageStop;//終了値
private $pageNumber;//ページング番号の数を表示
private $page;//現在のページ
private $pageSize;//各ページに表示される番号
private $pageToatl;//ページング
private $pageParam;//ページング変数
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%/Total%pageToatl% %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 = '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 = ''.$this->pageShow['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 ->ページ,$this->pageStop-$this->pageStart,$this->pageStart,$this->pageStop,$this->total,$first,$ending,$up,$ down,$input,$GoTo),$this->pageType);
}
/**
*番号ページネーション
*/
プライベート関数numberF(){
$pageF =tripos( $this->pageType,'%numberF%');
$pageD =tripos($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->page - $numberpage - $number-1:0;
if($this->page+$number-$DStart > $this- >pageToatl){
$DStop = ($this->page+$number-$DStart) - $this->pageToatl;
$forStop = $this->pageToatl+1;
}else{
$DStop = 0;
$forStop = $this->page+$number-$DStart+1;
}
$forStart = $this->page-$number-$DStoppage -$number-$DStop;
for($i=$forStart;$iif($i==$this->page){
$numberF .= '< ;span class="current">'.$i.' ';
}else{
$numberF .= ''.$i.' ';
}
}
}
if($pageD!==false){
$number = $this->pageNumber;
$forStart = $this->page-$number>0?$this->page-$number:1;
$forStop = $this->page+$number> ;$this->pageToatl?$this->pageToatl+1:$this->page+$number+1;
for($i=$forStart;$ipage;++$ i){
$numberD .= ''.$i .' ';
}
$numberD .= ''.$this->page.' ';
$start = $this ->page+1;
for($i=$start;$i$numberD .= ''.$i.' ';
}
}
$F = $forStart>1?'uri.'&'.$this->pageParam.'=1">1':'';
$E = $forStoppageToatl+1?''。 $this->pageToatl.' ':'';
if($forStart>2){
$omitF = '… ';
$startA = $this->page-$numberpage-$number;
$omitFA = '… ';
}
if($forStoppageToatl){
$omitE = '… ';
$stopA = $this->page+$number>$this->pageToatl?$this->pageToatl:$ this->page+$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 フィルタリングされた文字列 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'].'?';
}
}
/**
* 制限方法を設定し、開始番号と終了番号を計算します
*/
プライベート関数計算(){
$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->total?$this->total:$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;
default:
return;
}
}
}
复制發