nits
This commit is contained in:
parent
89673fb776
commit
848797030e
2 changed files with 62 additions and 67 deletions
|
@ -99,17 +99,16 @@ class Pool
|
||||||
return new Pool($row);
|
return new Pool($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_pool_id_by_title($poolTitle): ?int
|
public static function get_pool_id_by_title($poolTitle): ?int
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$row = $database->get_row("SELECT * FROM pools WHERE title=:title", ["title" => $poolTitle]);
|
$row = $database->get_row("SELECT * FROM pools WHERE title=:title", ["title" => $poolTitle]);
|
||||||
if ($row != null) {
|
if ($row != null) {
|
||||||
return $row['id'];
|
return $row['id'];
|
||||||
}
|
} else {
|
||||||
else {
|
return null;
|
||||||
return NULL;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _image_to_id(Image $image): int
|
function _image_to_id(Image $image): int
|
||||||
|
@ -215,23 +214,21 @@ class Pools extends Extension
|
||||||
public function onPageRequest(PageRequestEvent $event)
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
{
|
{
|
||||||
global $config, $database, $page, $user;
|
global $config, $database, $page, $user;
|
||||||
if ($event->page_matches("pool/list")) { //index
|
if ($event->page_matches("pool/list")) { //index
|
||||||
if (isset($_GET['search']) and $_GET['search'] != null) {
|
if (isset($_GET['search']) and $_GET['search'] != null) {
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
$page->set_redirect(make_link('pool/list').'/'.$_GET['search'].'/'.strval($event->try_page_num(1)));
|
$page->set_redirect(make_link('pool/list').'/'.$_GET['search'].'/'.strval($event->try_page_num(1)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (count($event->args) >= 4) { // Assume first 2 args are search and page num
|
if (count($event->args) >= 4) { // Assume first 2 args are search and page num
|
||||||
$search = $event->get_arg(0); // Search is based on name comparison instead of tag search
|
$search = $event->get_arg(0); // Search is based on name comparison instead of tag search
|
||||||
$page_num = $event->try_page_num(1);
|
$page_num = $event->try_page_num(1);
|
||||||
}
|
} else {
|
||||||
else {
|
$search = "";
|
||||||
$search = "";
|
$page_num = $event->try_page_num(0);
|
||||||
$page_num = $event->try_page_num(0);
|
}
|
||||||
}
|
$this->list_pools($page, $page_num, $search);
|
||||||
$this->list_pools($page, $page_num, $search);
|
} elseif ($event->page_matches("pool")) {
|
||||||
}
|
|
||||||
elseif ($event->page_matches("pool")) {
|
|
||||||
$pool_id = 0;
|
$pool_id = 0;
|
||||||
$pool = [];
|
$pool = [];
|
||||||
|
|
||||||
|
@ -344,37 +341,35 @@ class Pools extends Extension
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "reverse":
|
case "reverse":
|
||||||
if ($this->have_permission($user, $pool)) {
|
if ($this->have_permission($user, $pool)) {
|
||||||
$result = $database->execute(
|
$result = $database->execute(
|
||||||
"SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order DESC",
|
"SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order DESC",
|
||||||
["pid" => $pool_id]
|
["pid" => $pool_id]
|
||||||
);
|
);
|
||||||
$image_order = 1;
|
$image_order = 1;
|
||||||
try {
|
try {
|
||||||
$database->begin_transaction();
|
$database->begin_transaction();
|
||||||
while ($row = $result->fetch()) {
|
while ($row = $result->fetch()) {
|
||||||
$database->execute(
|
$database->execute(
|
||||||
"
|
"
|
||||||
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" => $image_order, "pid" => $pool_id, "iid" => (int)$row['image_id']]
|
["ord" => $image_order, "pid" => $pool_id, "iid" => (int)$row['image_id']]
|
||||||
);
|
);
|
||||||
$image_order = $image_order + 1;
|
$image_order = $image_order + 1;
|
||||||
}
|
}
|
||||||
$database->commit();
|
$database->commit();
|
||||||
}
|
} catch (\Exception $e) {
|
||||||
catch (Exception $e) {
|
$database->rollback();
|
||||||
$database->rollback();
|
}
|
||||||
}
|
$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 {
|
||||||
}
|
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
|
||||||
else {
|
}
|
||||||
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "import":
|
case "import":
|
||||||
if ($this->have_permission($user, $pool)) {
|
if ($this->have_permission($user, $pool)) {
|
||||||
$images = Image::find_images(
|
$images = Image::find_images(
|
||||||
|
@ -647,10 +642,10 @@ class Pools extends Extension
|
||||||
$order_by = "ORDER BY p.posts DESC";
|
$order_by = "ORDER BY p.posts DESC";
|
||||||
}
|
}
|
||||||
|
|
||||||
$where_clause = "WHERE LOWER(title) like '%%'";
|
$where_clause = "WHERE LOWER(title) like '%%'";
|
||||||
if ($search != null) {
|
if ($search != null) {
|
||||||
$where_clause = "WHERE LOWER(title) like '%".strtolower($search)."%'";
|
$where_clause = "WHERE LOWER(title) like '%".strtolower($search)."%'";
|
||||||
}
|
}
|
||||||
|
|
||||||
$pools = array_map([Pool::class, "makePool"], $database->get_all("
|
$pools = array_map([Pool::class, "makePool"], $database->get_all("
|
||||||
SELECT p.*, u.name as user_name
|
SELECT p.*, u.name as user_name
|
||||||
|
|
|
@ -86,9 +86,9 @@ class PoolsTheme extends Themelet
|
||||||
|
|
||||||
$page->add_block(new Block("Pools", $table, position: 10));
|
$page->add_block(new Block("Pools", $table, position: 10));
|
||||||
|
|
||||||
if ($search != "" and !str_starts_with($search, '/')) {
|
if ($search != "" and !str_starts_with($search, '/')) {
|
||||||
$search = '/'.$search;
|
$search = '/'.$search;
|
||||||
}
|
}
|
||||||
$this->display_paginator($page, "pool/list".$search, null, $pageNumber, $totalPages);
|
$this->display_paginator($page, "pool/list".$search, null, $pageNumber, $totalPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class PoolsTheme extends Themelet
|
||||||
SHM_A("pool/updated", "Pool Changes")
|
SHM_A("pool/updated", "Pool Changes")
|
||||||
);
|
);
|
||||||
|
|
||||||
$search = "<form action='".make_link('pool/list')."' method='GET'>
|
$search = "<form action='".make_link('pool/list')."' method='GET'>
|
||||||
<input name='search' type='text' style='width:75%'>
|
<input name='search' type='text' style='width:75%'>
|
||||||
<input type='submit' value='Go' style='width:20%'>
|
<input type='submit' value='Go' style='width:20%'>
|
||||||
<input type='hidden' name='q' value='pool/list'>
|
<input type='hidden' name='q' value='pool/list'>
|
||||||
|
@ -131,7 +131,7 @@ class PoolsTheme extends Themelet
|
||||||
|
|
||||||
$page->add_block(new NavBlock());
|
$page->add_block(new NavBlock());
|
||||||
$page->add_block(new Block("Pool Navigation", $poolnav, "left", 10));
|
$page->add_block(new Block("Pool Navigation", $poolnav, "left", 10));
|
||||||
$page->add_block(new Block("Search", $search, "left", 10));
|
$page->add_block(new Block("Search", $search, "left", 10));
|
||||||
|
|
||||||
if (!is_null($pool)) {
|
if (!is_null($pool)) {
|
||||||
if ($pool->public || $user->can(Permissions::POOLS_ADMIN)) {// IF THE POOL IS PUBLIC OR IS ADMIN SHOW EDIT PANEL
|
if ($pool->public || $user->can(Permissions::POOLS_ADMIN)) {// IF THE POOL IS PUBLIC OR IS ADMIN SHOW EDIT PANEL
|
||||||
|
|
Reference in a new issue