a bunch of pools cleanup

This commit is contained in:
Shish 2020-03-27 00:15:15 +00:00
parent 599043baa5
commit b5f0bc7621
3 changed files with 194 additions and 271 deletions

View File

@ -42,7 +42,12 @@ class PoolCreationEvent extends Event
public $new_id = -1;
public function __construct(string $title, User $pool_user = null, bool $public = false, string $description = "")
public function __construct(
string $title,
User $pool_user = null,
bool $public = false,
string $description = ""
)
{
parent::__construct();
global $user;
@ -54,6 +59,33 @@ class PoolCreationEvent extends Event
}
}
class Pool {
public $id;
public $user_id;
public $user_name;
public $public;
public $title;
public $description;
public $date;
public $posts;
public function __construct(array $row)
{
$this->id = (int)$row['id'];
$this->user_id = (int)$row['user_id'];
$this->user_name = $row['user_name'] ?? null;
$this->public = bool_escape($row['public']);
$this->title = $row['title'];
$this->description = $row['description'];
$this->date = $row['date'];
$this->posts = (int)$row['posts'];
}
public static function makePool(array $row): Pool {
return new Pool($row);
}
}
class Pools extends Extension
{
/** @var PoolsTheme */
@ -154,7 +186,7 @@ class Pools extends Extension
public function onPageRequest(PageRequestEvent $event)
{
global $page, $user;
global $config, $database, $page, $user;
if ($event->page_matches("pool")) {
$pool_id = 0;
@ -219,7 +251,12 @@ class Pools extends Extension
case "edit": // Edit the pool (remove images)
if ($this->have_permission($user, $pool)) {
$this->theme->edit_pool($page, $this->get_pool($pool_id), $this->edit_posts($pool_id));
$result = $database->execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", ["pid" => $pool_id]);
$images = [];
while ($row = $result->fetch()) {
$images[] = Image::by_id((int)$row["image_id"]);
}
$this->theme->edit_pool($page, $pool, $images);
} else {
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("pool/view/" . $pool_id));
@ -229,14 +266,40 @@ class Pools extends Extension
case "order": // Order the pool (view and change the order of images within the pool)
if (isset($_POST["order_view"])) {
if ($this->have_permission($user, $pool)) {
$this->theme->edit_order($page, $this->get_pool($pool_id), $this->edit_order($pool_id));
$result = $database->execute(
"SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC",
["pid" => $pool_id]
);
$images = [];
while ($row = $result->fetch()) {
$image = $database->get_row(
"
SELECT * FROM images AS i
INNER JOIN pool_images AS p ON i.id = p.image_id
WHERE pool_id=:pid AND i.id=:iid",
["pid" => $pool_id, "iid" => (int)$row['image_id']]
);
$images[] = ($image ? new Image($image) : null);
}
$this->theme->edit_order($page, $pool, $images);
} else {
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("pool/view/" . $pool_id));
}
} else {
if ($this->have_permission($user, $pool)) {
$this->order_posts();
foreach ($_POST['imgs'] as $data) {
list($imageORDER, $imageID) = $data;
$database->execute(
"
UPDATE pool_images
SET image_order = :ord
WHERE pool_id = :pid AND image_id = :iid",
["ord" => $imageORDER, "pid" => int_escape($_POST['pool_id']), "iid" => $imageID]
);
}
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("pool/view/" . $pool_id));
} else {
@ -247,7 +310,11 @@ class Pools extends Extension
case "import":
if ($this->have_permission($user, $pool)) {
$this->import_posts($pool_id);
$images = Image::find_images(
0, $config->get_int(PoolsConfig::MAX_IMPORT_RESULTS, 1000),
Tag::explode($_POST["pool_tag"])
);
$this->theme->pool_result($page, $images, $pool);
} else {
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
}
@ -269,7 +336,19 @@ class Pools extends Extension
case "remove_posts":
if ($this->have_permission($user, $pool)) {
$this->remove_posts();
$images = "";
foreach ($_POST['check'] as $imageID) {
$database->execute(
"DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid",
["pid" => $pool_id, "iid" => $imageID]
);
$images .= " " . $imageID;
}
$count = (int)$database->get_one(
"SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid",
["pid" => $pool_id]
);
$this->add_history($pool_id, 0, $images, $count);
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("pool/view/" . $pool_id));
} else {
@ -280,7 +359,10 @@ class Pools extends Extension
case "edit_description":
if ($this->have_permission($user, $pool)) {
$this->edit_description();
$database->execute(
"UPDATE pools SET description=:dsc WHERE id=:pid",
["dsc" => $_POST['description'], "pid" => int_escape($_POST['pool_id'])]
);
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("pool/view/" . $pool_id));
} else {
@ -300,11 +382,6 @@ class Pools extends Extension
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
}
break;
default:
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("pool/list"));
break;
}
}
}
@ -335,13 +412,10 @@ class Pools extends Extension
foreach ($poolsIDs as $poolID) {
$pool = $this->get_single_pool($poolID);
$navInfo[$pool['id']] = [];
$navInfo[$pool['id']]['info'] = $pool;
// Optionally show a link the Prev/Next image in the Pool.
if ($show_nav) {
$navInfo[$pool['id']]['nav'] = $this->get_nav_posts($pool, $imageID);
}
$navInfo[$pool->id] = [
"info" => $pool,
"nav" => $show_nav ? $this->get_nav_posts($pool, $imageID) : null,
];
}
$this->theme->pool_info($navInfo);
}
@ -352,11 +426,12 @@ class Pools extends Extension
global $config, $database, $user;
if ($config->get_bool(PoolsConfig::ADDER_ON_VIEW_IMAGE) && !$user->is_anonymous()) {
if ($user->can(Permissions::POOLS_ADMIN)) {
$pools = $database->get_all("SELECT * FROM pools");
$rows = $database->get_all("SELECT * FROM pools");
} else {
$pools = $database->get_all("SELECT * FROM pools WHERE user_id=:id", ["id" => $user->id]);
$rows = $database->get_all("SELECT * FROM pools WHERE user_id=:id", ["id" => $user->id]);
}
if (count($pools) > 0) {
if (count($rows) > 0) {
$pools = array_map([Pool::class, "makePool"], $rows);
$event->add_part($this->theme->get_adder_html($event->image, $pools));
}
}
@ -423,7 +498,7 @@ class Pools extends Extension
$pool = $this->get_single_pool_from_title($poolTag);
}
if ($pool ? $this->have_permission($user, $pool) : false) {
if ($pool && $this->have_permission($user, $pool)) {
$image_order = ($matches[2] ?: 0);
$this->add_post($pool['id'], $event->image_id, true, $image_order);
}
@ -434,7 +509,10 @@ class Pools extends Extension
{
global $database;
$pools = $database->get_all("SELECT * FROM pools ORDER BY title ");
$pools = array_map(
[Pool::class, "makePool"],
$database->get_all("SELECT * FROM pools ORDER BY title ")
);
$event->add_action("bulk_pool_add_existing", "Add To (P)ool", "p", "", $this->theme->get_bulk_pool_selector($pools));
$event->add_action("bulk_pool_add_new", "Create Pool", "", "", $this->theme->get_bulk_pool_input($event->search_terms));
@ -450,7 +528,7 @@ class Pools extends Extension
return;
}
$pool_id = intval($_POST['bulk_pool_select']);
$pool = $this->get_pool($pool_id);
$pool = $this->get_single_pool($pool_id);
if ($this->have_permission($user, $pool)) {
send_event(
@ -479,14 +557,16 @@ class Pools extends Extension
*
* TODO: Should the user variable be global?
*/
private function have_permission(User $user, array $pool): bool
private function have_permission(User $user, Pool $pool): bool
{
// If the pool is public and user is logged OR if the user is admin OR if the pool is owned by the user.
if ((($pool['public'] == "Y" || $pool['public'] == "y") && !$user->is_anonymous()) || $user->can(Permissions::POOLS_ADMIN) || $user->id == $pool['user_id']) {
return true;
} else {
return false;
}
// If the pool is public and user is logged
// OR if the user is admin
// OR if the pool is owned by the user.
return (
($pool->public && !$user->is_anonymous()) ||
$user->can(Permissions::POOLS_ADMIN) ||
$user->id == $pool->user_id
);
}
private function list_pools(Page $page, int $pageNumber)
@ -509,15 +589,14 @@ class Pools extends Extension
$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
$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
$order_by
LIMIT :l OFFSET :o
", ["l" => $poolsPerPage, "o" => $pageNumber * $poolsPerPage]);
", ["l" => $poolsPerPage, "o" => $pageNumber * $poolsPerPage]));
$totalPages = (int)ceil((int)$database->get_one("SELECT COUNT(*) FROM pools") / $poolsPerPage);
@ -542,7 +621,7 @@ class Pools extends Extension
"
INSERT INTO pools (user_id, public, title, description, date)
VALUES (:uid, :public, :title, :desc, now())",
["uid" => $event->user->id, "public" => $event->public ? "Y" : "N", "title" => $event->title, "desc" => $event->description]
["uid" => $event->user->id, "public" => $event->public, "title" => $event->title, "desc" => $event->description]
);
$poolID = $database->get_last_insert_id('pools_id_seq');
@ -551,33 +630,23 @@ class Pools extends Extension
$event->new_id = $poolID;
}
/**
* Retrieve information about pools given multiple pool IDs.
*
* TODO: What is the difference between this and get_single_pool() other than the db query?
*/
private function get_pool(int $poolID): array
{
global $database;
return $database->get_all("SELECT * FROM pools WHERE id=:id", ["id" => $poolID]);
}
/**
* Retrieve information about a pool given a pool ID.
*/
private function get_single_pool(int $poolID): array
private function get_single_pool(int $poolID): Pool
{
global $database;
return $database->get_row("SELECT * FROM pools WHERE id=:id", ["id" => $poolID]);
return new Pool($database->get_row("SELECT * FROM pools WHERE id=:id", ["id" => $poolID]));
}
/**
* 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): ?Pool
{
global $database;
return $database->get_row("SELECT * FROM pools WHERE title=:title", ["title" => $poolTitle]);
$row = $database->get_row("SELECT * FROM pools WHERE title=:title", ["title" => $poolTitle]);
return $row ? new Pool($row) : null;
}
/**
@ -595,23 +664,10 @@ class Pools extends Extension
/**
* Retrieve information about the last pool the given userID created
*/
private function get_last_userpool(int $userID): array
private function get_last_userpool(int $userID): Pool
{
global $database;
return $database->get_row("SELECT * FROM pools WHERE user_id=:uid ORDER BY id DESC", ["uid" => $userID]);
}
/**
* HERE WE GET THE IMAGES FROM THE TAG ON IMPORT
*/
private function import_posts(int $pool_id)
{
global $page, $config;
$poolsMaxResults = $config->get_int(PoolsConfig::MAX_IMPORT_RESULTS, 1000);
$images = $images = Image::find_images(0, $poolsMaxResults, Tag::explode($_POST["pool_tag"]));
$this->theme->pool_result($page, $images, $this->get_pool($pool_id));
return new Pool($database->get_row("SELECT * FROM pools WHERE user_id=:uid ORDER BY id DESC", ["uid" => $userID]));
}
/**
@ -634,94 +690,28 @@ class Pools extends Extension
}
if (!strlen($images) == 0) {
$count = int_escape($database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid" => $event->pool_id]));
$count = (int)$database->get_one(
"SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid",
["pid" => $event->pool_id]
);
$this->add_history($event->pool_id, 1, $images, $count);
}
}
/**
* TODO: Fix this so that the pool ID and images are passed as Arguments to the function.
*/
private function order_posts(): int
{
global $database;
$poolID = int_escape($_POST['pool_id']);
foreach ($_POST['imgs'] as $data) {
list($imageORDER, $imageID) = $data;
$database->execute(
"
UPDATE pool_images
SET image_order = :ord
WHERE pool_id = :pid AND image_id = :iid",
["ord" => $imageORDER, "pid" => $poolID, "iid" => $imageID]
);
}
return $poolID;
}
/**
* HERE WE REMOVE 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 remove_posts(): int
{
global $database;
$poolID = int_escape($_POST['pool_id']);
$images = "";
foreach ($_POST['check'] as $imageID) {
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", ["pid" => $poolID, "iid" => $imageID]);
$images .= " " . $imageID;
}
$count = (int)$database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid" => $poolID]);
$this->add_history($poolID, 0, $images, $count);
return $poolID;
}
/**
* Allows editing of pool description.
*/
private function edit_description(): int
{
global $database;
$poolID = int_escape($_POST['pool_id']);
$database->execute("UPDATE pools SET description=:dsc WHERE id=:pid", ["dsc" => $_POST['description'], "pid" => $poolID]);
return $poolID;
}
/**
* This function checks if a given image is contained within a given pool.
* Used by add_posts()
*/
private function check_post(int $poolID, int $imageID): bool
{
global $database;
$result = (int)$database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid AND image_id=:iid", ["pid" => $poolID, "iid" => $imageID]);
return ($result != 0);
}
/**
* Gets the previous and next successive images from a pool, given a pool ID and an image ID.
*
* #return int[] Array returning two elements (prev, next) in 1 dimension. Each returns ImageID or NULL if none.
*/
private function get_nav_posts(array $pool, int $imageID): array
private function get_nav_posts(Pool $pool, int $imageID): array
{
global $database;
if (empty($pool) || empty($imageID)) {
if (empty($imageID)) {
return null;
}
$result = $database->get_row(
return $database->get_row(
"
SELECT (
SELECT image_id
@ -751,15 +741,8 @@ class Pools extends Extension
) AS next
LIMIT 1",
["pid" => $pool['id'], "iid" => $imageID]
["pid" => $pool->id, "iid" => $imageID]
);
if (empty($result)) {
// assume that we are at the end of the pool
return null;
} else {
return $result;
}
}
/**
@ -770,7 +753,7 @@ class Pools extends Extension
global $config, $user, $database;
$pageNumber = $event->try_page_num(2) - 1;
$pool = $this->get_pool($poolID);
$pool = $this->get_single_pool($poolID);
$imagesPerPage = $config->get_int(PoolsConfig::IMAGES_PER_PAGE);
$query = "
@ -809,52 +792,6 @@ class Pools extends Extension
$this->theme->view_pool($pool, $images, $pageNumber + 1, $totalPages);
}
/**
* This function gets the current order of images from a given pool.
* #return Image[] Array of image objects.
*/
private function edit_posts(int $poolID): array
{
global $database;
$result = $database->execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", ["pid" => $poolID]);
$images = [];
while ($row = $result->fetch()) {
$image = Image::by_id((int)$row["image_id"]);
$images[] = [$image];
}
return $images;
}
/**
* WE GET THE ORDER OF THE IMAGES BUT HERE WE SEND KEYS ADDED IN ARRAY TO GET THE ORDER IN THE INPUT VALUE.
*
* #return Image[]
*/
private function edit_order(int $poolID): array
{
global $database;
$result = $database->execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", ["pid" => $poolID]);
$images = [];
while ($row = $result->fetch()) {
$image = $database->get_row(
"
SELECT * FROM images AS i
INNER JOIN pool_images AS p ON i.id = p.image_id
WHERE pool_id=:pid AND i.id=:iid",
["pid" => $poolID, "iid" => (int)$row['image_id']]
);
$image = ($image ? new Image($image) : null);
$images[] = [$image];
}
return $images;
}
/**
* HERE WE NUKE ENTIRE POOL. WE REMOVE POOLS AND POSTS FROM REMOVED POOL AND HISTORIES ENTRIES FROM REMOVED POOL.
*/
@ -948,13 +885,15 @@ class Pools extends Extension
}
} elseif ($entry['action'] == 1) {
// DELETE ENTRIES
foreach ($images as $image) {
$imageID = $image;
$this->delete_post($poolID, $imageID);
foreach ($images as $imageID) {
$database->execute(
"DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid",
["pid" => $poolID, "iid" => $imageID]
);
$imageArray .= " " . $imageID;
$newAction = 0;
}
$this->update_count($poolID);
} else {
// FIXME: should this throw an exception instead?
log_error("pools", "Invalid history action.");
@ -974,7 +913,12 @@ class Pools extends Extension
{
global $database, $config;
if (!$this->check_post($poolID, $imageID)) {
$result = (int)$database->get_one(
"SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid AND image_id=:iid",
["pid" => $poolID, "iid" => $imageID]
);
if ($result == 0) {
if ($config->get_bool(PoolsConfig::AUTO_INCREMENT_ORDER) && $imageOrder === 0) {
$imageOrder = (int)$database->get_one(
"
@ -1005,27 +949,12 @@ class Pools extends Extension
return true;
}
private function update_count($pool_id)
private function update_count(int $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.
* USED WITH FOREACH IN revert_history() & onTagTermParse().
*/
private function delete_post(int $poolID, int $imageID, bool $history = false)
{
global $database;
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", ["pid" => $poolID, "iid" => $imageID]);
$this->update_count($poolID);
if ($history) {
$count = (int)$database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", ["pid" => $poolID]);
$this->add_history($poolID, 0, (string)$imageID, $count);
}
$database->execute(
"UPDATE pools SET posts=(SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid) WHERE id=:pid",
["pid" => $pool_id]
);
}
}

View File

@ -39,6 +39,7 @@ class PoolsTest extends ShimmiePHPUnitTestCase
global $config;
$config->set_bool(PoolsConfig::ADDER_ON_VIEW_IMAGE, true);
$config->set_bool(PoolsConfig::INFO_ON_VIEW_IMAGE, true);
$config->set_bool(PoolsConfig::SHOW_NAV_LINKS, true);
$this->get_page("post/view/{$image_ids[0]}");
$this->assert_text("Pool");

View File

@ -11,16 +11,16 @@ class PoolsTheme extends Themelet
global $page;
$linksPools = [];
foreach ($navIDs as $poolID => $pool) {
$linksPools[] = "<a href='" . make_link("pool/view/" . $poolID) . "'>" . html_escape($pool['info']['title']) . "</a>";
foreach ($navIDs as $poolID => $poolInfo) {
$linksPools[] = "<a href='" . make_link("pool/view/" . $poolID) . "'>" . html_escape($poolInfo['info']->title) . "</a>";
if (array_key_exists('nav', $pool)) {
if (!empty($poolInfo['nav'])) {
$navlinks = "";
if (!empty($pool['nav']['prev'])) {
$navlinks .= '<a href="' . make_link('post/view/' . $pool['nav']['prev']) . '" class="pools_prev_img">Prev</a>';
if (!empty($poolInfo['nav']['prev'])) {
$navlinks .= '<a href="' . make_link('post/view/' . $poolInfo['nav']['prev']) . '" class="pools_prev_img">Prev</a>';
}
if (!empty($pool['nav']['next'])) {
$navlinks .= '<a href="' . make_link('post/view/' . $pool['nav']['next']) . '" class="pools_next_img">Next</a>';
if (!empty($poolInfo['nav']['next'])) {
$navlinks .= '<a href="' . make_link('post/view/' . $poolInfo['nav']['next']) . '" class="pools_next_img">Next</a>';
}
if (!empty($navlinks)) {
$navlinks .= "<div style='height: 5px'></div>";
@ -38,7 +38,7 @@ class PoolsTheme extends Themelet
{
$h = "";
foreach ($pools as $pool) {
$h .= "<option value='" . $pool['id'] . "'>" . html_escape($pool['title']) . "</option>";
$h .= "<option value='" . $pool->id . "'>" . html_escape($pool->title) . "</option>";
}
return "\n" . make_form(make_link("pool/add_post")) . "
<select name='pool_id'>
@ -66,14 +66,14 @@ class PoolsTheme extends Themelet
// Build up the list of pools.
foreach ($pools as $pool) {
$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>";
$public = ($pool['public'] == "Y" ? "Yes" : "No");
$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>";
$public = ($pool->public ? "Yes" : "No");
$html .= "<tr>" .
"<td class='left'>" . $pool_link . "</td>" .
"<td>" . $user_link . "</td>" .
"<td>" . $pool['posts'] . "</td>" .
"<td>" . $pool->posts . "</td>" .
"<td>" . $public . "</td>" .
"</tr>";
}
@ -118,7 +118,7 @@ class PoolsTheme extends Themelet
$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(?Pool $pool, string $heading, bool $check_all = false)
{
global $page, $user;
@ -134,28 +134,26 @@ class PoolsTheme extends Themelet
$page->add_block(new NavBlock());
$page->add_block(new Block("Pool Navigation", $poolnav_html, "left", 10));
if (!is_null($pools) && count($pools) == 1) {
$pool = $pools[0];
if ($pool['public'] == "Y" || $user->can(Permissions::POOLS_ADMIN)) {// IF THE POOL IS PUBLIC OR IS ADMIN SHOW EDIT PANEL
if (!is_null($pool)) {
if ($pool->public || $user->can(Permissions::POOLS_ADMIN)) {// IF THE POOL IS PUBLIC OR IS ADMIN SHOW EDIT PANEL
if (!$user->is_anonymous()) {// IF THE USER IS REGISTERED AND LOGGED IN SHOW EDIT PANEL
$this->sidebar_options($page, $pool, $check_all);
}
}
$tfe = new TextFormattingEvent($pool['description']);
$tfe = new TextFormattingEvent($pool->description);
send_event($tfe);
$page->add_block(new Block(html_escape($pool['title']), $tfe->formatted, "main", 10));
$page->add_block(new Block(html_escape($pool->title), $tfe->formatted, "main", 10));
}
}
/**
* HERE WE DISPLAY THE POOL WITH TITLE DESCRIPTION AND IMAGES WITH PAGINATION.
*/
public function view_pool(array $pools, array $images, int $pageNumber, int $totalPages)
public function view_pool(Pool $pool, array $images, int $pageNumber, int $totalPages)
{
global $page;
$this->display_top($pools, "Pool: " . html_escape($pools[0]['title']));
$this->display_top($pool, "Pool: " . html_escape($pool->title));
$pool_images = '';
foreach ($images as $image) {
@ -164,37 +162,37 @@ class PoolsTheme extends Themelet
}
$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/" . $pool->id, null, $pageNumber, $totalPages);
}
/**
* HERE WE DISPLAY THE POOL OPTIONS ON SIDEBAR BUT WE HIDE REMOVE OPTION IF THE USER IS NOT THE OWNER OR ADMIN.
*/
public function sidebar_options(Page $page, array $pool, bool $check_all)
public function sidebar_options(Page $page, Pool $pool, bool $check_all)
{
global $user;
$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="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>
' . make_form(make_link('pool/edit')) . '
<input type="submit" name="edit" id="edit_pool_btn" value="Edit Pool"/>
<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>
' . make_form(make_link('pool/order')) . '
<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="pool_id" value="' . $pool['id'] . '">
<input type="hidden" name="pool_id" value="' . $pool->id . '">
</form>
';
if ($user->id == $pool['user_id'] || $user->can(Permissions::POOLS_ADMIN)) {
if ($user->id == $pool->user_id || $user->can(Permissions::POOLS_ADMIN)) {
$editor .= "
<script type='text/javascript'>
<!--
@ -206,7 +204,7 @@ class PoolsTheme extends Themelet
" . make_form(make_link("pool/nuke")) . "
<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>
";
}
@ -231,7 +229,7 @@ class PoolsTheme extends Themelet
/**
* HERE WE DISPLAY THE RESULT OF THE SEARCH ON IMPORT.
*/
public function pool_result(Page $page, array $images, array $pool)
public function pool_result(Page $page, array $images, Pool $pool)
{
$this->display_top($pool, "Importing Posts", true);
$pool_images = "
@ -256,7 +254,7 @@ class PoolsTheme extends Themelet
$pool_images .= "<br>" .
"<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->id . "'>" .
"</form>";
$page->add_block(new Block("Import", $pool_images, "main", 30));
@ -267,14 +265,13 @@ class PoolsTheme extends Themelet
* HERE WE DISPLAY THE POOL ORDERER.
* WE LIST ALL IMAGES ON POOL WITHOUT PAGINATION AND WITH A TEXT INPUT TO SET A NUMBER AND CHANGE THE ORDER
*/
public function edit_order(Page $page, array $pools, array $images)
public function edit_order(Page $page, Pool $pool, array $images)
{
$this->display_top($pools, "Sorting Pool");
$this->display_top($pool, "Sorting Pool");
$pool_images = "\n<form action='" . make_link("pool/order") . "' method='POST' name='checks'>";
$i = 0;
foreach ($images as $pair) {
$image = $pair[0];
foreach ($images as $image) {
$thumb_html = $this->build_thumb_html($image);
$pool_images .= '<span class="thumb">' . "\n" . $thumb_html . "\n" .
'<br><input name="imgs[' . $i . '][]" type="number" style="max-width:50px;" value="' . $image->image_order . '" />' .
@ -285,7 +282,7 @@ class PoolsTheme extends Themelet
$pool_images .= "<br>" .
"<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='" . $pool->id . "'>" .
"</form>";
$page->add_block(new Block("Sorting Posts", $pool_images, "main", 30));
@ -297,13 +294,13 @@ class PoolsTheme extends Themelet
* WE LIST ALL IMAGES ON POOL WITHOUT PAGINATION AND WITH
* A CHECKBOX TO SELECT WHICH IMAGE WE WANT TO REMOVE
*/
public function edit_pool(Page $page, array $pools, array $images)
public function edit_pool(Page $page, Pool $pool, array $images)
{
/* EDIT POOL DESCRIPTION */
$desc_html = "
" . make_form(make_link("pool/edit_description")) . "
<textarea name='description'>" . $pools[0]['description'] . "</textarea><br />
<input type='hidden' name='pool_id' value='" . $pools[0]['id'] . "'>
<textarea name='description'>" . $pool->description . "</textarea><br />
<input type='hidden' name='pool_id' value='" . $pool->id . "'>
<input type='submit' value='Change Description' />
</form>
";
@ -311,9 +308,7 @@ class PoolsTheme extends Themelet
/* REMOVE POOLS */
$pool_images = "\n<form action='" . make_link("pool/remove_posts") . "' method='POST' name='checks'>";
foreach ($images as $pair) {
$image = $pair[0];
foreach ($images as $image) {
$thumb_html = $this->build_thumb_html($image);
$pool_images .= '<span class="thumb">' . "\n" . $thumb_html . "\n" .
@ -323,16 +318,15 @@ class PoolsTheme extends Themelet
$pool_images .= "<br>" .
"<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='" . $pool->id . "'>" .
"</form>";
$pools[0]['description'] = ""; //This is a rough fix to avoid showing the description twice.
$this->display_top($pools, "Editing Pool", true);
$pool->description = ""; //This is a rough fix to avoid showing the description twice.
$this->display_top($pool, "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));
}
/**
* HERE WE DISPLAY THE HISTORY LIST.
*/
@ -393,7 +387,7 @@ class PoolsTheme extends Themelet
{
$output = "<select name='bulk_pool_select' required='required'><option></option>";
foreach ($pools as $pool) {
$output .= "<option value='" . $pool["id"] . "' >" . $pool["title"] . "</option>";
$output .= "<option value='" . $pool->id . "' >" . $pool->title . "</option>";
}
return $output . "</select>";
}
@ -403,7 +397,6 @@ class PoolsTheme extends Themelet
return "<input type='text' name='bulk_pool_new' placeholder='New pool' required='required' value='".(implode(" ", $search_terms))."' />";
}
public function get_help_html()
{
return '<p>Search for images that are in a pool.</p>