[upload] build post fields using events

This commit is contained in:
discomrade 2024-03-28 01:36:34 +00:00 committed by Shish
parent 8af33ded18
commit 571839ec4a
8 changed files with 146 additions and 26 deletions

View file

@ -98,6 +98,21 @@ class PostSource extends Extension
}
}
public function onUploadHeaderBuilding(UploadHeaderBuildingEvent $event): void
{
$event->add_part("Source", 11);
}
public function onUploadCommonBuilding(UploadCommonBuildingEvent $event): void
{
$event->add_part($this->theme->get_upload_common_html(), 11);
}
public function onUploadSpecificBuilding(UploadSpecificBuildingEvent $event): void
{
$event->add_part($this->theme->get_upload_specific_html($event->suffix), 11);
}
private function mass_source_edit(string $tags, string $source): void
{
$tags = Tag::explode($tags);

View file

@ -51,4 +51,23 @@ class PostSourceTheme extends Themelet
}
return rawHTML("Unknown");
}
public function get_upload_common_html(): HTMLElement
{
return TR(
TH(["width" => "20"], "Common Source"),
TD(["colspan" => "6"], INPUT(["name" => "source", "type" => "text", "placeholder" => "https://..."]))
);
}
public function get_upload_specific_html(string $suffix): HTMLElement
{
return TD(
INPUT([
"type" => "text",
"name" => "source{$suffix}",
"value" => ($suffix == 0) ? @$_GET['source'] : null,
])
);
}
}

View file

@ -218,6 +218,22 @@ class PostTags extends Extension
}
}
public function onUploadHeaderBuilding(UploadHeaderBuildingEvent $event): void
{
$event->add_part("Tags", 10);
}
public function onUploadCommonBuilding(UploadCommonBuildingEvent $event): void
{
$event->add_part($this->theme->get_upload_common_html(), 10);
}
public function onUploadSpecificBuilding(UploadSpecificBuildingEvent $event): void
{
$event->add_part($this->theme->get_upload_specific_html($event->suffix), 10);
}
private function mass_tag_edit(string $search, string $replace, bool $commit): void
{
global $database, $tracer_enabled, $_tracer;

View file

@ -6,7 +6,7 @@ namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\{joinHTML, A, TEXTAREA};
use function MicroHTML\{joinHTML, A, TEXTAREA, TR, TH, TD, INPUT};
class PostTagsTheme extends Themelet
{
@ -53,4 +53,24 @@ class PostTagsTheme extends Themelet
null,
);
}
public function get_upload_common_html(): HTMLElement
{
return TR(
TH(["width" => "20"], "Common Tags"),
TD(["colspan" => "6"], INPUT(["name" => "tags", "type" => "text", "placeholder" => "tagme", "class" => "autocomplete_tags"]))
);
}
public function get_upload_specific_html(string $suffix): HTMLElement
{
return TD(
INPUT([
"type" => "text",
"name" => "tags{$suffix}",
"class" => "autocomplete_tags",
"value" => ($suffix == 0) ? @$_GET['tags'] : null,
])
);
}
}

View file

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
use MicroHTML\HTMLElement;
/**
* @extends PartListBuildingEvent<HTMLElement>
*/
class UploadCommonBuildingEvent extends PartListBuildingEvent
{
}

View file

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
/**
* @extends PartListBuildingEvent<string>
*/
class UploadHeaderBuildingEvent extends PartListBuildingEvent
{
}

View file

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
use MicroHTML\HTMLElement;
/**
* @extends PartListBuildingEvent<HTMLElement>
*/
class UploadSpecificBuildingEvent extends PartListBuildingEvent
{
public string $suffix;
public function __construct(string $suffix)
{
parent::__construct();
$this->suffix = $suffix;
}
}

View file

@ -4,6 +4,10 @@ declare(strict_types=1);
namespace Shimmie2;
require_once "events/upload_common_building_event.php";
require_once "events/upload_specific_building_event.php";
require_once "events/upload_header_building_event.php";
use MicroHTML\HTMLElement;
use function MicroHTML\{TABLE,TR,TH,TD};
@ -44,18 +48,17 @@ class UploadTheme extends Themelet
$max_total_kb = to_shorthand_int($max_total_size);
$upload_list = $this->build_upload_list();
$common_fields = emptyHTML();
$ucbe = send_event(new UploadCommonBuildingEvent());
foreach ($ucbe->get_parts() as $part) {
$common_fields->appendChild($part);
}
$form = SHM_FORM("upload", multipart: true, form_id: "file_upload");
$form->appendChild(
TABLE(
["id" => "large_upload_form", "class" => "form"],
TR(
TH(["width" => "20"], "Common Tags"),
TD(["colspan" => "6"], INPUT(["name" => "tags", "type" => "text", "placeholder" => "tagme", "class" => "autocomplete_tags"]))
),
TR(
TH(["width" => "20"], "Common Source"),
TD(["colspan" => "6"], INPUT(["name" => "source", "type" => "text", "placeholder" => "https://..."]))
),
$common_fields,
$upload_list,
TR(
TD(["colspan" => "7"], INPUT(["id" => "uploadbutton", "type" => "submit", "value" => "Post"]))
@ -96,17 +99,30 @@ class UploadTheme extends Themelet
$tl_enabled = ($config->get_string(UploadConfig::TRANSLOAD_ENGINE, "none") != "none");
$accept = $this->get_accept();
$headers = emptyHTML();
$uhbe = send_event(new UploadHeaderBuildingEvent());
foreach ($uhbe->get_parts() as $part) {
$headers->appendChild(
TH("Post-Specific $part")
);
}
$upload_list->appendChild(
TR(
["class" => "header"],
TH(["colspan" => 2], "Select File"),
TH($tl_enabled ? "or URL" : null),
TH("Post-Specific Tags"),
TH("Post-Specific Source"),
$headers,
)
);
for ($i = 0; $i < $upload_count; $i++) {
$specific_fields = emptyHTML();
$usfbe = send_event(new UploadSpecificBuildingEvent((string)$i));
foreach ($usfbe->get_parts() as $part) {
$specific_fields->appendChild($part);
}
$upload_list->appendChild(
TR(
TD(
@ -131,21 +147,7 @@ class UploadTheme extends Themelet
"value" => ($i == 0) ? @$_GET['url'] : null,
]) : null
),
TD(
INPUT([
"type" => "text",
"name" => "tags{$i}",
"class" => "autocomplete_tags",
"value" => ($i == 0) ? @$_GET['tags'] : null,
])
),
TD(
INPUT([
"type" => "text",
"name" => "source{$i}",
"value" => ($i == 0) ? @$_GET['source'] : null,
])
),
$specific_fields,
)
);
}