Added bulk action support to pools extension
This commit is contained in:
parent
8794258072
commit
9ca800d1c4
@ -9,6 +9,18 @@
|
|||||||
* Useful for related images like in a comic, etc.
|
* Useful for related images like in a comic, etc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
abstract class PoolsConfig
|
||||||
|
{
|
||||||
|
const MAX_IMPORT_RESULTS = "poolsMaxImportResults";
|
||||||
|
const IMAGES_PER_PAGE = "poolsImagesPerPage";
|
||||||
|
const LISTS_PER_PAGE = "poolsListsPerPage";
|
||||||
|
const UPDATED_PER_PAGE = "poolsUpdatedPerPage";
|
||||||
|
const INFO_ON_VIEW_IMAGE = "poolsInfoOnViewImage";
|
||||||
|
const ADDER_ON_VIEW_IMAGE = "poolsAdderOnViewImage";
|
||||||
|
const SHOW_NAV_LINKS = "poolsShowNavLinks";
|
||||||
|
const AUTO_INCREMENT_ORDER = "poolsAutoIncrementOrder";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is just a wrapper around SCoreException.
|
* This class is just a wrapper around SCoreException.
|
||||||
*/
|
*/
|
||||||
@ -23,6 +35,41 @@ class PoolCreationException extends SCoreException
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PoolAddPostsEvent extends Event
|
||||||
|
{
|
||||||
|
public $pool_id;
|
||||||
|
|
||||||
|
public $posts = [];
|
||||||
|
|
||||||
|
public function __construct(int $pool_id, array $posts)
|
||||||
|
{
|
||||||
|
$this->pool_id = $pool_id;
|
||||||
|
$this->posts = $posts;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class PoolCreationEvent extends Event
|
||||||
|
{
|
||||||
|
public $title;
|
||||||
|
public $user;
|
||||||
|
public $public;
|
||||||
|
public $description;
|
||||||
|
|
||||||
|
public $new_id = -1;
|
||||||
|
|
||||||
|
public function __construct(string $title, User $pool_user = null, bool $public = false, string $description = "")
|
||||||
|
{
|
||||||
|
global $user;
|
||||||
|
|
||||||
|
$this->title = $title;
|
||||||
|
$this->user = $pool_user ?? $user;
|
||||||
|
$this->public = $public;
|
||||||
|
$this->description = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class Pools extends Extension
|
class Pools extends Extension
|
||||||
{
|
{
|
||||||
public function onInitExt(InitExtEvent $event)
|
public function onInitExt(InitExtEvent $event)
|
||||||
@ -30,14 +77,14 @@ class Pools extends Extension
|
|||||||
global $config, $database;
|
global $config, $database;
|
||||||
|
|
||||||
// Set the defaults for the pools extension
|
// Set the defaults for the pools extension
|
||||||
$config->set_default_int("poolsMaxImportResults", 1000);
|
$config->set_default_int(PoolsConfig::MAX_IMPORT_RESULTS, 1000);
|
||||||
$config->set_default_int("poolsImagesPerPage", 20);
|
$config->set_default_int(PoolsConfig::IMAGES_PER_PAGE, 20);
|
||||||
$config->set_default_int("poolsListsPerPage", 20);
|
$config->set_default_int(PoolsConfig::LISTS_PER_PAGE, 20);
|
||||||
$config->set_default_int("poolsUpdatedPerPage", 20);
|
$config->set_default_int(PoolsConfig::UPDATED_PER_PAGE, 20);
|
||||||
$config->set_default_bool("poolsInfoOnViewImage", false);
|
$config->set_default_bool(PoolsConfig::INFO_ON_VIEW_IMAGE, false);
|
||||||
$config->set_default_bool("poolsAdderOnViewImage", false);
|
$config->set_default_bool(PoolsConfig::ADDER_ON_VIEW_IMAGE, false);
|
||||||
$config->set_default_bool("poolsShowNavLinks", false);
|
$config->set_default_bool(PoolsConfig::SHOW_NAV_LINKS, false);
|
||||||
$config->set_default_bool("poolsAutoIncrementOrder", false);
|
$config->set_default_bool(PoolsConfig::AUTO_INCREMENT_ORDER, false);
|
||||||
|
|
||||||
// Create the database tables
|
// Create the database tables
|
||||||
if ($config->get_int("ext_pools_version") < 1) {
|
if ($config->get_int("ext_pools_version") < 1) {
|
||||||
@ -86,21 +133,21 @@ class Pools extends Extension
|
|||||||
public function onSetupBuilding(SetupBuildingEvent $event)
|
public function onSetupBuilding(SetupBuildingEvent $event)
|
||||||
{
|
{
|
||||||
$sb = new SetupBlock("Pools");
|
$sb = new SetupBlock("Pools");
|
||||||
$sb->add_int_option("poolsMaxImportResults", "Max results on import: ");
|
$sb->add_int_option(PoolsConfig::MAX_IMPORT_RESULTS, "Max results on import: ");
|
||||||
$sb->add_int_option("poolsImagesPerPage", "<br>Images per page: ");
|
$sb->add_int_option(PoolsConfig::IMAGES_PER_PAGE, "<br>Images per page: ");
|
||||||
$sb->add_int_option("poolsListsPerPage", "<br>Index list items per page: ");
|
$sb->add_int_option(PoolsConfig::LISTS_PER_PAGE, "<br>Index list items per page: ");
|
||||||
$sb->add_int_option("poolsUpdatedPerPage", "<br>Updated list items per page: ");
|
$sb->add_int_option(PoolsConfig::UPDATED_PER_PAGE, "<br>Updated list items per page: ");
|
||||||
$sb->add_bool_option("poolsInfoOnViewImage", "<br>Show pool info on image: ");
|
$sb->add_bool_option(PoolsConfig::INFO_ON_VIEW_IMAGE, "<br>Show pool info on image: ");
|
||||||
$sb->add_bool_option("poolsShowNavLinks", "<br>Show 'Prev' & 'Next' links when viewing pool images: ");
|
$sb->add_bool_option(PoolsConfig::SHOW_NAV_LINKS, "<br>Show 'Prev' & 'Next' links when viewing pool images: ");
|
||||||
$sb->add_bool_option("poolsAutoIncrementOrder", "<br>Autoincrement order when post is added to pool:");
|
$sb->add_bool_option(PoolsConfig::AUTO_INCREMENT_ORDER, "<br>Autoincrement order when post is added to pool:");
|
||||||
//$sb->add_bool_option("poolsAdderOnViewImage", "<br>Show pool adder on image: ");
|
//$sb->add_bool_option(PoolsConfig::ADDER_ON_VIEW_IMAGE, "<br>Show pool adder on image: ");
|
||||||
|
|
||||||
$event->panel->add_block($sb);
|
$event->panel->add_block($sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPageRequest(PageRequestEvent $event)
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
{
|
{
|
||||||
global $page, $user;
|
global $page, $user, $database;
|
||||||
|
|
||||||
if ($event->page_matches("pool")) {
|
if ($event->page_matches("pool")) {
|
||||||
$pool_id = 0;
|
$pool_id = 0;
|
||||||
@ -129,9 +176,16 @@ class Pools extends Extension
|
|||||||
|
|
||||||
case "create": // ADD _POST
|
case "create": // ADD _POST
|
||||||
try {
|
try {
|
||||||
$newPoolID = $this->add_pool();
|
$title = $_POST["title"];
|
||||||
|
$event = new PoolCreationEvent(
|
||||||
|
$title,
|
||||||
|
$user,
|
||||||
|
$_POST["public"] === "Y",
|
||||||
|
$_POST["description"]);
|
||||||
|
|
||||||
|
send_event($event);
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
$page->set_redirect(make_link("pool/view/".$newPoolID));
|
$page->set_redirect(make_link("pool/view/" . $event->new_id));
|
||||||
} catch (PoolCreationException $e) {
|
} catch (PoolCreationException $e) {
|
||||||
$this->theme->display_error(400, "Error", $e->error);
|
$this->theme->display_error(400, "Error", $e->error);
|
||||||
}
|
}
|
||||||
@ -160,7 +214,7 @@ class Pools extends Extension
|
|||||||
$this->theme->edit_pool($page, $this->get_pool($pool_id), $this->edit_posts($pool_id));
|
$this->theme->edit_pool($page, $this->get_pool($pool_id), $this->edit_posts($pool_id));
|
||||||
} else {
|
} else {
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
$page->set_redirect(make_link("pool/view/".$pool_id));
|
$page->set_redirect(make_link("pool/view/" . $pool_id));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -170,13 +224,13 @@ class Pools extends Extension
|
|||||||
$this->theme->edit_order($page, $this->get_pool($pool_id), $this->edit_order($pool_id));
|
$this->theme->edit_order($page, $this->get_pool($pool_id), $this->edit_order($pool_id));
|
||||||
} else {
|
} else {
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
$page->set_redirect(make_link("pool/view/".$pool_id));
|
$page->set_redirect(make_link("pool/view/" . $pool_id));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($this->have_permission($user, $pool)) {
|
if ($this->have_permission($user, $pool)) {
|
||||||
$this->order_posts();
|
$this->order_posts();
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
$page->set_redirect(make_link("pool/view/".$pool_id));
|
$page->set_redirect(make_link("pool/view/" . $pool_id));
|
||||||
} else {
|
} else {
|
||||||
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
|
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
|
||||||
}
|
}
|
||||||
@ -193,9 +247,13 @@ class Pools extends Extension
|
|||||||
|
|
||||||
case "add_posts":
|
case "add_posts":
|
||||||
if ($this->have_permission($user, $pool)) {
|
if ($this->have_permission($user, $pool)) {
|
||||||
$this->add_posts();
|
$images = [];
|
||||||
|
foreach ($_POST['check'] as $imageID) {
|
||||||
|
$images[] = $imageID;
|
||||||
|
}
|
||||||
|
send_event(new PoolAddPostsEvent($pool_id, $images));
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
$page->set_redirect(make_link("pool/view/".$pool_id));
|
$page->set_redirect(make_link("pool/view/" . $pool_id));
|
||||||
} else {
|
} else {
|
||||||
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
|
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
|
||||||
}
|
}
|
||||||
@ -205,7 +263,7 @@ class Pools extends Extension
|
|||||||
if ($this->have_permission($user, $pool)) {
|
if ($this->have_permission($user, $pool)) {
|
||||||
$this->remove_posts();
|
$this->remove_posts();
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
$page->set_redirect(make_link("pool/view/".$pool_id));
|
$page->set_redirect(make_link("pool/view/" . $pool_id));
|
||||||
} else {
|
} else {
|
||||||
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
|
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
|
||||||
}
|
}
|
||||||
@ -216,7 +274,7 @@ class Pools extends Extension
|
|||||||
if ($this->have_permission($user, $pool)) {
|
if ($this->have_permission($user, $pool)) {
|
||||||
$this->edit_description();
|
$this->edit_description();
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
$page->set_redirect(make_link("pool/view/".$pool_id));
|
$page->set_redirect(make_link("pool/view/" . $pool_id));
|
||||||
} else {
|
} else {
|
||||||
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
|
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
|
||||||
}
|
}
|
||||||
@ -260,11 +318,11 @@ class Pools extends Extension
|
|||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if ($config->get_bool("poolsInfoOnViewImage")) {
|
if ($config->get_bool(PoolsConfig::INFO_ON_VIEW_IMAGE)) {
|
||||||
$imageID = $event->image->id;
|
$imageID = $event->image->id;
|
||||||
$poolsIDs = $this->get_pool_ids($imageID);
|
$poolsIDs = $this->get_pool_ids($imageID);
|
||||||
|
|
||||||
$show_nav = $config->get_bool("poolsShowNavLinks", false);
|
$show_nav = $config->get_bool(PoolsConfig::SHOW_NAV_LINKS, false);
|
||||||
|
|
||||||
$navInfo = [];
|
$navInfo = [];
|
||||||
foreach ($poolsIDs as $poolID) {
|
foreach ($poolsIDs as $poolID) {
|
||||||
@ -285,11 +343,11 @@ class Pools extends Extension
|
|||||||
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
|
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
|
||||||
{
|
{
|
||||||
global $config, $database, $user;
|
global $config, $database, $user;
|
||||||
if ($config->get_bool("poolsAdderOnViewImage") && !$user->is_anonymous()) {
|
if ($config->get_bool(PoolsConfig::ADDER_ON_VIEW_IMAGE) && !$user->is_anonymous()) {
|
||||||
if ($user->is_admin()) {
|
if ($user->is_admin()) {
|
||||||
$pools = $database->get_all("SELECT * FROM pools");
|
$pools = $database->get_all("SELECT * FROM pools");
|
||||||
} else {
|
} else {
|
||||||
$pools = $database->get_all("SELECT * FROM pools WHERE user_id=:id", ["id"=>$user->id]);
|
$pools = $database->get_all("SELECT * FROM pools WHERE user_id=:id", ["id" => $user->id]);
|
||||||
}
|
}
|
||||||
if (count($pools) > 0) {
|
if (count($pools) > 0) {
|
||||||
$event->add_part($this->theme->get_adder_html($event->image, $pools));
|
$event->add_part($this->theme->get_adder_html($event->image, $pools));
|
||||||
@ -327,7 +385,7 @@ class Pools extends Extension
|
|||||||
|
|
||||||
if (preg_match("/^pool[=|:]([^:]*|lastcreated):?([0-9]*)$/i", $event->term, $matches)) {
|
if (preg_match("/^pool[=|:]([^:]*|lastcreated):?([0-9]*)$/i", $event->term, $matches)) {
|
||||||
global $user;
|
global $user;
|
||||||
$poolTag = (string) str_replace("_", " ", $matches[1]);
|
$poolTag = (string)str_replace("_", " ", $matches[1]);
|
||||||
|
|
||||||
$pool = null;
|
$pool = null;
|
||||||
if ($poolTag == 'lastcreated') {
|
if ($poolTag == 'lastcreated') {
|
||||||
@ -350,6 +408,45 @@ class Pools extends Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event)
|
||||||
|
{
|
||||||
|
global $user, $database;
|
||||||
|
|
||||||
|
$pools = $database->get_all("SELECT * FROM pools ORDER BY title ");
|
||||||
|
|
||||||
|
|
||||||
|
$event->add_action("bulk_pool_add_existing", "Add To Pool", "", $this->theme->get_bulk_pool_selector($pools));
|
||||||
|
$event->add_action("bulk_pool_add_new", "Create Pool", "", $this->theme->get_bulk_pool_input());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBulkAction(BulkActionEvent $event)
|
||||||
|
{
|
||||||
|
global $user;
|
||||||
|
|
||||||
|
switch ($event->action) {
|
||||||
|
case "bulk_pool_add_existing":
|
||||||
|
if (!isset($_POST['bulk_pool_select'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$pool_id = intval($_POST['bulk_pool_select']);
|
||||||
|
$pool = $this->get_pool($pool_id);
|
||||||
|
|
||||||
|
if ($this->have_permission($user, $pool)) {
|
||||||
|
send_event(new PoolAddPostsEvent($pool_id, $event->items));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "bulk_pool_add_new":
|
||||||
|
if (!isset($_POST['bulk_pool_new'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$new_pool_title = $_POST['bulk_pool_new'];
|
||||||
|
$pce = new PoolCreationEvent($new_pool_title);
|
||||||
|
send_event($pce);
|
||||||
|
send_event(new PoolAddPostsEvent($pce->new_id, $event->items));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------- */
|
/* ------------------------------------------------- */
|
||||||
/* -------------- Private Functions -------------- */
|
/* -------------- Private Functions -------------- */
|
||||||
/* ------------------------------------------------- */
|
/* ------------------------------------------------- */
|
||||||
@ -378,7 +475,7 @@ class Pools extends Extension
|
|||||||
|
|
||||||
$pageNumber = clamp($pageNumber, 1, null) - 1;
|
$pageNumber = clamp($pageNumber, 1, null) - 1;
|
||||||
|
|
||||||
$poolsPerPage = $config->get_int("poolsListsPerPage");
|
$poolsPerPage = $config->get_int(PoolsConfig::LISTS_PER_PAGE);
|
||||||
|
|
||||||
$order_by = "";
|
$order_by = "";
|
||||||
$order = $page->get_cookie("ui-order-pool");
|
$order = $page->get_cookie("ui-order-pool");
|
||||||
@ -400,7 +497,7 @@ class Pools extends Extension
|
|||||||
ON p.user_id = u.id
|
ON p.user_id = u.id
|
||||||
$order_by
|
$order_by
|
||||||
LIMIT :l OFFSET :o
|
LIMIT :l OFFSET :o
|
||||||
", ["l"=>$poolsPerPage, "o"=>$pageNumber * $poolsPerPage]);
|
", ["l" => $poolsPerPage, "o" => $pageNumber * $poolsPerPage]);
|
||||||
|
|
||||||
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pools") / $poolsPerPage);
|
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pools") / $poolsPerPage);
|
||||||
|
|
||||||
@ -411,31 +508,32 @@ class Pools extends Extension
|
|||||||
/**
|
/**
|
||||||
* HERE WE CREATE A NEW POOL
|
* HERE WE CREATE A NEW POOL
|
||||||
*/
|
*/
|
||||||
private function add_pool(): int
|
public function onPoolCreation(PoolCreationEvent $event)
|
||||||
{
|
{
|
||||||
global $user, $database;
|
global $user, $database;
|
||||||
|
|
||||||
if ($user->is_anonymous()) {
|
if ($user->is_anonymous()) {
|
||||||
throw new PoolCreationException("You must be registered and logged in to add a image.");
|
throw new PoolCreationException("You must be registered and logged in to add a image.");
|
||||||
}
|
}
|
||||||
if (empty($_POST["title"])) {
|
if (empty($event->title)) {
|
||||||
throw new PoolCreationException("Pool title is empty.");
|
throw new PoolCreationException("Pool title is empty.");
|
||||||
}
|
}
|
||||||
if ($this->get_single_pool_from_title($_POST["title"])) {
|
if ($this->get_single_pool_from_title($event->title)) {
|
||||||
throw new PoolCreationException("A pool using this title already exists.");
|
throw new PoolCreationException("A pool using this title already exists.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$public = $_POST["public"] === "Y" ? "Y" : "N";
|
|
||||||
$database->execute(
|
$database->execute(
|
||||||
"
|
"
|
||||||
INSERT INTO pools (user_id, public, title, description, date)
|
INSERT INTO pools (user_id, public, title, description, date)
|
||||||
VALUES (:uid, :public, :title, :desc, now())",
|
VALUES (:uid, :public, :title, :desc, now())",
|
||||||
["uid"=>$user->id, "public"=>$public, "title"=>$_POST["title"], "desc"=>$_POST["description"]]
|
["uid" => $event->user->id, "public" => $event->public ? "Y" : "N", "title" => $event->title, "desc" => $event->description]
|
||||||
);
|
);
|
||||||
|
|
||||||
$poolID = $database->get_last_insert_id('pools_id_seq');
|
$poolID = $database->get_last_insert_id('pools_id_seq');
|
||||||
log_info("pools", "Pool {$poolID} created by {$user->name}");
|
log_info("pools", "Pool {$poolID} created by {$user->name}");
|
||||||
return $poolID;
|
|
||||||
|
$event->new_id = $poolID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -446,7 +544,7 @@ class Pools extends Extension
|
|||||||
private function get_pool(int $poolID): array
|
private function get_pool(int $poolID): array
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
return $database->get_all("SELECT * FROM pools WHERE id=:id", ["id"=>$poolID]);
|
return $database->get_all("SELECT * FROM pools WHERE id=:id", ["id" => $poolID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -455,16 +553,16 @@ class Pools extends Extension
|
|||||||
private function get_single_pool(int $poolID): array
|
private function get_single_pool(int $poolID): array
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
return $database->get_row("SELECT * FROM pools WHERE id=:id", ["id"=>$poolID]);
|
return $database->get_row("SELECT * FROM pools WHERE id=:id", ["id" => $poolID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve information about a pool given a pool title.
|
* Retrieve information about a pool given a pool title.
|
||||||
*/
|
*/
|
||||||
private function get_single_pool_from_title(string $poolTitle): array
|
private function get_single_pool_from_title(string $poolTitle): ?array
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
return $database->get_row("SELECT * FROM pools WHERE title=:title", ["title"=>$poolTitle]);
|
return $database->get_row("SELECT * FROM pools WHERE title=:title", ["title" => $poolTitle]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -474,7 +572,7 @@ class Pools extends Extension
|
|||||||
private function get_pool_ids(int $imageID): array
|
private function get_pool_ids(int $imageID): array
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
return $database->get_col("SELECT pool_id FROM pool_images WHERE image_id=:iid", ["iid"=>$imageID]);
|
return $database->get_col("SELECT pool_id FROM pool_images WHERE image_id=:iid", ["iid" => $imageID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -483,7 +581,7 @@ class Pools extends Extension
|
|||||||
private function get_last_userpool(int $userID): array
|
private function get_last_userpool(int $userID): array
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
return $database->get_row("SELECT * FROM pools WHERE user_id=:uid ORDER BY id DESC", ["uid"=>$userID]);
|
return $database->get_row("SELECT * FROM pools WHERE user_id=:uid ORDER BY id DESC", ["uid" => $userID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -493,7 +591,7 @@ class Pools extends Extension
|
|||||||
{
|
{
|
||||||
global $page, $config;
|
global $page, $config;
|
||||||
|
|
||||||
$poolsMaxResults = $config->get_int("poolsMaxImportResults", 1000);
|
$poolsMaxResults = $config->get_int(PoolsConfig::MAX_IMPORT_RESULTS, 1000);
|
||||||
|
|
||||||
$images = $images = Image::find_images(0, $poolsMaxResults, Tag::explode($_POST["pool_tag"]));
|
$images = $images = Image::find_images(0, $poolsMaxResults, Tag::explode($_POST["pool_tag"]));
|
||||||
$this->theme->pool_result($page, $images, $this->get_pool($pool_id));
|
$this->theme->pool_result($page, $images, $this->get_pool($pool_id));
|
||||||
@ -503,41 +601,27 @@ class Pools extends Extension
|
|||||||
/**
|
/**
|
||||||
* HERE WE ADD CHECKED IMAGES FROM POOL AND UPDATE THE HISTORY
|
* HERE WE ADD CHECKED IMAGES FROM POOL AND UPDATE THE HISTORY
|
||||||
*
|
*
|
||||||
* TODO: Fix this so that the pool ID and images are passed as Arguments to the function.
|
|
||||||
*/
|
*/
|
||||||
private function add_posts(): int
|
public function onPoolAddPosts(PoolAddPostsEvent $event)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database, $user;
|
||||||
|
|
||||||
$poolID = int_escape($_POST['pool_id']);
|
$pool = $this->get_single_pool($event->pool_id);
|
||||||
$images = "";
|
if (!$this->have_permission($user, $pool)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($_POST['check'] as $imageID) {
|
$images = " ";
|
||||||
if (!$this->check_post($poolID, $imageID)) {
|
foreach ($event->posts as $post_id) {
|
||||||
$database->execute(
|
if ($this->add_post($event->pool_id, $post_id, false)) {
|
||||||
"
|
$images .= " " . $post_id;
|
||||||
INSERT INTO pool_images (pool_id, image_id)
|
|
||||||
VALUES (:pid, :iid)",
|
|
||||||
["pid"=>$poolID, "iid"=>$imageID]
|
|
||||||
);
|
|
||||||
|
|
||||||
$images .= " ".$imageID;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strlen($images) == 0) {
|
if (!strlen($images) == 0) {
|
||||||
$count = int_escape($database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid"=>$poolID]));
|
$count = int_escape($database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid" => $event->pool_id]));
|
||||||
$this->add_history($poolID, 1, $images, $count);
|
$this->add_history($event->pool_id, 1, $images, $count);
|
||||||
}
|
}
|
||||||
|
|
||||||
$database->Execute(
|
|
||||||
"
|
|
||||||
UPDATE pools
|
|
||||||
SET posts=(SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid)
|
|
||||||
WHERE id=:pid",
|
|
||||||
["pid"=>$poolID]
|
|
||||||
);
|
|
||||||
return $poolID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -556,7 +640,7 @@ class Pools extends Extension
|
|||||||
UPDATE pool_images
|
UPDATE pool_images
|
||||||
SET image_order = :ord
|
SET image_order = :ord
|
||||||
WHERE pool_id = :pid AND image_id = :iid",
|
WHERE pool_id = :pid AND image_id = :iid",
|
||||||
["ord"=>$imageORDER, "pid"=>$poolID, "iid"=>$imageID]
|
["ord" => $imageORDER, "pid" => $poolID, "iid" => $imageID]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,11 +660,11 @@ class Pools extends Extension
|
|||||||
$images = "";
|
$images = "";
|
||||||
|
|
||||||
foreach ($_POST['check'] as $imageID) {
|
foreach ($_POST['check'] as $imageID) {
|
||||||
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", ["pid"=>$poolID, "iid"=>$imageID]);
|
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", ["pid" => $poolID, "iid" => $imageID]);
|
||||||
$images .= " ".$imageID;
|
$images .= " " . $imageID;
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid"=>$poolID]);
|
$count = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid" => $poolID]);
|
||||||
$this->add_history($poolID, 0, $images, $count);
|
$this->add_history($poolID, 0, $images, $count);
|
||||||
return $poolID;
|
return $poolID;
|
||||||
}
|
}
|
||||||
@ -593,7 +677,7 @@ class Pools extends Extension
|
|||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$poolID = int_escape($_POST['pool_id']);
|
$poolID = int_escape($_POST['pool_id']);
|
||||||
$database->execute("UPDATE pools SET description=:dsc WHERE id=:pid", ["dsc"=>$_POST['description'], "pid"=>$poolID]);
|
$database->execute("UPDATE pools SET description=:dsc WHERE id=:pid", ["dsc" => $_POST['description'], "pid" => $poolID]);
|
||||||
|
|
||||||
return $poolID;
|
return $poolID;
|
||||||
}
|
}
|
||||||
@ -605,7 +689,7 @@ class Pools extends Extension
|
|||||||
private function check_post(int $poolID, int $imageID): bool
|
private function check_post(int $poolID, int $imageID): bool
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$result = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid AND image_id=:iid", ["pid"=>$poolID, "iid"=>$imageID]);
|
$result = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid AND image_id=:iid", ["pid" => $poolID, "iid" => $imageID]);
|
||||||
return ($result != 0);
|
return ($result != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,7 +736,7 @@ class Pools extends Extension
|
|||||||
) AS next
|
) AS next
|
||||||
|
|
||||||
LIMIT 1",
|
LIMIT 1",
|
||||||
["pid"=>$pool['id'], "iid"=>$imageID]
|
["pid" => $pool['id'], "iid" => $imageID]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (empty($result)) {
|
if (empty($result)) {
|
||||||
@ -682,7 +766,7 @@ class Pools extends Extension
|
|||||||
$poolID = int_escape($poolID);
|
$poolID = int_escape($poolID);
|
||||||
$pool = $this->get_pool($poolID);
|
$pool = $this->get_pool($poolID);
|
||||||
|
|
||||||
$imagesPerPage = $config->get_int("poolsImagesPerPage");
|
$imagesPerPage = $config->get_int(PoolsConfig::IMAGES_PER_PAGE);
|
||||||
|
|
||||||
// WE CHECK IF THE EXTENSION RATING IS INSTALLED, WHICH VERSION AND IF IT
|
// WE CHECK IF THE EXTENSION RATING IS INSTALLED, WHICH VERSION AND IF IT
|
||||||
// WORKS TO SHOW/HIDE SAFE, QUESTIONABLE, EXPLICIT AND UNRATED IMAGES FROM USER
|
// WORKS TO SHOW/HIDE SAFE, QUESTIONABLE, EXPLICIT AND UNRATED IMAGES FROM USER
|
||||||
@ -698,17 +782,17 @@ class Pools extends Extension
|
|||||||
WHERE p.pool_id = :pid AND i.rating IN ($rating)
|
WHERE p.pool_id = :pid AND i.rating IN ($rating)
|
||||||
ORDER BY p.image_order ASC
|
ORDER BY p.image_order ASC
|
||||||
LIMIT :l OFFSET :o",
|
LIMIT :l OFFSET :o",
|
||||||
["pid"=>$poolID, "l"=>$imagesPerPage, "o"=>$pageNumber * $imagesPerPage]
|
["pid" => $poolID, "l" => $imagesPerPage, "o" => $pageNumber * $imagesPerPage]
|
||||||
);
|
);
|
||||||
|
|
||||||
$totalPages = ceil($database->get_one(
|
$totalPages = ceil($database->get_one(
|
||||||
"
|
"
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM pool_images AS p
|
FROM pool_images AS p
|
||||||
INNER JOIN images AS i ON i.id = p.image_id
|
INNER JOIN images AS i ON i.id = p.image_id
|
||||||
WHERE pool_id=:pid AND i.rating IN ($rating)",
|
WHERE pool_id=:pid AND i.rating IN ($rating)",
|
||||||
["pid"=>$poolID]
|
["pid" => $poolID]
|
||||||
) / $imagesPerPage);
|
) / $imagesPerPage);
|
||||||
} else {
|
} else {
|
||||||
$result = $database->get_all(
|
$result = $database->get_all(
|
||||||
"
|
"
|
||||||
@ -717,12 +801,13 @@ class Pools extends Extension
|
|||||||
WHERE pool_id=:pid
|
WHERE pool_id=:pid
|
||||||
ORDER BY image_order ASC
|
ORDER BY image_order ASC
|
||||||
LIMIT :l OFFSET :o",
|
LIMIT :l OFFSET :o",
|
||||||
["pid"=>$poolID, "l"=>$imagesPerPage, "o"=>$pageNumber * $imagesPerPage]
|
["pid" => $poolID, "l" => $imagesPerPage, "o" => $pageNumber * $imagesPerPage]
|
||||||
);
|
);
|
||||||
|
|
||||||
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid"=>$poolID]) / $imagesPerPage);
|
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid" => $poolID]) / $imagesPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$images = [];
|
$images = [];
|
||||||
foreach ($result as $singleResult) {
|
foreach ($result as $singleResult) {
|
||||||
$images[] = Image::by_id($singleResult["image_id"]);
|
$images[] = Image::by_id($singleResult["image_id"]);
|
||||||
@ -740,7 +825,7 @@ class Pools extends Extension
|
|||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", ["pid"=>$poolID]);
|
$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", ["pid" => $poolID]);
|
||||||
$images = [];
|
$images = [];
|
||||||
|
|
||||||
while ($row = $result->fetch()) {
|
while ($row = $result->fetch()) {
|
||||||
@ -761,7 +846,7 @@ class Pools extends Extension
|
|||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", ["pid"=>$poolID]);
|
$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", ["pid" => $poolID]);
|
||||||
$images = [];
|
$images = [];
|
||||||
|
|
||||||
while ($row = $result->fetch()) {
|
while ($row = $result->fetch()) {
|
||||||
@ -770,7 +855,7 @@ class Pools extends Extension
|
|||||||
SELECT * FROM images AS i
|
SELECT * FROM images AS i
|
||||||
INNER JOIN pool_images AS p ON i.id = p.image_id
|
INNER JOIN pool_images AS p ON i.id = p.image_id
|
||||||
WHERE pool_id=:pid AND i.id=:iid",
|
WHERE pool_id=:pid AND i.id=:iid",
|
||||||
["pid"=>$poolID, "iid"=>$row['image_id']]
|
["pid" => $poolID, "iid" => $row['image_id']]
|
||||||
);
|
);
|
||||||
$image = ($image ? new Image($image) : null);
|
$image = ($image ? new Image($image) : null);
|
||||||
$images[] = [$image];
|
$images[] = [$image];
|
||||||
@ -787,15 +872,15 @@ class Pools extends Extension
|
|||||||
{
|
{
|
||||||
global $user, $database;
|
global $user, $database;
|
||||||
|
|
||||||
$p_id = $database->get_one("SELECT user_id FROM pools WHERE id = :pid", ["pid"=>$poolID]);
|
$p_id = $database->get_one("SELECT user_id FROM pools WHERE id = :pid", ["pid" => $poolID]);
|
||||||
if ($user->is_admin()) {
|
if ($user->is_admin()) {
|
||||||
$database->execute("DELETE FROM pool_history WHERE pool_id = :pid", ["pid"=>$poolID]);
|
$database->execute("DELETE FROM pool_history WHERE pool_id = :pid", ["pid" => $poolID]);
|
||||||
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid", ["pid"=>$poolID]);
|
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid", ["pid" => $poolID]);
|
||||||
$database->execute("DELETE FROM pools WHERE id = :pid", ["pid"=>$poolID]);
|
$database->execute("DELETE FROM pools WHERE id = :pid", ["pid" => $poolID]);
|
||||||
} elseif ($user->id == $p_id) {
|
} elseif ($user->id == $p_id) {
|
||||||
$database->execute("DELETE FROM pool_history WHERE pool_id = :pid", ["pid"=>$poolID]);
|
$database->execute("DELETE FROM pool_history WHERE pool_id = :pid", ["pid" => $poolID]);
|
||||||
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid", ["pid"=>$poolID]);
|
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid", ["pid" => $poolID]);
|
||||||
$database->execute("DELETE FROM pools WHERE id = :pid AND user_id = :uid", ["pid"=>$poolID, "uid"=>$user->id]);
|
$database->execute("DELETE FROM pools WHERE id = :pid AND user_id = :uid", ["pid" => $poolID, "uid" => $user->id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,7 +897,7 @@ class Pools extends Extension
|
|||||||
"
|
"
|
||||||
INSERT INTO pool_history (pool_id, user_id, action, images, count, date)
|
INSERT INTO pool_history (pool_id, user_id, action, images, count, date)
|
||||||
VALUES (:pid, :uid, :act, :img, :count, now())",
|
VALUES (:pid, :uid, :act, :img, :count, now())",
|
||||||
["pid"=>$poolID, "uid"=>$user->id, "act"=>$action, "img"=>$images, "count"=>$count]
|
["pid" => $poolID, "uid" => $user->id, "act" => $action, "img" => $images, "count" => $count]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -831,7 +916,7 @@ class Pools extends Extension
|
|||||||
$pageNumber--;
|
$pageNumber--;
|
||||||
}
|
}
|
||||||
|
|
||||||
$historiesPerPage = $config->get_int("poolsUpdatedPerPage");
|
$historiesPerPage = $config->get_int(PoolsConfig::UPDATED_PER_PAGE);
|
||||||
|
|
||||||
$history = $database->get_all("
|
$history = $database->get_all("
|
||||||
SELECT h.id, h.pool_id, h.user_id, h.action, h.images,
|
SELECT h.id, h.pool_id, h.user_id, h.action, h.images,
|
||||||
@ -843,7 +928,7 @@ class Pools extends Extension
|
|||||||
ON h.user_id = u.id
|
ON h.user_id = u.id
|
||||||
ORDER BY h.date DESC
|
ORDER BY h.date DESC
|
||||||
LIMIT :l OFFSET :o
|
LIMIT :l OFFSET :o
|
||||||
", ["l"=>$historiesPerPage, "o"=>$pageNumber * $historiesPerPage]);
|
", ["l" => $historiesPerPage, "o" => $pageNumber * $historiesPerPage]);
|
||||||
|
|
||||||
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pool_history") / $historiesPerPage);
|
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pool_history") / $historiesPerPage);
|
||||||
|
|
||||||
@ -856,7 +941,7 @@ class Pools extends Extension
|
|||||||
private function revert_history(int $historyID)
|
private function revert_history(int $historyID)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$status = $database->get_all("SELECT * FROM pool_history WHERE id=:hid", ["hid"=>$historyID]);
|
$status = $database->get_all("SELECT * FROM pool_history WHERE id=:hid", ["hid" => $historyID]);
|
||||||
|
|
||||||
foreach ($status as $entry) {
|
foreach ($status as $entry) {
|
||||||
$images = trim($entry['images']);
|
$images = trim($entry['images']);
|
||||||
@ -871,7 +956,7 @@ class Pools extends Extension
|
|||||||
$imageID = $image;
|
$imageID = $image;
|
||||||
$this->add_post($poolID, $imageID);
|
$this->add_post($poolID, $imageID);
|
||||||
|
|
||||||
$imageArray .= " ".$imageID;
|
$imageArray .= " " . $imageID;
|
||||||
$newAction = 1;
|
$newAction = 1;
|
||||||
}
|
}
|
||||||
} elseif ($entry['action'] == 1) {
|
} elseif ($entry['action'] == 1) {
|
||||||
@ -880,7 +965,7 @@ class Pools extends Extension
|
|||||||
$imageID = $image;
|
$imageID = $image;
|
||||||
$this->delete_post($poolID, $imageID);
|
$this->delete_post($poolID, $imageID);
|
||||||
|
|
||||||
$imageArray .= " ".$imageID;
|
$imageArray .= " " . $imageID;
|
||||||
$newAction = 0;
|
$newAction = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -889,7 +974,7 @@ class Pools extends Extension
|
|||||||
continue; // go on to the next one.
|
continue; // go on to the next one.
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid"=>$poolID]);
|
$count = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid" => $poolID]);
|
||||||
$this->add_history($poolID, $newAction, $imageArray, $count);
|
$this->add_history($poolID, $newAction, $imageArray, $count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -898,18 +983,18 @@ class Pools extends Extension
|
|||||||
* HERE WE ADD A SIMPLE POST FROM POOL.
|
* HERE WE ADD A SIMPLE POST FROM POOL.
|
||||||
* USED WITH FOREACH IN revert_history() & onTagTermParse().
|
* USED WITH FOREACH IN revert_history() & onTagTermParse().
|
||||||
*/
|
*/
|
||||||
private function add_post(int $poolID, int $imageID, bool $history=false, int $imageOrder=0)
|
private function add_post(int $poolID, int $imageID, bool $history = false, int $imageOrder = 0): bool
|
||||||
{
|
{
|
||||||
global $database, $config;
|
global $database, $config;
|
||||||
|
|
||||||
if (!$this->check_post($poolID, $imageID)) {
|
if (!$this->check_post($poolID, $imageID)) {
|
||||||
if ($config->get_bool("poolsAutoIncrementOrder") && $imageOrder === 0) {
|
if ($config->get_bool(PoolsConfig::AUTO_INCREMENT_ORDER) && $imageOrder === 0) {
|
||||||
$imageOrder = $database->get_one(
|
$imageOrder = $database->get_one(
|
||||||
"
|
"
|
||||||
SELECT CASE WHEN image_order IS NOT NULL THEN MAX(image_order) + 1 ELSE 0 END
|
SELECT COALESCE(MAX(image_order),0) + 1
|
||||||
FROM pool_images
|
FROM pool_images
|
||||||
WHERE pool_id = :pid",
|
WHERE pool_id = :pid AND image_order IS NOT NULL",
|
||||||
["pid"=>$poolID]
|
["pid" => $poolID]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -917,31 +1002,43 @@ class Pools extends Extension
|
|||||||
"
|
"
|
||||||
INSERT INTO pool_images (pool_id, image_id, image_order)
|
INSERT INTO pool_images (pool_id, image_id, image_order)
|
||||||
VALUES (:pid, :iid, :ord)",
|
VALUES (:pid, :iid, :ord)",
|
||||||
["pid"=>$poolID, "iid"=>$imageID, "ord"=>$imageOrder]
|
["pid" => $poolID, "iid" => $imageID, "ord" => $imageOrder]
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
// If the post is already added, there is nothing else to do
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$database->execute("UPDATE pools SET posts=(SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid) WHERE id=:pid", ["pid"=>$poolID]);
|
$this->update_count($poolID);
|
||||||
|
|
||||||
if ($history) {
|
if ($history) {
|
||||||
$count = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid"=>$poolID]);
|
$count = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid" => $poolID]);
|
||||||
$this->add_history($poolID, 1, $imageID, $count);
|
$this->add_history($poolID, 1, $imageID, $count);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function update_count($pool_id)
|
||||||
|
{
|
||||||
|
global $database;
|
||||||
|
$database->execute("UPDATE pools SET posts=(SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid) WHERE id=:pid", ["pid" => $pool_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HERE WE REMOVE A SIMPLE POST FROM POOL.
|
* HERE WE REMOVE A SIMPLE POST FROM POOL.
|
||||||
* USED WITH FOREACH IN revert_history() & onTagTermParse().
|
* USED WITH FOREACH IN revert_history() & onTagTermParse().
|
||||||
*/
|
*/
|
||||||
private function delete_post(int $poolID, int $imageID, bool $history=false)
|
private function delete_post(int $poolID, int $imageID, bool $history = false)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", ["pid"=>$poolID, "iid"=>$imageID]);
|
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", ["pid" => $poolID, "iid" => $imageID]);
|
||||||
$database->execute("UPDATE pools SET posts=(SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid) WHERE id=:pid", ["pid"=>$poolID]);
|
|
||||||
|
$this->update_count($poolID);
|
||||||
|
|
||||||
if ($history) {
|
if ($history) {
|
||||||
$count = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid"=>$poolID]);
|
$count = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid" => $poolID]);
|
||||||
$this->add_history($poolID, 0, $imageID, $count);
|
$this->add_history($poolID, 0, $imageID, $count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,15 +12,15 @@ class PoolsTheme extends Themelet
|
|||||||
|
|
||||||
$linksPools = [];
|
$linksPools = [];
|
||||||
foreach ($navIDs as $poolID => $pool) {
|
foreach ($navIDs as $poolID => $pool) {
|
||||||
$linksPools[] = "<a href='".make_link("pool/view/".$poolID)."'>".html_escape($pool['info']['title'])."</a>";
|
$linksPools[] = "<a href='" . make_link("pool/view/" . $poolID) . "'>" . html_escape($pool['info']['title']) . "</a>";
|
||||||
|
|
||||||
if (array_key_exists('nav', $pool)) {
|
if (array_key_exists('nav', $pool)) {
|
||||||
$navlinks = "";
|
$navlinks = "";
|
||||||
if (!empty($pool['nav']['prev'])) {
|
if (!empty($pool['nav']['prev'])) {
|
||||||
$navlinks .= '<a href="'.make_link('post/view/'.$pool['nav']['prev']).'" class="pools_prev_img">Prev</a>';
|
$navlinks .= '<a href="' . make_link('post/view/' . $pool['nav']['prev']) . '" class="pools_prev_img">Prev</a>';
|
||||||
}
|
}
|
||||||
if (!empty($pool['nav']['next'])) {
|
if (!empty($pool['nav']['next'])) {
|
||||||
$navlinks .= '<a href="'.make_link('post/view/'.$pool['nav']['next']).'" class="pools_next_img">Next</a>';
|
$navlinks .= '<a href="' . make_link('post/view/' . $pool['nav']['next']) . '" class="pools_next_img">Next</a>';
|
||||||
}
|
}
|
||||||
if (!empty($navlinks)) {
|
if (!empty($navlinks)) {
|
||||||
$navlinks .= "<div style='height: 5px'></div>";
|
$navlinks .= "<div style='height: 5px'></div>";
|
||||||
@ -38,9 +38,9 @@ class PoolsTheme extends Themelet
|
|||||||
{
|
{
|
||||||
$h = "";
|
$h = "";
|
||||||
foreach ($pools as $pool) {
|
foreach ($pools as $pool) {
|
||||||
$h .= "<option value='".$pool['id']."'>".html_escape($pool['title'])."</option>";
|
$h .= "<option value='" . $pool['id'] . "'>" . html_escape($pool['title']) . "</option>";
|
||||||
}
|
}
|
||||||
$editor = "\n".make_form(make_link("pool/add_post"))."
|
$editor = "\n" . make_form(make_link("pool/add_post")) . "
|
||||||
<select name='pool_id'>
|
<select name='pool_id'>
|
||||||
$h
|
$h
|
||||||
</select>
|
</select>
|
||||||
@ -67,15 +67,15 @@ class PoolsTheme extends Themelet
|
|||||||
|
|
||||||
// Build up the list of pools.
|
// Build up the list of pools.
|
||||||
foreach ($pools as $pool) {
|
foreach ($pools as $pool) {
|
||||||
$pool_link = '<a href="'.make_link("pool/view/".$pool['id']).'">'.html_escape($pool['title'])."</a>";
|
$pool_link = '<a href="' . make_link("pool/view/" . $pool['id']) . '">' . html_escape($pool['title']) . "</a>";
|
||||||
$user_link = '<a href="'.make_link("user/".url_escape($pool['user_name'])).'">'.html_escape($pool['user_name'])."</a>";
|
$user_link = '<a href="' . make_link("user/" . url_escape($pool['user_name'])) . '">' . html_escape($pool['user_name']) . "</a>";
|
||||||
$public = ($pool['public'] == "Y" ? "Yes" : "No");
|
$public = ($pool['public'] == "Y" ? "Yes" : "No");
|
||||||
|
|
||||||
$html .= "<tr>".
|
$html .= "<tr>" .
|
||||||
"<td class='left'>".$pool_link."</td>".
|
"<td class='left'>" . $pool_link . "</td>" .
|
||||||
"<td>".$user_link."</td>".
|
"<td>" . $user_link . "</td>" .
|
||||||
"<td>".$pool['posts']."</td>".
|
"<td>" . $pool['posts'] . "</td>" .
|
||||||
"<td>".$public."</td>".
|
"<td>" . $public . "</td>" .
|
||||||
"</tr>";
|
"</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,6 @@ class PoolsTheme extends Themelet
|
|||||||
$page->add_block(new Block("Pools", $html, "main", 10));
|
$page->add_block(new Block("Pools", $html, "main", 10));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->display_paginator($page, "pool/list", null, $pageNumber, $totalPages);
|
$this->display_paginator($page, "pool/list", null, $pageNumber, $totalPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +105,7 @@ class PoolsTheme extends Themelet
|
|||||||
public function new_pool_composer(Page $page)
|
public function new_pool_composer(Page $page)
|
||||||
{
|
{
|
||||||
$create_html = "
|
$create_html = "
|
||||||
".make_form(make_link("pool/create"))."
|
" . make_form(make_link("pool/create")) . "
|
||||||
<table>
|
<table>
|
||||||
<tr><td>Title:</td><td><input type='text' name='title'></td></tr>
|
<tr><td>Title:</td><td><input type='text' name='title'></td></tr>
|
||||||
<tr><td>Public?</td><td><input name='public' type='checkbox' value='Y' checked='checked'/></td></tr>
|
<tr><td>Public?</td><td><input name='public' type='checkbox' value='Y' checked='checked'/></td></tr>
|
||||||
@ -120,7 +119,7 @@ class PoolsTheme extends Themelet
|
|||||||
$page->add_block(new Block("Create Pool", $create_html, "main", 20));
|
$page->add_block(new Block("Create Pool", $create_html, "main", 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function display_top(?array $pools, string $heading, bool $check_all=false)
|
private function display_top(?array $pools, string $heading, bool $check_all = false)
|
||||||
{
|
{
|
||||||
global $page, $user;
|
global $page, $user;
|
||||||
|
|
||||||
@ -128,9 +127,9 @@ class PoolsTheme extends Themelet
|
|||||||
$page->set_heading($heading);
|
$page->set_heading($heading);
|
||||||
|
|
||||||
$poolnav_html = '
|
$poolnav_html = '
|
||||||
<a href="'.make_link("pool/list").'">Pool Index</a>
|
<a href="' . make_link("pool/list") . '">Pool Index</a>
|
||||||
<br><a href="'.make_link("pool/new").'">Create Pool</a>
|
<br><a href="' . make_link("pool/new") . '">Create Pool</a>
|
||||||
<br><a href="'.make_link("pool/updated").'">Pool Changes</a>
|
<br><a href="' . make_link("pool/updated") . '">Pool Changes</a>
|
||||||
';
|
';
|
||||||
|
|
||||||
$page->add_block(new NavBlock());
|
$page->add_block(new NavBlock());
|
||||||
@ -157,16 +156,16 @@ class PoolsTheme extends Themelet
|
|||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
|
|
||||||
$this->display_top($pools, "Pool: ".html_escape($pools[0]['title']));
|
$this->display_top($pools, "Pool: " . html_escape($pools[0]['title']));
|
||||||
|
|
||||||
$pool_images = '';
|
$pool_images = '';
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
$thumb_html = $this->build_thumb_html($image);
|
$thumb_html = $this->build_thumb_html($image);
|
||||||
$pool_images .= "\n".$thumb_html."\n";
|
$pool_images .= "\n" . $thumb_html . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$page->add_block(new Block("Viewing Posts", $pool_images, "main", 30));
|
$page->add_block(new Block("Viewing Posts", $pool_images, "main", 30));
|
||||||
$this->display_paginator($page, "pool/view/".$pools[0]['id'], null, $pageNumber, $totalPages);
|
$this->display_paginator($page, "pool/view/" . $pools[0]['id'], null, $pageNumber, $totalPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -177,22 +176,22 @@ class PoolsTheme extends Themelet
|
|||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
$editor = "\n".make_form(make_link('pool/import')).'
|
$editor = "\n" . make_form(make_link('pool/import')) . '
|
||||||
<input type="text" name="pool_tag" id="edit_pool_tag" placeholder="Please enter a tag"/>
|
<input type="text" name="pool_tag" id="edit_pool_tag" placeholder="Please enter a tag"/>
|
||||||
<input type="submit" name="edit" id="edit_pool_import_btn" value="Import"/>
|
<input type="submit" name="edit" id="edit_pool_import_btn" value="Import"/>
|
||||||
<input type="hidden" name="pool_id" value="'.$pool['id'].'">
|
<input type="hidden" name="pool_id" value="' . $pool['id'] . '">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
'.make_form(make_link('pool/edit')).'
|
' . make_form(make_link('pool/edit')) . '
|
||||||
<input type="submit" name="edit" id="edit_pool_btn" value="Edit Pool"/>
|
<input type="submit" name="edit" id="edit_pool_btn" value="Edit Pool"/>
|
||||||
<input type="hidden" name="edit_pool" value="yes">
|
<input type="hidden" name="edit_pool" value="yes">
|
||||||
<input type="hidden" name="pool_id" value="'.$pool['id'].'">
|
<input type="hidden" name="pool_id" value="' . $pool['id'] . '">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
'.make_form(make_link('pool/order')).'
|
' . make_form(make_link('pool/order')) . '
|
||||||
<input type="submit" name="edit" id="edit_pool_order_btn" value="Order Pool"/>
|
<input type="submit" name="edit" id="edit_pool_order_btn" value="Order Pool"/>
|
||||||
<input type="hidden" name="order_view" value="yes">
|
<input type="hidden" name="order_view" value="yes">
|
||||||
<input type="hidden" name="pool_id" value="'.$pool['id'].'">
|
<input type="hidden" name="pool_id" value="' . $pool['id'] . '">
|
||||||
</form>
|
</form>
|
||||||
';
|
';
|
||||||
|
|
||||||
@ -206,9 +205,9 @@ class PoolsTheme extends Themelet
|
|||||||
//-->
|
//-->
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
".make_form(make_link("pool/nuke"))."
|
" . make_form(make_link("pool/nuke")) . "
|
||||||
<input type='submit' name='delete' id='delete_pool_btn' value='Delete Pool' onclick='return confirm_action()' />
|
<input type='submit' name='delete' id='delete_pool_btn' value='Delete Pool' onclick='return confirm_action()' />
|
||||||
<input type='hidden' name='pool_id' value='".$pool['id']."'>
|
<input type='hidden' name='pool_id' value='" . $pool['id'] . "'>
|
||||||
</form>
|
</form>
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
@ -246,19 +245,19 @@ class PoolsTheme extends Themelet
|
|||||||
</script>
|
</script>
|
||||||
";
|
";
|
||||||
|
|
||||||
$pool_images .= "<form action='".make_link("pool/add_posts")."' method='POST' name='checks'>";
|
$pool_images .= "<form action='" . make_link("pool/add_posts") . "' method='POST' name='checks'>";
|
||||||
|
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
$thumb_html = $this->build_thumb_html($image);
|
$thumb_html = $this->build_thumb_html($image);
|
||||||
|
|
||||||
$pool_images .= '<span class="thumb">'. $thumb_html .'<br>'.
|
$pool_images .= '<span class="thumb">' . $thumb_html . '<br>' .
|
||||||
'<input name="check[]" type="checkbox" value="'.$image->id.'" />'.
|
'<input name="check[]" type="checkbox" value="' . $image->id . '" />' .
|
||||||
'</span>';
|
'</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$pool_images .= "<br>".
|
$pool_images .= "<br>" .
|
||||||
"<input type='submit' name='edit' id='edit_pool_add_btn' value='Add Selected' onclick='return confirm_action()'/>".
|
"<input type='submit' name='edit' id='edit_pool_add_btn' value='Add Selected' onclick='return confirm_action()'/>" .
|
||||||
"<input type='hidden' name='pool_id' value='".$pool[0]['id']."'>".
|
"<input type='hidden' name='pool_id' value='" . $pool[0]['id'] . "'>" .
|
||||||
"</form>";
|
"</form>";
|
||||||
|
|
||||||
$page->add_block(new Block("Import", $pool_images, "main", 30));
|
$page->add_block(new Block("Import", $pool_images, "main", 30));
|
||||||
@ -273,21 +272,21 @@ class PoolsTheme extends Themelet
|
|||||||
{
|
{
|
||||||
$this->display_top($pools, "Sorting Pool");
|
$this->display_top($pools, "Sorting Pool");
|
||||||
|
|
||||||
$pool_images = "\n<form action='".make_link("pool/order")."' method='POST' name='checks'>";
|
$pool_images = "\n<form action='" . make_link("pool/order") . "' method='POST' name='checks'>";
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($images as $pair) {
|
foreach ($images as $pair) {
|
||||||
$image = $pair[0];
|
$image = $pair[0];
|
||||||
$thumb_html = $this->build_thumb_html($image);
|
$thumb_html = $this->build_thumb_html($image);
|
||||||
$pool_images .= '<span class="thumb">'."\n".$thumb_html."\n".
|
$pool_images .= '<span class="thumb">' . "\n" . $thumb_html . "\n" .
|
||||||
'<br><input name="imgs['.$i.'][]" type="number" style="max-width:50px;" value="'.$image->image_order.'" />'.
|
'<br><input name="imgs[' . $i . '][]" type="number" style="max-width:50px;" value="' . $image->image_order . '" />' .
|
||||||
'<input name="imgs['.$i.'][]" type="hidden" value="'.$image->id.'" />'.
|
'<input name="imgs[' . $i . '][]" type="hidden" value="' . $image->id . '" />' .
|
||||||
'</span>';
|
'</span>';
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pool_images .= "<br>".
|
$pool_images .= "<br>" .
|
||||||
"<input type='submit' name='edit' id='edit_pool_order' value='Order'/>".
|
"<input type='submit' name='edit' id='edit_pool_order' value='Order'/>" .
|
||||||
"<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>".
|
"<input type='hidden' name='pool_id' value='" . $pools[0]['id'] . "'>" .
|
||||||
"</form>";
|
"</form>";
|
||||||
|
|
||||||
$page->add_block(new Block("Sorting Posts", $pool_images, "main", 30));
|
$page->add_block(new Block("Sorting Posts", $pool_images, "main", 30));
|
||||||
@ -303,29 +302,29 @@ class PoolsTheme extends Themelet
|
|||||||
{
|
{
|
||||||
/* EDIT POOL DESCRIPTION */
|
/* EDIT POOL DESCRIPTION */
|
||||||
$desc_html = "
|
$desc_html = "
|
||||||
".make_form(make_link("pool/edit_description"))."
|
" . make_form(make_link("pool/edit_description")) . "
|
||||||
<textarea name='description'>".$pools[0]['description']."</textarea><br />
|
<textarea name='description'>" . $pools[0]['description'] . "</textarea><br />
|
||||||
<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>
|
<input type='hidden' name='pool_id' value='" . $pools[0]['id'] . "'>
|
||||||
<input type='submit' value='Change Description' />
|
<input type='submit' value='Change Description' />
|
||||||
</form>
|
</form>
|
||||||
";
|
";
|
||||||
|
|
||||||
/* REMOVE POOLS */
|
/* REMOVE POOLS */
|
||||||
$pool_images = "\n<form action='".make_link("pool/remove_posts")."' method='POST' name='checks'>";
|
$pool_images = "\n<form action='" . make_link("pool/remove_posts") . "' method='POST' name='checks'>";
|
||||||
|
|
||||||
foreach ($images as $pair) {
|
foreach ($images as $pair) {
|
||||||
$image = $pair[0];
|
$image = $pair[0];
|
||||||
|
|
||||||
$thumb_html = $this->build_thumb_html($image);
|
$thumb_html = $this->build_thumb_html($image);
|
||||||
|
|
||||||
$pool_images .= '<span class="thumb">'."\n".$thumb_html."\n".
|
$pool_images .= '<span class="thumb">' . "\n" . $thumb_html . "\n" .
|
||||||
'<br><input name="check[]" type="checkbox" value="'.$image->id.'" />'.
|
'<br><input name="check[]" type="checkbox" value="' . $image->id . '" />' .
|
||||||
'</span>';
|
'</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$pool_images .= "<br>".
|
$pool_images .= "<br>" .
|
||||||
"<input type='submit' name='edit' id='edit_pool_remove_sel' value='Remove Selected'/>".
|
"<input type='submit' name='edit' id='edit_pool_remove_sel' value='Remove Selected'/>" .
|
||||||
"<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>".
|
"<input type='hidden' name='pool_id' value='" . $pools[0]['id'] . "'>" .
|
||||||
"</form>";
|
"</form>";
|
||||||
|
|
||||||
$pools[0]['description'] = ""; //This is a rough fix to avoid showing the description twice.
|
$pools[0]['description'] = ""; //This is a rough fix to avoid showing the description twice.
|
||||||
@ -353,9 +352,9 @@ class PoolsTheme extends Themelet
|
|||||||
</tr></thead><tbody>';
|
</tr></thead><tbody>';
|
||||||
|
|
||||||
foreach ($histories as $history) {
|
foreach ($histories as $history) {
|
||||||
$pool_link = "<a href='".make_link("pool/view/".$history['pool_id'])."'>".html_escape($history['title'])."</a>";
|
$pool_link = "<a href='" . make_link("pool/view/" . $history['pool_id']) . "'>" . html_escape($history['title']) . "</a>";
|
||||||
$user_link = "<a href='".make_link("user/".url_escape($history['user_name']))."'>".html_escape($history['user_name'])."</a>";
|
$user_link = "<a href='" . make_link("user/" . url_escape($history['user_name'])) . "'>" . html_escape($history['user_name']) . "</a>";
|
||||||
$revert_link = "<a href='".make_link("pool/revert/".$history['id'])."'>Revert</a>";
|
$revert_link = "<a href='" . make_link("pool/revert/" . $history['id']) . "'>Revert</a>";
|
||||||
|
|
||||||
if ($history['action'] == 1) {
|
if ($history['action'] == 1) {
|
||||||
$prefix = "+";
|
$prefix = "+";
|
||||||
@ -370,16 +369,16 @@ class PoolsTheme extends Themelet
|
|||||||
|
|
||||||
$image_link = "";
|
$image_link = "";
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
$image_link .= "<a href='".make_link("post/view/".$image)."'>".$prefix.$image." </a>";
|
$image_link .= "<a href='" . make_link("post/view/" . $image) . "'>" . $prefix . $image . " </a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= "<tr>".
|
$html .= "<tr>" .
|
||||||
"<td class='left'>".$pool_link."</td>".
|
"<td class='left'>" . $pool_link . "</td>" .
|
||||||
"<td>".$history['count']."</td>".
|
"<td>" . $history['count'] . "</td>" .
|
||||||
"<td>".$image_link."</td>".
|
"<td>" . $image_link . "</td>" .
|
||||||
"<td>".$user_link."</td>".
|
"<td>" . $user_link . "</td>" .
|
||||||
"<td>".$history['date']."</td>".
|
"<td>" . $history['date'] . "</td>" .
|
||||||
"<td>".$revert_link."</td>".
|
"<td>" . $revert_link . "</td>" .
|
||||||
"</tr>";
|
"</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,4 +389,18 @@ class PoolsTheme extends Themelet
|
|||||||
|
|
||||||
$this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages);
|
$this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_bulk_pool_selector(array $pools)
|
||||||
|
{
|
||||||
|
$output = "<select name='bulk_pool_select' required='required'><option></option>";
|
||||||
|
foreach ($pools as $pool) {
|
||||||
|
$output .= "<option value='" . $pool["id"] . "' >" . $pool["title"] . "</option>";
|
||||||
|
}
|
||||||
|
return $output . "</select>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_bulk_pool_input()
|
||||||
|
{
|
||||||
|
return "<input type='text' name='bulk_pool_new' placeholder='New pool' required='required' />";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user