022 |
var $first_page = 'First' ; |
023 |
var $last_page = 'Last' ; |
026 |
var $format_left = '[' ; |
027 |
var $format_right = ']' ; |
036 |
var $ajax_action_name = '' ; |
046 |
function minupage( $array ) |
048 |
if ( is_array ( $array )){ |
049 |
if (! array_key_exists ( 'total' , $array )) $this ->error( __FUNCTION__ , 'need a param of total' ); |
050 |
$total = intval ( $array [ 'total' ]); |
051 |
$perpage =( array_key_exists ( 'perpage' , $array ))? intval ( $array [ 'perpage' ]):10; |
052 |
$nowindex =( array_key_exists ( 'nowindex' , $array ))? intval ( $array [ 'nowindex' ]): '' ; |
053 |
$url =( array_key_exists ( 'url' , $array ))? $array [ 'url' ]: '' ; |
060 |
if ((! is_int ( $total ))||( $total <0)) $this ->error( __FUNCTION__ , $total . ' is not a positive integer!' ); |
061 |
if ((! is_int ( $perpage ))||( $perpage <=0)) $this ->error( __FUNCTION__ , $perpage . ' is not a positive integer!' ); |
062 |
if (! empty ( $array [ 'page_name' ])) $this ->set( 'page_name' , $array [ 'page_name' ]); |
063 |
$this ->_set_nowindex( $nowindex ); |
064 |
$this ->_set_url( $url ); |
065 |
$this ->totalpage= ceil ( $total / $perpage ); |
066 |
$this ->offset=( $this ->nowindex-1)* $perpage ; |
067 |
if (! empty ( $array [ 'ajax' ])) $this ->open_ajax( $array [ 'ajax' ]); |
075 |
function set( $var , $value ) |
077 |
if (in_array( $var ,get_object_vars( $this ))) |
080 |
$this ->error( __FUNCTION__ , $var . " does not belong to PB_Page!" ); |
089 |
function open_ajax( $action ) |
092 |
$this ->ajax_action_name= $action ; |
100 |
function next_page( $style = '' ) |
102 |
if ( $this ->nowindex< $this ->totalpage){ |
103 |
return $this ->_get_link( $this ->_get_url( $this ->nowindex+1), $this ->next_page, $style ); |
105 |
return '<span class="' . $style . '">' . $this ->next_page. '</span>' ; |
114 |
function pre_page( $style = '' ) |
116 |
if ( $this ->nowindex>1){ |
117 |
return $this ->_get_link( $this ->_get_url( $this ->nowindex-1), $this ->pre_page, $style ); |
119 |
return '<span class="' . $style . '">' . $this ->pre_page. '</span>' ; |
127 |
function first_page( $style = '' ) |
129 |
if ( $this ->nowindex==1){ |
130 |
return '<span class="' . $style . '">' . $this ->first_page. '</span>' ; |
132 |
return $this ->_get_link( $this ->_get_url(1), $this ->first_page, $style ); |
140 |
function last_page( $style = '' ) |
142 |
if ( $this ->nowindex== $this ->totalpage){ |
143 |
return '<span class="' . $style . '">' . $this ->last_page. '</span>' ; |
145 |
return $this ->_get_link( $this ->_get_url( $this ->totalpage), $this ->last_page, $style ); |
148 |
function nowbar( $style = '' , $nowindex_style = '' ) |
150 |
$plus = ceil ( $this ->pagebarnum/2); |
151 |
if ( $this ->pagebarnum- $plus + $this ->nowindex> $this ->totalpage) $plus =( $this ->pagebarnum- $this ->totalpage+ $this ->nowindex); |
152 |
$begin = $this ->nowindex- $plus +1; |
153 |
$begin =( $begin >=1)? $begin :1; |
155 |
for ( $i = $begin ; $i < $begin + $this ->pagebarnum; $i ++) |
157 |
if ( $i <= $this ->totalpage){ |
158 |
if ( $i != $this ->nowindex) |
159 |
$return .= $this ->_get_text( $this ->_get_link( $this ->_get_url( $i ), $i , $style )); |
161 |
$return .= $this ->_get_text( '<span class="' . $nowindex_style . '">' . $i . '</span>' ); |
175 |
function select( $url ) |
177 |
$return = '<select name=";PB_Page_Select" >' ; |
178 |
for ( $i =1; $i <= $this ->totalpage; $i ++) |
180 |
if ( $i == $this ->nowindex){ |
181 |
$return .= '<option value=' . $url . $i . ' selected>' . $i . '</option>' ; |
183 |
$return .= '<option value=' . $url . $i . '>' . $i . '</option>' ; |
187 |
$return .= '</select>' ; |
198 |
return $this ->offset; |
207 |
function show( $mode =1, $url = '' ) |
212 |
$this ->next_page= '下一页' ; |
213 |
$this ->pre_page= '上一页' ; |
214 |
return $this ->pre_page(). $this ->nowbar(). $this ->next_page(). '第' . $this ->select( $url ). '页' ; |
217 |
$this ->next_page= '下一页' ; |
218 |
$this ->pre_page= '上一页' ; |
219 |
$this ->first_page= '首页' ; |
220 |
$this ->last_page= '尾页' ; |
221 |
return $this ->first_page(). $this ->pre_page(). '[第' . $this ->nowindex. ' 页]' . $this ->next_page(). $this ->last_page(). '第 ' . $this ->select( $url ). '页' ; |
224 |
$this ->next_page= '下一页' ; |
225 |
$this ->pre_page= '上一页' ; |
226 |
$this ->first_page= '首页' ; |
227 |
$this ->last_page= '尾页' ; |
228 |
return $this ->first_page(). $this ->pre_page(). $this ->next_page(). $this ->last_page(); |
231 |
$this ->next_page= '下一页' ; |
232 |
$this ->pre_page= '上一页' ; |
233 |
return $this ->pre_page(). $this ->nowbar(). $this ->next_page(); |
236 |
return $this ->pre_bar(). $this ->pre_page(). $this ->nowbar(). $this ->next_page(). $this ->next_bar(); |
247 |
function _set_url( $url = "" ) |
251 |
$this ->url= $url .(( stristr ( $url , '?' ))? '&' : '?' ). $this ->page_name. "=" ; |
254 |
if ( empty ( $_SERVER [ 'QUERY_STRING' ])){ |
256 |
$this ->url= $_SERVER [ 'REQUEST_URI' ]. "?" . $this ->page_name. "=" ; |
259 |
if ( stristr ( $_SERVER [ 'QUERY_STRING' ], $this ->page_name. '=' )){ |
261 |
$this ->url= str_replace ( $this ->page_name. '=' . $this ->nowindex, '' , $_SERVER [ 'REQUEST_URI' ]); |
262 |
$last = $this ->url[ strlen ( $this ->url)-1]; |
263 |
if ( $last == '?' || $last == '&' ){ |
264 |
$this ->url.= $this ->page_name. "=" ; |
266 |
$this ->url.= '&' . $this ->page_name. "=" ; |
270 |
$this ->url= $_SERVER [ 'REQUEST_URI' ]. '&' . $this ->page_name. '=' ; |
280 |
function _set_nowindex( $nowindex ) |
282 |
if ( empty ( $nowindex )){ |
285 |
if (isset( $_GET [ $this ->page_name])){ |
286 |
$this ->nowindex= intval ( $_GET [ $this ->page_name]); |
290 |
$this ->nowindex= intval ( $nowindex ); |
300 |
function _get_url( $pageno =1) |
302 |
return $this ->url. $pageno ; |
311 |
function _get_text( $str ) |
313 |
return $this ->format_left. $str . $this ->format_right; |
319 |
function _get_link( $url , $text , $style = '' ){ |
320 |
$style =( empty ( $style ))? '' : 'class="' . $style . '"' ; |
323 |
return '<a ' . $style . ' href="javascript:' . $this ->ajax_action_name. '('' . $url . '')">' . $text . '</a>' ; |
325 |
return '<a ' . $style . ' href="' . $url . '">' . $text . '</a>' ; |
331 |
function error( $function , $errormsg ) |
333 |
die ( 'Error in file <b>' . __FILE__ . '</b>,Function <b>' . $function . '()</b> :' . $errormsg ); |
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|