[upload] build post fields using events
This commit is contained in:
parent
8af33ded18
commit
571839ec4a
8 changed files with 146 additions and 26 deletions
|
@ -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
|
private function mass_source_edit(string $tags, string $source): void
|
||||||
{
|
{
|
||||||
$tags = Tag::explode($tags);
|
$tags = Tag::explode($tags);
|
||||||
|
|
|
@ -51,4 +51,23 @@ class PostSourceTheme extends Themelet
|
||||||
}
|
}
|
||||||
return rawHTML("Unknown");
|
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,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
private function mass_tag_edit(string $search, string $replace, bool $commit): void
|
||||||
{
|
{
|
||||||
global $database, $tracer_enabled, $_tracer;
|
global $database, $tracer_enabled, $_tracer;
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace Shimmie2;
|
||||||
|
|
||||||
use MicroHTML\HTMLElement;
|
use MicroHTML\HTMLElement;
|
||||||
|
|
||||||
use function MicroHTML\{joinHTML, A, TEXTAREA};
|
use function MicroHTML\{joinHTML, A, TEXTAREA, TR, TH, TD, INPUT};
|
||||||
|
|
||||||
class PostTagsTheme extends Themelet
|
class PostTagsTheme extends Themelet
|
||||||
{
|
{
|
||||||
|
@ -53,4 +53,24 @@ class PostTagsTheme extends Themelet
|
||||||
null,
|
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,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
14
ext/upload/events/upload_common_building_event.php
Normal file
14
ext/upload/events/upload_common_building_event.php
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use MicroHTML\HTMLElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends PartListBuildingEvent<HTMLElement>
|
||||||
|
*/
|
||||||
|
class UploadCommonBuildingEvent extends PartListBuildingEvent
|
||||||
|
{
|
||||||
|
}
|
12
ext/upload/events/upload_header_building_event.php
Normal file
12
ext/upload/events/upload_header_building_event.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends PartListBuildingEvent<string>
|
||||||
|
*/
|
||||||
|
class UploadHeaderBuildingEvent extends PartListBuildingEvent
|
||||||
|
{
|
||||||
|
}
|
22
ext/upload/events/upload_specific_building_event.php
Normal file
22
ext/upload/events/upload_specific_building_event.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,10 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
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 MicroHTML\HTMLElement;
|
||||||
|
|
||||||
use function MicroHTML\{TABLE,TR,TH,TD};
|
use function MicroHTML\{TABLE,TR,TH,TD};
|
||||||
|
@ -44,18 +48,17 @@ class UploadTheme extends Themelet
|
||||||
$max_total_kb = to_shorthand_int($max_total_size);
|
$max_total_kb = to_shorthand_int($max_total_size);
|
||||||
$upload_list = $this->build_upload_list();
|
$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 = SHM_FORM("upload", multipart: true, form_id: "file_upload");
|
||||||
$form->appendChild(
|
$form->appendChild(
|
||||||
TABLE(
|
TABLE(
|
||||||
["id" => "large_upload_form", "class" => "form"],
|
["id" => "large_upload_form", "class" => "form"],
|
||||||
TR(
|
$common_fields,
|
||||||
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://..."]))
|
|
||||||
),
|
|
||||||
$upload_list,
|
$upload_list,
|
||||||
TR(
|
TR(
|
||||||
TD(["colspan" => "7"], INPUT(["id" => "uploadbutton", "type" => "submit", "value" => "Post"]))
|
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");
|
$tl_enabled = ($config->get_string(UploadConfig::TRANSLOAD_ENGINE, "none") != "none");
|
||||||
$accept = $this->get_accept();
|
$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(
|
$upload_list->appendChild(
|
||||||
TR(
|
TR(
|
||||||
["class" => "header"],
|
["class" => "header"],
|
||||||
TH(["colspan" => 2], "Select File"),
|
TH(["colspan" => 2], "Select File"),
|
||||||
TH($tl_enabled ? "or URL" : null),
|
TH($tl_enabled ? "or URL" : null),
|
||||||
TH("Post-Specific Tags"),
|
$headers,
|
||||||
TH("Post-Specific Source"),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
for ($i = 0; $i < $upload_count; $i++) {
|
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(
|
$upload_list->appendChild(
|
||||||
TR(
|
TR(
|
||||||
TD(
|
TD(
|
||||||
|
@ -131,21 +147,7 @@ class UploadTheme extends Themelet
|
||||||
"value" => ($i == 0) ? @$_GET['url'] : null,
|
"value" => ($i == 0) ? @$_GET['url'] : null,
|
||||||
]) : null
|
]) : null
|
||||||
),
|
),
|
||||||
TD(
|
$specific_fields,
|
||||||
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,
|
|
||||||
])
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue