2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2014-04-29 05:51:13 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2014-04-29 05:51:13 +00:00
|
|
|
/**
|
|
|
|
* Class Themelet
|
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
class Themelet extends BaseThemelet
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Put something in a rounded rectangle box; specific to the default theme.
|
|
|
|
*/
|
|
|
|
public function rr(string $html): string
|
|
|
|
{
|
|
|
|
return "
|
2010-02-28 20:05:12 +00:00
|
|
|
<div class='tframe'>
|
2010-02-28 11:01:18 +00:00
|
|
|
$html
|
|
|
|
</div>
|
|
|
|
";
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 19:27:23 +00:00
|
|
|
public function display_paginator(Page $page, string $base, ?string $query, int $page_number, int $total_pages, bool $show_random = false)
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
if ($total_pages == 0) {
|
|
|
|
$total_pages = 1;
|
|
|
|
}
|
|
|
|
$body = $this->litetheme_build_paginator($page_number, $total_pages, $base, $query, $show_random);
|
|
|
|
$page->add_block(new Block(null, $body, "main", 90));
|
|
|
|
}
|
|
|
|
|
2020-01-26 13:19:35 +00:00
|
|
|
public function litetheme_gen_page_link(string $base_url, ?string $query, int $page, string $name, ?string $link_class=null): string
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$link = make_link("$base_url/$page", $query);
|
|
|
|
return "<a class='$link_class' href='$link'>$name</a>";
|
|
|
|
}
|
|
|
|
|
2020-01-26 13:19:35 +00:00
|
|
|
public function litetheme_gen_page_link_block(string $base_url, ?string $query, int $page, int $current_page, string $name): string
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$paginator = "";
|
|
|
|
|
|
|
|
if ($page == $current_page) {
|
|
|
|
$link_class = "tab-selected";
|
|
|
|
} else {
|
|
|
|
$link_class = "";
|
|
|
|
}
|
|
|
|
$paginator .= $this->litetheme_gen_page_link($base_url, $query, $page, $name, $link_class);
|
|
|
|
|
|
|
|
return $paginator;
|
|
|
|
}
|
|
|
|
|
2019-06-01 14:47:03 +00:00
|
|
|
public function litetheme_build_paginator(int $current_page, int $total_pages, string $base_url, ?string $query, bool $show_random): string
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$next = $current_page + 1;
|
|
|
|
$prev = $current_page - 1;
|
|
|
|
|
|
|
|
$at_start = ($current_page <= 1 || $total_pages <= 1);
|
|
|
|
$at_end = ($current_page >= $total_pages);
|
|
|
|
|
|
|
|
$first_html = $at_start ? "<span class='tab'>First</span>" : $this->litetheme_gen_page_link($base_url, $query, 1, "First");
|
2021-12-14 18:32:47 +00:00
|
|
|
$prev_html = $at_start ? "<span class='tab'>Prev</span>" : $this->litetheme_gen_page_link($base_url, $query, $prev, "Prev");
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
$random_html = "";
|
|
|
|
if ($show_random) {
|
|
|
|
$rand = mt_rand(1, $total_pages);
|
|
|
|
$random_html = $this->litetheme_gen_page_link($base_url, $query, $rand, "Random");
|
|
|
|
}
|
|
|
|
|
2021-12-14 18:32:47 +00:00
|
|
|
$next_html = $at_end ? "<span class='tab'>Next</span>" : $this->litetheme_gen_page_link($base_url, $query, $next, "Next");
|
|
|
|
$last_html = $at_end ? "<span class='tab'>Last</span>" : $this->litetheme_gen_page_link($base_url, $query, $total_pages, "Last");
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
$start = $current_page-5 > 1 ? $current_page-5 : 1;
|
|
|
|
$end = $start+10 < $total_pages ? $start+10 : $total_pages;
|
|
|
|
|
|
|
|
$pages = [];
|
|
|
|
foreach (range($start, $end) as $i) {
|
2020-02-10 19:11:26 +00:00
|
|
|
$pages[] = $this->litetheme_gen_page_link_block($base_url, $query, $i, $current_page, strval($i));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
$pages_html = implode(" ", $pages);
|
|
|
|
|
|
|
|
return "<div class='paginator sfoot'>
|
2010-02-28 11:01:18 +00:00
|
|
|
$first_html
|
|
|
|
$prev_html
|
|
|
|
$random_html
|
|
|
|
<< $pages_html >>
|
|
|
|
$next_html $last_html
|
|
|
|
</div>";
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2010-02-28 11:01:18 +00:00
|
|
|
}
|