commit
bf03c0849a
3 changed files with 65 additions and 7 deletions
|
@ -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,11 +243,10 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
private function update_auto_tag(string $tag, string $additional_tags): bool
|
||||
{
|
||||
|
|
|
@ -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(
|
||||
|
@ -489,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)
|
||||
|
|
|
@ -192,6 +192,14 @@ class PoolsTheme extends Themelet
|
|||
<input type="hidden" name="order_view" value="yes">
|
||||
<input type="hidden" name="pool_id" value="' . $pool->id . '">
|
||||
</form>
|
||||
' . make_form(make_link('pool/reverse')) . '
|
||||
<input type="submit" name="edit" id="reverse_pool_order_btn" value="Reverse Order"/>
|
||||
<input type="hidden" name="reverse_view" value="yes">
|
||||
<input type="hidden" name="pool_id" value="' . $pool->id . '">
|
||||
</form>
|
||||
' . make_form(make_link('post/list/pool_id%3A' . $pool->id . '/1')) . '
|
||||
<input type="submit" name="edit" id="postlist_pool_btn" value="Post/List View"/>
|
||||
</form>
|
||||
';
|
||||
|
||||
if ($user->id == $pool->user_id || $user->can(Permissions::POOLS_ADMIN)) {
|
||||
|
|
Reference in a new issue