From aef5bc9e2e4468d6529eeef96903fdee87903ea2 Mon Sep 17 00:00:00 2001 From: Luana Date: Wed, 5 Jul 2023 16:33:38 -0300 Subject: [PATCH] SHM_ functions in its own file --- core/microhtml.php | 153 +++++++++++++++++++++++++++++++++++++++++++++ core/util.php | 148 ------------------------------------------- index.php | 1 + 3 files changed, 154 insertions(+), 148 deletions(-) create mode 100644 core/microhtml.php diff --git a/core/microhtml.php b/core/microhtml.php new file mode 100644 index 00000000..4cb1a943 --- /dev/null +++ b/core/microhtml.php @@ -0,0 +1,153 @@ +make_link($target), + "method"=>$method + ]; + + if ($form_id) { + $attrs["id"] = $form_id; + } + if ($multipart) { + $attrs["enctype"] = 'multipart/form-data'; + } + if ($onsubmit) { + $attrs["onsubmit"] = $onsubmit; + } + if ($name) { + $attrs["name"] = $name; + } + return FORM( + $attrs, + INPUT(["type"=>"hidden", "name"=>"q", "value"=>$target]), + $method == "GET" ? "" : $user->get_auth_microhtml() + ); +} + +function SHM_SIMPLE_FORM($target, ...$children): HTMLElement +{ + $form = SHM_FORM($target); + $form->appendChild(emptyHTML(...$children)); + return $form; +} + +function SHM_SUBMIT(string $text, array $args=[]): HTMLElement +{ + $args["type"] = "submit"; + $args["value"] = $text; + return INPUT($args); +} + +function SHM_A(string $href, string|HTMLElement $text, string $id="", string $class="", array $args=[]): HTMLElement +{ + $args["href"] = make_link($href); + + if ($id) { + $args["id"] = $id; + } + if ($class) { + $args["class"] = $class; + } + + return A($args, $text); +} + +function SHM_COMMAND_EXAMPLE(string $ex, string $desc): HTMLElement +{ + return DIV( + ["class"=>"command_example"], + PRE($ex), + P($desc) + ); +} + +function SHM_USER_FORM(User $duser, string $target, string $title, $body, $foot): HTMLElement +{ + if (is_string($foot)) { + $foot = TFOOT(TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>$foot])))); + } + return SHM_SIMPLE_FORM( + $target, + P( + INPUT(["type"=>'hidden', "name"=>'id', "value"=>$duser->id]), + TABLE( + ["class"=>"form"], + THEAD(TR(TH(["colspan"=>"2"], $title))), + $body, + $foot + ) + ) + ); +} + +/** + * Generates a . + * @param array $options An array of pairs of parameters for