From 6d1bf8eede67489ceeb3162a5da9b01d81cc57eb Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Feb 2024 00:00:49 +0000 Subject: [PATCH] [admin] have AdminActionEvent carry its own params --- ext/admin/main.php | 10 ++++++++-- ext/approval/main.php | 2 +- ext/cron_uploader/main.php | 4 ++-- ext/rating/main.php | 8 ++++---- ext/regen_thumb/main.php | 16 ++++++++-------- ext/s3/main.php | 2 +- ext/tag_tools/test.php | 6 +++--- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/ext/admin/main.php b/ext/admin/main.php index 9a056f13..8e17fb7d 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -26,11 +26,17 @@ class AdminActionEvent extends Event { public string $action; public bool $redirect = true; + /** @var array */ + public array $params; - public function __construct(string $action) + /** + * @param array $params + */ + public function __construct(string $action, array $params) { parent::__construct(); $this->action = $action; + $this->params = $params; } } @@ -51,7 +57,7 @@ class AdminPage extends Extension send_event(new AdminBuildingEvent($page)); } else { $action = $event->get_arg(0); - $aae = new AdminActionEvent($action); + $aae = new AdminActionEvent($action, $_POST); if ($user->check_auth_token()) { log_info("admin", "Util: $action"); diff --git a/ext/approval/main.php b/ext/approval/main.php index 23b83536..7a8b5bc0 100644 --- a/ext/approval/main.php +++ b/ext/approval/main.php @@ -88,7 +88,7 @@ class Approval extends Extension $action = $event->action; $event->redirect = true; if ($action === "approval") { - $approval_action = $_POST["approval_action"]; + $approval_action = $event->params["approval_action"]; switch ($approval_action) { case "approve_all": $database->set_timeout(null); // These updates can take a little bit diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index e2da4392..c0eb5bf9 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -113,8 +113,8 @@ class CronUploader extends Extension break; case "cron_uploader_restage": $event->redirect = true; - if (array_key_exists("failed_dir", $_POST) && !empty($_POST["failed_dir"])) { - $this->restage_folder($_POST["failed_dir"]); + if (array_key_exists("failed_dir", $event->params) && !empty($event->params["failed_dir"])) { + $this->restage_folder($event->params["failed_dir"]); } break; } diff --git a/ext/rating/main.php b/ext/rating/main.php index 41ece5b4..56520960 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -322,14 +322,14 @@ class Ratings extends Extension switch ($action) { case "update_ratings": $event->redirect = true; - if (!array_key_exists("rating_old", $_POST) || empty($_POST["rating_old"])) { + if (!array_key_exists("rating_old", $event->params) || empty($event->params["rating_old"])) { return; } - if (!array_key_exists("rating_new", $_POST) || empty($_POST["rating_new"])) { + if (!array_key_exists("rating_new", $event->params) || empty($event->params["rating_new"])) { return; } - $old = $_POST["rating_old"]; - $new = $_POST["rating_new"]; + $old = $event->params["rating_old"]; + $new = $event->params["rating_new"]; if ($user->can(Permissions::BULK_EDIT_IMAGE_RATING)) { $database->execute("UPDATE images SET rating = :new WHERE rating = :old", ["new" => $new, "old" => $old ]); diff --git a/ext/regen_thumb/main.php b/ext/regen_thumb/main.php index 8c93604d..7778655f 100644 --- a/ext/regen_thumb/main.php +++ b/ext/regen_thumb/main.php @@ -103,17 +103,17 @@ class RegenThumb extends Extension case "regen_thumbs": $event->redirect = true; $force = false; - if (isset($_POST["regen_thumb_force"]) && $_POST["regen_thumb_force"] == "true") { + if (isset($event->params["regen_thumb_force"]) && $event->params["regen_thumb_force"] == "true") { $force = true; } $limit = 1000; - if (isset($_POST["regen_thumb_limit"]) && is_numeric($_POST["regen_thumb_limit"])) { - $limit = intval($_POST["regen_thumb_limit"]); + if (isset($event->params["regen_thumb_limit"]) && is_numeric($event->params["regen_thumb_limit"])) { + $limit = intval($event->params["regen_thumb_limit"]); } $mime = ""; - if (isset($_POST["regen_thumb_mime"])) { - $mime = $_POST["regen_thumb_mime"]; + if (isset($event->params["regen_thumb_mime"])) { + $mime = $event->params["regen_thumb_mime"]; } $images = Search::find_images(tags: ["mime=" . $mime]); @@ -138,8 +138,8 @@ class RegenThumb extends Extension case "delete_thumbs": $event->redirect = true; - if (isset($_POST["delete_thumb_mime"]) && $_POST["delete_thumb_mime"] != "") { - $images = Search::find_images(tags: ["mime=" . $_POST["delete_thumb_mime"]]); + if (isset($event->params["delete_thumb_mime"]) && $event->params["delete_thumb_mime"] != "") { + $images = Search::find_images(tags: ["mime=" . $event->params["delete_thumb_mime"]]); $i = 0; foreach ($images as $image) { @@ -149,7 +149,7 @@ class RegenThumb extends Extension $i++; } } - $page->flash("Deleted $i thumbnails for ".$_POST["delete_thumb_mime"]." images"); + $page->flash("Deleted $i thumbnails for ".$event->params["delete_thumb_mime"]." images"); } else { $dir = "data/thumbs/"; deltree($dir); diff --git a/ext/s3/main.php b/ext/s3/main.php index c00f08a2..276f039a 100644 --- a/ext/s3/main.php +++ b/ext/s3/main.php @@ -59,7 +59,7 @@ class S3 extends Extension if($event->action == "s3_process") { foreach($database->get_all( "SELECT * FROM s3_sync_queue ORDER BY time ASC LIMIT :count", - ["count" => isset($_POST['count']) ? int_escape($_POST["count"]) : 10] + ["count" => isset($event->params['count']) ? int_escape($event->params["count"]) : 10] ) as $row) { if($row['action'] == "S") { $image = Image::by_hash($row['hash']); diff --git a/ext/tag_tools/test.php b/ext/tag_tools/test.php index 41e88715..1997c69c 100644 --- a/ext/tag_tools/test.php +++ b/ext/tag_tools/test.php @@ -18,7 +18,7 @@ class TagToolsTest extends ShimmiePHPUnitTestCase $this->assertEquals("Post $image_id_1: TeStCase$ts", $page->title); // Fix - send_event(new AdminActionEvent('lowercase_all_tags')); + send_event(new AdminActionEvent('lowercase_all_tags', [])); // Validate fix $this->get_page("post/view/$image_id_1"); @@ -26,7 +26,7 @@ class TagToolsTest extends ShimmiePHPUnitTestCase // Change $_POST["tag"] = "TestCase$ts"; - send_event(new AdminActionEvent('set_tag_case')); + send_event(new AdminActionEvent('set_tag_case', [])); // Validate change $this->get_page("post/view/$image_id_1"); @@ -47,7 +47,7 @@ class TagToolsTest extends ShimmiePHPUnitTestCase ); // Fix - send_event(new AdminActionEvent('recount_tag_use')); + send_event(new AdminActionEvent('recount_tag_use', [])); // Validate fix $this->assertEquals(