page_matches("post/prev") || $event->page_matches("post/next")) { $image_id = int_escape($event->get_arg(0)); if (isset($_GET['search'])) { $search_terms = Tag::explode(Tag::decaret($_GET['search'])); $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; } $page->set_mode(PageMode::REDIRECT); $page->set_redirect(make_link("post/view/{$image->id}", $query)); } elseif ($event->page_matches("post/view")) { 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' $this->theme->display_error(404, "Image not found", "Invalid image ID"); return; } $image_id = int_escape($event->get_arg(0)); $image = Image::by_id($image_id); if (!is_null($image)) { send_event(new DisplayingImageEvent($image)); $iabbe = new ImageAdminBlockBuildingEvent($image, $user); send_event($iabbe); ksort($iabbe->parts); $this->theme->display_admin_block($page, $iabbe->parts); } 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']); send_event(new ImageInfoSetEvent(Image::by_id($image_id))); $page->set_mode(PageMode::REDIRECT); $page->set_redirect(make_link("post/view/$image_id", url_escape(@$_POST['query']))); } } public function onDisplayingImage(DisplayingImageEvent $event) { global $user; $iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user); send_event($iibbe); ksort($iibbe->parts); $this->theme->display_meta_headers($event->get_image()); $this->theme->display_page($event->get_image(), $iibbe->parts); } }