From 40244138f3fbe901a2f723312ffe6541c077d478 Mon Sep 17 00:00:00 2001 From: myname Date: Sun, 5 Nov 2023 09:40:12 -0600 Subject: [PATCH 1/3] Remove redundant button Fix parent-id type issue --- ext/relationships/theme.php | 2 +- themes/danbooru2/view.theme.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/relationships/theme.php b/ext/relationships/theme.php index 78b78f89d..c3cacf455 100644 --- a/ext/relationships/theme.php +++ b/ext/relationships/theme.php @@ -40,7 +40,7 @@ public function get_parent_editor_html(Image $image): HTMLElement return SHM_POST_INFO( "Parent", !$user->is_anonymous(), - $image->parent_id ?: "None", + strval($image->parent_id) ?: "None", INPUT(["type"=>"number", "name"=>"tag_edit__parent", "value"=>$image->parent_id]) ); } diff --git a/themes/danbooru2/view.theme.php b/themes/danbooru2/view.theme.php index 4a68b7a37..130eb81d0 100644 --- a/themes/danbooru2/view.theme.php +++ b/themes/danbooru2/view.theme.php @@ -72,7 +72,6 @@ protected function build_navigation(Image $image): string - "; From 5b2666164f4af23e64d2122897ab15c4768ec6a4 Mon Sep 17 00:00:00 2001 From: myname Date: Sun, 5 Nov 2023 23:50:33 -0600 Subject: [PATCH 2/3] Create function to search pool by name --- ext/pools/main.php | 106 ++++++++++++++++++++++++++++---------------- ext/pools/theme.php | 14 +++++- 2 files changed, 81 insertions(+), 39 deletions(-) diff --git a/ext/pools/main.php b/ext/pools/main.php index 34f872a1d..9b107b891 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -98,6 +98,18 @@ public static function makePool(array $row): Pool { return new Pool($row); } + + public static function get_pool_id_by_title($poolTitle): ?int + { + global $database; + $row = $database->get_row("SELECT * FROM pools WHERE title=:title", ["title" => $poolTitle]); + if ($row != null) { + return $row['id']; + } + else { + return NULL; + } + } } function _image_to_id(Image $image): int @@ -203,7 +215,23 @@ public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) public function onPageRequest(PageRequestEvent $event) { global $config, $database, $page, $user; - if ($event->page_matches("pool")) { + if ($event->page_matches("pool/list")) { //index + if (isset($_GET['search']) and $_GET['search'] != null) { + $page->set_mode(PageMode::REDIRECT); + $page->set_redirect(make_link('pool/list').'/'.$_GET['search'].'/'.strval($event->try_page_num(1))); + return; + } + if (count($event->args) >= 4) { // Assume first 2 args are search and page num + $search = $event->get_arg(0); // Search is based on name comparison instead of tag search + $page_num = $event->try_page_num(1); + } + else { + $search = ""; + $page_num = $event->try_page_num(0); + } + $this->list_pools($page, $page_num, $search); + } + elseif ($event->page_matches("pool")) { $pool_id = 0; $pool = []; @@ -215,10 +243,6 @@ public function onPageRequest(PageRequestEvent $event) // What action are we trying to perform? switch ($event->get_arg(0)) { - case "list": //index - $this->list_pools($page, $event->try_page_num(1)); - break; - case "new": // Show form for new pools if (!$user->is_anonymous()) { $this->theme->new_pool_composer($page); @@ -320,35 +344,37 @@ public function onPageRequest(PageRequestEvent $event) } } break; - case "reverse": - if ($this->have_permission($user, $pool)) { - $result = $database->execute( - "SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order DESC", - ["pid" => $pool_id] - ); - $image_order = 1; - try { - $database->begin_transaction(); - while ($row = $result->fetch()) { - $database->execute( - " - UPDATE pool_images - SET image_order=:ord + case "reverse": + if ($this->have_permission($user, $pool)) { + $result = $database->execute( + "SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order DESC", + ["pid" => $pool_id] + ); + $image_order = 1; + try { + $database->begin_transaction(); + while ($row = $result->fetch()) { + $database->execute( + " + UPDATE pool_images + SET image_order=:ord WHERE pool_id = :pid AND image_id = :iid", - ["ord" => $image_order, "pid" => $pool_id, "iid" => (int)$row['image_id']] - ); - $image_order = $image_order + 1; - } - $database->commit(); - } catch (\Exception $e) { - $database->rollback(); - } - $page->set_mode(PageMode::REDIRECT); - $page->set_redirect(make_link("pool/view/" . $pool_id)); - } else { - $this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page"); - } - break; + ["ord" => $image_order, "pid" => $pool_id, "iid" => (int)$row['image_id']] + ); + $image_order = $image_order + 1; + } + $database->commit(); + } + catch (Exception $e) { + $database->rollback(); + } + $page->set_mode(PageMode::REDIRECT); + $page->set_redirect(make_link("pool/view/" . $pool_id)); + } + else { + $this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page"); + } + break; case "import": if ($this->have_permission($user, $pool)) { $images = Image::find_images( @@ -509,6 +535,7 @@ public function onSearchTermParse(SearchTermParseEvent $event) $poolID = str_replace("_", " ", $matches[1]); $event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM pool_images WHERE pool_id = $poolID)")); } + } public function onTagTermCheck(TagTermCheckEvent $event) @@ -602,7 +629,7 @@ private function have_permission(User $user, Pool $pool): bool ); } - private function list_pools(Page $page, int $pageNumber) + private function list_pools(Page $page, int $pageNumber, $search) { global $config, $database; @@ -620,18 +647,23 @@ private function list_pools(Page $page, int $pageNumber) $order_by = "ORDER BY p.posts DESC"; } + $where_clause = "WHERE LOWER(title) like '%%'"; + if ($search != null) { + $where_clause = "WHERE LOWER(title) like '%".strtolower($search)."%'"; + } + $pools = array_map([Pool::class, "makePool"], $database->get_all(" SELECT p.*, u.name as user_name FROM pools AS p INNER JOIN users AS u ON p.user_id = u.id + $where_clause $order_by LIMIT :l OFFSET :o ", ["l" => $poolsPerPage, "o" => $pageNumber * $poolsPerPage])); + $totalPages = (int)ceil((int)$database->get_one("SELECT COUNT(*) FROM pools ".$where_clause) / $poolsPerPage); - $totalPages = (int)ceil((int)$database->get_one("SELECT COUNT(*) FROM pools") / $poolsPerPage); - - $this->theme->list_pools($page, $pools, $pageNumber + 1, $totalPages); + $this->theme->list_pools($page, $pools, $search, $pageNumber + 1, $totalPages); } public function onPoolCreation(PoolCreationEvent $event) diff --git a/ext/pools/theme.php b/ext/pools/theme.php index cbe04adc4..aaa41684f 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -55,7 +55,7 @@ public function get_adder_html(Image $image, array $pools): HTMLElement /** * HERE WE SHOWS THE LIST OF POOLS. */ - public function list_pools(Page $page, array $pools, int $pageNumber, int $totalPages) + public function list_pools(Page $page, array $pools, string $search, int $pageNumber, int $totalPages) { // Build up the list of pools. $pool_rows = []; @@ -86,7 +86,10 @@ public function list_pools(Page $page, array $pools, int $pageNumber, int $total $page->add_block(new Block("Pools", $table, position: 10)); - $this->display_paginator($page, "pool/list", null, $pageNumber, $totalPages); + if ($search != "" and !str_starts_with($search, '/')) { + $search = '/'.$search; + } + $this->display_paginator($page, "pool/list".$search, null, $pageNumber, $totalPages); } /* @@ -119,9 +122,16 @@ private function display_top(?Pool $pool, string $heading, bool $check_all = fal BR(), SHM_A("pool/updated", "Pool Changes") ); + + $search = "
+ + + +
"; $page->add_block(new NavBlock()); $page->add_block(new Block("Pool Navigation", $poolnav, "left", 10)); + $page->add_block(new Block("Search", $search, "left", 10)); if (!is_null($pool)) { if ($pool->public || $user->can(Permissions::POOLS_ADMIN)) {// IF THE POOL IS PUBLIC OR IS ADMIN SHOW EDIT PANEL From e498eb87c76d5cfda4ae5d438e8afe76a4897bed Mon Sep 17 00:00:00 2001 From: myname Date: Mon, 6 Nov 2023 06:47:59 -0600 Subject: [PATCH 3/3] Fix pool Post/List view --- ext/pools/theme.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/pools/theme.php b/ext/pools/theme.php index aaa41684f..43b168aff 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -203,8 +203,8 @@ public function sidebar_options(Page $page, Pool $pool, bool $check_all) SHM_SUBMIT("Reverse Order", ["name"=>"edit", "id"=>"reverse_pool_order_btn"]) ), SHM_SIMPLE_FORM( - "pool/list/pool_id%3A" . $pool->id . "/1", - SHM_SUBMIT("Post/List View", ["name"=>"edit", "id"=>"postlist_pool_btn"]) + "post/list/pool_id=" . $pool->id . "/1", + SHM_SUBMIT("Post/List View", ["name"=>"edit", "id"=>$pool->id]) ) );