diff --git a/app/Http/Controllers/Admin/PhotoCommentController.php b/app/Http/Controllers/Admin/PhotoCommentController.php index 04d6ac9..59b02ee 100644 --- a/app/Http/Controllers/Admin/PhotoCommentController.php +++ b/app/Http/Controllers/Admin/PhotoCommentController.php @@ -46,6 +46,15 @@ class PhotoCommentController extends Controller return redirect(route('comments.index')); } + public function approve($id) + { + $this->authorizeAccessToAdminPanel('admin:manage-comments'); + + $comment = $this->loadCommentByID($id); + + return Theme::render('admin.approve_comment', ['comment' => $comment]); + } + public function bulkAction(Request $request) { $this->authorizeAccessToAdminPanel('admin:manage-comments'); @@ -76,15 +85,57 @@ class PhotoCommentController extends Controller return redirect(route('comments.index')); } + public function confirmApprove(Request $request, $id) + { + $this->authorizeAccessToAdminPanel('admin:manage-comments'); + + $comment = $this->loadCommentByID($id); + + // Mark as approved + $comment->approved_at = new \DateTime(); + $comment->approved_user_id = $this->getUser()->id; + + // The comment may have already been rejected - remove the data if so + $comment->rejected_at = null; + $comment->rejected_user_id = null; + + $comment->save(); + + $request->session()->flash('success', trans('admin.comment_approval_successful', [ + 'author_name' => $comment->authorDisplayName() + ])); + + return redirect(route('comments.index')); + } + + public function confirmReject(Request $request, $id) + { + $this->authorizeAccessToAdminPanel('admin:manage-comments'); + + $comment = $this->loadCommentByID($id); + + // Mark as rejected + $comment->rejected_at = new \DateTime(); + $comment->rejected_user_id = $this->getUser()->id; + + // The comment may have already been approved - remove the data if so + $comment->approved_at = null; + $comment->approved_user_id = null; + + $comment->save(); + + $request->session()->flash('success', trans('admin.comment_rejection_successful', [ + 'author_name' => $comment->authorDisplayName() + ])); + + return redirect(route('comments.index')); + } + public function delete($id) { $this->authorizeAccessToAdminPanel('admin:manage-comments'); - $comment = PhotoComment::where('id', intval($id))->first(); - if (is_null($comment)) - { - App::abort(404); - } + $comment = $this->loadCommentByID($id); return Theme::render('admin.delete_comment', ['comment' => $comment]); } @@ -94,11 +145,7 @@ class PhotoCommentController extends Controller $this->authorizeAccessToAdminPanel('admin:manage-comments'); /** @var PhotoComment $comment */ - $comment = PhotoComment::where('id', intval($id))->first(); - if (is_null($comment)) - { - App::abort(404); - } + $comment = $this->loadCommentByID($id); $comment->delete(); $request->session()->flash('success', trans('admin.comment_deletion_successful', [ @@ -154,4 +201,29 @@ class PhotoCommentController extends Controller 'warning' => $request->session()->get('warning') ]); } + + public function reject($id) + { + $this->authorizeAccessToAdminPanel('admin:manage-comments'); + + $comment = $this->loadCommentByID($id); + + return Theme::render('admin.reject_comment', ['comment' => $comment]); + } + + /** + * Loads a given comment by its ID. + * @param $id + * @return PhotoComment + */ + private function loadCommentByID($id) + { + $comment = PhotoComment::where('id', intval($id))->first(); + if (is_null($comment)) + { + App::abort(404); + } + + return $comment; + } } \ No newline at end of file diff --git a/app/PhotoComment.php b/app/PhotoComment.php index 0f72751..87f542f 100644 --- a/app/PhotoComment.php +++ b/app/PhotoComment.php @@ -61,6 +61,11 @@ class PhotoComment extends Model return (!is_null($this->approved_at) || !is_null($this->rejected_at)); } + public function isRejected() + { + return (!is_null($this->rejected_at) && is_null($this->approved_at)); + } + public function parent() { return $this->belongsTo(PhotoComment::class, 'parent_comment_id'); diff --git a/resources/lang/en/admin.php b/resources/lang/en/admin.php index cdf30c8..92bd876 100644 --- a/resources/lang/en/admin.php +++ b/resources/lang/en/admin.php @@ -59,13 +59,22 @@ return [ 'analyse_photos_failed' => 'The following items could not be analysed and were removed:', 'analyse_photos_failed_metadata' => 'The following items could not be analysed:', 'anonymous_users' => 'Anonymous (not logged in)', + 'approve_comment' => 'Approve comment by :author_name', + 'approve_comment_confirm' => 'Are you sure you want to approve this comment by ":author_name"?', 'bulk_comments_deleted' => ':number comment was deleted successfully.|:number comments were deleted successfully.', 'bulk_photos_changed' => ':number photo was updated successfully.|:number photos were updated successfully.', 'cannot_delete_own_user_account' => 'It is not possible to delete your own user account. Please ask another administrator to delete it for you.', 'cannot_remove_own_admin' => 'You cannot remove your own administrator permissions. Please ask another administrator to remove the administrator permissions for you.', 'change_album_message' => 'Please select the album to move the photo(s) to:', 'change_album_title' => 'Move photo(s) to another album', + 'comment_approval_successful' => 'The comment by ":author_name" was approved successfully.', + 'comment_badge' => [ + 'approved' => 'Approved', + 'new' => 'New', + 'rejected' => 'Rejected' + ], 'comment_deletion_successful' => 'The comment by ":author_name" was removed successfully.', + 'comment_rejection_successful' => 'The comment by ":author_name" was rejected successfully.', 'comment_summary' => ':album_name / :photo_name / :comment_date', 'create_album' => 'Create a photo album', 'create_album_intro' => 'Photo albums contain individual photographs together in the same way as a physical photo album or memory book.', @@ -222,6 +231,8 @@ return [ 'redirects_actions_heading' => 'Actions', 'redirects_source_url_heading' => 'Source Address', 'redirects_text' => 'To access this album using different addresses, you can use redirects. This is useful when you have moved the album to a different parent and the old address no longer works.', + 'reject_comment' => 'Reject comment by :author_name', + 'reject_comment_confirm' => 'Are you sure you want to reject this comment by ":author_name"?', 'replace_image_message' => 'If your photo isn\'t quite perfect, don\'t worry - just upload a new image using the field below and we\'ll replace it.', 'replace_image_title' => 'Replace photo', 'save_changes_heading' => 'Save changes', diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index 1e86f42..cffb9e4 100644 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -10,6 +10,7 @@ return [ 'album_source_label' => 'Storage location:', 'album_view_label' => 'View as:', 'apply_action' => 'Apply', + 'approve_action' => 'Approve', 'bulk_edit_photos_label' => 'Bulk edit selected photos:', 'bulk_edit_photos_placeholder' => 'Select an action', 'cancel_action' => 'Cancel', @@ -48,6 +49,7 @@ return [ 'quick_upload_file_label' => 'Photo:', 'realname_label' => 'Your name:', 'register_action' => 'Create account', + 'reject_action' => 'Reject', 'remember_me_label' => 'Remember me', 'remove_action' => 'Remove', 'review_photo_comment_action' => 'Approve/reject comment', diff --git a/resources/lang/en/gallery.php b/resources/lang/en/gallery.php index 4acfa4a..ce11487 100644 --- a/resources/lang/en/gallery.php +++ b/resources/lang/en/gallery.php @@ -39,9 +39,7 @@ return [ 'photo_comment_posted_successfully' => 'Your comment was posted successfully.', 'photo_comment_posted_successfully_pending_moderation' => 'Your comment was posted successfully and will appear after it has been moderated.', 'photo_comment_rejected_successfully' => 'The comment was rejected.', - 'photo_comments_approve_action' => 'Approve', 'photo_comments_heading' => 'Comments', - 'photo_comments_reject_action' => 'Reject', 'photo_comments_reply_action' => 'Reply', 'photo_comments_reply_form_heading' => 'Leave a reply', 'photo_comments_reply_form_p1' => 'Complete the form below to start a new reply thread.', diff --git a/resources/lang/en/navigation.php b/resources/lang/en/navigation.php index d8defdc..1c50af9 100644 --- a/resources/lang/en/navigation.php +++ b/resources/lang/en/navigation.php @@ -4,6 +4,7 @@ return [ 'about' => 'About', 'admin' => 'Admin', 'albums' => 'Albums', + 'approve_comment' => 'Approve comment', 'comments' => 'Comments', 'create_album' => 'Create album', 'create_group' => 'Create group', @@ -25,6 +26,7 @@ return [ 'home' => 'Gallery', 'labels' => 'Labels', 'metadata_upgrade' => 'Update Photo Metadata', + 'reject_comment' => 'Reject comment', 'settings' => 'Settings', 'storage' => 'Storage', 'users' => 'Users' diff --git a/resources/views/themes/base/admin/approve_comment.blade.php b/resources/views/themes/base/admin/approve_comment.blade.php new file mode 100644 index 0000000..415b2d8 --- /dev/null +++ b/resources/views/themes/base/admin/approve_comment.blade.php @@ -0,0 +1,34 @@ +@extends(Theme::viewName('layout')) +@section('title', trans('admin.approve_comment', ['author_name' => $comment->authorDisplayName()])) + +@section('breadcrumb') + + + + +@endsection + +@section('content') +
+
+
+
+
@yield('title')
+
+

@lang('admin.approve_comment_confirm', ['author_name' => $comment->authorDisplayName()])

+ + {!! $comment->textAsHtml() !!} + +
+
+ {{ csrf_field() }} + @lang('forms.cancel_action') + +
+
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/themes/base/admin/list_comments.blade.php b/resources/views/themes/base/admin/list_comments.blade.php index b460c77..33c0d4f 100644 --- a/resources/views/themes/base/admin/list_comments.blade.php +++ b/resources/views/themes/base/admin/list_comments.blade.php @@ -45,13 +45,38 @@

- {{ $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))]) }}

{!! $comment->textAsHtml() !!}
- - @lang('forms.delete_action') + +

+ @if (!$comment->isModerated()) + @lang('admin.comment_badge.new') + @elseif ($comment->isApproved()) + @lang('admin.comment_badge.approved') + @elseif ($comment->isRejected()) + @lang('admin.comment_badge.rejected') + @endif +

+ +
+
+ @if (!$comment->isModerated()) + @lang('forms.approve_action') + @lang('forms.reject_action') + @elseif ($comment->isApproved()) + @lang('forms.reject_action') + @elseif ($comment->isRejected()) + @lang('forms.approve_action') + @endif +
+ + @lang('forms.delete_action') +
@endforeach diff --git a/resources/views/themes/base/admin/reject_comment.blade.php b/resources/views/themes/base/admin/reject_comment.blade.php new file mode 100644 index 0000000..ca3fd0a --- /dev/null +++ b/resources/views/themes/base/admin/reject_comment.blade.php @@ -0,0 +1,34 @@ +@extends(Theme::viewName('layout')) +@section('title', trans('admin.reject_comment', ['author_name' => $comment->authorDisplayName()])) + +@section('breadcrumb') + + + + +@endsection + +@section('content') +
+
+
+
+
@yield('title')
+
+

@lang('admin.reject_comment_confirm', ['author_name' => $comment->authorDisplayName()])

+ + {!! $comment->textAsHtml() !!} + +
+
+ {{ csrf_field() }} + @lang('forms.cancel_action') + +
+
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/themes/base/partials/photo_single_comment_moderate.blade.php b/resources/views/themes/base/partials/photo_single_comment_moderate.blade.php index 9c79140..c8a9d8a 100644 --- a/resources/views/themes/base/partials/photo_single_comment_moderate.blade.php +++ b/resources/views/themes/base/partials/photo_single_comment_moderate.blade.php @@ -10,8 +10,8 @@
{{ csrf_field() }} - - + +
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index fd1b498..abb18de 100644 --- a/routes/web.php +++ b/routes/web.php @@ -68,9 +68,16 @@ Route::group(['prefix' => 'admin'], function () { Route::resource('groups', 'Admin\GroupController'); // Comments management + Route::get('comments/{id}/approve', 'Admin\PhotoCommentController@approve')->name('comments.approve'); + Route::post('comments/{id}/approve', 'Admin\PhotoCommentController@confirmApprove')->name('comments.confirmApprove'); + + Route::get('comments/{id}/reject', 'Admin\PhotoCommentController@reject')->name('comments.reject'); + Route::post('comments/{id}/reject', 'Admin\PhotoCommentController@confirmReject')->name('comments.confirmReject'); + Route::get('comments/{id}/delete', 'Admin\PhotoCommentController@delete')->name('comments.delete'); - Route::post('comments/bulk-action', 'Admin\PhotoCommentController@bulkAction')->name('comments.bulkAction'); + Route::post('comments/apply-bulk-action', 'Admin\PhotoCommentController@applyBulkAction')->name('comments.applyBulkAction'); + Route::post('comments/bulk-action', 'Admin\PhotoCommentController@bulkAction')->name('comments.bulkAction'); Route::resource('comments', 'Admin\PhotoCommentController'); });