forked from Public/pics
79 lines
2.2 KiB
PHP
79 lines
2.2 KiB
PHP
<?php
|
|
/*****************************************************************************
|
|
* PageIndexWidget.php
|
|
* Contains the template that displays a page index.
|
|
*
|
|
* Kabuki CMS (C) 2013-2023, Aaron van Geffen
|
|
*****************************************************************************/
|
|
|
|
class PageIndexWidget extends Template
|
|
{
|
|
private $index;
|
|
private string $class;
|
|
|
|
private static $unique_index_count = 0;
|
|
|
|
public function __construct(PageIndex $index)
|
|
{
|
|
$this->index = $index;
|
|
$this->class = $index->getPageIndexClass();
|
|
}
|
|
|
|
public function html_main()
|
|
{
|
|
self::paginate($this->index, $this->class);
|
|
}
|
|
|
|
public static function paginate(PageIndex $index, $class = null)
|
|
{
|
|
$page_index = $index->getPageIndex();
|
|
if (empty($page_index) || count($page_index) == 1)
|
|
return;
|
|
|
|
if (!isset($class))
|
|
$class = $index->getPageIndexClass();
|
|
|
|
echo '
|
|
<ul class="pagination', $class ? ' ' . $class : '', '">
|
|
<li class="page-item', empty($page_index['previous']) ? ' disabled' : '', '">',
|
|
'<a class="page-link"', !empty($page_index['previous']) ? ' href="' . $page_index['previous']['href'] . '"' : '', '>',
|
|
'« previous</a></li>';
|
|
|
|
$num_wildcards = 0;
|
|
foreach ($page_index as $key => $page)
|
|
{
|
|
if (!is_numeric($key))
|
|
continue;
|
|
|
|
if (!is_array($page))
|
|
{
|
|
$num_wildcards++;
|
|
echo '
|
|
<li class="page-item page-padding wildcard" onclick="javascript:promptGoToPage(', self::$unique_index_count, ')"><a class="page-link">...</a></li>';
|
|
}
|
|
else
|
|
echo '
|
|
<li class="page-item page-number', $page['is_selected'] ? ' active" aria-current="page' : '', '">',
|
|
'<a class="page-link" href="', $page['href'], '">', $page['index'], '</a></li>';
|
|
}
|
|
|
|
echo '
|
|
<li class="page-item', empty($page_index['next']) ? ' disabled' : '', '">',
|
|
'<a class="page-link"', !empty($page_index['next']) ? ' href="' . $page_index['next']['href'] . '"' : '', '>',
|
|
'next »</a></li>
|
|
</ul>';
|
|
|
|
if ($num_wildcards)
|
|
{
|
|
echo '
|
|
<script type="text/javascript">
|
|
var page_index_', self::$unique_index_count++, ' = {
|
|
wildcard_url: "', $index->getLink("%d"), '",
|
|
num_pages: ', $index->getNumberOfPages(), ',
|
|
per_page: ', $index->getItemsPerPage(), '
|
|
};
|
|
</script>';
|
|
}
|
|
}
|
|
}
|