diff --git a/core/microhtml.php b/core/microhtml.php index aadd633df..e7f4b71e4 100644 --- a/core/microhtml.php +++ b/core/microhtml.php @@ -15,6 +15,7 @@ use function MicroHTML\PRE; use function MicroHTML\P; use function MicroHTML\SELECT; +use function MicroHTML\SPAN; use function MicroHTML\TABLE; use function MicroHTML\THEAD; use function MicroHTML\TFOOT; @@ -154,17 +155,20 @@ function SHM_OPTION(string $value, string $text, bool $selected = false): HTMLEl function SHM_POST_INFO( HTMLElement|string $title, - bool $can_edit, - HTMLElement|string $view, - HTMLElement|string $edit = "", + HTMLElement|string|null $view = null, + HTMLElement|string|null $edit = null, ): HTMLElement { - return TR( - TH(["width" => "50px"], $title), - $can_edit ? - emptyHTML( - TD(["class" => "view"], $view), - TD(["class" => "edit"], $edit), - ) : - TD($view) - ); + if(!is_null($view) && !is_null($edit)) { + $show = emptyHTML( + SPAN(["class" => "view"], $view), + SPAN(["class" => "edit"], $edit), + ); + } elseif(!is_null($edit)) { + $show = $edit; + } elseif(!is_null($view)) { + $show = $view; + } else { + $show = "???"; + } + return TR(TH(["width" => "50px"], $title), TD($show)); } diff --git a/ext/artists/theme.php b/ext/artists/theme.php index 5db8f1e61..12e9e9219 100644 --- a/ext/artists/theme.php +++ b/ext/artists/theme.php @@ -15,7 +15,6 @@ public function get_author_editor_html(string $author): HTMLElement { return SHM_POST_INFO( "Author", - true, $author, INPUT(["type" => "text", "name" => "tag_edit__author", "value" => $author]) ); diff --git a/ext/image_view_counter/main.php b/ext/image_view_counter/main.php index 269bd0950..cb4b945a4 100644 --- a/ext/image_view_counter/main.php +++ b/ext/image_view_counter/main.php @@ -70,7 +70,7 @@ public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) ["image_id" => $event->image->id] ); - $event->add_part(SHM_POST_INFO("Views", false, $view_count, ""), 38); + $event->add_part(SHM_POST_INFO("Views", $view_count), 38); } } diff --git a/ext/post_titles/theme.php b/ext/post_titles/theme.php index 72ead5c88..f468fea23 100644 --- a/ext/post_titles/theme.php +++ b/ext/post_titles/theme.php @@ -14,9 +14,8 @@ public function get_title_set_html(string $title, bool $can_set): HTMLElement { return SHM_POST_INFO( "Title", - $can_set, $title, - INPUT(["type" => "text", "name" => "post_title", "value" => $title]) + $can_set ? INPUT(["type" => "text", "name" => "post_title", "value" => $title]) : null ); } } diff --git a/ext/rating/theme.php b/ext/rating/theme.php index 654e9482b..a3bb0cd0c 100644 --- a/ext/rating/theme.php +++ b/ext/rating/theme.php @@ -20,9 +20,8 @@ public function get_rater_html(int $image_id, string $rating, bool $can_rate): H { return SHM_POST_INFO( "Rating", - $can_rate, A(["href" => search_link(["rating=$rating"])], Ratings::rating_to_human($rating)), - $this->get_selection_rater_html("rating", selected_options: [$rating]) + $can_rate ? $this->get_selection_rater_html("rating", selected_options: [$rating]) : null ); } diff --git a/ext/relationships/theme.php b/ext/relationships/theme.php index 0a8af4a56..9b976a32c 100644 --- a/ext/relationships/theme.php +++ b/ext/relationships/theme.php @@ -39,9 +39,8 @@ public function get_parent_editor_html(Image $image): HTMLElement return SHM_POST_INFO( "Parent", - !$user->is_anonymous(), strval($image->parent_id) ?: "None", - INPUT(["type" => "number", "name" => "tag_edit__parent", "value" => $image->parent_id]) + !$user->is_anonymous() ? INPUT(["type" => "number", "name" => "tag_edit__parent", "value" => $image->parent_id]) : null ); } diff --git a/ext/rule34/main.php b/ext/rule34/main.php index ee3da462b..7eebd6de0 100644 --- a/ext/rule34/main.php +++ b/ext/rule34/main.php @@ -41,7 +41,6 @@ public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) $event->add_part( SHM_POST_INFO( "Links", - false, emptyHTML( A(["href" => $url0], "File Only"), " (", diff --git a/ext/tag_edit/theme.php b/ext/tag_edit/theme.php index 66f4c8a24..b0e9a3d8c 100644 --- a/ext/tag_edit/theme.php +++ b/ext/tag_edit/theme.php @@ -56,16 +56,15 @@ public function get_tag_editor_html(Image $image): HTMLElement return SHM_POST_INFO( "Tags", - $user->can(Permissions::EDIT_IMAGE_TAG), joinHTML(", ", $tag_links), - INPUT([ + $user->can(Permissions::EDIT_IMAGE_TAG) ? INPUT([ "class" => "autocomplete_tags", "type" => "text", "name" => "tag_edit__tags", "value" => $image->get_tag_list(), "id" => "tag_editor", "autocomplete" => "off" - ]) + ]) : null ); } @@ -77,9 +76,8 @@ public function get_user_editor_html(Image $image): HTMLElement $ip = $user->can(Permissions::VIEW_IP) ? rawHTML(" (" . show_ip($image->owner_ip, "Post posted {$image->posted}") . ")") : ""; $info = SHM_POST_INFO( "Uploader", - $user->can(Permissions::EDIT_IMAGE_OWNER), emptyHTML(A(["class" => "username", "href" => make_link("user/$owner")], $owner), $ip, ", ", $date), - INPUT(["type" => "text", "name" => "tag_edit__owner", "value" => $owner]) + $user->can(Permissions::EDIT_IMAGE_OWNER) ? INPUT(["type" => "text", "name" => "tag_edit__owner", "value" => $owner]) : null ); // SHM_POST_INFO returns a TR, let's sneakily append // a TD with the avatar in it @@ -97,12 +95,11 @@ public function get_source_editor_html(Image $image): HTMLElement global $user; return SHM_POST_INFO( "Source", - $user->can(Permissions::EDIT_IMAGE_SOURCE), DIV( ["style" => "overflow: hidden; white-space: nowrap; max-width: 350px; text-overflow: ellipsis;"], $this->format_source($image->get_source()) ), - INPUT(["type" => "text", "name" => "tag_edit__source", "value" => $image->get_source()]) + $user->can(Permissions::EDIT_IMAGE_SOURCE) ? INPUT(["type" => "text", "name" => "tag_edit__source", "value" => $image->get_source()]) : null ); } @@ -127,9 +124,8 @@ public function get_lock_editor_html(Image $image): HTMLElement global $user; return SHM_POST_INFO( "Locked", - $user->can(Permissions::EDIT_IMAGE_LOCK), $image->is_locked() ? "Yes (Only admins may edit these details)" : "No", - INPUT(["type" => "checkbox", "name" => "tag_edit__locked", "checked" => $image->is_locked()]) + $user->can(Permissions::EDIT_IMAGE_LOCK) ? INPUT(["type" => "checkbox", "name" => "tag_edit__locked", "checked" => $image->is_locked()]) : null ); } } diff --git a/ext/view/main.php b/ext/view/main.php index 52e674fb2..0c7b2775d 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -123,7 +123,7 @@ public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) global $config; $image_info = $config->get_string(ImageConfig::INFO); if ($image_info) { - $event->add_part(SHM_POST_INFO("Info", false, $event->image->get_info()), 85); + $event->add_part(SHM_POST_INFO("Info", $event->image->get_info()), 85); } } } diff --git a/themes/rule34v2/tag_edit.theme.php b/themes/rule34v2/tag_edit.theme.php index d1a5138e1..88725ce81 100644 --- a/themes/rule34v2/tag_edit.theme.php +++ b/themes/rule34v2/tag_edit.theme.php @@ -27,36 +27,31 @@ public function display_mass_editor() public function get_tag_editor_html(Image $image): HTMLElement { - $h_tags = html_escape($image->get_tag_list()); - return rawHTML(" -