This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/post_owner/main.php
Shish 845c8b3d85 [core] Make User::by_name / User::by_id not-null
Nearly everywhere that these functions are called, the result is assumed to be not-null, and a null will break things
2024-08-31 20:39:36 +01:00

47 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Shimmie2;
class OwnerSetEvent extends Event
{
public Image $image;
public User $owner;
public function __construct(Image $image, User $owner)
{
parent::__construct();
$this->image = $image;
$this->owner = $owner;
}
}
class PostOwner extends Extension
{
/** @var PostOwnerTheme */
protected Themelet $theme;
public function onImageInfoSet(ImageInfoSetEvent $event): void
{
global $page, $user;
$owner = $event->get_param('owner');
if ($user->can(Permissions::EDIT_IMAGE_OWNER) && !is_null($owner)) {
$owner_ob = User::by_name($owner);
send_event(new OwnerSetEvent($event->image, $owner_ob));
}
}
public function onOwnerSet(OwnerSetEvent $event): void
{
global $user;
if ($user->can(Permissions::EDIT_IMAGE_OWNER)) {
$event->image->set_owner($event->owner);
}
}
public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event): void
{
$event->add_part($this->theme->get_owner_editor_html($event->image), 39);
}
}