From dbb8bb8280fb5e18f57c8f850ae25534b5904d8c Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 19 Jan 2024 18:57:02 +0000 Subject: [PATCH] have image admin controls block use microhtml consistently --- ext/approval/main.php | 2 +- ext/favorites/main.php | 2 +- ext/featured/theme.php | 4 ++-- ext/handle_pixel/main.php | 4 ++-- ext/image/theme.php | 17 ++++++++++------- ext/image_hash_ban/theme.php | 4 ++-- ext/media/theme.php | 4 ++-- ext/pools/main.php | 2 +- ext/private_image/theme.php | 4 ++-- ext/regen_thumb/theme.php | 4 ++-- ext/replace_file/theme.php | 4 ++-- ext/resize/theme.php | 8 +++++--- ext/rotate/theme.php | 4 ++-- ext/source_history/main.php | 6 ++++-- ext/tag_history/main.php | 6 ++++-- ext/transcode/theme.php | 6 ++++-- ext/transcode_video/theme.php | 6 ++++-- ext/trash/theme.php | 4 ++-- .../events/image_admin_block_building_event.php | 4 ++-- ext/view/theme.php | 9 ++++++--- 20 files changed, 60 insertions(+), 44 deletions(-) diff --git a/ext/approval/main.php b/ext/approval/main.php index d3725580..9417157e 100644 --- a/ext/approval/main.php +++ b/ext/approval/main.php @@ -229,7 +229,7 @@ class Approval extends Extension { global $user, $config; if ($user->can(Permissions::APPROVE_IMAGE) && $config->get_bool(ApprovalConfig::IMAGES)) { - $event->add_part((string)$this->theme->get_image_admin_html($event->image)); + $event->add_part($this->theme->get_image_admin_html($event->image)); } } diff --git a/ext/favorites/main.php b/ext/favorites/main.php index 171f7108..43189490 100644 --- a/ext/favorites/main.php +++ b/ext/favorites/main.php @@ -44,7 +44,7 @@ class Favorites extends Extension ["user_id" => $user_id, "image_id" => $image_id] ) > 0; - $event->add_part((string)$this->theme->get_voter_html($event->image, $is_favorited)); + $event->add_part($this->theme->get_voter_html($event->image, $is_favorited)); } } diff --git a/ext/featured/theme.php b/ext/featured/theme.php index fd9c1e42..d3c5f58d 100644 --- a/ext/featured/theme.php +++ b/ext/featured/theme.php @@ -16,9 +16,9 @@ class FeaturedTheme extends Themelet $page->add_block(new Block("Featured Post", $this->build_featured_html($image), "left", 3)); } - public function get_buttons_html(int $image_id): string + public function get_buttons_html(int $image_id): \MicroHTML\HTMLElement { - return (string)SHM_SIMPLE_FORM( + return SHM_SIMPLE_FORM( "featured_image/set", INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]), INPUT(["type" => 'submit', "value" => 'Feature This']), diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index ba2af98d..9c89e4d3 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -55,7 +55,7 @@ class PixelFileHandler extends DataHandlerExtension public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event): void { if ($event->context == "view") { - $event->add_part(" + $event->add_part(\MicroHTML\rawHTML("
- ", 20); + "), 20); } } } diff --git a/ext/image/theme.php b/ext/image/theme.php index 8b4a99cb..3fceb2d7 100644 --- a/ext/image/theme.php +++ b/ext/image/theme.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shimmie2; -use function MicroHTML\INPUT; +use function MicroHTML\{INPUT, SPAN}; class ImageIOTheme extends Themelet { @@ -12,12 +12,15 @@ class ImageIOTheme extends Themelet * Display a link to delete an image * (Added inline Javascript to confirm the deletion) */ - public function get_deleter_html(int $image_id): string + public function get_deleter_html(int $image_id): \MicroHTML\HTMLElement { - return (string)"".SHM_SIMPLE_FORM( - "image/delete", - INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]), - INPUT(["type" => 'submit', "value" => 'Delete', "onclick" => 'return confirm("Delete the image?");', "id" => "image_delete_button"]), - ).""; + return SPAN( + ["id"=>"image_delete_form"], + SHM_SIMPLE_FORM( + "image/delete", + INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]), + INPUT(["type" => 'submit', "value" => 'Delete', "onclick" => 'return confirm("Delete the image?");', "id" => "image_delete_button"]), + ) + ); } } diff --git a/ext/image_hash_ban/theme.php b/ext/image_hash_ban/theme.php index 7d347d38..3671ac0f 100644 --- a/ext/image_hash_ban/theme.php +++ b/ext/image_hash_ban/theme.php @@ -22,9 +22,9 @@ class ImageBanTheme extends Themelet /* * Display a link to delete an image */ - public function get_buttons_html(Image $image): string + public function get_buttons_html(Image $image): \MicroHTML\HTMLElement { - return (string)SHM_SIMPLE_FORM( + return SHM_SIMPLE_FORM( "image_hash_ban/add", INPUT(["type" => 'hidden', "name" => 'c_hash', "value" => $image->hash]), INPUT(["type" => 'hidden', "name" => 'c_image_id', "value" => $image->id]), diff --git a/ext/media/theme.php b/ext/media/theme.php index ca020597..3438b866 100644 --- a/ext/media/theme.php +++ b/ext/media/theme.php @@ -8,9 +8,9 @@ use function MicroHTML\INPUT; class MediaTheme extends Themelet { - public function get_buttons_html(int $image_id): string + public function get_buttons_html(int $image_id): \MicroHTML\HTMLElement { - return (string)SHM_SIMPLE_FORM( + return SHM_SIMPLE_FORM( "media_rescan/", INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]), SHM_SUBMIT('Scan Media Properties'), diff --git a/ext/pools/main.php b/ext/pools/main.php index c0fc0beb..5308a1fc 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -497,7 +497,7 @@ class Pools extends Extension $pools = $database->get_pairs("SELECT id,title FROM pools WHERE user_id=:id ORDER BY title", ["id" => $user->id]); } if (count($pools) > 0) { - $event->add_part((string)$this->theme->get_adder_html($event->image, $pools)); + $event->add_part($this->theme->get_adder_html($event->image, $pools)); } } } diff --git a/ext/private_image/theme.php b/ext/private_image/theme.php index 44387653..9e8fe687 100644 --- a/ext/private_image/theme.php +++ b/ext/private_image/theme.php @@ -8,7 +8,7 @@ use function MicroHTML\INPUT; class PrivateImageTheme extends Themelet { - public function get_image_admin_html(Image $image): string + public function get_image_admin_html(Image $image): \MicroHTML\HTMLElement { if ($image['private'] === false) { $html = SHM_SIMPLE_FORM( @@ -24,7 +24,7 @@ class PrivateImageTheme extends Themelet ); } - return (string)$html; + return $html; } public function get_help_html(): string diff --git a/ext/regen_thumb/theme.php b/ext/regen_thumb/theme.php index 9a0d2ab1..e6f4a16f 100644 --- a/ext/regen_thumb/theme.php +++ b/ext/regen_thumb/theme.php @@ -11,9 +11,9 @@ class RegenThumbTheme extends Themelet /** * Show a form which offers to regenerate the thumb of an image with ID #$image_id */ - public function get_buttons_html(int $image_id): string + public function get_buttons_html(int $image_id): \MicroHTML\HTMLElement { - return (string)SHM_SIMPLE_FORM( + return SHM_SIMPLE_FORM( "regen_thumb/one", INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]), SHM_SUBMIT('Regenerate Thumbnail') diff --git a/ext/replace_file/theme.php b/ext/replace_file/theme.php index 1eca111c..8fbbb4ca 100644 --- a/ext/replace_file/theme.php +++ b/ext/replace_file/theme.php @@ -66,11 +66,11 @@ class ReplaceFileTheme extends Themelet /** * Display link to replace the image */ - public function get_replace_html(int $image_id): string + public function get_replace_html(int $image_id): \MicroHTML\HTMLElement { $form = SHM_FORM("replace/$image_id", "GET"); $form->appendChild(INPUT(["type" => 'submit', "value" => 'Replace'])); - return (string)$form; + return $form; } protected function get_accept(): string diff --git a/ext/resize/theme.php b/ext/resize/theme.php index 384a27c0..04900c96 100644 --- a/ext/resize/theme.php +++ b/ext/resize/theme.php @@ -4,12 +4,14 @@ declare(strict_types=1); namespace Shimmie2; +use function MicroHTML\{rawHTML}; + class ResizeImageTheme extends Themelet { /* * Display a link to resize an image */ - public function get_resize_html(Image $image): string + public function get_resize_html(Image $image): \MicroHTML\HTMLElement { global $config; @@ -23,7 +25,7 @@ class ResizeImageTheme extends Themelet $default_height = $image->height; } - $html = " + $html = rawHTML(" ".make_form(make_link("resize/{$image->id}"), 'POST')." @@ -33,7 +35,7 @@ class ResizeImageTheme extends Themelet

- "; + "); return $html; } diff --git a/ext/rotate/theme.php b/ext/rotate/theme.php index b5e0ba79..703006ea 100644 --- a/ext/rotate/theme.php +++ b/ext/rotate/theme.php @@ -11,9 +11,9 @@ class RotateImageTheme extends Themelet /** * Display a link to rotate an image. */ - public function get_rotate_html(int $image_id): string + public function get_rotate_html(int $image_id): \MicroHTML\HTMLElement { - return (string)SHM_SIMPLE_FORM( + return SHM_SIMPLE_FORM( 'rotate/'.$image_id, INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]), INPUT(["type" => 'number', "name" => 'rotate_deg', "id" => "rotate_deg", "placeholder" => "Rotation degrees"]), diff --git a/ext/source_history/main.php b/ext/source_history/main.php index 158c5846..8e8417a3 100644 --- a/ext/source_history/main.php +++ b/ext/source_history/main.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Shimmie2; +use function MicroHTML\{rawHTML}; + class SourceHistory extends Extension { /** @var SourceHistoryTheme */ @@ -58,11 +60,11 @@ class SourceHistory extends Extension public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event): void { - $event->add_part(" + $event->add_part(rawHTML("
- ", 20); + "), 20); } /* diff --git a/ext/tag_history/main.php b/ext/tag_history/main.php index a68d54a0..867bac17 100644 --- a/ext/tag_history/main.php +++ b/ext/tag_history/main.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Shimmie2; +use function MicroHTML\rawHTML; + class TagHistory extends Extension { /** @var TagHistoryTheme */ @@ -52,11 +54,11 @@ class TagHistory extends Extension public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event): void { - $event->add_part(" + $event->add_part(rawHTML("
- ", 20); + "), 20); } /* diff --git a/ext/transcode/theme.php b/ext/transcode/theme.php index 171df779..d656181a 100644 --- a/ext/transcode/theme.php +++ b/ext/transcode/theme.php @@ -4,12 +4,14 @@ declare(strict_types=1); namespace Shimmie2; +use function MicroHTML\{rawHTML}; + class TranscodeImageTheme extends Themelet { /* * Display a link to resize an image */ - public function get_transcode_html(Image $image, array $options): string + public function get_transcode_html(Image $image, array $options): \MicroHTML\HTMLElement { $html = " ".make_form( @@ -26,7 +28,7 @@ class TranscodeImageTheme extends Themelet "; - return $html; + return rawHTML($html); } public function get_transcode_picker_html(array $options): string diff --git a/ext/transcode_video/theme.php b/ext/transcode_video/theme.php index 29c8c1de..4340c6b9 100644 --- a/ext/transcode_video/theme.php +++ b/ext/transcode_video/theme.php @@ -4,12 +4,14 @@ declare(strict_types=1); namespace Shimmie2; +use function MicroHTML\{rawHTML}; + class TranscodeVideoTheme extends Themelet { /* * Display a link to resize an image */ - public function get_transcode_html(Image $image, array $options): string + public function get_transcode_html(Image $image, array $options): \MicroHTML\HTMLElement { $html = " ".make_form( @@ -26,7 +28,7 @@ class TranscodeVideoTheme extends Themelet "; - return $html; + return rawHTML($html); } public function get_transcode_picker_html(array $options): string diff --git a/ext/trash/theme.php b/ext/trash/theme.php index 9c65c138..7844722a 100644 --- a/ext/trash/theme.php +++ b/ext/trash/theme.php @@ -8,9 +8,9 @@ use function MicroHTML\INPUT; class TrashTheme extends Themelet { - public function get_image_admin_html(int $image_id): string + public function get_image_admin_html(int $image_id): \MicroHTML\HTMLElement { - return (string)SHM_SIMPLE_FORM( + return SHM_SIMPLE_FORM( 'trash_restore/'.$image_id, INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]), INPUT(["type" => 'submit', "value" => 'Restore From Trash']), diff --git a/ext/view/events/image_admin_block_building_event.php b/ext/view/events/image_admin_block_building_event.php index 9f2fe701..2de8b099 100644 --- a/ext/view/events/image_admin_block_building_event.php +++ b/ext/view/events/image_admin_block_building_event.php @@ -8,7 +8,7 @@ use MicroHTML\HTMLElement; class ImageAdminBlockBuildingEvent extends Event { - /** @var HTMLElement[]|string[] */ + /** @var HTMLElement[] */ public array $parts = []; public Image $image; public User $user; @@ -22,7 +22,7 @@ class ImageAdminBlockBuildingEvent extends Event $this->context = $context; } - public function add_part(HTMLElement|string $html, int $position = 50) + public function add_part(HTMLElement $html, int $position = 50) { while (isset($this->parts[$position])) { $position++; diff --git a/ext/view/theme.php b/ext/view/theme.php index c38ca4c6..30e24457 100644 --- a/ext/view/theme.php +++ b/ext/view/theme.php @@ -6,7 +6,7 @@ namespace Shimmie2; use MicroHTML\HTMLElement; -use function MicroHTML\{A, joinHTML, TABLE, TR, TD, INPUT, emptyHTML}; +use function MicroHTML\{A, joinHTML, TABLE, TR, TD, INPUT, emptyHTML, DIV, BR}; class ViewPostTheme extends Themelet { @@ -41,10 +41,13 @@ class ViewPostTheme extends Themelet } } - public function display_admin_block(Page $page, $parts): void + /** + * @param HTMLElement[] $parts + */ + public function display_admin_block(Page $page, array $parts): void { if (count($parts) > 0) { - $page->add_block(new Block("Post Controls", join("
", $parts), "left", 50)); + $page->add_block(new Block("Post Controls", DIV(["class"=>"post_controls"], joinHTML(BR(), $parts)), "left", 50)); } }