From 7bfc8299314101c89c9bb0d838b66223bc4c845e Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Tue, 12 Sep 2017 20:54:29 +0100 Subject: [PATCH] #32: Added next/previous buttons to the individual photo page --- .../Controllers/Gallery/PhotoController.php | 20 +++++++++++------- resources/lang/en/gallery.php | 2 ++ .../views/themes/base/gallery/photo.blade.php | 21 +++++++++++++------ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Gallery/PhotoController.php b/app/Http/Controllers/Gallery/PhotoController.php index b69ad54..57c38ff 100644 --- a/app/Http/Controllers/Gallery/PhotoController.php +++ b/app/Http/Controllers/Gallery/PhotoController.php @@ -102,12 +102,17 @@ class PhotoController extends Controller $isOriginalAllowed = Gate::forUser($this->getUser())->allows('photo.download_original', $photo); - $returnAlbumUrl = $album->url(); - $referer = $request->headers->get('Referer'); - if (strlen($referer) > 0 && MiscHelper::isSafeUrl($referer)) - { - $returnAlbumUrl = $referer; - } + // Load the Next/Previous buttons + $thisPhotoDate = is_null($photo->taken_at) ? $photo->created_at : $photo->taken_at; + + $previousPhoto = $album->photos() + ->where(DB::raw('COALESCE(taken_at, created_at)'), '<', $thisPhotoDate) + ->orderBy(DB::raw('COALESCE(taken_at, created_at)'), 'desc') + ->first(); + $nextPhoto = $album->photos() + ->where(DB::raw('COALESCE(taken_at, created_at)'), '>', $thisPhotoDate) + ->orderBy(DB::raw('COALESCE(taken_at, created_at)')) + ->first(); // Record the visit to the photo if (UserConfig::get('enable_visitor_hits')) @@ -124,8 +129,9 @@ class PhotoController extends Controller return Theme::render('gallery.photo', [ 'album' => $album, 'is_original_allowed' => $isOriginalAllowed, + 'next_photo' => $nextPhoto, 'photo' => $photo, - 'return_album_url' => $returnAlbumUrl + 'previous_photo' => $previousPhoto ]); } diff --git a/resources/lang/en/gallery.php b/resources/lang/en/gallery.php index ab6853a..c8d7c38 100644 --- a/resources/lang/en/gallery.php +++ b/resources/lang/en/gallery.php @@ -17,10 +17,12 @@ return [ 'labels_title' => 'Labels', 'manage_album_link' => 'Manage', 'manage_album_link_2' => 'Manage Album', + 'next_button' => 'Next Photo »', 'open_album_link' => 'Open Album', 'other_albums_description' => 'You may also be interested in the following albums.', 'other_albums_heading' => 'More Albums in :album_name', 'photos' => 'photo|photos', + 'previous_button' => '« Previous Photo', 'show_more_labels' => '... and :count other|... and :count others', 'statistics' => [ 'album_by_photos' => 'Top 10 largest albums - number of photos', diff --git a/resources/views/themes/base/gallery/photo.blade.php b/resources/views/themes/base/gallery/photo.blade.php index eb6fcde..c5bfbe6 100644 --- a/resources/views/themes/base/gallery/photo.blade.php +++ b/resources/views/themes/base/gallery/photo.blade.php @@ -4,11 +4,7 @@ @section('breadcrumb') @foreach ($album->albumParentTree() as $parentAlbum) - @if ($parentAlbum->id == $photo->album->id) - - @else - - @endif + @endforeach @endsection @@ -34,6 +30,19 @@ @endif +
+
+ @if (!is_null($previous_photo)) + @lang('gallery.previous_button') + @endif +
+
+ @if (!is_null($next_photo)) + @lang('gallery.next_button') + @endif +
+
+ @if ($photo->labels()->count() > 0)

@lang('gallery.labels')