2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-02-22 19:57:45 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
/**
|
2024-02-20 21:28:14 +00:00
|
|
|
* A new image is being added to the database - just the image,
|
|
|
|
* metadata will come later with ImageInfoSetEvent (and if that
|
|
|
|
* fails, then the image addition transaction will be rolled back)
|
2019-05-28 16:59:38 +00:00
|
|
|
*/
|
2022-10-28 00:45:35 +00:00
|
|
|
public function __construct(
|
|
|
|
public Image $image,
|
|
|
|
) {
|
2020-01-26 13:19:35 +00:00
|
|
|
parent::__construct();
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Deletes an image.
|
|
|
|
*
|
|
|
|
* Used by things like tags and comments handlers to
|
|
|
|
* clean out related rows in their tables.
|
|
|
|
*/
|
2022-10-28 00:45:35 +00:00
|
|
|
public function __construct(
|
|
|
|
public Image $image,
|
|
|
|
public bool $force = false,
|
|
|
|
) {
|
2020-01-26 13:19:35 +00:00
|
|
|
parent::__construct();
|
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
|
|
|
|
{
|
2024-01-09 15:27:02 +00:00
|
|
|
public string $old_hash;
|
2024-01-09 02:33:14 +00:00
|
|
|
public string $new_hash;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
/**
|
2024-01-09 02:33:14 +00:00
|
|
|
* Replaces an image file.
|
2019-05-28 16:59:38 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2022-10-28 00:45:35 +00:00
|
|
|
public function __construct(
|
2024-01-09 02:33:14 +00:00
|
|
|
public Image $image,
|
|
|
|
public string $tmp_filename,
|
2022-10-28 00:45:35 +00:00
|
|
|
) {
|
2020-01-26 13:19:35 +00:00
|
|
|
parent::__construct();
|
2024-01-09 15:27:02 +00:00
|
|
|
$this->old_hash = $image->hash;
|
2024-01-20 14:10:59 +00:00
|
|
|
$hash = md5_file($tmp_filename);
|
|
|
|
assert($hash !== false, "Failed to hash file $tmp_filename");
|
|
|
|
$this->new_hash = $hash;
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
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 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
|
|
|
|
*/
|
2022-10-28 00:45:35 +00:00
|
|
|
public function __construct(
|
2024-01-09 01:03:46 +00:00
|
|
|
public Image $image,
|
2023-11-11 21:49:12 +00:00
|
|
|
public bool $force = false
|
2022-10-28 00:45:35 +00:00
|
|
|
) {
|
2020-01-26 13:19:35 +00:00
|
|
|
parent::__construct();
|
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
|
|
|
}
|