more microhtml

This commit is contained in:
Luana 2023-07-10 15:03:54 -03:00 committed by Shish
parent aef5bc9e2e
commit b29d536e19
6 changed files with 52 additions and 63 deletions

View file

@ -4,36 +4,35 @@ declare(strict_types=1);
namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML;
use function MicroHTML\{BR,INPUT};
class AliasEditorTheme extends Themelet
{
/**
* Show a page of aliases.
*
* Note: $can_manage = whether things like "add new alias" should be shown
*/
public function display_aliases($table, $paginator): void
public function display_aliases(HTMLElement $table, HTMLElement $paginator): void
{
global $page, $user;
$can_manage = $user->can(Permissions::MANAGE_ALIAS_LIST);
$html = "
$table
$paginator
<p><a href='".make_link("alias/export/aliases.csv")."' download='aliases.csv'>Download as CSV</a></p>
";
$html = emptyHTML($table, BR(), $paginator, BR(), SHM_A("alias/export/aliases.csv", "Download as CSV", args: ["download"=>"aliases.csv"]));
$bulk_html = "
".make_form(make_link("alias/import"), 'post', true)."
<input type='file' name='alias_file'>
<input type='submit' value='Upload List'>
</form>
";
$bulk_form = SHM_FORM("alias/import", multipart: true);
$bulk_form->appendChild(
INPUT(["type"=>"file", "name"=>"alias_file"]),
SHM_SUBMIT("Upload List")
);
$bulk_html = emptyHTML($bulk_form);
$page->set_title("Alias List");
$page->set_heading("Alias List");
$page->add_block(new NavBlock());
$page->add_block(new Block("Aliases", $html));
if ($can_manage) {
if ($user->can(Permissions::MANAGE_ALIAS_LIST)) {
$page->add_block(new Block("Bulk Upload", $bulk_html, "main", 51));
}
}

View file

@ -168,10 +168,7 @@ class Approval extends Extension
global $user, $config;
if ($event->key===HelpPages::SEARCH) {
if ($user->can(Permissions::APPROVE_IMAGE) && $config->get_bool(ApprovalConfig::IMAGES)) {
$block = new Block();
$block->header = "Approval";
$block->body = $this->theme->get_help_html();
$event->add_block($block);
$event->add_block(new Block("Approval", $this->theme->get_help_html()));
}
}
}
@ -231,7 +228,7 @@ class Approval extends Extension
{
global $user, $config;
if ($user->can(Permissions::APPROVE_IMAGE) && $config->get_bool(ApprovalConfig::IMAGES)) {
$event->add_part($this->theme->get_image_admin_html($event->image));
$event->add_part((string)$this->theme->get_image_admin_html($event->image));
}
}

View file

@ -4,43 +4,40 @@ declare(strict_types=1);
namespace Shimmie2;
use function MicroHTML\BR;
use function MicroHTML\BUTTON;
use function MicroHTML\INPUT;
use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML;
use function MicroHTML\{BUTTON,INPUT,P};
class ApprovalTheme extends Themelet
{
public function get_image_admin_html(Image $image): string
public function get_image_admin_html(Image $image): HTMLElement
{
if ($image->approved===true) {
$html = SHM_SIMPLE_FORM(
$form = SHM_SIMPLE_FORM(
'disapprove_image/'.$image->id,
INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image->id]),
SHM_SUBMIT("Disapprove")
);
} else {
$html = SHM_SIMPLE_FORM(
$form = SHM_SIMPLE_FORM(
'approve_image/'.$image->id,
INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image->id]),
SHM_SUBMIT("Approve")
);
}
return (string)$html;
return $form;
}
public function get_help_html(): string
public function get_help_html(): HTMLElement
{
return '<p>Search for posts that are approved/not approved.</p>
<div class="command_example">
<pre>approved:yes</pre>
<p>Returns posts that have been approved.</p>
</div>
<div class="command_example">
<pre>approved:no</pre>
<p>Returns posts that have not been approved.</p>
</div>
';
return emptyHTML(
P("Search for posts that are approved/not approved."),
SHM_COMMAND_EXAMPLE("approved:yes", "Returns posts that have been approved."),
SHM_COMMAND_EXAMPLE("approved:no", "Returns posts that have not been approved.")
);
}
public function display_admin_block(SetupBuildingEvent $event)
@ -53,12 +50,13 @@ class ApprovalTheme extends Themelet
{
global $page;
$html = (string)SHM_SIMPLE_FORM(
$form = SHM_SIMPLE_FORM(
"admin/approval",
BUTTON(["name"=>'approval_action', "value"=>'approve_all'], "Approve All Posts"),
BR(),
" ",
BUTTON(["name"=>'approval_action', "value"=>'disapprove_all'], "Disapprove All Posts"),
);
$page->add_block(new Block("Approval", $html));
$page->add_block(new Block("Approval", $form));
}
}

View file

@ -57,10 +57,7 @@ class Artists extends Extension
public function onHelpPageBuilding(HelpPageBuildingEvent $event)
{
if ($event->key===HelpPages::SEARCH) {
$block = new Block();
$block->header = "Artist";
$block->body = $this->theme->get_help_html();
$event->add_block($block);
$event->add_block(new Block("Artist", $this->theme->get_help_html()));
}
}

View file

@ -4,20 +4,20 @@ declare(strict_types=1);
namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML;
use function MicroHTML\{INPUT,P,SPAN,TD,TH,TR};
class ArtistsTheme extends Themelet
{
public function get_author_editor_html(string $author): string
{
$h_author = html_escape($author);
return "
<tr>
<th>Author</th>
<td>
<span class='view'>$h_author</span>
<input class='edit' type='text' name='tag_edit__author' value='$h_author'>
</td>
</tr>
";
return (string)TR(TH("Author", TD(
SPAN(["class"=>"view"], $h_author),
INPUT(["class"=>"edit", "type"=>"text", "name"=>"tag_edit__author", "value"=>$h_author])
)));
}
public function sidebar_options(string $mode, ?int $artistID=null, $is_admin=false): void
@ -554,13 +554,11 @@ class ArtistsTheme extends Themelet
return $html;
}
public function get_help_html(): string
public function get_help_html(): HTMLElement
{
return '<p>Search for posts with a particular artist.</p>
<div class="command_example">
<pre>artist=leonardo</pre>
<p>Returns posts with the artist "leonardo".</p>
</div>
';
return emptyHTML(
P("Search for posts with a particular artist."),
SHM_COMMAND_EXAMPLE("artist=leonardo", "Returns posts with the artist \"leonardo\".")
);
}
}

View file

@ -7,7 +7,7 @@ namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML;
use function MicroHTML\{DIV,INPUT,P,PRE,SPAN,TABLE,TD,TH,TR};
use function MicroHTML\{P,SPAN,TABLE,TD,TH,TR};
class RatingsTheme extends Themelet
{