class Pagination 獨立分頁類
呼叫方式:
$pagenation = new Pagination( 4, 10, 200 ); // 4(第一個參數) = currentPage, 10(第二個參數) = pageSize, 200(第三個參數) = 總數
$pagenation->set_link( 'http://www.360hqb.com' );
$pagenation->show();
-
/**
- * class Pagination
- *
- * 獨立分頁類別
- * 呼叫方式:
- * $pagenation = new Pagination( 4, 10, 200 ); // 4(第一個參數) = currentPage, 10(第二個參數) = pageSize, 200(第三個參數) = 總數
- * $pagenation->set_link( 'http://www.360hqb.com' );
- * $ pagenation->show();
- */
- class Java_Pagination
- {
- protected $_total = 0;
- protected _ = 0;
- 受保護的$_page = 1;
- 受保護的$_page_size = 10;
- 受保護的$_link = '';
- 受保護的$_grep = 3;
-
- 受保護的$_admin = false;
- protected $_css_next = '下一頁';
- protected $_css_prev = '上一頁';
- protected $_css_curr = '當前頁';
- protected $_css_page = ' page-nav inline-block';
-
- public function __construct ( $page, $page_size, $total, $admin = false )
- {
- $this- >set_current_page( $page );
- $this->set_page_size( $page_size );
- $this->set_total( $total );
-
- if ( $admin )
- {
-
- if ( $ > $this-> ;_admin = $admin;
- }
- //$this->_link = $_SERVER['REQUEST_URI'];
- $this->set_link( $_SERVER['REQUEST_URI'] );
- }
-
- public function set_link ( $link, $is_shop = TRUE )
- {
- $len = strlen( $link );
- $substr = substr( $link , $len - 1 );
- if ( '&' == $substr )
- {
- $link = substr( $link, 0, $len - 1 );
- }
- $pos = strpos( $link, '?' );
- if ( $pos )
- {
- $link = substr( $link, 0, $pos );
- }
- if ( !empty ( $_GET ) )
- {
- $link .= '?';
- foreach ( $_GET as $k=>$v )
- {
- if ( 'page' == strtolower( $k ) )
- {
- 繼續;
- }
- $link .= $k.'='.$v.'&';
- }
- $ len = strlen( $link );
- $substr = substr( $link, $len - 1 );
- if ( '&' == $substr )
- {
- $link = substr( $link , 0, $len - 1);
- }
- }
- elseif ( isset( $_SERVER['QUERY_STRING'] ) AND !empty( $_SERVER['QUERY_STRING'] ) AND $is_shop )
- {
- $link .= '?'.$_SERVER['QUERY_STRING'];
- $len = strlen( $link );
- $substr = substr( $link, $len - 1 );
- if ( '&' == $substr )
- {
- $link = substr( $link, 0, $len - 1);
- }
- }
- $ this- >_link = $link;
- }
-
- public function set_page_size ( $page_size )
- {
- if (empty( $page_size ) )
- { $ ;_page_size = 10;
- }
- else
- {
- $this->_page_size = (int) $page_size;
- }
- }
-
-
- }
- }
-
- {
- $page_size = 空( $this->_page_size )?10:$this->_page_size;
- $this->_total = $total;
- if (0 = = = ( $total % $page_size ) )
- {
- $this->_total_page = intval( $total / $page_size );
- }
- else
- {
- $this-> _total_page = intval( $total / $page_size ) + 1;
- }
- if ( $this->_page >; $this->_total_page )
- {
- $this->_page = $this ->_total_page;
- }
- }
-
- public function set_current_page ( $page )
- {
- if ( 空( $page ) )
- { $_page = 1;
- }
- else
- {
- $this-> _page = (int) $page;
- }
- }
- public function get
- }
- {
- if ( $this->_page _total_page )
- {
- $link = '';
- if ( strpos( $this->_link, '? ' ) )
- {
- $link = $this->_link. '&page='.( $this->_page + 1 );
- }
- else
- {
- $ link = $this->_link.'?page='.( $this ->_page + 1 );
- }
- if ( $this->_admin )
- {
- return '下一個頁';
- }
- else { return '
- 下一頁
'; } }- if ( $this->_admin )
- return '下一頁?';
- else
- return '';
- }
-
- public function get_prev_page_btn ( ) {
- if ( $this->_page > 1 )
- {
- $link = '';
- if ( strpos( $this->_link, '?' ) )
- {
- $link = $this->_link.'&page='.( $this->_page - 1 );
- }
- else
- {
- $link = $this->_link .'?page='.( $this->_page - 1 );
- }
- if ( $this->_admin )
- {
- return '上一頁';
- }
- else
- {
- return '
- 上一頁
';- }
- }
- if ( $this->_admin )
- return '? 上一頁';
- else
- return '';
- }
-
- public function get_current_page ()
- {
- if ( $this->_admin )
- {
- if ( $this->_admin )
- return ''.$this->_page.'';
- else
- return '
- '.$this->_page .'
';- }
-
- 公用函數get_page_link ( $page )
- {
- $link = '';
- if ( strpos ( $this->_link, '?' ) )
- {
- $link = $this->_link.'&page='. $page;
- }
- else
- {
- $link = $this->_link.'?page='.$page;
- }
- if ( $this->_admin )
- {
- return ''.$page.'';
- }
- else
- {
- return '
- '.$page.'
';- }
- }
-
- 公用函數get_prev_pages ()
- {
- $pages = array();
- $begin = $this->_page - $this->_grep;
- if ( $begin {
- $begin = 1;
- }
- elseif ( $begin > 2 )
- {
- $pages[] = $this->get_page_link( 1 ) ;
- if ( $this->_admin )
- {
- $pages[] = ' ... ';
- }
- else
- {
- $ page[] = '> else
- {
- $ page[] = '
- ...
';- }
- }
- elseif ( $begin == 2 )
- {
- $pages[] = $this->get_page_link( 1 );
- }
- for ( $i = $begin; $i _page; $i++ )
- {
- $pages[] = $this->get_page_link( $i ) ;
- }
- return $pages;
- }
-
- public function get_next_pages ()
- {
- $pages = array( );
- $be = $-me >_page + 1;
- if ( $begin _total_page )
- {
- $end = $begin + $this-> ;_grep;
- if ( $end > $this- >_total_page )
- {
- $end = $this->_total_page;
- }
- for ( $i = $begin ; $i {
- $pages[] = $this->get_page_link( $i );
- }
- if ( $i _total_page )
- {
- if ( $this->_admin )
- {
- $pages[] = ' ... ';
- }
- else
- {
- $pages[] = '
- ...
'; - }
- $pages[] = $this->get_page_link( $ this->_total_page );
- }
- else
- {
- $pages[] = $this->get_page_link->get_page_link ( $this->_total_page );
- }
- }
- elseif ( $begin == $this->_total_page )
- {
- $pages[] = $this->get_page_link( $ this->_total_page );
- }
- return $pages;
- }
-
- public function show ()
- {
- if ( $this->_total_page { 回傳; }
- if ( $this->_admin )
- {
- echo '
- echo '共同'.$this->; _total.'筆記錄';
- }
- else
- {
- echo '
'; - }
- echo $this->get_prev_page_btn();
- $prev_pages = $this->get_prev_pages ();
- if ( !empty( $prev_pages ) );
- if ( !empty( $prev_pages ) ) {
- echo $page;
- }
- }
- echo $this->get_current_page();
- $next_pages = $this->get_next_page ();
- $next_pages = $this->get_next_page ( );
- if ( !empty( $next_pages ) )
- {
- foreach ( $next_pages as $page )
- {
- echo $page;
- }
- }
- echo $page;
- }
- }
- echo $page;
- }
- }
- echo $page;
- }
- }
- echo $this->get_next_page_btn();
- if ( $this->_admin )
{ echo ''; } else { | {
echo '';