2023-03-11 13:20:59 +01:00
|
|
|
<?php
|
|
|
|
/*****************************************************************************
|
|
|
|
* PageIndexWidget.php
|
|
|
|
* Contains the template that displays a page index.
|
|
|
|
*
|
2023-04-08 21:32:38 +02:00
|
|
|
* Kabuki CMS (C) 2013-2023, Aaron van Geffen
|
2023-03-11 13:20:59 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
class PageIndexWidget extends Template
|
|
|
|
{
|
|
|
|
private $index;
|
|
|
|
private string $class;
|
|
|
|
|
|
|
|
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>';
|
|
|
|
|
|
|
|
foreach ($page_index as $key => $page)
|
|
|
|
{
|
|
|
|
if (!is_numeric($key))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!is_array($page))
|
|
|
|
echo '
|
2023-03-21 23:12:47 +01:00
|
|
|
<li class="page-item page-padding disabled"><a class="page-link">...</a></li>';
|
2023-03-11 13:20:59 +01:00
|
|
|
else
|
|
|
|
echo '
|
2023-03-21 23:12:47 +01:00
|
|
|
<li class="page-item page-number', $page['is_selected'] ? ' active" aria-current="page' : '', '">',
|
2023-03-11 13:20:59 +01:00
|
|
|
'<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>';
|
|
|
|
}
|
|
|
|
}
|