diff --git a/app/Http/Controllers/Admin/PhotoCommentController.php b/app/Http/Controllers/Admin/PhotoCommentController.php index bac407a..ce41bed 100644 --- a/app/Http/Controllers/Admin/PhotoCommentController.php +++ b/app/Http/Controllers/Admin/PhotoCommentController.php @@ -2,11 +2,18 @@ namespace App\Http\Controllers\Admin; +use App\Album; use App\Facade\Theme; use App\Facade\UserConfig; use App\Http\Controllers\Controller; +use App\Mail\PhotoCommentApproved; +use App\Mail\PhotoCommentApprovedUser; +use App\Mail\PhotoCommentRepliedTo; +use App\Photo; use App\PhotoComment; +use App\User; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\View; class PhotoCommentController extends Controller @@ -47,6 +54,12 @@ class PhotoCommentController extends Controller /** @var PhotoComment $comment */ foreach ($comments as $comment) { + if ($comment->isApproved()) + { + // Don't make changes if already approved + continue; + } + // Mark as approved $comment->approved_at = new \DateTime(); $comment->approved_user_id = $this->getUser()->id; @@ -55,8 +68,15 @@ class PhotoCommentController extends Controller $comment->rejected_at = null; $comment->rejected_user_id = null; + // Send the notification e-mail to the owner + $comment->save(); $commentsActioned++; + + // Send e-mail notification + $photo = $comment->photo; + $album = $photo->album; + $this->notifyAlbumOwnerAndPoster($album, $photo, $comment); } $request->session()->flash('success', trans_choice('admin.bulk_comments_approved', $commentsActioned, ['number' => $commentsActioned])); @@ -66,6 +86,12 @@ class PhotoCommentController extends Controller /** @var PhotoComment $comment */ foreach ($comments as $comment) { + if ($comment->isRejected()) + { + // Don't make changes if already rejected + continue; + } + // Mark as rejected $comment->rejected_at = new \DateTime(); $comment->rejected_user_id = $this->getUser()->id; @@ -157,6 +183,12 @@ class PhotoCommentController extends Controller $comment = $this->loadCommentByID($id); + if ($comment->isApproved()) + { + // Comment has already been approved + return redirect(route('comments.index')); + } + // Mark as approved $comment->approved_at = new \DateTime(); $comment->approved_user_id = $this->getUser()->id; @@ -171,6 +203,11 @@ class PhotoCommentController extends Controller 'author_name' => $comment->authorDisplayName() ])); + // Send e-mail notification + $photo = $comment->photo; + $album = $photo->album; + $this->notifyAlbumOwnerAndPoster($album, $photo, $comment); + return redirect(route('comments.index')); } @@ -180,6 +217,12 @@ class PhotoCommentController extends Controller $comment = $this->loadCommentByID($id); + if ($comment->isRejected()) + { + // Comment has already been rejected + return redirect(route('comments.index')); + } + // Mark as rejected $comment->rejected_at = new \DateTime(); $comment->rejected_user_id = $this->getUser()->id; @@ -292,4 +335,41 @@ class PhotoCommentController extends Controller return $comment; } + + /** + * Sends an e-mail notification to an album's owned that a comment has been posted/approved. + * @param Album $album + * @param Photo $photo + * @param PhotoComment $comment + */ + private function notifyAlbumOwnerAndPoster(Album $album, Photo $photo, PhotoComment $comment) + { + $owner = $album->user; + + Mail::to($owner)->send(new PhotoCommentApproved($owner, $album, $photo, $comment)); + + // Also send a notification to the comment poster + $poster = new User(); + $poster->name = $comment->authorDisplayName(); + $poster->email = $comment->authorEmail(); + + Mail::to($poster)->send(new PhotoCommentApprovedUser($poster, $album, $photo, $comment)); + + // Send notification to the parent comment owner (if this is a reply) + if (!is_null($comment->parent_comment_id)) + { + $parentComment = $this->loadCommentByID($comment->parent_comment_id); + + if (is_null($parentComment)) + { + return; + } + + $parentPoster = new User(); + $parentPoster->name = $parentComment->authorDisplayName(); + $parentPoster->email = $parentComment->authorEmail(); + + Mail::to($parentPoster)->send(new PhotoCommentRepliedTo($parentPoster, $album, $photo, $comment)); + } + } } \ No newline at end of file diff --git a/app/Http/Controllers/Gallery/PhotoCommentController.php b/app/Http/Controllers/Gallery/PhotoCommentController.php index 9a477bc..3ae5db5 100644 --- a/app/Http/Controllers/Gallery/PhotoCommentController.php +++ b/app/Http/Controllers/Gallery/PhotoCommentController.php @@ -54,7 +54,7 @@ class PhotoCommentController extends Controller $comment->approved_user_id = $this->getUser()->id; $comment->save(); - $this->notifyAlbumOwner($album, $photo, $comment); + $this->notifyAlbumOwnerAndPoster($album, $photo, $comment); $request->getSession()->flash('success', trans('gallery.photo_comment_approved_successfully')); } else if ($request->has('reject')) @@ -191,7 +191,7 @@ class PhotoCommentController extends Controller } else { - $this->notifyAlbumOwner($album, $photo, $comment); + $this->notifyAlbumOwnerAndPoster($album, $photo, $comment); $request->getSession()->flash('success', trans('gallery.photo_comment_posted_successfully')); } @@ -281,16 +281,35 @@ class PhotoCommentController extends Controller * @param Photo $photo * @param PhotoComment $comment */ - private function notifyAlbumOwner(Album $album, Photo $photo, PhotoComment $comment) + private function notifyAlbumOwnerAndPoster(Album $album, Photo $photo, PhotoComment $comment) { $owner = $album->user; + Mail::to($owner)->send(new PhotoCommentApproved($owner, $album, $photo, $comment)); + + // Also send a notification to the comment poster $poster = new User(); $poster->name = $comment->authorDisplayName(); $poster->email = $comment->authorEmail(); - Mail::to($owner)->send(new PhotoCommentApproved($owner, $album, $photo, $comment)); Mail::to($poster)->send(new PhotoCommentApprovedUser($poster, $album, $photo, $comment)); + + // Send notification to the parent comment owner (if this is a reply) + if (!is_null($comment->parent_comment_id)) + { + $parentComment = $this->loadCommentByID($comment->parent_comment_id); + + if (is_null($parentComment)) + { + return; + } + + $parentPoster = new User(); + $parentPoster->name = $parentComment->authorDisplayName(); + $parentPoster->email = $parentComment->authorEmail(); + + Mail::to($parentPoster)->send(new PhotoCommentRepliedTo($parentPoster, $album, $photo, $comment)); + } } private function stripDisallowedHtmlTags($commentText) diff --git a/app/Mail/PhotoCommentRepliedTo.php b/app/Mail/PhotoCommentRepliedTo.php new file mode 100644 index 0000000..77dcebc --- /dev/null +++ b/app/Mail/PhotoCommentRepliedTo.php @@ -0,0 +1,60 @@ +user = $user; + $this->album = $album; + $this->photo = $photo; + $this->comment = $comment; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + $subject = trans('email.photo_comment_replied_to_subject', ['album_name' => $this->album->name]); + + return $this + ->subject($subject) + ->markdown(Theme::viewName('email.photo_comment_replied_to')) + ->with([ + 'album' => $this->album, + 'comment' => $this->comment, + 'photo' => $this->photo, + 'subject' => $subject, + 'user' => $this->user + ]); + } +} diff --git a/resources/lang/en/email.php b/resources/lang/en/email.php index 472becd..f42da70 100644 --- a/resources/lang/en/email.php +++ b/resources/lang/en/email.php @@ -25,5 +25,9 @@ return [ 'photo_comment_approved_user_comment_label' => 'Comments:', 'photo_comment_approved_user_p1' => 'Your comment has been successfully posted in the :album_name album.', 'photo_comment_approved_user_p2' => 'Click the button below to view the photo\'s page to see your comment.', - 'photo_comment_approved_user_subject' => 'Your comment was posted in :album_name' + 'photo_comment_approved_user_subject' => 'Your comment was posted in :album_name', + 'photo_comment_replied_to_comment_label' => 'Comments:', + 'photo_comment_replied_to_p1' => 'A reply to your comment has been posted in the :album_name album.', + 'photo_comment_replied_to_p2' => 'Click the button below to view the photo\'s page to see the reply to your comment.', + 'photo_comment_replied_to_subject' => 'A reply to your comment was posted in :album_name' ]; \ No newline at end of file diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index e6339e7..429aa08 100644 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -40,6 +40,7 @@ return [ 'parent_album_placeholder' => 'None (top-level album)', 'password_label' => 'Password:', 'password_confirm_label' => 'Confirm password:', + 'photo_comment_email_help' => 'We\'ll only use this to send you notifications about your comment. It won\'t be published.', 'photo_comment_reply_action' => 'Post reply', 'photo_comment_submit_action' => 'Post comment', 'photo_comment_text_label' => 'Your message/comments:', diff --git a/resources/views/themes/base/admin/list_comments.blade.php b/resources/views/themes/base/admin/list_comments.blade.php index 0920fac..d301b4e 100644 --- a/resources/views/themes/base/admin/list_comments.blade.php +++ b/resources/views/themes/base/admin/list_comments.blade.php @@ -45,7 +45,8 @@

- {{ $comment->name }} + {{-- TODO: edit comments {{ $comment->name }} --}} + {{ $comment->name }}
{{ trans('admin.comment_summary', ['album_name' => $comment->photo->album->name, 'photo_name' => $comment->photo->name, 'comment_date' => date(UserConfig::get('date_format'), strtotime($comment->created_at))]) }} diff --git a/resources/views/themes/base/email/photo_comment_replied_to.blade.php b/resources/views/themes/base/email/photo_comment_replied_to.blade.php new file mode 100644 index 0000000..49eacf6 --- /dev/null +++ b/resources/views/themes/base/email/photo_comment_replied_to.blade.php @@ -0,0 +1,22 @@ +@component('mail::message') +@lang('email.generic_intro', ['user_name' => $user->name]) + + +@lang('email.photo_comment_replied_to_p1', ['album_name' => $album->name]) + + +@lang('email.photo_comment_replied_to_p2') + + +@lang('email.photo_comment_replied_to_comment_label') + +{!! $comment->comment !!} + +@component('mail::button', ['url' => $photo->url(), 'color' => 'blue']) + @lang('forms.view_photo_comment_action') +@endcomponent + +@lang('email.generic_regards')
+{{ UserConfig::get('app_name') }}
+{{ route('home') }} +@endcomponent \ No newline at end of file diff --git a/resources/views/themes/base/partials/photo_comments_reply_form.blade.php b/resources/views/themes/base/partials/photo_comments_reply_form.blade.php index 3288811..ac7e524 100644 --- a/resources/views/themes/base/partials/photo_comments_reply_form.blade.php +++ b/resources/views/themes/base/partials/photo_comments_reply_form.blade.php @@ -3,7 +3,7 @@ $is_reply = isset($reply_comment); $is_known_user = !is_null(Auth::user()) @endphp -{{-- Show a previous of the comment we're replying to --}} +{{-- Show a preview of the comment we're replying to --}} @if ($is_reply)

@include (Theme::viewName('partials.photo_single_comment'), ['comment' => $reply_comment, 'is_reply' => true]) @@ -31,6 +31,7 @@ $is_known_user = !is_null(Auth::user())
+ @lang('forms.photo_comment_email_help') @if ($errors->has('email'))