[image info] have ImageInfoSetEvent carry its own params

This commit is contained in:
Shish 2024-02-10 00:00:49 +00:00
parent 09774416c3
commit f95e59cbae
9 changed files with 29 additions and 24 deletions

View file

@ -38,8 +38,8 @@ class Artists extends Extension
public function onImageInfoSet(ImageInfoSetEvent $event): void public function onImageInfoSet(ImageInfoSetEvent $event): void
{ {
global $user; global $user;
if ($user->can(Permissions::EDIT_IMAGE_ARTIST) && isset($_POST["tag_edit__author"])) { if ($user->can(Permissions::EDIT_IMAGE_ARTIST) && isset($event->params["tag_edit__author"])) {
send_event(new AuthorSetEvent($event->image, $user, $_POST["tag_edit__author"])); send_event(new AuthorSetEvent($event->image, $user, $event->params["tag_edit__author"]));
} }
} }

View file

@ -89,10 +89,10 @@ class Favorites extends Extension
global $user; global $user;
if ( if (
$user->can(Permissions::EDIT_FAVOURITES) && $user->can(Permissions::EDIT_FAVOURITES) &&
in_array('favorite_action', $_POST) && in_array('favorite_action', $event->params) &&
(($_POST['favorite_action'] == "set") || ($_POST['favorite_action'] == "unset")) (($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")));
} }
} }

View file

@ -33,7 +33,7 @@ class MetadataInput
$_POST['tag_edit__source'] = $metadata->source; $_POST['tag_edit__source'] = $metadata->source;
$image = Image::by_id($post_id); $image = Image::by_id($post_id);
if (!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) { 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); return Image::by_id($post_id);
} }

View file

@ -56,9 +56,8 @@ class PostTitles extends Extension
{ {
global $user; global $user;
if ($user->can(Permissions::EDIT_IMAGE_TITLE) && isset($_POST["post_title"])) { if ($user->can(Permissions::EDIT_IMAGE_TITLE) && isset($event->params["post_title"])) {
$title = $_POST["post_title"]; send_event(new PostTitleSetEvent($event->image, $event->params["post_title"]));
send_event(new PostTitleSetEvent($event->image, $title));
} }
} }

View file

@ -216,8 +216,8 @@ class Ratings extends Extension
public function onImageInfoSet(ImageInfoSetEvent $event): void public function onImageInfoSet(ImageInfoSetEvent $event): void
{ {
global $user; global $user;
if ($user->can(Permissions::EDIT_IMAGE_RATING) && isset($_POST["rating"])) { if ($user->can(Permissions::EDIT_IMAGE_RATING) && isset($event->params["rating"])) {
$rating = $_POST["rating"]; $rating = $event->params["rating"];
if (Ratings::rating_is_valid($rating)) { if (Ratings::rating_is_valid($rating)) {
send_event(new RatingSetEvent($event->image, $rating)); send_event(new RatingSetEvent($event->image, $rating));
} }

View file

@ -56,9 +56,9 @@ class Relationships extends Extension
{ {
global $user; global $user;
if ($user->can(Permissions::EDIT_IMAGE_RELATIONSHIPS)) { 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($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($_POST["tag_edit__parent"]) ? ctype_digit($_POST["tag_edit__parent"]) : false) { if (isset($event->params["tag_edit__parent"]) ? ctype_digit($event->params["tag_edit__parent"]) : false) {
send_event(new ImageRelationshipSetEvent($event->image->id, (int) $_POST["tag_edit__parent"])); send_event(new ImageRelationshipSetEvent($event->image->id, (int) $event->params["tag_edit__parent"]));
} else { } else {
$this->remove_parent($event->image->id); $this->remove_parent($event->image->id);
} }

View file

@ -205,17 +205,17 @@ class TagEdit extends Extension
public function onImageInfoSet(ImageInfoSetEvent $event): void public function onImageInfoSet(ImageInfoSetEvent $event): void
{ {
global $page, $user; global $page, $user;
if ($user->can(Permissions::EDIT_IMAGE_OWNER) && isset($_POST['tag_edit__owner'])) { if ($user->can(Permissions::EDIT_IMAGE_OWNER) && isset($event->params['tag_edit__owner'])) {
$owner = User::by_name($_POST['tag_edit__owner']); $owner = User::by_name($event->params['tag_edit__owner']);
if ($owner instanceof User) { if ($owner instanceof User) {
send_event(new OwnerSetEvent($event->image, $owner)); send_event(new OwnerSetEvent($event->image, $owner));
} else { } else {
throw new NullUserException("Error: No user with that name was found."); 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 { 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) { } catch (TagSetException $e) {
if ($e->redirect) { if ($e->redirect) {
$page->flash("{$e->getMessage()}, please see {$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 ($user->can(Permissions::EDIT_IMAGE_SOURCE) && isset($event->params['tag_edit__source'])) {
if (isset($_POST['tag_edit__tags']) ? !preg_match('/source[=|:]/', $_POST["tag_edit__tags"]) : true) { if (isset($event->params['tag_edit__tags']) ? !preg_match('/source[=|:]/', $event->params["tag_edit__tags"]) : true) {
send_event(new SourceSetEvent($event->image, $_POST['tag_edit__source'])); send_event(new SourceSetEvent($event->image, $event->params['tag_edit__source']));
} }
} }
if ($user->can(Permissions::EDIT_IMAGE_LOCK)) { 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)); send_event(new LockSetEvent($event->image, $locked));
} }
} }

View file

@ -7,10 +7,16 @@ namespace Shimmie2;
class ImageInfoSetEvent extends Event class ImageInfoSetEvent extends Event
{ {
public Image $image; public Image $image;
/** @var array<string, mixed> */
public array $params;
public function __construct(Image $image) /**
* @param array<string, mixed> $params
*/
public function __construct(Image $image, array $params)
{ {
parent::__construct(); parent::__construct();
$this->image = $image; $this->image = $image;
$this->params = $params;
} }
} }

View file

@ -80,7 +80,7 @@ class ViewPost extends Extension
$image_id = int_escape($_POST['image_id']); $image_id = int_escape($_POST['image_id']);
$image = Image::by_id($image_id); $image = Image::by_id($image_id);
if (!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) { 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); $page->set_mode(PageMode::REDIRECT);
if ($event->get_GET('search')) { if ($event->get_GET('search')) {