霜天部落 | 关注LAMP高性能、高并发架构的设计与研究

PHP分页类发布,支持自定义风格,默认4种显示模式(下)

PHP分页类发布,支持自定义风格,默认4种显示模式。接上篇文章


<?php

/**
* 获取显示跳转按钮的代码
*
* @return string
*/
function select()
{
$return='<select name="PB_Page_Select" >'<span%20style="color: #007700;">;
for(
$i=1;$i<=$this->totalpage;$i++)
{
if(
$i==$this->nowindex){
$return.='<option value="'<span%20style="color: #007700;">.$i.'" selected>'<span%20style="color: #007700;">.$i.'</option>'<span%20style="color: #007700;">;
}else{
$return.='<option value="'<span%20style="color: #007700;">.$i.'">'<span%20style="color: #007700;">.$i.'</option>'<span%20style="color: #007700;">;
}
}
unset($i);
$return.='</select>'<span%20style="color: #007700;">;
return $return;
}
/**
* 获取mysql 语句中limit需要的值
*
* @return string
*/
function offset()
{
return
$this->offset;
}
/**
* 控制分页显示风格(你可以增加相应的风格)
*
* @param int $mode
* @return string
*/
function show($mode=1)
{
switch (
$mode)
{
case
'1'<span%20style="color: #007700;">:
$this->next_page='下一页'<span%20style="color: #007700;">;
$this->pre_page='上一页'<span%20style="color: #007700;">;
return $this->pre_page().$this->nowbar().$this->next_page().'第'<span%20style="color: #007700;">.$this->select().'页'<span%20style="color: #007700;">;
break;
case '2'<span%20style="color: #007700;">:
$this->next_page='下一页'<span%20style="color: #007700;">;
$this->pre_page='上一页'<span%20style="color: #007700;">;
$this->first_page='首页'<span%20style="color: #007700;">;
$this->last_page='尾页'<span%20style="color: #007700;">;
return $this->first_page().$this->pre_page().'[第'<span%20style="color: #007700;">.$this->nowindex.'页]'<span%20style="color: #007700;">.$this->next_page().$this->last_page().'第'<span%20style="color: #007700;">.$this->select().'页'<span%20style="color: #007700;">;
break;
case '3'<span%20style="color: #007700;">:
$this->next_page='下一页'<span%20style="color: #007700;">;
$this->pre_page='上一页'<span%20style="color: #007700;">;
$this->first_page='首页'<span%20style="color: #007700;">;
$this->last_page='尾页'<span%20style="color: #007700;">;
return $this->first_page().$this->pre_page().$this->next_page().$this->last_page();
break;
case
'4'<span%20style="color: #007700;">:
$this->next_page='下一页'<span%20style="color: #007700;">;
$this->pre_page='上一页'<span%20style="color: #007700;">;
return $this->pre_page().$this->nowbar().$this->next_page();
break;
case
'5'<span%20style="color: #007700;">:
return $this->pre_bar().$this->pre_page().$this->nowbar().$this->next_page().$this->next_bar();
break;
}

}
/*--------private function (私有方法)------------*/
/**
* 设置url头地址
* @param: String $url
* @return boolean
*/
function _set_url($url="")
{
if(!empty(
$url)){
//手动设置
$this->url=$url.((stristr($url,'?'<span%20style="color: #007700;">))?
'&'<span%20style="color: #007700;">:'?'<span%20style="color: #007700;">).$this->page_name."=";
}else{
//自动获取
if(empty($_SERVER['QUERY_STRING'<span%20style="color: #007700;">])){
//不存在QUERY_STRING时
$this->url=$_SERVER['REQUEST_URI'<span%20style="color: #007700;">]."?".$this->page_name."=";
}else{
//
if(stristr($_SERVER['QUERY_STRING'<span%20style="color: #007700;">],$this->page_name.'='<span%20style="color: #007700;">)){
//地址存在页面参数
$this->url=str_replace($this->page_name.'='<span%20style="color: #007700;">.$this->nowindex,''<span%20style="color: #007700;">,$_SERVER['REQUEST_URI'<span%20style="color: #007700;">]);
$last=$this->url[strlen($this->url)-1];
if(
$last=='?'<span%20style="color: #007700;">||$last=='&'<span%20style="color: #007700;">){
$this->url.=$this->page_name."=";
}else{
$this->url.='&'<span%20style="color: #007700;">.$this->page_name."=";
}
}else{
//
$this->url=$_SERVER['REQUEST_URI'<span%20style="color: #007700;">].'&'<span%20style="color: #007700;">.$this->page_name.'='<span%20style="color: #007700;">;
}//end if
}//end if
}//end if
}

/**
* 设置当前页面
*
*/
function _set_nowindex($nowindex)
{
if(empty(
$nowindex)){
//系统获取

if(isset($_GET[$this->page_name])){
$this->nowindex=intval($_GET[$this->page_name]);
}
}else{
//手动设置
$this->nowindex=intval($nowindex);
}
}

/**
* 为指定的页面返回地址值
*
* @param int $pageno
* @return string $url
*/
function _get_url($pageno=1)
{
return
$this->url.$pageno;
}

/**
* 获取分页显示文字,比如说默认情况下_get_text('<a href="">1</a>')将返回[<a href="">1</a>]
*
* @param String $str
* @return string $url
*/
function _get_text($str)
{
return
$this->format_left.$str.$this->format_right;
}

/**
* 获取链接地址
*/
function _get_link($url,$text,$style=''<span%20style="color: #007700;">){
$style=(empty($style))?''<span%20style="color: #007700;">:'class="'<span%20style="color: #007700;">.$style.'"'<span%20style="color: #007700;">;
if($this->is_ajax){
//如果是使用AJAX模式
return '<a '<span%20style="color: #007700;">.$style.' href="javascript:'<span%20style="color: #007700;">.$this->ajax_action_name.'(\''<span%20style="color: #007700;">.$url.'\')">'<span%20style="color: #007700;">.$text.'</a>'<span%20style="color: #007700;">;
}else{
return '<a '<span%20style="color: #007700;">.$style.' href="'<span%20style="color: #007700;">.$url.'">'<span%20style="color: #007700;">.$text.'</a>'<span%20style="color: #007700;">;
}
}
/**
* 出错处理方式
*/
function error($function,$errormsg)
{
die(
'Error in file <b>'<span%20style="color: #007700;">.__FILE__.'</b> ,Function <b>'<span%20style="color: #007700;">.$function.'()</b> :'<span%20style="color: #007700;">.$errormsg);
}
?>
(完)