2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2007-11-14 10:11:56 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
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
|
|
|
|
2023-12-31 01:20:36 +00:00
|
|
|
class ViewPost extends Extension
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2023-12-31 01:20:36 +00:00
|
|
|
/** @var ViewPostTheme */
|
2023-06-27 14:56:49 +00:00
|
|
|
protected Themelet $theme;
|
2020-01-26 13:19:35 +00:00
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onPageRequest(PageRequestEvent $event): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $page, $user;
|
|
|
|
|
2024-02-11 11:34:09 +00:00
|
|
|
if ($event->page_matches("post/prev/{image_id}") || $event->page_matches("post/next/{image_id}")) {
|
|
|
|
$image_id = $event->get_iarg('image_id');
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2024-02-09 16:36:57 +00:00
|
|
|
$search = $event->get_GET('search');
|
|
|
|
if ($search) {
|
|
|
|
$search_terms = Tag::explode($search);
|
|
|
|
$query = "#search=".url_escape($search);
|
2019-05-28 16:59:38 +00:00
|
|
|
} else {
|
|
|
|
$search_terms = [];
|
|
|
|
$query = null;
|
|
|
|
}
|
|
|
|
|
2024-02-20 00:22:25 +00:00
|
|
|
$image = Image::by_id_ex($image_id);
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2024-02-11 11:34:09 +00:00
|
|
|
if ($event->page_matches("post/next/{image_id}")) {
|
2019-05-28 16:59:38 +00:00
|
|
|
$image = $image->get_next($search_terms);
|
|
|
|
} else {
|
|
|
|
$image = $image->get_prev($search_terms);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($image)) {
|
2020-10-26 15:13:47 +00:00
|
|
|
$this->theme->display_error(404, "Post not found", "No more posts");
|
2019-05-28 16:59:38 +00:00
|
|
|
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));
|
2024-02-11 11:34:09 +00:00
|
|
|
} elseif ($event->page_matches("post/view/{image_id}")) {
|
|
|
|
if (!is_numeric($event->get_arg('image_id'))) {
|
2019-06-16 18:25:40 +00:00
|
|
|
// 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'
|
2020-10-26 15:13:47 +00:00
|
|
|
$this->theme->display_error(404, "Post not found", "Invalid post ID");
|
2019-06-16 17:22:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-11 11:34:09 +00:00
|
|
|
$image_id = $event->get_iarg('image_id');
|
2024-02-20 00:22:25 +00:00
|
|
|
$image = Image::by_id_ex($image_id);
|
|
|
|
send_event(new DisplayingImageEvent($image));
|
2024-02-10 23:03:14 +00:00
|
|
|
} elseif ($event->page_matches("post/set", method: "POST")) {
|
2024-02-10 00:08:55 +00:00
|
|
|
$image_id = int_escape($event->req_POST('image_id'));
|
2024-02-20 00:22:25 +00:00
|
|
|
$image = Image::by_id_ex($image_id);
|
2020-02-13 20:54:45 +00:00
|
|
|
if (!$image->is_locked() || $user->can(Permissions::EDIT_IMAGE_LOCK)) {
|
2024-02-20 21:28:14 +00:00
|
|
|
send_event(new ImageInfoSetEvent($image, 0, only_strings($event->POST)));
|
2020-02-08 00:24:13 +00:00
|
|
|
$page->set_mode(PageMode::REDIRECT);
|
2020-10-08 22:19:08 +00:00
|
|
|
|
2024-02-09 16:36:57 +00:00
|
|
|
if ($event->get_GET('search')) {
|
|
|
|
$query = "search=" . url_escape($event->get_GET('search'));
|
2020-10-08 22:19:08 +00:00
|
|
|
} else {
|
|
|
|
$query = null;
|
|
|
|
}
|
2021-01-18 14:37:32 +00:00
|
|
|
$page->set_redirect(make_link("post/view/$image_id", null, $query));
|
2020-02-08 00:24:13 +00:00
|
|
|
} else {
|
2020-10-26 15:13:47 +00:00
|
|
|
$this->theme->display_error(403, "Post Locked", "An admin has locked this post");
|
2020-02-08 00:24:13 +00:00
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onRobotsBuilding(RobotsBuildingEvent $event): void
|
2023-03-30 19:36:58 +00:00
|
|
|
{
|
|
|
|
// next and prev are just CPU-heavier ways of getting
|
|
|
|
// to the same images that the index shows
|
|
|
|
$event->add_disallow("post/next");
|
|
|
|
$event->add_disallow("post/prev");
|
|
|
|
}
|
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onDisplayingImage(DisplayingImageEvent $event): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
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);
|
|
|
|
|
2023-02-04 20:50:26 +00:00
|
|
|
$iibbe = send_event(new ImageInfoBoxBuildingEvent($image, $user));
|
2024-03-28 12:42:39 +00:00
|
|
|
$this->theme->display_page($image, $iibbe->get_parts());
|
2020-03-23 00:06:43 +00:00
|
|
|
|
2023-02-04 20:50:26 +00:00
|
|
|
$iabbe = send_event(new ImageAdminBlockBuildingEvent($image, $user, "view"));
|
2024-03-28 12:42:39 +00:00
|
|
|
$this->theme->display_admin_block($page, $iabbe->get_parts());
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2020-07-31 14:50:57 +00:00
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event): void
|
2020-07-31 14:50:57 +00:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$image_info = $config->get_string(ImageConfig::INFO);
|
|
|
|
if ($image_info) {
|
2023-12-19 11:36:35 +00:00
|
|
|
$event->add_part(SHM_POST_INFO("Info", $event->image->get_info()), 85);
|
2020-07-31 14:50:57 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|