2020-01-26 13:19:35 +00:00
|
|
|
<?php declare(strict_types=1);
|
2019-02-22 19:57:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An image is being added to the database.
|
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
class ImageAdditionEvent extends Event
|
|
|
|
{
|
2021-03-14 23:43:50 +00:00
|
|
|
public User $user;
|
|
|
|
public Image $image;
|
|
|
|
public bool $merged = false;
|
2019-06-20 00:40:25 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
/**
|
|
|
|
* Inserts a new image into the database with its associated
|
|
|
|
* information. Also calls TagSetEvent to set the tags for
|
|
|
|
* this new image.
|
|
|
|
*/
|
|
|
|
public function __construct(Image $image)
|
|
|
|
{
|
2020-01-26 13:19:35 +00:00
|
|
|
parent::__construct();
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->image = $image;
|
|
|
|
}
|
2019-02-22 19:57:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class ImageAdditionException extends SCoreException
|
|
|
|
{
|
2019-02-22 19:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An image is being deleted.
|
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
class ImageDeletionEvent extends Event
|
|
|
|
{
|
2021-03-14 23:43:50 +00:00
|
|
|
public Image $image;
|
|
|
|
public bool $force = false;
|
2019-06-27 18:34:25 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
/**
|
|
|
|
* Deletes an image.
|
|
|
|
*
|
|
|
|
* Used by things like tags and comments handlers to
|
|
|
|
* clean out related rows in their tables.
|
|
|
|
*/
|
2019-06-27 18:34:25 +00:00
|
|
|
public function __construct(Image $image, bool $force = false)
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-01-26 13:19:35 +00:00
|
|
|
parent::__construct();
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->image = $image;
|
2019-06-27 18:34:25 +00:00
|
|
|
$this->force = $force;
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2019-02-22 19:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An image is being replaced.
|
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
class ImageReplaceEvent extends Event
|
|
|
|
{
|
2021-03-14 23:43:50 +00:00
|
|
|
public int $id;
|
|
|
|
public Image $image;
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces an image.
|
|
|
|
*
|
|
|
|
* Updates an existing ID in the database to use a new image
|
|
|
|
* file, leaving the tags and such unchanged. Also removes
|
|
|
|
* the old image file and thumbnail from the disk.
|
|
|
|
*/
|
|
|
|
public function __construct(int $id, Image $image)
|
|
|
|
{
|
2020-01-26 13:19:35 +00:00
|
|
|
parent::__construct();
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->id = $id;
|
|
|
|
$this->image = $image;
|
|
|
|
}
|
2019-02-22 19:57:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class ImageReplaceException extends SCoreException
|
|
|
|
{
|
2019-02-22 19:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request a thumbnail be made for an image object.
|
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
class ThumbnailGenerationEvent extends Event
|
|
|
|
{
|
2021-03-14 23:43:50 +00:00
|
|
|
public string $hash;
|
|
|
|
public string $mime;
|
|
|
|
public bool $force;
|
|
|
|
public bool $generated;
|
2019-06-09 18:22:48 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
/**
|
|
|
|
* Request a thumbnail be made for an image object
|
|
|
|
*/
|
2020-06-14 16:05:55 +00:00
|
|
|
public function __construct(string $hash, string $mime, bool $force=false)
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-01-26 13:19:35 +00:00
|
|
|
parent::__construct();
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->hash = $hash;
|
2020-06-14 16:05:55 +00:00
|
|
|
$this->mime = $mime;
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->force = $force;
|
2019-06-09 18:22:48 +00:00
|
|
|
$this->generated = false;
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2019-02-22 19:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ParseLinkTemplateEvent:
|
2020-02-25 12:26:56 +00:00
|
|
|
* $link -- the formatted text (with each element URL Escape'd)
|
|
|
|
* $text -- the formatted text (not escaped)
|
2019-02-22 19:57:45 +00:00
|
|
|
* $original -- the formatting string, for reference
|
|
|
|
* $image -- the image who's link is being parsed
|
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
class ParseLinkTemplateEvent extends Event
|
|
|
|
{
|
2021-03-14 23:43:50 +00:00
|
|
|
public string $link;
|
|
|
|
public string $text;
|
|
|
|
public string $original;
|
|
|
|
public Image $image;
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
public function __construct(string $link, Image $image)
|
|
|
|
{
|
2020-01-26 13:19:35 +00:00
|
|
|
parent::__construct();
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->link = $link;
|
2020-02-25 12:26:56 +00:00
|
|
|
$this->text = $link;
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->original = $link;
|
|
|
|
$this->image = $image;
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:22:25 +00:00
|
|
|
public function replace(string $needle, ?string $replace): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-02-23 18:12:14 +00:00
|
|
|
if (!is_null($replace)) {
|
2020-02-25 12:26:56 +00:00
|
|
|
$this->link = str_replace($needle, url_escape($replace), $this->link);
|
|
|
|
$this->text = str_replace($needle, $replace, $this->text);
|
2020-02-09 19:22:25 +00:00
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2019-02-22 19:57:45 +00:00
|
|
|
}
|