class 페이지 매김 독립 페이징 클래스
호출 방법:
$pagenation = new Pagination( 4, 10, 200 ); // 4(첫 번째 매개변수) = currentPage, 10(두 번째 매개변수) = pageSize, 200(세 번째 매개변수) = 총 개수
$pagenation->set_link( 'http://www.360hqb.com' );
$pagenation->show();
- /**
- * 클래스 Pagination
- *
- * 독립 페이징 클래스
- * 호출 방법:
- * $pagenation = new Pagination( 4, 10, 200 ) // 4(첫 번째 매개변수) = currentPage , 10(두 번째 매개변수) = 페이지 크기, 200(세 번째 매개변수) = 총 개수
- * $pagenation->set_link( 'http://www.360hqb.com' );
- * $pagenation-> 표시();
- */
- 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 = ' 페이지 탐색 인라인 블록';
-
- 공개 함수 __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'] );
- }
-
- 공개 함수 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 ( '페이지' == 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;
- }
-
- 공개 함수 set_page_size ( $page_size )
- {
- if ( 비어 있음( $page_size ) )
- {
- $this-> ;_page_size = 10;
- }
- else
- {
- $this->_page_size = (int) $page_size;
- }
- }
-
- 공개 함수 set_total ( $total )
- {
- $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;
- }
- }
-
- 공개 함수 set_current_page( $page )
- {
- if ( 비어 있음( $page ) )
- {
- $this->_page = 1;
- }
- else
- {
- $this-> _page = (int) $page;
- }
- }
-
- 공개 함수 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- >_페이지 1 );
- }
- if ( $this->_admin )
- {
- return '下一页< ;/a>';
- }
- else
- {
- return '
- 下一页
';
- }
- }
- if ( $this->_admin )
- return '下一页 ?';
- else
- return '';
- }
-
- 공개 함수 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 '';
- }
-
- 공개 함수 get_current_page ()
- {
- if ( $this->_admin )
- return ''.$this->_page.'';
- else
- '
- '.$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 < 1 )
- {
- $begin = 1;
- }
- elseif ( $begin > 2 )
- {
- $pages[] = $this->get_page_link( 1 ) ;
- if ( $this->_admin )
- {
- $pages[] = ' ... ';
- }
- else
- {
- $ 페이지[] = '
- ...
';
- }
- }
- elseif ( $begin == 2 )
- {
- $pages[] = $this->get_page_link( 1 );
- }
- for ( $i = $begin; $i < $this->_page; $i )
- {
- $pages[] = $this->get_page_link( $i );
- }
- return $pages;
- }
-
- 공개 함수 get_next_pages()
- {
- $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;
- }
-
- 공개 함수 show ()
- {
- if ( $this->_total_page <= 1 )
- {
- return;
- }
- 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 ) )
- {
- 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 '';
- }
- }
- }
复代码
|