szurubooru/src/Views/post-list.phtml
Marcin Kurczewski 8fdc90bab7 Worked on #4, #1 and #2
Also:
- enhanced form stylesheets
- W3C validation
2013-10-15 00:41:04 +02:00

81 lines
2.4 KiB
PHTML

<?php if (empty($this->context->transport->posts)): ?>
<p class="alert alert-warning">No posts to show.</p>
<?php else: ?>
<div class="posts paginator-content">
<?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>
<?php endif ?>
<?php
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->pageCount, $page);
$params = [];
$params['page'] = $page;
if ($context->transport->searchQuery != '')
{
$params['query'] = $context->transport->searchQuery;
}
return \Chibi\UrlHelper::route($controller, $action, $params);
}
}
?>
<?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 if (!empty($pagesVisible)): ?>
<nav class="paginator-wrapper">
<ul class="paginator">
<?php if ($this->context->transport->page > 1): ?>
<li class="prev">
<?php else: ?>
<li class="prev disabled">
<?php endif ?>
<a href="<?php echo pageUrl($this->context->transport->page - 1) ?>">
&laquo;
</a>
</li>
<?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): ?>
<li class="next">
<?php else: ?>
<li class="next disabled">
<?php endif ?>
<a href="<?php echo pageUrl($this->context->transport->page + 1) ?>">
&raquo;
</a>
</li>
</ul>
</nav>
<?php endif ?>