Skip to content

Commit

Permalink
use joinHTML for paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Aug 17, 2023
1 parent 5879184 commit 91266c5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
19 changes: 3 additions & 16 deletions core/basethemelet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use MicroHTML\HTMLElement;

use function MicroHTML\{A,B,BR,IMG,emptyHTML};
use function MicroHTML\{A,B,BR,IMG,emptyHTML,joinHTML};

/**
* Class BaseThemelet
Expand Down Expand Up @@ -135,19 +135,6 @@ private function gen_page_link_block(string $base_url, ?string $query, int $page
return $paginator;
}

protected function implode(string|HTMLElement $glue, array $pieces): HTMLElement
{
$out = emptyHTML();
$n = 0;
foreach ($pieces as $piece) {
if ($n++ > 0) {
$out->appendChild($glue);
}
$out->appendChild($piece);
}
return $out;
}

private function build_paginator(int $current_page, int $total_pages, string $base_url, ?string $query, bool $show_random): HTMLElement
{
$next = $current_page + 1;
Expand Down Expand Up @@ -175,10 +162,10 @@ private function build_paginator(int $current_page, int $total_pages, string $ba
foreach (range($start, $end) as $i) {
$pages[] = $this->gen_page_link_block($base_url, $query, $i, $current_page, (string)$i);
}
$pages_html = $this->implode(" | ", $pages);
$pages_html = joinHTML(" | ", $pages);

return emptyHTML(
$this->implode(" | ", [
joinHTML(" | ", [
$first_html,
$prev_html,
$random_html,
Expand Down
6 changes: 3 additions & 3 deletions themes/danbooru/themelet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use MicroHTML\HTMLElement;

use function MicroHTML\{A, B, DIV};
use function MicroHTML\{A, B, DIV, joinHTML};

class Themelet extends BaseThemelet
{
Expand Down Expand Up @@ -54,7 +54,7 @@ private function build_paginator(int $current_page, int $total_pages, string $ba
foreach (range($start, $end) as $i) {
$pages[] = $this->gen_page_link_block($base_url, $query, $i, $current_page, (string)$i);
}
$pages_html = $this->implode(" ", $pages);
$pages_html = joinHTML(" ", $pages);

if ($first_html) {
$pdots = "...";
Expand All @@ -68,6 +68,6 @@ private function build_paginator(int $current_page, int $total_pages, string $ba
$ndots = "";
}

return DIV(["id"=>'paginator'], $this->implode(" ", [$prev_html, $first_html, $pdots, $pages_html, $ndots, $last_html, $next_html]));
return DIV(["id"=>'paginator'], joinHTML(" ", [$prev_html, $first_html, $pdots, $pages_html, $ndots, $last_html, $next_html]));
}
}
6 changes: 3 additions & 3 deletions themes/danbooru2/themelet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use MicroHTML\HTMLElement;

use function MicroHTML\{A,B,DIV};
use function MicroHTML\{A,B,DIV,joinHTML};

class Themelet extends BaseThemelet
{
Expand Down Expand Up @@ -54,7 +54,7 @@ private function build_paginator(int $current_page, int $total_pages, string $ba
foreach (range($start, $end) as $i) {
$pages[] = $this->gen_page_link_block($base_url, $query, $i, $current_page, (string)$i);
}
$pages_html = $this->implode(" ", $pages);
$pages_html = joinHTML(" ", $pages);

if ($first_html) {
$pdots = "...";
Expand All @@ -68,6 +68,6 @@ private function build_paginator(int $current_page, int $total_pages, string $ba
$ndots = "";
}

return DIV(["id"=>"paginator"], $this->implode(" ", [$prev_html, $first_html, $pdots, $pages_html, $ndots, $last_html, $next_html]));
return DIV(["id"=>"paginator"], joinHTML(" ", [$prev_html, $first_html, $pdots, $pages_html, $ndots, $last_html, $next_html]));
}
}
4 changes: 2 additions & 2 deletions themes/lite/themelet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use MicroHTML\HTMLElement;

use function MicroHTML\{A,DIV,SPAN};
use function MicroHTML\{A,DIV,SPAN,joinHTML};

/**
* Class Themelet
Expand Down Expand Up @@ -83,7 +83,7 @@ public function litetheme_build_paginator(int $current_page, int $total_pages, s
$prev_html,
$random_html,
"<< ",
$this->implode(" ", $pages),
joinHTML(" ", $pages),
" >>",
$next_html,
$last_html
Expand Down

0 comments on commit 91266c5

Please sign in to comment.