Skip to content

Commit

Permalink
Make SHM_POST_INFO more logical
Browse files Browse the repository at this point in the history
Rather than having a boolean for view or edit + optional editor, use the
existence of the editor to know if a field is editable
  • Loading branch information
shish committed Dec 19, 2023
1 parent 60da9ef commit 4155950
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 63 deletions.
28 changes: 16 additions & 12 deletions core/microhtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
1 change: 0 additions & 1 deletion ext/artists/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])
);
Expand Down
2 changes: 1 addition & 1 deletion ext/image_view_counter/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 1 addition & 2 deletions ext/post_titles/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
3 changes: 1 addition & 2 deletions ext/rating/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
3 changes: 1 addition & 2 deletions ext/relationships/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
1 change: 0 additions & 1 deletion ext/rule34/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event)
$event->add_part(
SHM_POST_INFO(
"Links",
false,
emptyHTML(
A(["href" => $url0], "File Only"),
" (",
Expand Down
14 changes: 5 additions & 9 deletions ext/tag_edit/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand All @@ -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
Expand All @@ -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
);
}

Expand All @@ -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
);
}
}
2 changes: 1 addition & 1 deletion ext/view/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
56 changes: 24 additions & 32 deletions themes/rule34v2/tag_edit.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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("
<tr>
<th width='50px'><a href='".make_link("tag_history/{$image->id}")."'>Tags</a></th>
<td>
<input type='text' name='tag_edit__tags' value='$h_tags'>
</td>
</tr>
");
global $user;
return SHM_POST_INFO(
"Tags",
INPUT([
"type" => "text",
"name" => "tag_edit__tags",
"value" => $image->get_tag_list(),
"autocomplete" => "off"
])
);
}

public function get_source_editor_html(Image $image): HTMLElement
{
global $user;
$h_source = html_escape($image->get_source());
$f_source = $this->format_source($image->get_source());
$style = "overflow: hidden; white-space: nowrap; max-width: 350px; text-overflow: ellipsis;";
return rawHTML("
<tr>
<th><a href='".make_link("source_history/{$image->id}")."'>Source&nbsp;Link</a></th>
<td>
".($user->can("edit_image_source") ? "
<div class='view' style='$style'>$f_source</div>
<input class='edit' type='text' name='tag_edit__source' value='$h_source'>
" : "
<div style='$style'>$f_source</div>
")."
</td>
</tr>
");
return SHM_POST_INFO(
A(["href" => make_link("source_history/{$image->id}")], rawHTML("Source&nbsp;Link")),
emptyHTML(
DIV(
["style" => "overflow: hidden; white-space: nowrap; max-width: 350px; text-overflow: ellipsis;"],
$this->format_source($image->get_source())
),
$user->can(Permissions::EDIT_IMAGE_SOURCE) ? INPUT(["type" => "text", "name" => "tag_edit__source", "value" => $image->get_source()]) : null
)
);
}

public function get_user_editor_html(Image $image): HTMLElement
Expand All @@ -67,13 +62,12 @@ 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
Expand All @@ -92,11 +86,9 @@ public function get_lock_editor_html(Image $image): HTMLElement
global $user;
return SHM_POST_INFO(
"Locked",
$user->can(Permissions::EDIT_IMAGE_LOCK),
emptyHTML(
INPUT(["type" => "checkbox", "name" => "tag_edit__locked", "checked" => $image->is_locked()]),
$image->is_locked() ? "Yes (Only admins may edit these details)" : "No",
),
$user->can(Permissions::EDIT_IMAGE_LOCK) ?
INPUT(["type" => "checkbox", "name" => "tag_edit__locked", "checked" => $image->is_locked()]) :
emptyHTML($image->is_locked() ? "Yes (Only admins may edit these details)" : "No")
);
}
}

0 comments on commit 4155950

Please sign in to comment.