szurubooru/src/Views/post-list.phtml

82 lines
2.5 KiB
PHTML
Raw Normal View History

2013-10-07 23:17:33 +02:00
<?php if (!empty($this->context->transport->errorMessage)): ?>
<p class="alert alert-error"><?php echo $this->context->transport->errorMessage ?></p>
2013-10-09 12:19:42 +02:00
<?php elseif (empty($this->context->transport->posts)): ?>
<p class="alert alert-warning">No posts to show.</p>
2013-10-07 23:17:33 +02:00
<?php else: ?>
2013-10-10 00:12:27 +02:00
<div class="posts paginator-content">
2013-10-09 12:18:22 +02:00
<?php foreach ($this->context->transport->posts as $post): ?>
<a href="<?php echo \Chibi\UrlHelper::route('post', 'view', ['id' => $post['id']]) ?>">
<img src="<?php echo \Chibi\UrlHelper::route('post', 'thumb', ['id' => $post['id']]) ?>" alt="@<?php echo $post['id'] ?>"/>
</a>
<?php endforeach ?>
</div>
2013-10-07 23:17:33 +02:00
<?php endif ?>
2013-10-09 11:45:18 +02:00
<?php
if (!function_exists('pageUrl'))
{
function pageUrl($page)
{
$context = \Chibi\Registry::getContext();
2013-10-09 12:24:25 +02:00
$controller = $context->route->simpleControllerName;
$action = $context->route->simpleActionName;
2013-10-09 11:45:18 +02:00
$page = max(1, $page);
$page = min($context->transport->pageCount, $page);
$params = [];
$params['page'] = $page;
if (!empty($context->transport->searchQuery))
{
$params['query'] = $context->transport->searchQuery;
}
2013-10-09 12:24:25 +02:00
return \Chibi\UrlHelper::route($controller, $action, $params);
2013-10-09 11:45:18 +02:00
}
}
?>
<nav class="paginator-wrapper">
<ul class="paginator">
<?php if ($this->context->transport->page > 1): ?>
2013-10-09 12:18:22 +02:00
<li class="prev">
2013-10-09 11:45:18 +02:00
<?php else: ?>
2013-10-09 12:18:22 +02:00
<li class="prev inactive">
2013-10-09 11:45:18 +02:00
<?php endif ?>
<a href="<?php echo pageUrl($this->context->transport->page - 1) ?>">
&laquo;
</a>
</li>
<?php
$pagesVisible = [];
$pagesVisible []= 1;
$pagesVisible []= $this->context->transport->pageCount;
$delta = 3;
$pagesVisible = array_merge($pagesVisible, range($this->context->transport->page - $delta, $this->context->transport->page + $delta));
$pagesVisible = array_filter($pagesVisible, function($x) { return $x >= 1 and $x <= $this->context->transport->pageCount; });
$pagesVisible = array_unique($pagesVisible);
sort($pagesVisible, SORT_NUMERIC);
?>
<?php foreach ($pagesVisible as $page): ?>
<?php if ($page == $this->context->transport->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->page < $this->context->transport->pageCount): ?>
2013-10-09 12:18:22 +02:00
<li class="next">
2013-10-09 11:45:18 +02:00
<?php else: ?>
2013-10-09 12:18:22 +02:00
<li class="next inactive">
2013-10-09 11:45:18 +02:00
<?php endif ?>
<a href="<?php echo pageUrl($this->context->transport->page + 1) ?>">
&raquo;
</a>
</li>
</ul>
</nav>