totalRows = $totalRows; $this->parameter = $parameter; $this->rollPage = C('PAGE_ROLLPAGE') ? C('PAGE_ROLLPAGE') : 2; $this->listRows = !empty($listRows)?$listRows:C('PAGE_LISTROWS'); $this->totalPages = ceil($this->totalRows/$this->listRows); //总页数 if (!define('PAGESTOTAL')) define('PAGESTOTAL', $this->totalPages); $this->coolPages = ceil($this->totalPages/$this->rollPage); if($p){ $this->nowPage =$p; }else{ $this->nowPage = !empty($_GET[C('VAR_PAGE')])?intval($_GET[C('VAR_PAGE')]):1; } if(!empty($this->totalPages) && $this->nowPage>$this->totalPages) { $this->nowPage = $this->totalPages; } $this->firstRow = $this->listRows*($this->nowPage-1); } public function show(){ if($this->totalRows == 0 OR $this->listRows == 0 OR $this->totalPages <= 1){ return ''; } $urlrule = str_replace('%7B%24page%7D','{$page}',$this->urlrule); //urldecode if(!$urlrule){ $p = C('VAR_PAGE'); $nowCoolPage = ceil($this->nowPage/$this->rollPage); $url = $_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'],'?')?'':"?").$this->parameter; $parse = parse_url($url); if(isset($parse['query'])) { parse_str($parse['query'],$params); unset($params[$p]); $urlrule = $parse['path'].'?'.http_build_query($params); } $urlrule = $urlrule."&".$p.'={$page}'; } $pre_page = $this->nowPage-1; $next_page = $this->nowPage +1; if($this->nowPage >=$this->totalPages){ $next_page = $this->nowPage = $this->totalPages; } if($this->nowPage <= 1){ $pre_page = $this->nowPage = 1; } $output = ''; $output .= ''.$this->totalRows.L('page_item').''; $output .= ''.L('first_page').''; $output .= ''.L('previous').''; $show_nums = $this->rollPage*2+1;// 显示页码的个数 if($this->totalPages <= $show_nums){ for($i = 1;$i<=$this->totalPages;$i++){ if($i == $this->nowPage){ $output .= ''.$i.''; }else{ $output .= ''.$i.''; } } }else{ if($this->nowPage < (1+$this->rollPage)){ for($i = 1;$i<=$show_nums;$i++){ if($i == $this->nowPage){ $output .= ''.$i.''; }else{ $output .= ''.$i.''; } } }else if($this->nowPage >= ($this->totalPages - $this->rollPage)){ for($i = $this->totalPages - $show_nums ; $i <= $this->totalPages ; $i++){ if($i == $this->nowPage){ $output .= ''.$i.''; }else{ $output .= ''.$i.''; } } }else{ $start_page = $this->nowPage - $this->rollPage; $end_page = $this->nowPage + $this->rollPage; for($i = $start_page ; $i<=$end_page ; $i++){ if($i == $this->nowPage){ $output .= ''.$i.''; }else{ $output .= ''.$i.''; } } } } $output .=''.L('next').""; $output .=''.L('Last_page').""; return $output; } public function pageurl($urlrule, $page, $array = array()) { @extract($array, EXTR_SKIP); if(is_array($urlrule)) { //$urlrules = explode('|', $urlrule); $urlrule = $page < 2 ? $urlrule[0] : $urlrule[1]; } $url = str_replace('{$page}', $page, $urlrule); return $url; } } ?>