diff --git a/core/microhtml.php b/core/microhtml.php
index 4cb1a943..23c895aa 100644
--- a/core/microhtml.php
+++ b/core/microhtml.php
@@ -151,3 +151,20 @@ function SHM_OPTION(string $value, string $text, bool $selected=false): HTMLElem
return OPTION(["value"=>$value], $text);
}
+
+function SHM_POST_INFO(
+ HTMLElement|string $title,
+ bool $can_edit,
+ HTMLElement|string $view,
+ HTMLElement|string $edit = "",
+): HTMLElement {
+ return TR(
+ TH(["width"=>"50px"], $title),
+ $can_edit ?
+ emptyHTML(
+ TD(["class"=>"view"], $view),
+ TD(["class"=>"edit"], $edit),
+ ) :
+ TD($view)
+ );
+}
diff --git a/ext/artists/theme.php b/ext/artists/theme.php
index c367518f..be501636 100644
--- a/ext/artists/theme.php
+++ b/ext/artists/theme.php
@@ -7,17 +7,18 @@ namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML;
-use function MicroHTML\{INPUT,P,SPAN,TD,TH,TR};
+use function MicroHTML\{INPUT,P};
class ArtistsTheme extends Themelet
{
- public function get_author_editor_html(string $author): string
+ public function get_author_editor_html(string $author): HTMLElement
{
- $h_author = html_escape($author);
- return (string)TR(TH("Author", TD(
- SPAN(["class"=>"view"], $h_author),
- INPUT(["class"=>"edit", "type"=>"text", "name"=>"tag_edit__author", "value"=>$h_author])
- )));
+ return SHM_POST_INFO(
+ "Author",
+ true,
+ $author,
+ INPUT(["type"=>"text", "name"=>"tag_edit__author", "value"=>$author])
+ );
}
public function sidebar_options(string $mode, ?int $artistID=null, $is_admin=false): void
diff --git a/ext/image_view_counter/main.php b/ext/image_view_counter/main.php
index 4b79d50e..667d7449 100644
--- a/ext/image_view_counter/main.php
+++ b/ext/image_view_counter/main.php
@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Shimmie2;
+use function MicroHTML\{TD,TH,TR};
+
class ImageViewCounter extends Extension
{
/** @var ImageViewCounterTheme */
@@ -63,15 +65,12 @@ class ImageViewCounter extends Extension
global $user, $database;
if ($user->can(Permissions::SEE_IMAGE_VIEW_COUNTS)) {
- $view_count = (int)$database->get_one(
+ $view_count = (string)$database->get_one(
"SELECT COUNT(*) FROM image_views WHERE image_id =:image_id",
["image_id" => $event->image->id]
);
- $event->add_part(
- "
Views: | $view_count |
",
- 38
- );
+ $event->add_part(SHM_POST_INFO("Views", false, $view_count, ""), 38);
}
}
diff --git a/ext/post_titles/theme.php b/ext/post_titles/theme.php
index aa3c9d35..72ead5c8 100644
--- a/ext/post_titles/theme.php
+++ b/ext/post_titles/theme.php
@@ -4,23 +4,19 @@ declare(strict_types=1);
namespace Shimmie2;
+use MicroHTML\HTMLElement;
+
+use function MicroHTML\{INPUT};
+
class PostTitlesTheme extends Themelet
{
- public function get_title_set_html(string $title, bool $can_set): string
+ public function get_title_set_html(string $title, bool $can_set): HTMLElement
{
- $html = "
-
- Title |
-
- ".($can_set ? "
- ".html_escape($title)."
-
- " : html_escape("
- $title
- "))."
- |
-
- ";
- return $html;
+ return SHM_POST_INFO(
+ "Title",
+ $can_set,
+ $title,
+ INPUT(["type" => "text", "name" => "post_title", "value" => $title])
+ );
}
}
diff --git a/ext/rating/main.php b/ext/rating/main.php
index ba5a4b66..9f222951 100644
--- a/ext/rating/main.php
+++ b/ext/rating/main.php
@@ -203,7 +203,7 @@ class Ratings extends Extension
{
global $user;
$event->add_part(
- (string)$this->theme->get_rater_html(
+ $this->theme->get_rater_html(
$event->image->id,
$event->image->rating,
$user->can(Permissions::EDIT_IMAGE_RATING)
diff --git a/ext/rating/theme.php b/ext/rating/theme.php
index 929a5288..eafcfee0 100644
--- a/ext/rating/theme.php
+++ b/ext/rating/theme.php
@@ -18,22 +18,12 @@ class RatingsTheme extends Themelet
public function get_rater_html(int $image_id, string $rating, bool $can_rate): HTMLElement
{
- $human_rating = Ratings::rating_to_human($rating);
-
- $html = TR(TH("Rating"));
-
- if ($can_rate) {
- $selector = $this->get_selection_rater_html(selected_options: [$rating]);
-
- $html->appendChild(TD(
- SPAN(["class"=>"view"], $human_rating),
- SPAN(["class"=>"edit"], $selector)
- ));
- } else {
- $html->appendChild(TD($human_rating));
- }
-
- return $html;
+ return SHM_POST_INFO(
+ "Rating",
+ $can_rate,
+ Ratings::rating_to_human($rating),
+ $this->get_selection_rater_html("rating", selected_options: [$rating])
+ );
}
public function display_form(array $current_ratings)
diff --git a/ext/relationships/theme.php b/ext/relationships/theme.php
index 96e73cde..67cecc6a 100644
--- a/ext/relationships/theme.php
+++ b/ext/relationships/theme.php
@@ -4,6 +4,10 @@ declare(strict_types=1);
namespace Shimmie2;
+use MicroHTML\HTMLElement;
+
+use function MicroHTML\{TR, TH, TD, emptyHTML, DIV, INPUT};
+
class RelationshipsTheme extends Themelet
{
public function relationship_info(Image $image)
@@ -29,26 +33,16 @@ class RelationshipsTheme extends Themelet
}
}
- public function get_parent_editor_html(Image $image): string
+ public function get_parent_editor_html(Image $image): HTMLElement
{
global $user;
- $h_parent_id = $image->parent_id;
- $s_parent_id = $h_parent_id ?: "None";
-
- $html = "\n".
- " Parent | \n".
- " \n".
- (
- !$user->is_anonymous() ?
- " {$s_parent_id}\n".
- " \n"
- :
- $s_parent_id
- ).
- " | \n".
- " |
\n";
- return $html;
+ return SHM_POST_INFO(
+ "Parent",
+ !$user->is_anonymous(),
+ $image->parent_id ?: "None",
+ INPUT(["type"=>"number", "name"=>"tag_edit__parent", "value"=>$image->parent_id])
+ );
}
diff --git a/ext/rule34/main.php b/ext/rule34/main.php
index ed76e517..2ec39607 100644
--- a/ext/rule34/main.php
+++ b/ext/rule34/main.php
@@ -4,12 +4,10 @@ declare(strict_types=1);
namespace Shimmie2;
-use function MicroHTML\TR;
-use function MicroHTML\TH;
-use function MicroHTML\TD;
-use function MicroHTML\A;
+use function MicroHTML\{emptyHTML, A};
-if ( // kill these glitched requests immediately
+if (
+ // kill these glitched requests immediately
!empty($_SERVER["REQUEST_URI"])
&& str_contains(@$_SERVER["REQUEST_URI"], "/http")
&& str_contains(@$_SERVER["REQUEST_URI"], "paheal.net")
@@ -40,16 +38,19 @@ class Rule34 extends Extension
$image_link = $config->get_string(ImageConfig::ILINK);
$url0 = $event->image->parse_link_template($image_link, 0);
$url1 = $event->image->parse_link_template($image_link, 1);
- $html = (string)TR(
- TH("Links"),
- TD(
- A(["href"=>$url0], "File Only"),
- " (",
- A(["href"=>$url1], "Backup Server"),
- ")"
- )
+ $event->add_part(
+ SHM_POST_INFO(
+ "Links",
+ false,
+ emptyHTML(
+ A(["href" => $url0], "File Only"),
+ " (",
+ A(["href" => $url1], "Backup Server"),
+ ")"
+ )
+ ),
+ 90
);
- $event->add_part($html, 90);
}
public function onAdminBuilding(AdminBuildingEvent $event)
@@ -66,7 +67,7 @@ class Rule34 extends Extension
{
global $database, $user, $config;
if ($user->can(Permissions::CHANGE_SETTING) && $config->get_bool('r34_comic_integration')) {
- $current_state = bool_escape($database->get_one("SELECT comic_admin FROM users WHERE id=:id", ['id'=>$event->display_user->id]));
+ $current_state = bool_escape($database->get_one("SELECT comic_admin FROM users WHERE id=:id", ['id' => $event->display_user->id]));
$this->theme->show_comic_changer($event->display_user, $current_state);
}
}
@@ -128,7 +129,7 @@ class Rule34 extends Extension
]);
$database->execute(
'UPDATE users SET comic_admin=:is_admin WHERE id=:id',
- ['is_admin'=>$input['is_admin'] ? 't' : 'f', 'id'=>$input['user_id']]
+ ['is_admin' => $input['is_admin'] ? 't' : 'f', 'id' => $input['user_id']]
);
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(referer_or(make_link()));
diff --git a/ext/tag_edit/theme.php b/ext/tag_edit/theme.php
index 3d9e18f9..9b9e8010 100644
--- a/ext/tag_edit/theme.php
+++ b/ext/tag_edit/theme.php
@@ -4,6 +4,10 @@ declare(strict_types=1);
namespace Shimmie2;
+use MicroHTML\HTMLElement;
+
+use function MicroHTML\{TR, TH, TD, emptyHTML, rawHTML, joinHTML, DIV, INPUT, A};
+
class TagEditTheme extends Themelet
{
/*
@@ -14,7 +18,7 @@ class TagEditTheme extends Themelet
{
global $page;
$html = "
- ".make_form(make_link("tag_edit/replace"))."
+ " . make_form(make_link("tag_edit/replace")) . "