|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace think\paginator\driver; |
|
|
|
|
|
use think\Paginator; |
|
|
|
|
|
class Bootstrap 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 getNextButton($text = '»') |
|
|
{ |
|
|
if (!$this->hasMore) { |
|
|
return $this->getDisabledTextWrapper($text); |
|
|
} |
|
|
|
|
|
$url = $this->url($this->currentPage() + 1); |
|
|
|
|
|
return $this->getPageLinkWrapper($url, $text); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function getLinks() |
|
|
{ |
|
|
if ($this->simple) |
|
|
return ''; |
|
|
|
|
|
$block = [ |
|
|
'first' => null, |
|
|
'slider' => null, |
|
|
'last' => null |
|
|
]; |
|
|
|
|
|
$side = 3; |
|
|
$window = $side * 2; |
|
|
|
|
|
if ($this->lastPage < $window + 6) { |
|
|
$block['first'] = $this->getUrlRange(1, $this->lastPage); |
|
|
} elseif ($this->currentPage <= $window) { |
|
|
$block['first'] = $this->getUrlRange(1, $window + 2); |
|
|
$block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage); |
|
|
} elseif ($this->currentPage > ($this->lastPage - $window)) { |
|
|
$block['first'] = $this->getUrlRange(1, 2); |
|
|
$block['last'] = $this->getUrlRange($this->lastPage - ($window + 2), $this->lastPage); |
|
|
} else { |
|
|
$block['first'] = $this->getUrlRange(1, 2); |
|
|
$block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side); |
|
|
$block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage); |
|
|
} |
|
|
|
|
|
$html = ''; |
|
|
|
|
|
if (is_array($block['first'])) { |
|
|
$html .= $this->getUrlLinks($block['first']); |
|
|
} |
|
|
|
|
|
if (is_array($block['slider'])) { |
|
|
$html .= $this->getDots(); |
|
|
$html .= $this->getUrlLinks($block['slider']); |
|
|
} |
|
|
|
|
|
if (is_array($block['last'])) { |
|
|
$html .= $this->getDots(); |
|
|
$html .= $this->getUrlLinks($block['last']); |
|
|
} |
|
|
|
|
|
return $html; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function render() |
|
|
{ |
|
|
if ($this->hasPages()) { |
|
|
if ($this->simple) { |
|
|
return sprintf( |
|
|
'<ul class="pager">%s %s</ul>', |
|
|
$this->getPreviousButton(), |
|
|
$this->getNextButton() |
|
|
); |
|
|
} else { |
|
|
return sprintf( |
|
|
'<ul class="pagination">%s %s %s</ul>', |
|
|
$this->getPreviousButton(), |
|
|
$this->getLinks(), |
|
|
$this->getNextButton() |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
{ |
|
|
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); |
|
|
} |
|
|
} |
|
|
|