diff --git a/core/imageboard/misc.php b/core/imageboard/misc.php index 6e13527d..8bef7bec 100644 --- a/core/imageboard/misc.php +++ b/core/imageboard/misc.php @@ -187,3 +187,27 @@ function create_scaled_image(string $inname, string $outname, array $tsize, stri true )); } + +function redirect_to_next_image(Image $image): void +{ + global $page; + + if (isset($_GET['search'])) { + $search_terms = Tag::explode(Tag::decaret($_GET['search'])); + $query = "search=" . url_escape($_GET['search']); + } else { + $search_terms = []; + $query = null; + } + + $target_image = $image->get_next($search_terms); + + if ($target_image == null) { + $redirect_target = referer_or(make_link("post/list"), ['post/view']); + } else { + $redirect_target = make_link("post/view/{$target_image->id}", null, $query); + } + + $page->set_mode(PageMode::REDIRECT); + $page->set_redirect($redirect_target); +} diff --git a/ext/image/config.php b/ext/image/config.php index e622bef6..80666f24 100644 --- a/ext/image/config.php +++ b/ext/image/config.php @@ -23,4 +23,8 @@ abstract class ImageConfig const COLLISION_MERGE = 'merge'; const COLLISION_ERROR = 'error'; + + const ON_DELETE = 'image_on_delete'; + const ON_DELETE_NEXT = 'next'; + const ON_DELETE_LIST = 'list'; } diff --git a/ext/image/main.php b/ext/image/main.php index b3ffa092..d6dbffcb 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -15,6 +15,11 @@ class ImageIO extends Extension 'Merge'=>ImageConfig::COLLISION_MERGE ]; + const ON_DELETE_OPTIONS = [ + 'Return to post list'=>ImageConfig::ON_DELETE_LIST, + 'Go to next image'=>ImageConfig::ON_DELETE_NEXT + ]; + const EXIF_READ_FUNCTION = "exif_read_data"; const THUMBNAIL_ENGINES = [ @@ -70,14 +75,20 @@ class ImageIO extends Extension public function onPageRequest(PageRequestEvent $event) { + global $config; if ($event->page_matches("image/delete")) { global $page, $user; if ($user->can(Permissions::DELETE_IMAGE) && isset($_POST['image_id']) && $user->check_auth_token()) { $image = Image::by_id(int_escape($_POST['image_id'])); if ($image) { send_event(new ImageDeletionEvent($image)); - $page->set_mode(PageMode::REDIRECT); - $page->set_redirect(referer_or(make_link("post/list"), ['post/view'])); + + if ($config->get_string(ImageConfig::ON_DELETE)===ImageConfig::ON_DELETE_NEXT) { + redirect_to_next_image($image); + } else { + $page->set_mode(PageMode::REDIRECT); + $page->set_redirect(referer_or(make_link("post/list"), ['post/view'])); + } } } } elseif ($event->page_matches("image/replace")) { @@ -254,6 +265,7 @@ class ImageIO extends Extension $sb->add_text_option(ImageConfig::TIP, "Image tooltip", true); $sb->add_text_option(ImageConfig::INFO, "Image info", true); $sb->add_choice_option(ImageConfig::UPLOAD_COLLISION_HANDLER, self::COLLISION_OPTIONS, "Upload collision handler", true); + $sb->add_choice_option(ImageConfig::ON_DELETE, self::ON_DELETE_OPTIONS, "On Delete", true); if (function_exists(self::EXIF_READ_FUNCTION)) { $sb->add_bool_option(ImageConfig::SHOW_META, "Show metadata", true); }