szurubooru/src/Views/paginator.phtml

64 lines
1.9 KiB
PHTML
Raw Normal View History

2013-10-16 13:07:01 +02:00
<?php
$pagesVisible = [];
$pagesVisible []= 1;
$pagesVisible []= $this->context->transport->paginator->pageCount;
$delta = 3;
$pagesVisible = array_merge($pagesVisible, range($this->context->transport->paginator->page - $delta, $this->context->transport->paginator->page + $delta));
$pagesVisible = array_filter($pagesVisible, function($x) { return $x >= 1 and $x <= $this->context->transport->paginator->pageCount; });
$pagesVisible = array_unique($pagesVisible);
sort($pagesVisible, SORT_NUMERIC);
if (!function_exists('pageUrl'))
{
function pageUrl($page)
{
$context = \Chibi\Registry::getContext();
$controller = $context->route->simpleControllerName;
$action = $context->route->simpleActionName;
$page = max(1, $page);
$page = min($context->transport->paginator->pageCount, $page);
$params = $context->route->arguments;
$params['page'] = $page;
return \Chibi\UrlHelper::route($controller, $action, $params);
}
}
?>
<?php if (!empty($pagesVisible)): ?>
<nav class="paginator-wrapper">
<ul class="paginator">
<?php if ($this->context->transport->paginator->page > 1): ?>
<li class="prev">
<?php else: ?>
<li class="prev disabled">
<?php endif ?>
<a href="<?php echo pageUrl($this->context->transport->paginator->page - 1) ?>">
&laquo;
</a>
</li>
<?php foreach ($pagesVisible as $page): ?>
<?php if ($page == $this->context->transport->paginator->page): ?>
<li class="active">
<?php else: ?>
<li>
<?php endif ?>
<a href="<?php echo pageUrl($page) ?>">
<?php echo $page ?>
</a>
</li>
<?php endforeach ?>
<?php if ($this->context->transport->paginator->page < $this->context->transport->paginator->pageCount): ?>
<li class="next">
<?php else: ?>
<li class="next disabled">
<?php endif ?>
<a href="<?php echo pageUrl($this->context->transport->paginator->page + 1) ?>">
&raquo;
</a>
</li>
</ul>
</nav>
<?php endif ?>