diff --git a/app/Http/Controllers/Gallery/PhotoCommentController.php b/app/Http/Controllers/Gallery/PhotoCommentController.php new file mode 100644 index 0000000..c4b0804 --- /dev/null +++ b/app/Http/Controllers/Gallery/PhotoCommentController.php @@ -0,0 +1,50 @@ +authorizeForUser($this->getUser(), 'view', $album); + + $photo = PhotoController::loadPhotoByAlbumAndFilename($album, $photoFilename); + + if (!UserConfig::get('allow_photo_comments')) + { + // Not allowed to post comments - redirect back to URL + return redirect($photo->url()); + } + + $comment = new PhotoComment(); + $comment->photo_id = $photo->id; + $comment->fill($request->only(['commentor_email', 'commentor_name', 'comment_text'])); + + $user = $this->getUser(); + if (!is_null($user) && !$user->isAnonymous()) + { + $comment->created_user_id = $user->id; + } + + $comment->save(); + + $request->getSession()->flash('success', trans('gallery.photo_comment_posted_successfully')); + + return redirect($photo->url()); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Gallery/PhotoController.php b/app/Http/Controllers/Gallery/PhotoController.php index bd50bb0..98a3eb8 100644 --- a/app/Http/Controllers/Gallery/PhotoController.php +++ b/app/Http/Controllers/Gallery/PhotoController.php @@ -157,7 +157,8 @@ class PhotoController extends Controller 'is_original_allowed' => $isOriginalAllowed, 'next_photo' => $nextPhoto, 'photo' => $photo, - 'previous_photo' => $previousPhoto + 'previous_photo' => $previousPhoto, + 'success' => $request->getSession()->get('success') ]); } diff --git a/app/Photo.php b/app/Photo.php index 486e979..bf224ff 100644 --- a/app/Photo.php +++ b/app/Photo.php @@ -77,6 +77,14 @@ class Photo extends Model return $this->belongsToMany(Label::class, 'photo_labels'); } + public function postCommentUrl() + { + return route('postPhotoComment', [ + 'albumUrlAlias' => $this->album->url_path, + 'photoFilename' => $this->storage_file_name + ]); + } + public function thumbnailUrl($thumbnailName = null, $cacheBust = true) { $url = $this->album->getAlbumSource()->getUrlToPhoto($this, $thumbnailName); diff --git a/app/PhotoComment.php b/app/PhotoComment.php new file mode 100644 index 0000000..293b477 --- /dev/null +++ b/app/PhotoComment.php @@ -0,0 +1,19 @@ +bigIncrements('id'); + $table->unsignedBigInteger('photo_id'); + $table->string('commentor_name'); + $table->string('commentor_email'); + $table->text('comment_text'); + $table->unsignedInteger('created_user_id')->nullable(true); + $table->unsignedInteger('approved_user_id')->nullable(true); + $table->dateTime('approved_at')->nullable(true); + $table->unsignedBigInteger('parent_comment_id')->nullable(true); + $table->timestamps(); + + $table->foreign('photo_id') + ->references('id')->on('photos') + ->onDelete('cascade'); + $table->foreign('created_user_id') + ->references('id')->on('users') + ->onDelete('cascade'); + $table->foreign('approved_user_id') + ->references('id')->on('users') + ->onDelete('cascade'); + $table->foreign('parent_comment_id') + ->references('id')->on('photo_comments') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('photo_comments'); + } +} diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index e579b3d..a45679b 100644 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -26,6 +26,7 @@ return [ 'edit_action' => 'Edit', 'edit_album_action' => 'Edit this album', 'email_label' => 'E-mail address:', + 'email_placeholder' => 'name@example.com', 'enable_profile_page_label' => 'Allow others to see my profile page', 'inherit_album_permissions' => 'Inherit permissions from parent album', 'labels_label' => 'Labels:', @@ -35,6 +36,8 @@ return [ 'parent_album_placeholder' => 'None (top-level album)', 'password_label' => 'Password:', 'password_confirm_label' => 'Confirm password:', + 'photo_comment_submit_action' => 'Post comment', + 'photo_comment_text_label' => 'Your message/comments:', 'please_select' => '- Select an Option -', 'private_album_label' => 'Private album (only visible to me)', 'profile_alias_label' => 'Alias:', diff --git a/resources/lang/en/gallery.php b/resources/lang/en/gallery.php index 485683a..301cb06 100644 --- a/resources/lang/en/gallery.php +++ b/resources/lang/en/gallery.php @@ -33,6 +33,10 @@ return [ 'other_albums_description' => 'You may also be interested in the following albums.', 'other_albums_description_empty' => 'The :album_name album does not contain any photos - however you may also be interested in the following albums.', 'other_albums_heading' => 'More Albums in :album_name', + 'photo_comment_posted_successfully' => 'Your comment was posted successfully and will appear after it has been moderated.', + 'photo_comments_heading' => 'Comments', + 'photo_comments_reply_form_heading' => 'Leave a reply', + 'photo_comments_reply_form_p1' => 'Complete the form below to start a new reply thread.', 'photos' => 'photo|photos', 'previous_button' => '« Previous Photo', 'show_more_albums' => '... and :count other|... and :count others', diff --git a/resources/views/themes/base/gallery/photo.blade.php b/resources/views/themes/base/gallery/photo.blade.php index e380356..61fcc74 100644 --- a/resources/views/themes/base/gallery/photo.blade.php +++ b/resources/views/themes/base/gallery/photo.blade.php @@ -21,7 +21,7 @@
@lang('gallery.photo_comments_reply_form_p1')
+