2020-01-26 13:19:35 +00:00
|
|
|
<?php declare(strict_types=1);
|
2007-11-14 10:11:56 +00:00
|
|
|
|
2019-07-13 22:12:03 +00:00
|
|
|
require_once "events/displaying_image_event.php";
|
|
|
|
require_once "events/image_info_box_building_event.php";
|
|
|
|
require_once "events/image_info_set_event.php";
|
|
|
|
require_once "events/image_admin_block_building_event.php";
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2020-07-31 14:50:57 +00:00
|
|
|
use function MicroHTML\TR;
|
|
|
|
use function MicroHTML\TH;
|
|
|
|
use function MicroHTML\TD;
|
2009-05-11 21:09:24 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class ViewImage extends Extension
|
|
|
|
{
|
2020-01-26 13:19:35 +00:00
|
|
|
/** @var ViewImageTheme */
|
|
|
|
protected $theme;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onPageRequest(PageRequestEvent $event)
|
|
|
|
{
|
|
|
|
global $page, $user;
|
|
|
|
|
|
|
|
if ($event->page_matches("post/prev") || $event->page_matches("post/next")) {
|
|
|
|
$image_id = int_escape($event->get_arg(0));
|
|
|
|
|
|
|
|
if (isset($_GET['search'])) {
|
2020-01-30 22:10:51 +00:00
|
|
|
$search_terms = Tag::explode(Tag::decaret($_GET['search']));
|
2019-05-28 16:59:38 +00:00
|
|
|
$query = "#search=".url_escape($_GET['search']);
|
|
|
|
} else {
|
|
|
|
$search_terms = [];
|
|
|
|
$query = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$image = Image::by_id($image_id);
|
|
|
|
if (is_null($image)) {
|
|
|
|
$this->theme->display_error(404, "Image not found", "Image $image_id could not be found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($event->page_matches("post/next")) {
|
|
|
|
$image = $image->get_next($search_terms);
|
|
|
|
} else {
|
|
|
|
$image = $image->get_prev($search_terms);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($image)) {
|
|
|
|
$this->theme->display_error(404, "Image not found", "No more images");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-19 01:58:28 +00:00
|
|
|
$page->set_mode(PageMode::REDIRECT);
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_redirect(make_link("post/view/{$image->id}", $query));
|
|
|
|
} elseif ($event->page_matches("post/view")) {
|
2019-06-16 18:25:40 +00:00
|
|
|
if (!is_numeric($event->get_arg(0))) {
|
|
|
|
// For some reason there exists some very broken mobile client
|
|
|
|
// who follows up every request to '/post/view/123' with
|
|
|
|
// '/post/view/12300000000000Image 123: tags' which spams the
|
|
|
|
// database log with 'integer out of range'
|
2019-06-16 17:22:44 +00:00
|
|
|
$this->theme->display_error(404, "Image not found", "Invalid image ID");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$image_id = int_escape($event->get_arg(0));
|
|
|
|
|
|
|
|
$image = Image::by_id($image_id);
|
|
|
|
|
|
|
|
if (!is_null($image)) {
|
2020-01-28 21:19:59 +00:00
|
|
|
send_event(new DisplayingImageEvent($image));
|
2019-05-28 16:59:38 +00:00
|
|
|
} else {
|
|
|
|
$this->theme->display_error(404, "Image not found", "No image in the database has the ID #$image_id");
|
|
|
|
}
|
|
|
|
} elseif ($event->page_matches("post/set")) {
|
|
|
|
if (!isset($_POST['image_id'])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$image_id = int_escape($_POST['image_id']);
|
2020-02-08 00:24:13 +00:00
|
|
|
$image = Image::by_id($image_id);
|
2020-02-13 20:54:45 +00:00
|
|
|
if (!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) {
|
2020-02-08 00:24:13 +00:00
|
|
|
send_event(new ImageInfoSetEvent($image));
|
|
|
|
$page->set_mode(PageMode::REDIRECT);
|
|
|
|
$page->set_redirect(make_link("post/view/$image_id", url_escape(@$_POST['query'])));
|
|
|
|
} else {
|
|
|
|
$this->theme->display_error(403, "Image Locked", "An admin has locked this image");
|
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onDisplayingImage(DisplayingImageEvent $event)
|
|
|
|
{
|
2020-03-23 00:24:37 +00:00
|
|
|
global $page, $user;
|
2020-03-23 19:56:05 +00:00
|
|
|
$image = $event->get_image();
|
2020-03-23 00:06:43 +00:00
|
|
|
|
2020-03-23 00:21:35 +00:00
|
|
|
$this->theme->display_meta_headers($image);
|
|
|
|
|
|
|
|
$iibbe = new ImageInfoBoxBuildingEvent($image, $user);
|
2019-05-28 16:59:38 +00:00
|
|
|
send_event($iibbe);
|
|
|
|
ksort($iibbe->parts);
|
2020-03-23 00:21:35 +00:00
|
|
|
$this->theme->display_page($image, $iibbe->parts);
|
2020-03-23 00:06:43 +00:00
|
|
|
|
|
|
|
$iabbe = new ImageAdminBlockBuildingEvent($image, $user);
|
|
|
|
send_event($iabbe);
|
|
|
|
ksort($iabbe->parts);
|
|
|
|
$this->theme->display_admin_block($page, $iabbe->parts);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2020-07-31 14:50:57 +00:00
|
|
|
|
|
|
|
public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$image_info = $config->get_string(ImageConfig::INFO);
|
|
|
|
if ($image_info) {
|
|
|
|
$html = (string)TR(
|
|
|
|
TH("Info"),
|
2020-08-28 14:41:25 +00:00
|
|
|
TD($event->image->get_info())
|
2020-07-31 14:50:57 +00:00
|
|
|
);
|
|
|
|
$event->add_part($html, 85);
|
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|