diff --git a/ext/view/main.php b/ext/view/main.php
index 2e1a637f..b01e7be3 100644
--- a/ext/view/main.php
+++ b/ext/view/main.php
@@ -67,6 +67,40 @@ class ViewImage implements Extension {
public function receive_event(Event $event) {
if(is_null($this->theme)) $this->theme = get_theme_object($this);
+ if(is_a($event, 'PageRequestEvent') && (
+ $event->page_matches("post/prev") ||
+ $event->page_matches("post/next")
+ )) {
+ global $config;
+ global $database;
+ $image_id = int_escape($event->get_arg(0));
+
+ if(isset($_GET['search'])) {
+ $search_terms = explode(' ', $_GET['search']);
+ $query = "search=".url_escape($_GET['search']);
+ }
+ else {
+ $search_terms = array();
+ $query = null;
+ }
+
+ $image = Image::by_id($config, $database, $image_id);
+ if($event->page_matches("post/next")) {
+ $image = $image->get_next($search_terms);
+ }
+ else {
+ $image = $image->get_prev($search_terms);
+ }
+
+ if(!is_null($image)) {
+ $event->page->set_mode("redirect");
+ $event->page->set_redirect(make_link("post/view/{$image->id}", $query));
+ }
+ else {
+ $this->theme->display_error($event->page, "Image not found", "No more images");
+ }
+ }
+
if(($event instanceof PageRequestEvent) && $event->page_matches("post/view")) {
$image_id = int_escape($event->get_arg(0));
diff --git a/ext/view/theme.php b/ext/view/theme.php
index 2f602ecc..3b59668e 100644
--- a/ext/view/theme.php
+++ b/ext/view/theme.php
@@ -37,12 +37,9 @@ class ViewImageTheme extends Themelet {
$query = null;
}
- $next = $image->get_next($search_terms);
- $prev = $image->get_prev($search_terms);
-
- $h_prev = (!is_null($prev) ? "Prev" : "Prev");
+ $h_prev = "Prev";
$h_index = "Index";
- $h_next = (!is_null($next) ? "Next" : "Next");
+ $h_next = "Next";
$this->pin = "$h_prev | $h_index | $h_next";
return $this->pin;