From 59eb6d7ec280ab8105b6bf0579809da12e4a7f2d Mon Sep 17 00:00:00 2001 From: Daku Date: Sun, 29 Dec 2013 20:46:37 +0000 Subject: [PATCH 1/8] pool title should be unique --- ext/pools/main.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ext/pools/main.php b/ext/pools/main.php index b161e8bb..42bbe2c9 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -71,6 +71,11 @@ class Pools extends Extension { log_info("pools", "extension installed"); } + + if ($config->get_int("ext_pools_version") < 2){ + $database->Execute("ALTER TABLE `pools` ADD UNIQUE INDEX (`title`);"); + $config->set_int("ext_pools_version", 2); + } } // Add a block to the Board Config / Setup From 3e240fa78d8e24daf0088d5d723c7d8e6ed131fa Mon Sep 17 00:00:00 2001 From: Daku Date: Sun, 29 Dec 2013 22:24:34 +0000 Subject: [PATCH 2/8] return error when pool title exists + fix pool error reporting --- ext/pools/main.php | 34 +++++++++++++++++++++++----------- ext/pools/theme.php | 15 --------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/ext/pools/main.php b/ext/pools/main.php index 42bbe2c9..e449ab1f 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -116,7 +116,7 @@ class Pools extends Extension { $this->theme->new_pool_composer($page); } else { $errMessage = "You must be registered and logged in to create a new pool."; - $this->theme->display_error($errMessage); + $this->theme->display_error(401, "Error", $errMessage); } break; @@ -127,7 +127,7 @@ class Pools extends Extension { $page->set_redirect(make_link("pool/view/".$newPoolID)); } catch(PoolCreationException $e) { - $this->theme->display_error($e->error); + $this->theme->display_error(400, "Error", $e->error); } break; @@ -173,7 +173,7 @@ class Pools extends Extension { $page->set_mode("redirect"); $page->set_redirect(make_link("pool/view/".$pool_id)); } else { - $this->theme->display_error("Permssion denied."); + $this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page"); } } break; @@ -182,7 +182,7 @@ class Pools extends Extension { if ($this->have_permission($user, $pool)) { $this->import_posts($pool_id); } else { - $this->theme->display_error("Permssion denied."); + $this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page"); } break; @@ -192,7 +192,7 @@ class Pools extends Extension { $page->set_mode("redirect"); $page->set_redirect(make_link("pool/view/".$pool_id)); } else { - $this->theme->display_error("Permssion denied."); + $this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page"); } break; @@ -202,7 +202,7 @@ class Pools extends Extension { $page->set_mode("redirect"); $page->set_redirect(make_link("pool/view/".$pool_id)); } else { - $this->theme->display_error("Permssion denied."); + $this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page"); } break; @@ -215,7 +215,7 @@ class Pools extends Extension { $page->set_mode("redirect"); $page->set_redirect(make_link("pool/list")); } else { - $this->theme->display_error("Permssion denied."); + $this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page"); } break; @@ -336,14 +336,16 @@ class Pools extends Extension { */ private function add_pool() { global $user, $database; - + #throw new PoolCreationException("Pool needs a title"); if($user->is_anonymous()) { throw new PoolCreationException("You must be registered and logged in to add a image."); } if(empty($_POST["title"])) { - throw new PoolCreationException("Pool needs a title"); + throw new PoolCreationException("Pool title is empty."); + } + if($this->get_single_pool_from_title($_POST["title"])) { + throw new PoolCreationException("A pool using this title already exists."); } - $public = $_POST["public"] == "Y" ? "Y" : "N"; $database->execute(" INSERT INTO pools (user_id, public, title, description, date) @@ -366,7 +368,7 @@ class Pools extends Extension { global $database; return $database->get_all("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID)); } - + /** * Retrieve information about a pool given a pool ID. * @param $poolID Integer @@ -377,6 +379,16 @@ class Pools extends Extension { return $database->get_row("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID)); } + /** + * Retrieve information about a pool given a pool title. + * @param $poolTitle Integer + * @retval 2D array (with only 1 element in the one dimension) + */ + private function get_single_pool_from_title(/*string*/ $poolTitle) { + global $database; + return $database->get_row("SELECT * FROM pools WHERE title=:title", array("title"=>$poolTitle)); + } + /** * Get all of the pool IDs that an image is in, given an image ID. * @param $imageID Integer diff --git a/ext/pools/theme.php b/ext/pools/theme.php index d9c397c7..39c4318e 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -389,20 +389,5 @@ class PoolsTheme extends Themelet { $this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages); } - - - /** - * Display an error message to the user. - */ - public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) { - global $page; - - // Quick n' Dirty fix - $message = $code; - - $page->set_title("Error"); - $page->set_heading("Error"); - $page->add_block(new Block("Error", $errMessage, "main", 10)); - } } ?> From b79a042bdcb68524a872038d440c15bfda7c5856 Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 30 Dec 2013 01:48:07 +0000 Subject: [PATCH 3/8] added option to order pool list by created date/last updated/title/count --- ext/pools/main.php | 17 ++++++++++++++++- ext/pools/script.js | 10 ++++++++++ ext/pools/theme.php | 10 ++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 ext/pools/script.js diff --git a/ext/pools/main.php b/ext/pools/main.php index e449ab1f..7cdc0374 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -74,6 +74,8 @@ class Pools extends Extension { if ($config->get_int("ext_pools_version") < 2){ $database->Execute("ALTER TABLE `pools` ADD UNIQUE INDEX (`title`);"); + $database->Execute("ALTER TABLE `pools` ADD `lastupdated` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;"); + $config->set_int("ext_pools_version", 2); } } @@ -314,13 +316,26 @@ class Pools extends Extension { $poolsPerPage = $config->get_int("poolsListsPerPage"); + + $order_by = ""; + $order = get_prefixed_cookie("ui-order-pool"); + if($order == "created" || is_null($order)){ + $order_by = "ORDER BY p.date DESC"; + }elseif($order == "updated"){ + $order_by = "ORDER BY p.lastupdated DESC"; + }elseif($order == "name"){ + $order_by = "ORDER BY p.title ASC"; + }elseif($order == "count"){ + $order_by = "ORDER BY p.posts DESC"; + } + $pools = $database->get_all(" SELECT p.id, p.user_id, p.public, p.title, p.description, p.posts, u.name as user_name FROM pools AS p INNER JOIN users AS u ON p.user_id = u.id - ORDER BY p.date DESC + $order_by LIMIT :l OFFSET :o ", array("l"=>$poolsPerPage, "o"=>$pageNumber * $poolsPerPage) ); diff --git a/ext/pools/script.js b/ext/pools/script.js new file mode 100644 index 00000000..72ea80e6 --- /dev/null +++ b/ext/pools/script.js @@ -0,0 +1,10 @@ +$(function() { + var order_pool = $.cookie("shm_ui-order-pool"); + $("#order_pool option[value="+order_pool+"]").attr("selected", true); + + $('#order_pool').change(function(){ + var val = $("#order_pool option:selected").val(); + $.cookie("shm_ui-order-pool", val, {path: '/', expires: 365}); //FIXME: This won't play nice if COOKIE_PREFIX is not "shm_". + window.location.href = ''; + }); +}); diff --git a/ext/pools/theme.php b/ext/pools/theme.php index 39c4318e..cc924045 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -67,11 +67,21 @@ class PoolsTheme extends Themelet {
Pool Changes '; + $order_html = ' + + '; + $blockTitle = "Pools"; $page->set_title(html_escape($blockTitle)); $page->set_heading(html_escape($blockTitle)); $page->add_block(new Block($blockTitle, $html, "main", 10)); $page->add_block(new Block("Navigation", $nav_html, "left", 10)); + $page->add_block(new Block("Order By", $order_html, "left", 15)); $this->display_paginator($page, "pool/list", null, $pageNumber, $totalPages); } From 9511569ed425270f3624e0bed2be8205ed40409e Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 30 Dec 2013 06:51:47 +0000 Subject: [PATCH 4/8] added option to edit pool description to pool edit page --- ext/pools/main.php | 22 ++++++++++++++++++++++ ext/pools/theme.php | 14 +++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ext/pools/main.php b/ext/pools/main.php index 7cdc0374..6bb9a24d 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -209,6 +209,17 @@ class Pools extends Extension { break; + case "edit_description": + if ($this->have_permission($user, $pool)) { + $this->edit_description(); + $page->set_mode("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 "nuke": // Completely remove the given pool. // -> Only admins and owners may do this @@ -508,6 +519,17 @@ class Pools extends Extension { return $poolID; } + /* + * Allows editing of pool description. + */ + private function edit_description() { + global $database; + + $poolID = int_escape($_POST['pool_id']); + $database->execute("UPDATE pools SET description=:dsc WHERE id=:pid", array("dsc"=>$_POST['description'], "pid"=>$poolID)); + + return $poolID; + } /** * This function checks if a given image is contained within a given pool. diff --git a/ext/pools/theme.php b/ext/pools/theme.php index cc924045..269b9a1c 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -322,8 +322,17 @@ class PoolsTheme extends Themelet { public function edit_pool(Page $page, /*array*/ $pools, /*array*/ $images) { global $user; - $this->display_top($pools, "Editing Pool", true); + /* EDIT POOL DESCRIPTION */ + $desc_html = " + ".make_form(make_link("pool/edit_description"))." +
+ + + + "; + + /* REMOVE POOLS */ $pool_images = "\n
"; foreach($images as $pair) { @@ -341,6 +350,9 @@ class PoolsTheme extends Themelet { "". "
"; + $pools[0]['description'] = ""; //This is a rogue fix to avoid showing the description twice. + $this->display_top($pools, "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)); } From 9eaebfd1c28d36fd605195c7ad68e62c7ce30466 Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 30 Dec 2013 06:52:17 +0000 Subject: [PATCH 5/8] if cookie doesn't exist, default to "created" --- ext/pools/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/pools/script.js b/ext/pools/script.js index 72ea80e6..505718a9 100644 --- a/ext/pools/script.js +++ b/ext/pools/script.js @@ -1,5 +1,5 @@ $(function() { - var order_pool = $.cookie("shm_ui-order-pool"); + var order_pool = $.cookie("shm_ui-order-pool") || "created"; $("#order_pool option[value="+order_pool+"]").attr("selected", true); $('#order_pool').change(function(){ From 3dd31019959625efe5e22c155bc06d9544e4a5f4 Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 30 Dec 2013 08:15:10 +0000 Subject: [PATCH 6/8] added option to set pool & source via tag --- core/imageboard.pack.php | 12 ++++++++++++ ext/pools/main.php | 20 +++++++++++++++++++- ext/pools/theme.php | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index e36c40ee..869e7de6 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -476,6 +476,18 @@ class Image { $this->delete_tags_from_image(); // insert each new tags foreach($tags as $tag) { + if(preg_match("/^source=(.*)$/i", $tag, $matches)) { + $this->set_source($matches[1]); + continue; + } + if(preg_match("/^pool=(.*)$/i", $tag, $matches)) { + if(class_exists("Pools")) { + $pls = new Pools(); + $pls->add_post_from_tag($matches[1], $this->id); + } + continue; + } + $id = $database->get_one( $database->scoreql_to_sql( "SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)" diff --git a/ext/pools/main.php b/ext/pools/main.php index 6bb9a24d..22ac55d8 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -293,6 +293,23 @@ class Pools extends Extension { } } + public function add_post_from_tag(/*str*/ $poolTag, /*int*/ $imageID){ + $poolTag = str_replace("_", " ", $poolTag); + //First check if pool tag is a title + if(ctype_digit($poolTag)){ + //If string only contains numeric characters, assume it is $poolID + if($this->get_single_pool($poolTag)){ //Make sure pool exists + $this->add_post($poolTag, $imageID); + } + }else{ + //If string doesn't contain only numeric characters, check to see if tag is title. + $pool = $this->get_single_pool_from_title($poolTag); + if($pool){ + $this->add_post($pool['id'], $imageID); + } + } + } + /* ------------------------------------------------- */ /* -------------- Private Functions -------------- */ /* ------------------------------------------------- */ @@ -362,7 +379,7 @@ class Pools extends Extension { */ private function add_pool() { global $user, $database; - #throw new PoolCreationException("Pool needs a title"); + if($user->is_anonymous()) { throw new PoolCreationException("You must be registered and logged in to add a image."); } @@ -372,6 +389,7 @@ class Pools extends Extension { if($this->get_single_pool_from_title($_POST["title"])) { throw new PoolCreationException("A pool using this title already exists."); } + $public = $_POST["public"] == "Y" ? "Y" : "N"; $database->execute(" INSERT INTO pools (user_id, public, title, description, date) diff --git a/ext/pools/theme.php b/ext/pools/theme.php index 269b9a1c..3b2e315c 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -350,7 +350,7 @@ class PoolsTheme extends Themelet { "". ""; - $pools[0]['description'] = ""; //This is a rogue fix to avoid showing the description twice. + $pools[0]['description'] = ""; //This is a rough fix to avoid showing the description twice. $this->display_top($pools, "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)); From fd6f2ddb431e45d33b0ea3617e3a32dc461bd94d Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 30 Dec 2013 08:42:29 +0000 Subject: [PATCH 7/8] show pool navigation box on pool/view pages --- ext/pools/theme.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ext/pools/theme.php b/ext/pools/theme.php index 3b2e315c..444e76b5 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -166,6 +166,13 @@ class PoolsTheme extends Themelet { $pool_images .= "\n".$thumb_html."\n"; } + $nav_html = ' + Index +
Create Pool +
Pool Changes + '; + + $page->add_block(new Block("Navigation", $nav_html, "left", 10)); $page->add_block(new Block("Viewing Posts", $pool_images, "main", 30)); $this->display_paginator($page, "pool/view/".$pools[0]['id'], null, $pageNumber, $totalPages); } From c892386bcb64a48ed06a1a30cd06aa00c332d33e Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 30 Dec 2013 10:36:32 +0000 Subject: [PATCH 8/8] remove backticks --- ext/pools/main.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/pools/main.php b/ext/pools/main.php index 22ac55d8..008838d3 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -73,8 +73,8 @@ class Pools extends Extension { } if ($config->get_int("ext_pools_version") < 2){ - $database->Execute("ALTER TABLE `pools` ADD UNIQUE INDEX (`title`);"); - $database->Execute("ALTER TABLE `pools` ADD `lastupdated` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;"); + $database->Execute("ALTER TABLE pools ADD UNIQUE INDEX (title);"); + $database->Execute("ALTER TABLE pools ADD lastupdated TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;"); $config->set_int("ext_pools_version", 2); }