Added ImageDownloadingEvent that allows extensions to stop a user from viewing an image or perform other operations on the image before the image is downloaded to the user

This commit is contained in:
Matthew Barbour
2020-06-16 18:40:13 -05:00
committed by Shish
parent 40b80bca93
commit 9b5d963aa3
8 changed files with 130 additions and 14 deletions

View File

@ -41,11 +41,31 @@ class Trash extends Extension
}
}
private function check_permissions(Image $image): bool
{
global $user;
if ($image->trash===true && !$user->can(Permissions::VIEW_TRASH)) {
return false;
}
return true;
}
public function onImageDownloading(ImageDownloadingEvent $event)
{
/**
* Deny images upon insufficient permissions.
**/
if (!$this->check_permissions($event->image)) {
throw new SCoreException("Access denied");
}
}
public function onDisplayingImage(DisplayingImageEvent $event)
{
global $user, $page;
global $page;
if ($event->image->trash===true && !$user->can(Permissions::VIEW_TRASH)) {
if (!$this->check_permissions(($event->image))) {
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("post/list"));
}