From ff237fc00cc1eaabb17c2b39f5e76c87e6da74a3 Mon Sep 17 00:00:00 2001 From: Luana Date: Wed, 5 Jul 2023 16:04:26 -0300 Subject: [PATCH] pools theme fully MicroHTML --- ext/pools/theme.php | 145 +++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 76 deletions(-) diff --git a/ext/pools/theme.php b/ext/pools/theme.php index 76ce953b..93c018db 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -8,7 +8,7 @@ use MicroHTML\HTMLElement; use function MicroHTML\emptyHTML; use function MicroHTML\rawHTML; -use function MicroHTML\{A,BR,INPUT,P,SCRIPT,TABLE,THEAD,TBODY,TR,TH,TD,TEXTAREA,SPAN}; +use function MicroHTML\{A,BR,DIV,INPUT,P,SCRIPT,SPAN,TABLE,TBODY,TD,TEXTAREA,TH,THEAD,TR}; class PoolsTheme extends Themelet { @@ -20,27 +20,25 @@ class PoolsTheme extends Themelet { global $page; - $linksPools = []; + //TODO: Use a 3 column table? + $linksPools = emptyHTML(); foreach ($navIDs as $poolID => $poolInfo) { - $linksPools[] = "" . html_escape($poolInfo['info']->title) . ""; + $div = DIV(A(["href"=>make_link("pool/view/" . $poolID)], $poolInfo["info"]->title)); - if (!empty($poolInfo['nav'])) { - $navlinks = ""; - if (!empty($poolInfo['nav']['prev'])) { - $navlinks .= 'Prev'; + if (!empty($poolInfo["nav"])) { + if (!empty($poolInfo["nav"]["prev"])) { + $div->appendChild(A(["href"=>make_link("post/view/" . $poolInfo["nav"]["prev"]), "class"=>"pools_prev_img"], "Prev")); } - if (!empty($poolInfo['nav']['next'])) { - $navlinks .= 'Next'; - } - if (!empty($navlinks)) { - $navlinks .= "
"; - $linksPools[] = $navlinks; + if (!empty($poolInfo["nav"]["next"])) { + $div->appendChild(A(["href"=>make_link("post/view/" . $poolInfo["nav"]["next"]), "class"=>"pools_next_img"], "Next")); } } + + $linksPools->appendChild($div); } - if (count($linksPools) > 0) { - $page->add_block(new Block("Pools", implode("
", $linksPools), "left")); + if (!empty($navIDs)) { + $page->add_block(new Block("Pools", $linksPools, "left")); } } @@ -280,23 +278,22 @@ class PoolsTheme extends Themelet { $this->display_top($pool, "Sorting Pool"); - $pool_images = "\n
"; - $i = 0; - foreach ($images as $image) { - $thumb_html = $this->build_thumb_html($image); - $pool_images .= '' . "\n" . $thumb_html . "\n" . - '
' . - '' . - '
'; - $i++; + $form = SHM_FORM("pool/order", name: "checks"); + foreach ($images as $i=>$image) { + $form->appendChild(SPAN( + ["class"=>"thumb"], + $this->build_thumb_html($image), + INPUT(["type"=>"number", "name"=>"imgs[$i][]", "value"=>$image->image_order, "style"=>"max-width: 50px;"]), + INPUT(["type"=>"hidden", "name"=>"imgs[$i][]", "value"=>$image->id]) + )); } - $pool_images .= "
" . - "" . - "" . - "
"; + $form->appendChild( + INPUT(["type"=>"hidden", "name"=>"pool_id", "value"=>$pool->id]), + SHM_SUBMIT("Order", ["name"=>"edit", "id"=>"edit_pool_order"]) + ); - $page->add_block(new Block("Sorting Posts", $pool_images, "main", 30)); + $page->add_block(new Block("Sorting Posts", $form, position: 30)); } /** @@ -307,35 +304,35 @@ class PoolsTheme extends Themelet */ public function edit_pool(Page $page, Pool $pool, array $images) { - /* EDIT POOL DESCRIPTION */ - $desc_html = " - " . make_form(make_link("pool/edit_description")) . " -
- - - - "; + $_input_id = INPUT(["type"=>"hidden", "name"=>"pool_id", "value"=>$pool->id]); - /* REMOVE POOLS */ - $pool_images = "\n
"; + $desc_form = SHM_SIMPLE_FORM( + "pool/edit/description", + TEXTAREA(["name"=>"description"], $pool->description), + BR(), + $_input_id, + SHM_SUBMIT("Change Description") + ); + $images_form = SHM_FORM("pool/remove_posts", name: "checks"); foreach ($images as $image) { - $thumb_html = $this->build_thumb_html($image); - - $pool_images .= '' . "\n" . $thumb_html . "\n" . - '
' . - '
'; + $images_form->appendChild(SPAN( + ["class"=>"thumb"], + $this->build_thumb_html($image), + INPUT(["type"=>"checkbox", "name"=>"check[]", "value"=>$image->id]) + )); } - $pool_images .= "
" . - "" . - "" . - "
"; + $images_form->appendChild( + BR(), + $_input_id, + SHM_SUBMIT("Remove Selected", ["name"=>"edit", "id"=>"edit_pool_remove_sel"]) + ); $pool->description = ""; //This is a rough fix to avoid showing the description twice. $this->display_top($pool, "Editing Pool", true); - $page->add_block(new Block("Editing Description", $desc_html, "main", 28)); - $page->add_block(new Block("Editing Posts", $pool_images, "main", 30)); + $page->add_block(new Block("Editing Description", $desc_form, position: 28)); + $page->add_block(new Block("Editing Posts", $images_form, position: 30)); } /** @@ -344,21 +341,17 @@ class PoolsTheme extends Themelet public function show_history(array $histories, int $pageNumber, int $totalPages) { global $page; - $html = ' - - - - - - - - - '; + $table = TABLE( + ["id"=>"poolsList", "class"=>"zebra"], + THEAD(TR(TH("Pool"), TH("Post Count"), TH("Changes"), TH("Updater"), TH("Date"), TH("Action"))) + ); + + $body = []; foreach ($histories as $history) { - $pool_link = "" . html_escape($history['title']) . ""; - $user_link = "" . html_escape($history['user_name']) . ""; - $revert_link = "Revert"; + $pool_link = A(["href"=>make_link("pool/view/" . $history["pool_id"])], $history["title"]); + $user_link = A(["href"=>make_link("user/" . url_escape($history["user_name"]))], $history["user_name"]); + $revert_link = A(["href"=>make_link("pool/revert/" . $history["id"])], "Revert"); if ($history['action'] == 1) { $prefix = "+"; @@ -368,28 +361,28 @@ class PoolsTheme extends Themelet throw new \RuntimeException("history['action'] not in {0, 1}"); } - $images = trim($history['images']); + $images = trim($history["images"]); $images = explode(" ", $images); - $image_link = ""; + $image_links = emptyHTML(); foreach ($images as $image) { - $image_link .= "" . $prefix . $image . " "; + $image_links->appendChild(" ", A(["href"=>make_link("post/view/" . $image)], $prefix . $image)); } - $html .= "" . - "" . - "" . - "" . - "" . - "" . - "" . - ""; + $body[] = TR( + TD(["class"=>"left"], $pool_link), + TD($history["count"]), + TD($image_links), + TD($user_link), + TD($history["date"]), + TD($revert_link) + ); } - $html .= "
PoolPost CountChangesUpdaterDateAction
" . $pool_link . "" . $history['count'] . "" . $image_link . "" . $user_link . "" . $history['date'] . "" . $revert_link . "
"; + $table->appendChild(TBODY(...$body)); $this->display_top(null, "Recent Changes"); - $page->add_block(new Block("Recent Changes", $html, "main", 10)); + $page->add_block(new Block("Recent Changes", $table, position: 10)); $this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages); }