<?php
<448901948@qq.com>
namespace think\paginator\driver;
use think\Paginator;
class BootstrapDetailed extends Paginator
{
protected function getPreviousButton($text = "上一页")
{
if ($this->currentPage() <= 1) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->url(
$this->currentPage() - 1
);
return $this->getPageLinkWrapper($url, $text);
}
protected function totalshow()
{
$totalhtml="<li class=\"disabled\"><span>共".$this->total."条记录  第".$this->currentPage()."页/共".$this->lastPage()."页</span></li>";
return $totalhtml;
}
protected function showlastpage($text = '尾页')
{
if($this->currentPage()==$this->lastPage())
{
return $this->getDisabledTextWrapper($text);
}
$url = $this->url($this->lastPage());
return $this->getPageLinkWrapper($url, $text);
}
protected function showfirstpage($text = '首页')
{
if($this->currentPage()==1)
{
return $this->getDisabledTextWrapper($text);
}
$url = $this->url(1);
return $this->getPageLinkWrapper($url, $text);
}
protected function afivepage($text = '后五页')
{
if($this->lastPage()<$this->currentPage()+5)
{
return $this->getDisabledTextWrapper($text);
}
$url = $this->url($this->currentPage()+5);
return $this->getPageLinkWrapper($url, $text);
}
protected function bfivepage($text = '前五页')
{
if($this->currentPage()<5)
{
return $this->getDisabledTextWrapper($text);
}
$url = $this->url($this->currentPage()-5);
return $this->getPageLinkWrapper($url, $text);
}
protected function getNextButton($text = '下一页')
{
if (!$this->hasMore) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->url($this->currentPage() + 1);
return $this->getPageLinkWrapper($url, $text);
}
protected function gopage()
{
return $gotohtml="<li><form action='' method='get' ><span><input type='text' name='page'> <input type='submit' value='确定'> </span></form></li>";
}
protected function getLinks()
{
if ($this->simple)
return '';
$block = [
'first' => null,
'slider' => null,
'last' => null
];
$side = 2;
$window = $side * 2;
if ($this->lastPage < $window +1) {
$block['slider'] = $this->getUrlRange(1, $this->lastPage);
} elseif ($this->currentPage <= $window-1) {
$block['slider'] = $this->getUrlRange(1, $window + 1);
} elseif ($this->currentPage > ($this->lastPage - $window+1)) {
$block['slider'] = $this->getUrlRange($this->lastPage - ($window), $this->lastPage);
} else {
$block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side);
}
$html = '';
if (is_array($block['first'])) {
$html .= $this->getUrlLinks($block['first']);
}
if (is_array($block['slider'])) {
$html .= $this->getUrlLinks($block['slider']);
}
if (is_array($block['last'])) {
$html .= $this->getUrlLinks($block['last']);
}
return $html;
}
public function render()
{
if ($this->hasPages()) {
if ($this->simple) {
return sprintf(
'<ul class="pager">%s %s %s</ul>',
$this->getPreviousButton(),
$this->getNextButton()
);
} else {
return sprintf(
'<ul class="pagination"> %s %s %s %s %s %s %s %s </ul>',
$this->totalshow(),
$this->showfirstpage(),
$this->getPreviousButton(),
$this->bfivepage(),
$this->getLinks(),
$this->afivepage(),
$this->getNextButton(),
$this->showlastpage()
);
}
}
}
protected function getAvailablePageWrapper($url, $page)
{
return '<li><a href="' . htmlentities($url) . '">' . $page . '</a></li>';
}
protected function getDisabledTextWrapper($text)
{
return '<li class="disabled"><span>' . $text . '</span></li>';
}
protected function getActivePageWrapper($text)
{
return '<li class="active"><span>' . $text . '</span></li>';
}
protected function getDots($text = '...')
{
return $this->getDisabledTextWrapper('...');
}
protected function getUrlLinks(array $urls)
{
$html = '';
foreach ($urls as $page => $url) {
$html .= $this->getPageLinkWrapper($url, $page);
}
return $html;
}
protected function getPageLinkWrapper($url, $page)
{
if ($page == $this->currentPage()) {
return $this->getActivePageWrapper($page);
}
return $this->getAvailablePageWrapper($url, $page);
}
}