Merge photo comments feature #114
50
app/Http/Controllers/Gallery/PhotoCommentController.php
Normal file
50
app/Http/Controllers/Gallery/PhotoCommentController.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Gallery;
|
||||||
|
|
||||||
|
use App\Facade\UserConfig;
|
||||||
|
use App\Helpers\DbHelper;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\PhotoComment;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class PhotoCommentController extends Controller
|
||||||
|
{
|
||||||
|
public function store(Request $request, $albumUrlAlias, $photoFilename)
|
||||||
|
{
|
||||||
|
$album = DbHelper::getAlbumByPath($albumUrlAlias);
|
||||||
|
if (is_null($album))
|
||||||
|
{
|
||||||
|
App::abort(404);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->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());
|
||||||
|
}
|
||||||
|
}
|
@ -157,7 +157,8 @@ class PhotoController extends Controller
|
|||||||
'is_original_allowed' => $isOriginalAllowed,
|
'is_original_allowed' => $isOriginalAllowed,
|
||||||
'next_photo' => $nextPhoto,
|
'next_photo' => $nextPhoto,
|
||||||
'photo' => $photo,
|
'photo' => $photo,
|
||||||
'previous_photo' => $previousPhoto
|
'previous_photo' => $previousPhoto,
|
||||||
|
'success' => $request->getSession()->get('success')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +77,14 @@ class Photo extends Model
|
|||||||
return $this->belongsToMany(Label::class, 'photo_labels');
|
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)
|
public function thumbnailUrl($thumbnailName = null, $cacheBust = true)
|
||||||
{
|
{
|
||||||
$url = $this->album->getAlbumSource()->getUrlToPhoto($this, $thumbnailName);
|
$url = $this->album->getAlbumSource()->getUrlToPhoto($this, $thumbnailName);
|
||||||
|
19
app/PhotoComment.php
Normal file
19
app/PhotoComment.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class PhotoComment extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'commentor_name',
|
||||||
|
'commentor_email',
|
||||||
|
'comment_text'
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreatePhotoCommentsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('photo_comments', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,7 @@ return [
|
|||||||
'edit_action' => 'Edit',
|
'edit_action' => 'Edit',
|
||||||
'edit_album_action' => 'Edit this album',
|
'edit_album_action' => 'Edit this album',
|
||||||
'email_label' => 'E-mail address:',
|
'email_label' => 'E-mail address:',
|
||||||
|
'email_placeholder' => 'name@example.com',
|
||||||
'enable_profile_page_label' => 'Allow others to see my profile page',
|
'enable_profile_page_label' => 'Allow others to see my profile page',
|
||||||
'inherit_album_permissions' => 'Inherit permissions from parent album',
|
'inherit_album_permissions' => 'Inherit permissions from parent album',
|
||||||
'labels_label' => 'Labels:',
|
'labels_label' => 'Labels:',
|
||||||
@ -35,6 +36,8 @@ return [
|
|||||||
'parent_album_placeholder' => 'None (top-level album)',
|
'parent_album_placeholder' => 'None (top-level album)',
|
||||||
'password_label' => 'Password:',
|
'password_label' => 'Password:',
|
||||||
'password_confirm_label' => 'Confirm password:',
|
'password_confirm_label' => 'Confirm password:',
|
||||||
|
'photo_comment_submit_action' => 'Post comment',
|
||||||
|
'photo_comment_text_label' => 'Your message/comments:',
|
||||||
'please_select' => '- Select an Option -',
|
'please_select' => '- Select an Option -',
|
||||||
'private_album_label' => 'Private album (only visible to me)',
|
'private_album_label' => 'Private album (only visible to me)',
|
||||||
'profile_alias_label' => 'Alias:',
|
'profile_alias_label' => 'Alias:',
|
||||||
|
@ -33,6 +33,10 @@ return [
|
|||||||
'other_albums_description' => 'You may also be interested in the following albums.',
|
'other_albums_description' => 'You may also be interested in the following albums.',
|
||||||
'other_albums_description_empty' => 'The <b>:album_name</b> album does not contain any photos - however you may also be interested in the following albums.',
|
'other_albums_description_empty' => 'The <b>:album_name</b> album does not contain any photos - however you may also be interested in the following albums.',
|
||||||
'other_albums_heading' => 'More Albums in :album_name',
|
'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',
|
'photos' => 'photo|photos',
|
||||||
'previous_button' => '« Previous Photo',
|
'previous_button' => '« Previous Photo',
|
||||||
'show_more_albums' => '... and :count other|... and :count others',
|
'show_more_albums' => '... and :count other|... and :count others',
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-8 content-body">
|
<div class="col-lg-8 content-body">
|
||||||
@if ($is_original_allowed)
|
@if ($is_original_allowed)
|
||||||
<a href="{{ $photo->thumbnailUrl() }}">
|
<a href="{{ $photo->thumbnailUrl() }}">
|
||||||
@endif
|
@endif
|
||||||
@ -44,7 +44,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if ($photo->labels()->count() > 0)
|
@if ($photo->labels()->count() > 0)
|
||||||
<h4>@lang('gallery.labels')</h4>
|
<h2 class="h4">@lang('gallery.labels')</h2>
|
||||||
<ul class="nav nav-pills mb-4">
|
<ul class="nav nav-pills mb-4">
|
||||||
@foreach ($photo->labels()->orderBy('name')->get() as $label)
|
@foreach ($photo->labels()->orderBy('name')->get() as $label)
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
@ -55,9 +55,13 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if (UserConfig::get('allow_photo_comments'))
|
||||||
|
@include (Theme::viewName('partials.gallery_photo_comments'))
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-4">
|
<div class="col-lg-4">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">Information about this photo:</div>
|
<div class="card-header">Information about this photo:</div>
|
||||||
<div class="card-body" style="padding: 0;">
|
<div class="card-body" style="padding: 0;">
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
<form action="{{ $photo->postCommentUrl() }}" method="post">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="commentor-name">@lang('forms.name_label')</label>
|
||||||
|
<input type="text" class="form-control" id="commentor-name" name="commentor_name"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="commentor-email">@lang('forms.email_label')</label>
|
||||||
|
<input type="email" class="form-control" id="commentor-email" name="commentor_email" placeholder="@lang('forms.email_placeholder')"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="comment-text">@lang('forms.photo_comment_text_label')</label>
|
||||||
|
<textarea class="form-control" id="comment-text" name="comment_text" rows="10"></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group text-right">
|
||||||
|
<button type="submit" class="btn btn-success">@lang('forms.photo_comment_submit_action')</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -0,0 +1,10 @@
|
|||||||
|
<div class="row">
|
||||||
|
<div class="col mt-4">
|
||||||
|
<h2>@lang('gallery.photo_comments_heading')</h2>
|
||||||
|
|
||||||
|
<h3>@lang('gallery.photo_comments_reply_form_heading')</h3>
|
||||||
|
<p>@lang('gallery.photo_comments_reply_form_p1')</p>
|
||||||
|
<hr/>
|
||||||
|
@include(Theme::viewName('gallery.photo_comments_reply_form'))
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -106,6 +106,9 @@ Route::get('a/{albumUrlAlias}', 'Gallery\AlbumController@index')
|
|||||||
Route::get('exif/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@showExifData')
|
Route::get('exif/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@showExifData')
|
||||||
->name('viewExifData')
|
->name('viewExifData')
|
||||||
->where('albumUrlAlias', '.*');
|
->where('albumUrlAlias', '.*');
|
||||||
|
Route::post('p/{albumUrlAlias}/{photoFilename}/comments', 'Gallery\PhotoCommentController@store')
|
||||||
|
->name('postPhotoComment')
|
||||||
|
->where('albumUrlAlias', '.*');
|
||||||
Route::get('p/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@show')
|
Route::get('p/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@show')
|
||||||
->name('viewPhoto')
|
->name('viewPhoto')
|
||||||
->where('albumUrlAlias', '.*');
|
->where('albumUrlAlias', '.*');
|
||||||
|
Loading…
Reference in New Issue
Block a user