From a00b522f342e393ec3793f0b4222075f37dfdc87 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 31 Dec 2023 01:10:03 +0000 Subject: [PATCH] [view] more microhtml --- ext/view/theme.php | 57 ++++++++++++++++++---------------- themes/rule34v2/view.theme.php | 38 ++++++++++------------- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/ext/view/theme.php b/ext/view/theme.php index b2dc3583..655bc809 100644 --- a/ext/view/theme.php +++ b/ext/view/theme.php @@ -4,6 +4,10 @@ declare(strict_types=1); namespace Shimmie2; +use MicroHTML\HTMLElement; + +use function MicroHTML\{A, joinHTML, TABLE, TR, TD, INPUT, emptyHTML}; + class ViewImageTheme extends Themelet { public function display_meta_headers(Image $image) @@ -52,14 +56,14 @@ class ViewImageTheme extends Themelet return $query; } - protected function build_pin(Image $image): string + protected function build_pin(Image $image): HTMLElement { $query = $this->get_query(); - $h_prev = "Prev"; - $h_index = "Index"; - $h_next = "Next"; - - return "$h_prev | $h_index | $h_next"; + return joinHTML(" | ", [ + A(["href" => make_link("post/prev/{$image->id}", $query), "id" => "prevlink"], "Prev"), + A(["href" => make_link()], "Index"), + A(["href" => make_link("post/next/{$image->id}", $query), "id" => "nextlink"], "Next"), + ]); } protected function build_navigation(Image $image): string @@ -76,36 +80,35 @@ class ViewImageTheme extends Themelet return "$h_pin
$h_search"; } - protected function build_info(Image $image, $editor_parts): string + protected function build_info(Image $image, $editor_parts): HTMLElement { global $user; if (count($editor_parts) == 0) { - return ($image->is_locked() ? "
[Post Locked]" : ""); + return emptyHTML($image->is_locked() ? "[Post Locked]" : ""); } - $html = make_form(make_link("post/set"))." - - - "; - foreach ($editor_parts as $part) { - $html .= $part; - } - if ( + if( (!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) && $user->can(Permissions::EDIT_IMAGE_TAG) ) { - $html .= " - - "; + $editor_parts[] = TR(TD( + ["colspan" => 4], + INPUT(["class" => "view", "type" => "button", "value" => "Edit", "onclick" => "clearViewMode()"]), + INPUT(["class" => "edit", "type" => "submit", "value" => "Set"]) + )); } - $html .= " -
- - -
- - "; - return $html; + + return SHM_SIMPLE_FORM( + "post/set", + INPUT(["type" => "hidden", "name" => "image_id", "value" => $image->id]), + TABLE( + [ + "class" => "image_info form", + "style" => "width: 500px; max-width: 100%;" + ], + ...$editor_parts, + ), + ); } } diff --git a/themes/rule34v2/view.theme.php b/themes/rule34v2/view.theme.php index 0e4c02d1..85a48fb6 100644 --- a/themes/rule34v2/view.theme.php +++ b/themes/rule34v2/view.theme.php @@ -6,40 +6,36 @@ namespace Shimmie2; use MicroHTML\HTMLElement; -use function MicroHTML\{TR, TH, TD, emptyHTML, rawHTML, joinHTML, DIV, INPUT, A}; +use function MicroHTML\{TR, TH, TD, emptyHTML, rawHTML, joinHTML, DIV, TABLE, INPUT, A}; class CustomViewImageTheme extends ViewImageTheme { // override to make info box always in edit mode - protected function build_info(Image $image, $editor_parts): string + protected function build_info(Image $image, $editor_parts): HTMLElement { global $user; if (count($editor_parts) == 0) { - return ($image->is_locked() ? "
[Post Locked]" : ""); + return emptyHTML($image->is_locked() ? "[Post Locked]" : ""); } - $html = make_form(make_link("post/set"))." - - - "; - foreach ($editor_parts as $part) { - $html .= $part; - } - if ( + if( (!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) && $user->can(Permissions::EDIT_IMAGE_TAG) ) { - $html .= " - - "; + $editor_parts[] = TR(TD(["colspan" => 4], INPUT(["type" => "submit", "value" => "Set"]))); } - $html .= " -
- -
- - "; - return $html; + + return SHM_SIMPLE_FORM( + "post/set", + INPUT(["type" => "hidden", "name" => "image_id", "value" => $image->id]), + TABLE( + [ + "class" => "image_info form", + "style" => "width: 500px; max-width: 100%;" + ], + ...$editor_parts, + ), + ); } }