クラス ページネーションに依存しないページング クラス
呼び出し方法:
$pagenation = new Pagination( 4, 10, 200 ); // 4(最初のパラメータ) = currentPage, 10(2 番目のパラメータ) = pageSize, 200(3 番目のパラメータ) = 合計数
$pagenation->set_link( 'http://www.360hqb.com' );
$pagenation->show();
- /**
- * class Pagination
- *
- * 独立したページネーション クラス
- * メソッドの呼び出し:
- * $pagenation = new Pagination( 4, 10, 200 ); // 4 (最初のパラメーター) = currentPage, 10 (2 番目のパラメーター) = pageSize, 200 (3 番目のパラメーター) = 合計数
- * $pagenation->set_link( 'http://www.360hqb.com' );
- * $pagenation->show();
- */
- class Java_Pagination
- {
- protected $_total = 0;
- protected $_total_page = 0;
- protected $_page = 1;
- protected $_page_size = 10;
- protected $_link = '';
- protected $_grep = 3;
-
- protected $_admin = false;
- protected $_css_next = '次のページ';
- protected $_css_prev = '前のページ';
- protected $_css_curr = 'curr-page';
- 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 )
- {
- $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' == strto lower( $k ) )
- {
- continue;
- }
- $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 ) )
- {
- $this->gt;_page_size = 10;
- }
- else
- {
- $this-> ;_page_size = (int) $page_size;
- }
- }
-
- public function set_total ( $total )
- {
- $page_size = empty( $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 ( empty( $page ) )
- {
- $this->_page = 1;
- }
- else
- {
- $this->_page = (int) $page;
- }
- }
-
- public function get_next_page_btn ()
- {
- if ( $this-> ;_page < $this->_total_page )
- {
- $link = '';
- if ( strpos( $this->_link, '?' ) )
- {
- $link = $this->_link. '&page='.( $this->_page + 1 );
- }
- else
- {
- $link = $this->_link.'?page='.( $this->_page + 1 );
- }
- if ( $this->gt;_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 )
- return '_page.'';
- else
- return '
- '.$this->_page.'
';
- }
-
- public function 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.' a>
';
- }
- }
-
- public function get_prev_pages ()
- {
- $pages = array();
- $begin = $this->>_page - $this->gt;_grep;
- if ( $begin {
- $begin = 1;
- }
- elseif ( $begin > 2 )
- {
- $pages[] = $this->get_page_link( 1 );
- if ( $this->_admin )
- {
- $pages[] = ' ... ';
- }
- else
- {
- $pages[] = '
- ...< /li>';
- }
- }
- elseif ( $begin == 2 )
- {
- $pages[] = $this->get_page_link( 1 );
- }
- for ( $i = $begin; $i < ; $this->_page; $i++ )
- {
- $pages[] = $this->get_page_link( $i );
- }
- return $pages;
- }
-
- public function get_next_pages ()
- $ページ = array();
- $begin = $this->_page + 1;
- if ( $begin < $this->_total_page )
- {
- $end = $begin + $this->_grep;
- if ( $end > $this->_total_page )
- {
- $end = $this->_total_page;
- }
- for ( $i = $begin; $i < $end; $i++ )
- {
- $pages[] = $this->get_page_link( $i );
- }
- if ( $i < $this->_total_page )
- {
- if ( $this->_admin )
- {
- $pages[ ] = ' ... ';
- }
- else
- {
- $pages[] = '
- ...
';
- }
- $pages[] = $this- >get_page_link( $this->_total_page );
- }
- else
- {
- $pages[] = $this->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 {
- return;
- }
- if ( $this->_admin )
- {
- echo '
- echo '共有'.$this->_total.'条记录 span>';
- }
- else
- {
- echo '
- }
- echo $this->get_prev_page_btn();
- $prev_pages = $this->get_prev_pages ();
- if ( !empty( $prev_pages ) )
- {
- foreach ( $prev_pages as $page )
- {
- echo $page;
- }
- }
- echo $this->get_current_page ();
- $next_pages = $this->get_next_pages ();
- if ( !empty( $next_pages ) )
- {
- foreach ( $next_pages as $page )
- {
- echo $page;
- }
- }
- echo $this->get_next_page_btn();
- if ( $this->_admin )
- {
- echo '';
- }
- else
- {
- echo '';
- }
- }
- }
复制代
|