[view] more microhtml

This commit is contained in:
Shish
2023-12-31 01:10:03 +00:00
parent 9c4138399d
commit a00b522f34
2 changed files with 47 additions and 48 deletions

View File

@@ -4,6 +4,10 @@ declare(strict_types=1);
namespace Shimmie2; namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\{A, joinHTML, TABLE, TR, TD, INPUT, emptyHTML};
class ViewImageTheme extends Themelet class ViewImageTheme extends Themelet
{ {
public function display_meta_headers(Image $image) public function display_meta_headers(Image $image)
@@ -52,14 +56,14 @@ class ViewImageTheme extends Themelet
return $query; return $query;
} }
protected function build_pin(Image $image): string protected function build_pin(Image $image): HTMLElement
{ {
$query = $this->get_query(); $query = $this->get_query();
$h_prev = "<a id='prevlink' href='".make_link("post/prev/{$image->id}", $query)."'>Prev</a>"; return joinHTML(" | ", [
$h_index = "<a href='".make_link()."'>Index</a>"; A(["href" => make_link("post/prev/{$image->id}", $query), "id" => "prevlink"], "Prev"),
$h_next = "<a id='nextlink' href='".make_link("post/next/{$image->id}", $query)."'>Next</a>"; A(["href" => make_link()], "Index"),
A(["href" => make_link("post/next/{$image->id}", $query), "id" => "nextlink"], "Next"),
return "$h_prev | $h_index | $h_next"; ]);
} }
protected function build_navigation(Image $image): string protected function build_navigation(Image $image): string
@@ -76,36 +80,35 @@ class ViewImageTheme extends Themelet
return "$h_pin<br>$h_search"; return "$h_pin<br>$h_search";
} }
protected function build_info(Image $image, $editor_parts): string protected function build_info(Image $image, $editor_parts): HTMLElement
{ {
global $user; global $user;
if (count($editor_parts) == 0) { if (count($editor_parts) == 0) {
return ($image->is_locked() ? "<br>[Post Locked]" : ""); return emptyHTML($image->is_locked() ? "[Post Locked]" : "");
} }
$html = make_form(make_link("post/set"))." if(
<input type='hidden' name='image_id' value='{$image->id}'>
<table style='width: 500px; max-width: 100%;' class='image_info form'>
";
foreach ($editor_parts as $part) {
$html .= $part;
}
if (
(!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) && (!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) &&
$user->can(Permissions::EDIT_IMAGE_TAG) $user->can(Permissions::EDIT_IMAGE_TAG)
) { ) {
$html .= " $editor_parts[] = TR(TD(
<tr><td colspan='4'> ["colspan" => 4],
<input class='view' type='button' value='Edit' onclick='clearViewMode()'> INPUT(["class" => "view", "type" => "button", "value" => "Edit", "onclick" => "clearViewMode()"]),
<input class='edit' type='submit' value='Set'> INPUT(["class" => "edit", "type" => "submit", "value" => "Set"])
</td></tr> ));
";
} }
$html .= "
</table> return SHM_SIMPLE_FORM(
</form> "post/set",
"; INPUT(["type" => "hidden", "name" => "image_id", "value" => $image->id]),
return $html; TABLE(
[
"class" => "image_info form",
"style" => "width: 500px; max-width: 100%;"
],
...$editor_parts,
),
);
} }
} }

View File

@@ -6,40 +6,36 @@ namespace Shimmie2;
use MicroHTML\HTMLElement; 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 class CustomViewImageTheme extends ViewImageTheme
{ {
// override to make info box always in edit mode // 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; global $user;
if (count($editor_parts) == 0) { if (count($editor_parts) == 0) {
return ($image->is_locked() ? "<br>[Post Locked]" : ""); return emptyHTML($image->is_locked() ? "[Post Locked]" : "");
} }
$html = make_form(make_link("post/set"))." if(
<input type='hidden' name='image_id' value='{$image->id}'>
<table style='width: 500px; max-width: 100%;' class='image_info form'>
";
foreach ($editor_parts as $part) {
$html .= $part;
}
if (
(!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) && (!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) &&
$user->can(Permissions::EDIT_IMAGE_TAG) $user->can(Permissions::EDIT_IMAGE_TAG)
) { ) {
$html .= " $editor_parts[] = TR(TD(["colspan" => 4], INPUT(["type" => "submit", "value" => "Set"])));
<tr><td colspan='4'>
<input class='edit' type='submit' value='Set'>
</td></tr>
";
} }
$html .= "
</table> return SHM_SIMPLE_FORM(
</form> "post/set",
"; INPUT(["type" => "hidden", "name" => "image_id", "value" => $image->id]),
return $html; TABLE(
[
"class" => "image_info form",
"style" => "width: 500px; max-width: 100%;"
],
...$editor_parts,
),
);
} }
} }