<?php
class
cmtTail{
private
$currentPage
;
private
$totalPage
;
function
__do(
$currentPage
,
$totalPage
) {
$this
->currentPage=
$currentPage
;
$this
->totalPage=
$totalPage
;
if
(
$this
->totalPage<=10){
if
(
$this
->currentPage==1){
$str
='上一页'.
$this
->currentTag();
for
(
$i
= 2;
$i
<=
$this
->totalPage;
$i
++) {
$str
=
$str
.
$this
->commonTag(
$i
);
}
$str
=
$str
.
$this
->next();
}
elseif
(
$this
->currentPage==
$this
->totalPage){
$str
=
$this
->up();
for
(
$i
= 1;
$i
<=
$this
->totalPage-1;
$i
++) {
$str
=
$str
.
$this
->commonTag(
$i
);
}
$str
=
$str
.
$this
->currentTag();
$str
=
$str
.
$this
->next();
}
else
{
$str
=
$this
->up();
for
(
$i
=1;
$i
<
$this
->currentPage;
$i
++){
$str
=
$str
.
$this
->commonTag(
$i
);
}
$str
=
$str
.
$this
->currentTag();
for
(
$i
=
$this
->currentPage+1;
$i
<=
$this
->totalPage;
$i
++) {
$str
=
$str
.
$this
->commonTag(
$i
);
}
$str
=
$str
.
$this
->next();
}
}
elseif
(
$this
->totalPage>10){
if
(
$this
->currentPage==1){
$str
='上一页'.
$this
->currentTag();
for
(
$i
= 2;
$i
<= 8;
$i
++) {
$str
=
$str
.
$this
->commonTag(
$i
);
}
$str
=
$str
.'...';
$str
=
$str
.
$this
->commonTag(
$this
->totalPage-1);
$str
=
$str
.
$this
->commonTag(
$this
->totalPage);
}
elseif
(
$this
->currentPage==
$this
->totalPage) {
$str
=
$this
->up();
$str
=
$str
.
$this
->commonTag(1);
$str
=
$str
.'...';
for
(
$i
=
$this
->totalPage-6;
$i
<
$this
->totalPage;
$i
++) {
$str
=
$str
.
$this
->commonTag(
$i
);
}
$str
=
$str
.
$this
->currentTag();
$str
=
$str
.
$this
->next();
}
else
{
if
(
$this
->currentPage<6) {
$str
=
$this
->up();
for
(
$i
= 1;
$i
<
$this
->currentPage;
$i
++) {
$str
=
$str
.
$this
->commonTag(
$i
);
}
$str
=
$str
.
$this
->currentTag();
for
(
$i
=
$this
->currentPage+1;
$i
<= 7;
$i
++) {
$str
=
$str
.
$this
->commonTag(
$i
);
}
$str
=
$str
.'...';
$str
=
$str
.
$this
->commonTag(
$this
->totalPage);
$str
=
$str
.
$this
->next();
}
else
{
if
(
$this
->currentPage>=
$this
->totalPage-4) {
$str
=
$this
->up();
$str
=
$str
.
$this
->commonTag(1);
$str
=
$str
.'...';
for
(
$i
=
$this
->totalPage-6;
$i
<
$this
->currentPage;
$i
++) {
$str
=
$str
.
$this
->commonTag(
$i
);
}
$str
=
$str
.
$this
->currentTag();
for
(
$i
=
$this
->currentPage+1;
$i
<=
$this
->totalPage;
$i
++) {
$str
=
$str
.
$this
->commonTag(
$i
);
}
$str
=
$str
.
$this
->next();
}
elseif
(
$this
->currentPage<
$this
->totalPage-4){
$str
=
$this
->up();
$str
=
$str
.
$this
->commonTag(1);
$str
=
$str
.'...';
$str
=
$str
.
$this
->commonTag(
$this
->currentPage-2);
$str
=
$str
.
$this
->commonTag(
$this
->currentPage-1);
$str
=
$str
.
$this
->currentTag();
$str
=
$str
.
$this
->commonTag(
$this
->currentPage+1);
$str
=
$str
.
$this
->commonTag(
$this
->currentPage+2);
$str
=
$str
.'...';
$str
=
$str
.
$this
->commonTag(
$this
->totalPage);
$str
=
$str
.
$this
->next();
}
};
}
}
elseif
(
$this
->totalPage<=0){
throw
new
Exception("页面不可能小于1");
}
return
$str
;
}
function
commonTag(
$param
) {
return
'<a page="'.
$param
.'">'.
$param
.'</a>';
}
function
currentTag() {
return
'<strong id="on">'.
$this
->currentPage.'</strong>';
}
function
next() {
if
(
$this
->currentPage==
$this
->totalPage) {
return
'下一页';
}
return
'<a page="'.(
$this
->currentPage+1).'">下一页</a>';
}
function
up() {
if
(
$this
->currentPage==1){
return
'上一页';
}
else
{
return
'<a page="'.(
$this
->currentPage-1).'">上一页</a>';
}
}
static
function
GO(
$currentPage
,
$totalPage
) {
$p
=
new
cmtTail();
return
$p
->__do(
$currentPage
,
$totalPage
);
}
}