forms
This commit is contained in:
parent
50f3d04f0c
commit
4bd1d8b6ee
10 changed files with 100 additions and 83 deletions
|
@ -32,7 +32,7 @@ class Block
|
|||
/**
|
||||
* How far down the section the block should appear, higher
|
||||
* numbers appear lower. The scale is 0-100 by convention,
|
||||
* though any number or string will work.
|
||||
* though any number will work.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -711,6 +711,11 @@ function SHM_SIMPLE_FORM($target, ...$children)
|
|||
return $form;
|
||||
}
|
||||
|
||||
function SHM_SUBMIT(string $text)
|
||||
{
|
||||
return INPUT(["type"=>"submit", "value"=>$text]);
|
||||
}
|
||||
|
||||
function SHM_COMMAND_EXAMPLE(string $ex, string $desc)
|
||||
{
|
||||
return DIV(
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\INPUT;
|
||||
|
||||
class AdminPageTheme extends Themelet
|
||||
{
|
||||
|
@ -50,10 +51,11 @@ class AdminPageTheme extends Themelet
|
|||
}
|
||||
$page->add_block(new Block("Misc Admin Tools", $html));
|
||||
|
||||
$html = make_form(make_link("admin/set_tag_case"), "POST");
|
||||
$html .= "<input type='text' name='tag' placeholder='Enter tag with correct case' class='autocomplete_tags' autocomplete='off'>";
|
||||
$html .= "<input type='submit' value='Set Tag Case'>";
|
||||
$html .= "</form>\n";
|
||||
$html = (string)SHM_SIMPLE_FORM(
|
||||
make_link("admin/set_tag_case"),
|
||||
INPUT(["type"=>'text', "name"=>'tag', "placeholder"=>'Enter tag with correct case', "class"=>'autocomplete_tags', "autocomplete"=>'off']),
|
||||
SHM_SUBMIT('Set Tag Case'),
|
||||
);
|
||||
$page->add_block(new Block("Set Tag Case", $html));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,27 @@
|
|||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\BR;
|
||||
use function MicroHTML\BUTTON;
|
||||
use function MicroHTML\INPUT;
|
||||
|
||||
class ApprovalTheme extends Themelet
|
||||
{
|
||||
public function get_image_admin_html(Image $image)
|
||||
{
|
||||
if ($image->approved===true) {
|
||||
$html = "
|
||||
".make_form(make_link('disapprove_image/'.$image->id), 'POST')."
|
||||
<input type='hidden' name='image_id' value='$image->id'>
|
||||
<input type='submit' value='Disapprove'>
|
||||
</form>
|
||||
";
|
||||
$html = SHM_SIMPLE_FORM(
|
||||
make_link('disapprove_image/'.$image->id),
|
||||
INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image->id]),
|
||||
SHM_SUBMIT("Disapprove")
|
||||
);
|
||||
} else {
|
||||
$html = "
|
||||
".make_form(make_link('approve_image/'.$image->id), 'POST')."
|
||||
<input type='hidden' name='image_id' value='$image->id'>
|
||||
<input type='submit' value='Approve'>
|
||||
</form>
|
||||
";
|
||||
$html = SHM_SIMPLE_FORM(
|
||||
make_link('approve_image/'.$image->id),
|
||||
INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image->id]),
|
||||
SHM_SUBMIT("Approve")
|
||||
);
|
||||
}
|
||||
|
||||
return $html;
|
||||
return (string)$html;
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,11 +31,11 @@ class ApprovalTheme extends Themelet
|
|||
<div class="command_example">
|
||||
<pre>approved:yes</pre>
|
||||
<p>Returns images that have been approved.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="command_example">
|
||||
<pre>approved:no</pre>
|
||||
<p>Returns images that have not been approved.</p>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
|
@ -49,10 +50,12 @@ class ApprovalTheme extends Themelet
|
|||
{
|
||||
global $page;
|
||||
|
||||
$html = make_form(make_link("admin/approval"), "POST");
|
||||
$html .= "<button name='approval_action' value='approve_all'>Approve All Images</button><br/>";
|
||||
$html .= "<button name='approval_action' value='disapprove_all'>Disapprove All Images</button>";
|
||||
$html .= "</form>\n";
|
||||
$html = (string)SHM_SIMPLE_FORM(
|
||||
make_link("admin/approval"),
|
||||
BUTTON(["name"=>'approval_action', "value"=>'approve_all'], "Approve All Images"),
|
||||
BR(),
|
||||
BUTTON(["name"=>'approval_action', "value"=>'disapprove_all'], "Disapprove All Images"),
|
||||
);
|
||||
$page->add_block(new Block("Approval", $html));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\INPUT;
|
||||
|
||||
class FeaturedTheme extends Themelet
|
||||
{
|
||||
|
@ -9,14 +10,11 @@ class FeaturedTheme extends Themelet
|
|||
|
||||
public function get_buttons_html(int $image_id): string
|
||||
{
|
||||
global $user;
|
||||
return "
|
||||
".make_form(make_link("featured_image/set"))."
|
||||
".$user->get_auth_html()."
|
||||
<input type='hidden' name='image_id' value='{$image_id}'>
|
||||
<input type='submit' value='Feature This'>
|
||||
</form>
|
||||
";
|
||||
return (string)SHM_SIMPLE_FORM(
|
||||
make_link("featured_image/set"),
|
||||
INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image_id]),
|
||||
INPUT(["type"=>'submit', "value"=>'Feature This']),
|
||||
);
|
||||
}
|
||||
|
||||
public function build_featured_html(Image $image, ?string $query=null): string
|
||||
|
|
|
@ -136,7 +136,6 @@ class Media extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
|
||||
{
|
||||
global $user;
|
||||
|
@ -145,11 +144,9 @@ class Media extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event)
|
||||
{
|
||||
global $user;
|
||||
|
||||
if ($user->can(Permissions::RESCAN_MEDIA)) {
|
||||
$event->add_action("bulk_media_rescan", "Scan Media Properties");
|
||||
}
|
||||
|
@ -282,11 +279,9 @@ class Media extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public function onTagTermParse(TagTermParseEvent $event)
|
||||
{
|
||||
$matches = [];
|
||||
|
||||
if (preg_match(self::CONTENT_SEARCH_TERM_REGEX, strtolower($event->term), $matches) && $event->parse) {
|
||||
$event->metatag = true;
|
||||
}
|
||||
|
@ -466,7 +461,7 @@ class Media extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
public static function determine_ext(String $format): String
|
||||
public static function determine_ext(string $format): string
|
||||
{
|
||||
$format = self::normalize_format($format);
|
||||
switch ($format) {
|
||||
|
@ -599,8 +594,8 @@ class Media extends Extension
|
|||
}
|
||||
|
||||
public static function image_resize_convert(
|
||||
String $input_path,
|
||||
String $input_type,
|
||||
string $input_path,
|
||||
string $input_type,
|
||||
int $new_width,
|
||||
int $new_height,
|
||||
string $output_filename,
|
||||
|
@ -687,7 +682,7 @@ class Media extends Extension
|
|||
* @throws InsufficientMemoryException if the estimated memory usage exceeds the memory limit.
|
||||
*/
|
||||
public static function image_resize_gd(
|
||||
String $image_filename,
|
||||
string $image_filename,
|
||||
array $info,
|
||||
int $new_width,
|
||||
int $new_height,
|
||||
|
@ -847,7 +842,7 @@ class Media extends Extension
|
|||
* @param String $image_filename The path of the file to check.
|
||||
* @return bool true if the file is an animated gif, false if it is not.
|
||||
*/
|
||||
public static function is_animated_gif(String $image_filename): bool
|
||||
public static function is_animated_gif(string $image_filename): bool
|
||||
{
|
||||
$is_anim_gif = 0;
|
||||
if (($fh = @fopen($image_filename, 'rb'))) {
|
||||
|
@ -865,7 +860,7 @@ class Media extends Extension
|
|||
}
|
||||
|
||||
|
||||
private static function compare_file_bytes(String $file_name, array $comparison): bool
|
||||
private static function compare_file_bytes(string $file_name, array $comparison): bool
|
||||
{
|
||||
$size = filesize($file_name);
|
||||
if ($size < count($comparison)) {
|
||||
|
@ -897,17 +892,17 @@ class Media extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
public static function is_animated_webp(String $image_filename): bool
|
||||
public static function is_animated_webp(string $image_filename): bool
|
||||
{
|
||||
return self::compare_file_bytes($image_filename, self::WEBP_ANIMATION_HEADER);
|
||||
}
|
||||
|
||||
public static function is_lossless_webp(String $image_filename): bool
|
||||
public static function is_lossless_webp(string $image_filename): bool
|
||||
{
|
||||
return self::compare_file_bytes($image_filename, self::WEBP_LOSSLESS_HEADER);
|
||||
}
|
||||
|
||||
public static function supports_alpha(string $format)
|
||||
public static function supports_alpha(string $format): bool
|
||||
{
|
||||
return in_array(self::normalize_format($format), self::ALPHA_FORMATS);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\INPUT;
|
||||
use function MicroHTML\TABLE;
|
||||
use function MicroHTML\TR;
|
||||
use function MicroHTML\TH;
|
||||
use function MicroHTML\TD;
|
||||
use function MicroHTML\SELECT;
|
||||
use function MicroHTML\OPTION;
|
||||
|
||||
class MediaTheme extends Themelet
|
||||
{
|
||||
|
@ -6,27 +13,31 @@ class MediaTheme extends Themelet
|
|||
{
|
||||
global $page;
|
||||
|
||||
$html = "Use this to force scanning for media properties.";
|
||||
$html .= make_form(make_link("admin/media_rescan"));
|
||||
$html .= "<table class='form'>";
|
||||
$html .= "<tr><th>Image Type</th><td><select name='media_rescan_type'><option value=''>All</option>";
|
||||
$select = SELECT(["name"=>"media_rescan_type"]);
|
||||
$select->appendChild(OPTION(["value"=>""], "All"));
|
||||
foreach ($types as $type) {
|
||||
$html .= "<option value='".$type["ext"]."'>".$type["ext"]." (".$type["count"].")</option>";
|
||||
$select->appendChild(OPTION(["value"=>$type["ext"]], "{$type["ext"]} ({$type["count"]})"));
|
||||
}
|
||||
$html .= "</select></td></tr>";
|
||||
$html .= "<tr><td colspan='2'><input type='submit' value='Scan Media Information'></td></tr>";
|
||||
$html .= "</table></form>\n";
|
||||
|
||||
$html = (string)SHM_SIMPLE_FORM(
|
||||
make_link("admin/media_rescan"),
|
||||
"Use this to force scanning for media properties.",
|
||||
TABLE(
|
||||
["class"=>"form"],
|
||||
TR(TH("Image Type"), TD($select)),
|
||||
TR(TD(["colspan"=>"2"], SHM_SUBMIT('Scan Media Information')))
|
||||
)
|
||||
);
|
||||
$page->add_block(new Block("Media Tools", $html));
|
||||
}
|
||||
|
||||
public function get_buttons_html(int $image_id): string
|
||||
{
|
||||
return "
|
||||
".make_form(make_link("media_rescan/"))."
|
||||
<input type='hidden' name='image_id' value='$image_id'>
|
||||
<input type='submit' value='Scan Media Properties'>
|
||||
</form>
|
||||
";
|
||||
return (string)SHM_SIMPLE_FORM(
|
||||
make_link("media_rescan/"),
|
||||
INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image_id]),
|
||||
SHM_SUBMIT('Scan Media Properties'),
|
||||
);
|
||||
}
|
||||
|
||||
public function get_help_html()
|
||||
|
@ -35,12 +46,12 @@ class MediaTheme extends Themelet
|
|||
<div class="command_example">
|
||||
<pre>content:audio</pre>
|
||||
<p>Returns items that contain audio, including videos and audio files.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="command_example">
|
||||
<pre>content:video</pre>
|
||||
<p>Returns items that contain video, including animated GIFs.</p>
|
||||
</div>
|
||||
<p>These search terms depend on the items being scanned for media content. Automatic scanning was implemented in mid-2019, so items uploaded before, or items uploaded on a system without ffmpeg, will require additional scanning before this will work.</p>
|
||||
<p>These search terms depend on the items being scanned for media content. Automatic scanning was implemented in mid-2019, so items uploaded before, or items uploaded on a system without ffmpeg, will require additional scanning before this will work.</p>
|
||||
';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\INPUT;
|
||||
|
||||
class RegenThumbTheme extends Themelet
|
||||
{
|
||||
|
@ -7,12 +8,11 @@ class RegenThumbTheme extends Themelet
|
|||
*/
|
||||
public function get_buttons_html(int $image_id): string
|
||||
{
|
||||
return "
|
||||
".make_form(make_link("regen_thumb/one"))."
|
||||
<input type='hidden' name='image_id' value='$image_id'>
|
||||
<input type='submit' value='Regenerate Thumbnail'>
|
||||
</form>
|
||||
";
|
||||
return (string)SHM_SIMPLE_FORM(
|
||||
make_link("regen_thumb/one"),
|
||||
INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image_id]),
|
||||
SHM_SUBMIT('Regenerate Thumbnail')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\INPUT;
|
||||
|
||||
class ReportImageTheme extends Themelet
|
||||
{
|
||||
|
@ -88,14 +89,12 @@ class ReportImageTheme extends Themelet
|
|||
|
||||
public function get_nuller(User $duser)
|
||||
{
|
||||
global $user, $page;
|
||||
$html = "
|
||||
<form action='".make_link("image_report/remove_reports_by")."' method='POST'>
|
||||
".$user->get_auth_html()."
|
||||
<input type='hidden' name='user_id' value='{$duser->id}'>
|
||||
<input type='submit' value='Delete all reports by this user'>
|
||||
</form>
|
||||
";
|
||||
global $page;
|
||||
$html = (string)SHM_SIMPLE_FORM(
|
||||
make_link("image_report/remove_reports_by"),
|
||||
INPUT(["type"=>'hidden', "name"=>'user_id', "value"=>$duser->id]),
|
||||
SHM_SUBMIT('Delete all reports by this user')
|
||||
);
|
||||
$page->add_block(new Block("Reports", $html, "main", 80));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\INPUT;
|
||||
use function MicroHTML\LABEL;
|
||||
use function MicroHTML\BR;
|
||||
|
||||
class Rule34Theme extends Themelet
|
||||
{
|
||||
public function show_comic_changer(User $duser, bool $current_state): void
|
||||
{
|
||||
global $page;
|
||||
$checked = $current_state ? 'checked="checked"' : '';
|
||||
$html = make_form(make_link("rule34/comic_admin"), "POST");
|
||||
$html .= "<input type='hidden' name='user_id' value='{$duser->id}'>";
|
||||
$html .= "<label><input type='checkbox' name='is_admin' $checked> Comic Admin</label>";
|
||||
$html .= "<br/><input type='submit' id='Set'>";
|
||||
$html .= "</form>\n";
|
||||
|
||||
$html = (string)SHM_SIMPLE_FORM(
|
||||
make_link("rule34/comic_admin"),
|
||||
INPUT(["type"=>'hidden', "name"=>'user_id', "value"=>$duser->id]),
|
||||
LABEL(INPUT(["type"=>'checkbox', "name"=>'is_admin', "checked"=>$current_state]), "Comic Admin"),
|
||||
BR(),
|
||||
SHM_SUBMIT("Set")
|
||||
);
|
||||
|
||||
$page->add_block(new Block("Rule34 Comic Options", $html));
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue