From 531b9038309a48e02873198d06f1ea3fe86d9fbc Mon Sep 17 00:00:00 2001 From: myname Date: Thu, 6 Oct 2022 17:34:04 -0500 Subject: [PATCH 1/4] Pool - Reverse function --- ext/pools/main.php | 33 +++++++++++++++++++++++++++++++-- ext/pools/theme.php | 5 +++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ext/pools/main.php b/ext/pools/main.php index f24a1ef4..0854f892 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -206,7 +206,6 @@ class Pools extends Extension public function onPageRequest(PageRequestEvent $event) { global $config, $database, $page, $user; - if ($event->page_matches("pool")) { $pool_id = 0; $pool = []; @@ -326,7 +325,37 @@ class Pools extends Extension } } 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 + 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; case "import": if ($this->have_permission($user, $pool)) { $images = Image::find_images( diff --git a/ext/pools/theme.php b/ext/pools/theme.php index d57268f9..8f54038c 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -192,6 +192,11 @@ class PoolsTheme extends Themelet + ' . make_form(make_link('pool/reverse')) . ' + + + + '; if ($user->id == $pool->user_id || $user->can(Permissions::POOLS_ADMIN)) { From d52d4a6899a3ff8caece80699ecf8da2eea53d9e Mon Sep 17 00:00:00 2001 From: myname Date: Fri, 7 Oct 2022 15:19:50 -0500 Subject: [PATCH 2/4] Add search by pool id --- ext/pools/main.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/pools/main.php b/ext/pools/main.php index 0854f892..90ee31ba 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -518,7 +518,11 @@ class Pools extends Extension $poolID = $pool->id; } $event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM pool_images WHERE pool_id = $poolID)")); + } elseif (preg_match("/^pool_id[=|:](.*)$/i", $event->term, $matches)) { + $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) From 3154a833f741cc0db6276f7c59c23bea12e27510 Mon Sep 17 00:00:00 2001 From: myname Date: Fri, 7 Oct 2022 15:33:24 -0500 Subject: [PATCH 3/4] Add Post/List view button to pools, for easier access to functions in the post/list extension --- ext/pools/theme.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/pools/theme.php b/ext/pools/theme.php index 8f54038c..2a00f816 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -197,6 +197,9 @@ class PoolsTheme extends Themelet + ' . make_form(make_link('post/list/pool_id%3A' . $pool->id . '/1')) . ' + + '; if ($user->id == $pool->user_id || $user->can(Permissions::POOLS_ADMIN)) { From ccb78e272c0cd7d9eb67ba4c040228db0ea95784 Mon Sep 17 00:00:00 2001 From: myname Date: Fri, 7 Oct 2022 18:41:53 -0500 Subject: [PATCH 4/4] Allows appending new tags to existing ones in auto_tagger --- ext/auto_tagger/main.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/ext/auto_tagger/main.php b/ext/auto_tagger/main.php index f07804e9..3ffd75ea 100644 --- a/ext/auto_tagger/main.php +++ b/ext/auto_tagger/main.php @@ -210,8 +210,26 @@ class AutoTagger extends Extension private function add_auto_tag(string $tag, string $additional_tags) { global $database; - if ($database->exists("SELECT * FROM auto_tag WHERE LOWER(tag)=LOWER(:tag)", ["tag"=>$tag])) { - throw new AutoTaggerException("Auto-Tag is already set for that tag"); + $existing_tags = $database->get_one("SELECT additional_tags FROM auto_tag WHERE LOWER(tag)=LOWER(:tag)", ["tag"=>$tag]); + if (!is_null($existing_tags)) { + // Auto Tags already exist, so we will append new tags to the existing one + $tag = Tag::sanitize($tag); + $additional_tags = Tag::explode($additional_tags); + $existing_tags = Tag::explode($existing_tags); + foreach ($additional_tags as $t) { + if (!in_array(strtolower($t), $existing_tags)) { + array_push($existing_tags, strtolower($t)); + } + } + + $database->execute( + "UPDATE auto_tag set additional_tags=:existing_tags where tag=:tag", + ["tag"=>$tag, "existing_tags"=>Tag::implode($existing_tags)] + ); + log_info( + AutoTaggerInfo::KEY, + "Updated auto-tag for {$tag} -> {".implode(" ", $additional_tags)."}" + ); } else { $tag = Tag::sanitize($tag); $additional_tags = Tag::explode($additional_tags); @@ -225,10 +243,9 @@ class AutoTagger extends Extension AutoTaggerInfo::KEY, "Added auto-tag for {$tag} -> {".implode(" ", $additional_tags)."}" ); - - // Now we apply it to existing items - $this->apply_new_auto_tag($tag); } + // Now we apply it to existing items + $this->apply_new_auto_tag($tag); } private function update_auto_tag(string $tag, string $additional_tags): bool