diff --git a/ext/artists/main.php b/ext/artists/main.php index 30303069..ec71d447 100644 --- a/ext/artists/main.php +++ b/ext/artists/main.php @@ -38,8 +38,8 @@ class Artists extends Extension public function onImageInfoSet(ImageInfoSetEvent $event): void { global $user; - if ($user->can(Permissions::EDIT_IMAGE_ARTIST) && isset($_POST["tag_edit__author"])) { - send_event(new AuthorSetEvent($event->image, $user, $_POST["tag_edit__author"])); + if ($user->can(Permissions::EDIT_IMAGE_ARTIST) && isset($event->params["tag_edit__author"])) { + send_event(new AuthorSetEvent($event->image, $user, $event->params["tag_edit__author"])); } } diff --git a/ext/favorites/main.php b/ext/favorites/main.php index d5ad9306..459cf5a6 100644 --- a/ext/favorites/main.php +++ b/ext/favorites/main.php @@ -89,10 +89,10 @@ class Favorites extends Extension global $user; if ( $user->can(Permissions::EDIT_FAVOURITES) && - in_array('favorite_action', $_POST) && - (($_POST['favorite_action'] == "set") || ($_POST['favorite_action'] == "unset")) + in_array('favorite_action', $event->params) && + (($event->params['favorite_action'] == "set") || ($event->params['favorite_action'] == "unset")) ) { - send_event(new FavoriteSetEvent($event->image->id, $user, ($_POST['favorite_action'] == "set"))); + send_event(new FavoriteSetEvent($event->image->id, $user, ($event->params['favorite_action'] == "set"))); } } diff --git a/ext/graphql/main.php b/ext/graphql/main.php index 48de5587..c42162db 100644 --- a/ext/graphql/main.php +++ b/ext/graphql/main.php @@ -33,7 +33,7 @@ class MetadataInput $_POST['tag_edit__source'] = $metadata->source; $image = Image::by_id($post_id); if (!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) { - send_event(new ImageInfoSetEvent($image)); + send_event(new ImageInfoSetEvent($image, $_POST)); } return Image::by_id($post_id); } diff --git a/ext/post_titles/main.php b/ext/post_titles/main.php index d8a66fc3..ca84b401 100644 --- a/ext/post_titles/main.php +++ b/ext/post_titles/main.php @@ -56,9 +56,8 @@ class PostTitles extends Extension { global $user; - if ($user->can(Permissions::EDIT_IMAGE_TITLE) && isset($_POST["post_title"])) { - $title = $_POST["post_title"]; - send_event(new PostTitleSetEvent($event->image, $title)); + if ($user->can(Permissions::EDIT_IMAGE_TITLE) && isset($event->params["post_title"])) { + send_event(new PostTitleSetEvent($event->image, $event->params["post_title"])); } } diff --git a/ext/rating/main.php b/ext/rating/main.php index 62ccb512..41ece5b4 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -216,8 +216,8 @@ class Ratings extends Extension public function onImageInfoSet(ImageInfoSetEvent $event): void { global $user; - if ($user->can(Permissions::EDIT_IMAGE_RATING) && isset($_POST["rating"])) { - $rating = $_POST["rating"]; + if ($user->can(Permissions::EDIT_IMAGE_RATING) && isset($event->params["rating"])) { + $rating = $event->params["rating"]; if (Ratings::rating_is_valid($rating)) { send_event(new RatingSetEvent($event->image, $rating)); } diff --git a/ext/relationships/main.php b/ext/relationships/main.php index fd12a064..eec11679 100644 --- a/ext/relationships/main.php +++ b/ext/relationships/main.php @@ -56,9 +56,9 @@ class Relationships extends Extension { global $user; if ($user->can(Permissions::EDIT_IMAGE_RELATIONSHIPS)) { - if (isset($_POST['tag_edit__tags']) ? !preg_match('/parent[=|:]/', $_POST["tag_edit__tags"]) : true) { //Ignore tag_edit__parent if tags contain parent metatag - if (isset($_POST["tag_edit__parent"]) ? ctype_digit($_POST["tag_edit__parent"]) : false) { - send_event(new ImageRelationshipSetEvent($event->image->id, (int) $_POST["tag_edit__parent"])); + if (isset($event->params['tag_edit__tags']) ? !preg_match('/parent[=|:]/', $event->params["tag_edit__tags"]) : true) { //Ignore tag_edit__parent if tags contain parent metatag + if (isset($event->params["tag_edit__parent"]) ? ctype_digit($event->params["tag_edit__parent"]) : false) { + send_event(new ImageRelationshipSetEvent($event->image->id, (int) $event->params["tag_edit__parent"])); } else { $this->remove_parent($event->image->id); } diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index caba7468..02692636 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -205,17 +205,17 @@ class TagEdit extends Extension public function onImageInfoSet(ImageInfoSetEvent $event): void { global $page, $user; - if ($user->can(Permissions::EDIT_IMAGE_OWNER) && isset($_POST['tag_edit__owner'])) { - $owner = User::by_name($_POST['tag_edit__owner']); + if ($user->can(Permissions::EDIT_IMAGE_OWNER) && isset($event->params['tag_edit__owner'])) { + $owner = User::by_name($event->params['tag_edit__owner']); if ($owner instanceof User) { send_event(new OwnerSetEvent($event->image, $owner)); } else { throw new NullUserException("Error: No user with that name was found."); } } - if ($user->can(Permissions::EDIT_IMAGE_TAG) && isset($_POST['tag_edit__tags'])) { + if ($user->can(Permissions::EDIT_IMAGE_TAG) && isset($event->params['tag_edit__tags'])) { try { - send_event(new TagSetEvent($event->image, Tag::explode($_POST['tag_edit__tags']))); + send_event(new TagSetEvent($event->image, Tag::explode($event->params['tag_edit__tags']))); } catch (TagSetException $e) { if ($e->redirect) { $page->flash("{$e->getMessage()}, please see {$e->redirect}"); @@ -224,13 +224,13 @@ class TagEdit extends Extension } } } - if ($user->can(Permissions::EDIT_IMAGE_SOURCE) && isset($_POST['tag_edit__source'])) { - if (isset($_POST['tag_edit__tags']) ? !preg_match('/source[=|:]/', $_POST["tag_edit__tags"]) : true) { - send_event(new SourceSetEvent($event->image, $_POST['tag_edit__source'])); + if ($user->can(Permissions::EDIT_IMAGE_SOURCE) && isset($event->params['tag_edit__source'])) { + if (isset($event->params['tag_edit__tags']) ? !preg_match('/source[=|:]/', $event->params["tag_edit__tags"]) : true) { + send_event(new SourceSetEvent($event->image, $event->params['tag_edit__source'])); } } if ($user->can(Permissions::EDIT_IMAGE_LOCK)) { - $locked = isset($_POST['tag_edit__locked']) && $_POST['tag_edit__locked'] == "on"; + $locked = isset($event->params['tag_edit__locked']) && $event->params['tag_edit__locked'] == "on"; send_event(new LockSetEvent($event->image, $locked)); } } diff --git a/ext/view/events/image_info_set_event.php b/ext/view/events/image_info_set_event.php index 0602804d..d90982af 100644 --- a/ext/view/events/image_info_set_event.php +++ b/ext/view/events/image_info_set_event.php @@ -7,10 +7,16 @@ namespace Shimmie2; class ImageInfoSetEvent extends Event { public Image $image; + /** @var array */ + public array $params; - public function __construct(Image $image) + /** + * @param array $params + */ + public function __construct(Image $image, array $params) { parent::__construct(); $this->image = $image; + $this->params = $params; } } diff --git a/ext/view/main.php b/ext/view/main.php index c6e8a531..63ccf3dc 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -80,7 +80,7 @@ class ViewPost extends Extension $image_id = int_escape($_POST['image_id']); $image = Image::by_id($image_id); if (!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) { - send_event(new ImageInfoSetEvent($image)); + send_event(new ImageInfoSetEvent($image, $_POST)); $page->set_mode(PageMode::REDIRECT); if ($event->get_GET('search')) {