/*
* Template Paging class, from the easp tutorial of the Database tutorial paging method, is easp pagination of the PHP standalone version
* Support dynamic and static paging mode
* Easp official website http://easp.lengshi.com/
* Author: Zhongjingjing
* Date: 2010-11-3
* Email: zhongjingjing@gmail.com
* Blog: http://blog.zaimer.com
* page ([total number of records =1],[page size =20],[current page =1],[show pages =6],[Paging parameter = ' page '],[paging link = Current page],[whether static =false])
Dynamic
* Simple usage:
* $page = new page (50);
* $page->setpager (' zjj ', ' Total {RecordCount}} products current {pageindex} page/Total {PageCount} page pagination: {first}{prev} {list} {Next}{last} Go to {Jump} page ', Array ("Listlong" = "6", "First" = "Home", "last" = "End", "prev" = "prev", "Next" = "Next", "list" = > "page", "Jump" = "select");
* Echo $page->getpager (' zjj ');
* Full parameter usage:
* $page = new page (50,20,1,6, ' page ', ' prrr.php ', false);
* $page->setpager (' zjj ', ' Total {RecordCount}} products current {pageindex} page/Total {PageCount} page pagination: {first}{prev} {list} {Next}{last} Go to {Jump} page ', Array ("Listlong" = "6", "First" = "Home", "last" = "End", "prev" = "prev", "Next" = "Next", "list" = > "page", "Jump" = "select");
* Echo $page->getpager (' zjj ');
Static
* $page = new page (50,20,1,6, ' page ', ' prrr{page}.html ', true);
* $page->setpager (' zjj ', ' Total {RecordCount}} products current {pageindex} page/Total {PageCount} page pagination: {first}{prev} {list} {Next}{last} Go to {Jump} page ', Array ("Listlong" = "6", "First" = "Home", "last" = "End", "prev" = "prev", "Next" = "Next", "list" = > "page", "Jump" = "select");
* Echo $page->getpager (' zjj ');
*/
Class Page {
Private $page _size; The number of entries displayed per page
Private $total _size; Total number of entries
Private $current _page; The page that is currently selected
Private $sub _pages; Number of pages per display
Private $total _pages; Total pages
Private $page _TPL = Array (); Pagination Template
Private $pageparam;
Private $pagelink;
Private $static;
function __construct ($total _size = 1, $page _size = $, $current _page = 1, $sub _pages = 6, $pageparam = ' page ', $pagelink = ", $static = False) {
$this->page_size = intval ($page _size);
$this->total_size = intval ($total _size);
if (! $current _page) {
$this->current_page = 1;
} else {
$this->current_page = intval ($current _page);
}
$this->total_pages = ceil ($total _size/$page _size);
$this->sub_pages = intval ($sub _pages);
$this->pageparam = $pageparam;
$this->pagelink = (empty ($pagelink)? $_server ["Php_self"]: $pagelink);
$this->static = $static;
$this->page_tpl [' default '] = Array (' TPL ' = ' = ' {first}{prev}{liststart}{list}{listend}{next}{last} jumps to {jump} page ', ' config ' = = array ());
}
Public Function __set ($param, $value) {
$this $param = $value;
}
Public Function __get ($param) {
return $this $param;
}
/*
The __destruct destructor is called when the class is not in use, and the function is used to free resources.
*/
function __destruct () {
unset ($page _size); The number of entries displayed per page
unset ($total _size); Total number of entries
unset ($current _page); The page that is currently selected
unset ($sub _pages); Number of pages per display
unset ($total _pages); Total pages
unset ($page _tpl); Pagination Template
Unset ($pageparam); Paging parameters, default page
Unset ($pagelink);
Unset ($static);
}
Private Function urlparameters ($url = Array ()) {
foreach ($url as $key = = $val) {
if ($key! = $this->pageparam)
$arg [] = $key. '=' . $val;
}
$arg [] = $this->pageparam. '=*';
if ($this->static)
Return Str_replace (' {page} ', ' * ', $this->pagelink);
Else
Return $this->pagelink. '?' . Implode (' & ', $arg);
}
Public Function Setpager ($tpl _name = ' Default ', $tpl = ', $config = Array ()) {
if (empty ($TPL))
$TPL = $this->page_tpl [' Default '] [' TPL '];
if (empty ($config))
$config = $this->page_tpl [' Default '] [' config '];
$this->page_tpl [$tpl _name] = array (' TPL ' = = $tpl, ' config ' = = $config);
}
Public Function Getpager ($tpl _name = ' default ') {
$this->getcurrentpage ();
return $this->pager ($this->page_tpl [$tpl _name]);
}
Public Function Getcurrentpage () {
$this->current_page = ($_get [$this->pageparam] <= intval ($this->total_pages)? ($_get [$this->pageparam] < 1 1: $_get [$this->pageparam]): Intval ($this->total_pages));
}
Public Function Pager ($page _TPL = ") {
if (Empty ($page _tpl))
$page _TPL = $this->page_tpl [' Default '];
$cfg = Array (' RecordCount ' = intval ($this->total_size), ' pageindex ' = intval ($this->current_page), ' p Agecount ' + intval ($this->total_pages), ' pagesize ' + intval ($this->page_size), ' listlong ' = intval ($this->sub_pages), ' Listsidelong ' + 2, ' list ' = ' * ', ' currentclass ' + ' current ', ' link ' and ' = ' $this-> ; Urlparameters ($_get), ' first ' = ' «', ' prev ' + ' ‹ ', ' Next ' + ' › ', ' last ' + '» ', ' more ' = ' ... ', ' di Sabledclass ' + ' disabled ', ' jump ' = ' input ', ' jumpplus ' + ' ', ' jumpaction ' + ' ', ' jumplong ' and ' = 50 ';
if (! empty ($page _tpl [' config '])) {
foreach ($page _tpl [' config '] as $key = + $val) {
if (Array_key_exists ($key, $cfg))
$cfg [$key] = $val;
}
}
$tmps Tutorial tr = $page _tpl [' TPL '];
$pstart = $cfg [' pageindex ']-(($cfg [' Listlong ']/2) + ($cfg [' Listlong ']% 2)) + 1;
$pend = $cfg [' pageindex '] + $cfg [' Listlong ']/2;
if ($pstart < 1) {
$pstart = 1;
$pend = $cfg [' Listlong '];
}
if ($pend > $cfg [' PageCount ']) {
$pstart = $cfg [' PageCount ']-$cfg [' Listlong '] + 1;
$pend = $cfg [' PageCount '];
}
if ($pstart < 1)
$pstart = 1;
for ($i = $pstart; $i <= $pend; $i + +) {
if ($i = = $cfg [' pageindex '])
$plist. = ' '. Str_replace (' * ', $i, $cfg [' List ']). '';
Else
$plist. = '. Str_replace (' * ', $i, $cfg [' List ']). ' ';
}
if ($cfg [' Listsidelong '] > 0) {
if ($cfg [' Listsidelong '] < $pstart) {
for ($i = 1; $i <= $cfg [' Listsidelong ']; $i + +) {
$pliststart. = '. Str_replace (' * ', $i, $cfg [' List ']). ' ';
}
$pliststart. = ($cfg [' Listsidelong '] + 1) = = $pstart? ": $cfg [' more ']. ' ';
} else {
if ($cfg [' Listsidelong '] >= $pstart && $pstart > 1) {
for ($i = 1; $i <= ($pstart-1); $i + +) {
$pliststart. = '. Str_replace (' * ', $i, $cfg [' List ']). ' ';
}
}
}
if ($cfg [' PageCount ']-$cfg [' Listsidelong ']) > $pend) {
$plistend = '. $cfg [' More ']. $plistend;
for ($i = ($cfg [' PageCount ']-$cfg [' Listsidelong ']) + 1); $i <= $cfg [' PageCount ']; $i + +) {
$plistend. = '. Str_replace (' * ', $i, $cfg [' List ']). ' ';
}
} else {
if ($cfg [' PageCount ']-$cfg [' Listsidelong ']) <= $pend && $pend < $cfg [' PageCount ']) {
for ($i = ($pend + 1), $i <= $cfg [' PageCount ']; $i + +) {
$plistend. = '. Str_replace (' * ', $i, $cfg [' List ']). ' ';
}
}
}
}
if ($cfg [' pageindex '] > 1) {
$pfirst = '. $cfg [' first ']. ' ';
$pprev = '. $cfg [' prev ']. ' ';
} else {
$pfirst = ' '. $cfg [' first ']. '';
$pprev = ' '. $cfg [' prev ']. '';
}
if ($cfg [' pageindex '] < $cfg [' PageCount ']) {
$plast = '. $cfg [' last ']. ' ';
$pnext = '. $cfg [' Next ']. ' ';
} else {
$plast = ' '. $cfg [' last ']. '';
$pnext = ' '. $cfg [' Next ']. '';
}
Switch (Strtolower ($cfg [' jump ')]) {
Case ' input ':
$pjumpvalue = ' This.value ';
$pjump = '
$pjump. = ' onkeydown= ' web effects: if (event.charcode==13| | event.keycode==13) {if (!isnan ('. $pjumpvalue. ')){';
$pjump. = ($cfg [' jumpaction '] = = '? ((Strtolower (substr ($cfg [' link '], 0, one)) = = ' javascript: ')? Str_replace (' * ', $pjumpvalue, substr ($cfg [' link ') ]): "Document.location.href= '". Str_replace (' * ', ' + '. $pjumpvalue. ' + ', $cfg [' link ']). '';') : Str_replace ("*", $pjumpvalue, $cfg [' jumpaction ']));
$pjump. = '}return false;} ' /> ';
Break
Case ' SELECT ':
$pjumpvalue = "This.options[this.selectedindex].value";
$pjump = ' $pjump. = ' "title=" Please select the number of pages to jump to ">";
if ($cfg [' jumplong '] = = 0) {
for ($i = 0; $i <= $cfg [' PageCount ']; $i + +) {
$pjump. = ' ' . $i. '';
}
} else {
$pjumplong = Intval ($cfg [' Jumplong ']/2);
$pjumpstart = (($cfg [' pageindex ']-$pjumplong) < 1)? 1: ($cfg [' pageindex ']-$pjumplong));
$pjumpstart = (($cfg [' PageCount ']-$cfg [' pageindex ']) < $pjumplong)? ($pjumpstart-($pjumplong-($cfg [' PageCount ']-$cfg [' pageindex ']) + 1): $pjumpstart);
$pjumpstart = (($pjumpstart < 1)? 1: $pjumpstart);
$j = 1;
for ($i = $pjumpstart; $i <= $cfg [' pageindex ']; $i + +, $j + +) {
$pjump. = ' ' . $i. '';
}
$pjumplong = $cfg [' PageCount ']-$cfg [' pageindex '] < $pjumplong? $pjumplong: $pjumplong + ($pjumplong-$j) + 1;
$pjumpend = $cfg [' pageindex '] + $pjumplong > $cfg [' PageCount ']? $cfg [' PageCount ']: $cfg [' pageindex '] + $pjumplong;
for ($i = $cfg [' pageindex '] + 1; $i <= $pjumpend; $i + +) {
$pjump. = ' ' . $i. '';
}
}
$pjump. = '';
Break
}
$patterns = Array ('/{recordcount}/', '/{pagecount}/', '/{pageindex}/', '/{pagesize}/', '/{list}/', '/{liststart}/', '/ {listend}/', '/{first}/', '/{prev}/', '/{next}/', '/{last}/', '/{jump}/');
$replace = Array ($cfg [' RecordCount '], $cfg [' PageCount '], $cfg [' pageindex '], $cfg [' pagesize '], $plist, $pliststart, $p Listend, $pfirst, $pprev, $pnext, $plast, $pjump);
$TMPSTR = Chr (13). Chr (10). Preg_replace ($patterns, $replace, $tmpstr). Chr (13). Chr (10);
Unset ($CFG);
return $tmpstr;
}
}
?>
http://www.bkjia.com/PHPjc/631735.html www.bkjia.com true http://www.bkjia.com/PHPjc/631735.html techarticle PHP Tutorial/* * Template Paging class, from the easp tutorial of the Database tutorial paging method, is easp pagination of the PHP Independent version * Support dynamic and static paging method * Easp official website Http://easp.leng ...