Init
This commit is contained in:
91
resources/views/vendor/comments/_comment.blade.php
vendored
Normal file
91
resources/views/vendor/comments/_comment.blade.php
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
@inject('markdown', 'Parsedown')
|
||||
@php
|
||||
// TODO: There should be a better place for this.
|
||||
$markdown->setSafeMode(true);
|
||||
@endphp
|
||||
|
||||
|
||||
<div id="comment-{{ $comment->getKey() }}" class="flex rounded-lg p-1 mb-2 ">
|
||||
|
||||
<a class="contents" href="{{ route('user.index', ['username' => $comment->commenter->username]) }}">
|
||||
@if($comment->commenter->avatar)
|
||||
<img class="w-12 h-12 rounded-lg m-2" src="https://external-content.duckduckgo.com/iu/?u=https://cdn.discordapp.com/avatars/{{ $comment->commenter->id }}/{{ $comment->commenter->avatar }}.webp" alt="{{ $comment->commenter->global_name ?? $comment->commenter->username }} Avatar">
|
||||
@else
|
||||
<img class="w-12 h-12 rounded-lg m-2" src="/images/default-avatar.webp" alt="{{ $comment->commenter->global_name ?? $comment->commenter->username }} Avatar">
|
||||
@endif
|
||||
</a>
|
||||
|
||||
<div class="text-gray-800 dark:text-gray-200">
|
||||
<a href="{{ route('user.index', ['username' => $comment->commenter->username]) }}">
|
||||
@if($comment->commenter->is_patreon)
|
||||
<h5 class="text-gray-800 dark:text-gray-400">{{ $comment->commenter->global_name ?? $comment->commenter->username }} <a data-te-toggle="tooltip" title="Badge of appreciation for the horny people supporting us! :3"><i class="fa-solid fa-hand-holding-heart text-rose-600 animate-pulse"></i></a> <small class="text-muted">- {{ $comment->created_at->diffForHumans() }}</small></h5>
|
||||
@else
|
||||
<h5 class="text-gray-800 dark:text-gray-400">{{ $comment->commenter->global_name ?? $comment->commenter->username }} <small class="text-muted">- {{ $comment->created_at->diffForHumans() }}</small></h5>
|
||||
@endif
|
||||
</a>
|
||||
<div style="white-space: pre-wrap;">{!! $markdown->line($comment->comment) !!}</div>
|
||||
|
||||
@if (! Illuminate\Support\Facades\Route::is('profile.comments'))
|
||||
<div>
|
||||
@can('reply-to-comment', $comment)
|
||||
<button data-te-toggle="modal" data-te-target="#reply-modal-{{ $comment->getKey() }}" class="inline-flex items-center px-4 py-2 mt-2 dark:focus:ring-offset-gray-800 bg-rose-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-rose-700 focus:bg-rose-700 active:bg-rose-900 focus:outline-none focus:ring-2 focus:ring-rose-500 focus:ring-offset-2 transition ease-in-out duration-150">@lang('comments::comments.reply')</button>
|
||||
@endcan
|
||||
@can('edit-comment', $comment)
|
||||
<button data-te-toggle="modal" data-te-target="#comment-modal-{{ $comment->getKey() }}" class="inline-flex items-center px-4 py-2 mt-2 dark:focus:ring-offset-gray-800 bg-rose-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-rose-700 focus:bg-rose-700 active:bg-rose-900 focus:outline-none focus:ring-2 focus:ring-rose-500 focus:ring-offset-2 transition ease-in-out duration-150">@lang('comments::comments.edit')</button>
|
||||
@endcan
|
||||
@can('delete-comment', $comment)
|
||||
<a href="{{ route('comments.destroy', $comment->getKey()) }}" onclick="event.preventDefault();document.getElementById('comment-delete-form-{{ $comment->getKey() }}').submit();" class="inline-flex items-center px-4 py-2 bg-red-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-red-500 active:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 dark:focus:ring-offset-gray-800 transition ease-in-out duration-150 mt-2">@lang('comments::comments.delete')</a>
|
||||
<form id="comment-delete-form-{{ $comment->getKey() }}" action="{{ route('comments.destroy', $comment->getKey()) }}" method="POST" style="display: none;">
|
||||
@method('DELETE')
|
||||
@csrf
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
@can('edit-comment', $comment)
|
||||
@include('modals.comment-edit')
|
||||
@endcan
|
||||
|
||||
@can('reply-to-comment', $comment)
|
||||
@include('modals.comment-reply')
|
||||
@endcan
|
||||
|
||||
<br />{{-- Margin bottom --}}
|
||||
|
||||
<?php
|
||||
if (!isset($indentationLevel)) {
|
||||
$indentationLevel = 1;
|
||||
} else {
|
||||
$indentationLevel++;
|
||||
}
|
||||
?>
|
||||
|
||||
{{-- Recursion for children --}}
|
||||
@if($grouped_comments->has($comment->getKey()) && $indentationLevel <= $maxIndentationLevel)
|
||||
{{-- TODO: Don't repeat code. Extract to a new file and include it. --}}
|
||||
@foreach($grouped_comments[$comment->getKey()] as $child)
|
||||
<div class="flex">
|
||||
<div class="h-[100px] bg-rose-600 w-[4px] rounded-lg"></div>
|
||||
@include('comments::_comment', [
|
||||
'comment' => $child,
|
||||
'grouped_comments' => $grouped_comments
|
||||
])
|
||||
</div>
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Recursion for children --}}
|
||||
@if($grouped_comments->has($comment->getKey()) && $indentationLevel > $maxIndentationLevel)
|
||||
{{-- TODO: Don't repeat code. Extract to a new file and include it. --}}
|
||||
@foreach($grouped_comments[$comment->getKey()] as $child)
|
||||
@include('comments::_comment', [
|
||||
'comment' => $child,
|
||||
'grouped_comments' => $grouped_comments
|
||||
])
|
||||
@endforeach
|
||||
@endif
|
30
resources/views/vendor/comments/_form.blade.php
vendored
Normal file
30
resources/views/vendor/comments/_form.blade.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
<div class="pt-5">
|
||||
@if($errors->has('commentable_type'))
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ $errors->first('commentable_type') }}
|
||||
</div>
|
||||
@endif
|
||||
@if($errors->has('commentable_id'))
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ $errors->first('commentable_id') }}
|
||||
</div>
|
||||
@endif
|
||||
<form class="block rounded-lg p-6 dark:bg-neutral-700/40" method="POST" action="{{ route('comments.store') }}">
|
||||
@csrf
|
||||
@honeypot
|
||||
<input type="hidden" name="commentable_type" value="\{{ get_class($model) }}" />
|
||||
<input type="hidden" name="commentable_id" value="{{ $model->getKey() }}" />
|
||||
|
||||
<div class="pb-5">
|
||||
<label class="mb-2 text-xl font-medium leading-tight text-gray-800 dark:text-gray-200 w-full" for="message">@lang('comments::comments.enter_your_message_here')</label>
|
||||
<textarea class="peer block min-h-[auto] w-full border-1 bg-transparent px-3 py-[0.32rem] leading-[1.6] outline-none transition-all duration-200 ease-linear dark:placeholder:text-neutral-200 border-gray-300 dark:border-neutral-950 dark:bg-neutral-900 dark:text-gray-300 focus:border-rose-500 dark:focus:border-rose-600 focus:ring-rose-500 dark:focus:ring-rose-600 rounded-md shadow-sm @if($errors->has('message')) is-invalid @endif" name="message" rows="3"></textarea>
|
||||
</div>
|
||||
|
||||
<x-primary-button>
|
||||
@lang('comments::comments.submit')
|
||||
</x-primary-button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<br />
|
80
resources/views/vendor/comments/components/comments.blade.php
vendored
Normal file
80
resources/views/vendor/comments/components/comments.blade.php
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
@php
|
||||
if (isset($approved) and $approved == true) {
|
||||
$comments = $model->approvedComments;
|
||||
} else {
|
||||
$comments = $model->comments;
|
||||
}
|
||||
@endphp
|
||||
|
||||
@if($comments->count() < 1)
|
||||
<div class="mb-4 rounded-lg text-black px-6 py-5 text-base dark:text-neutral-50 bg-white dark:bg-neutral-700/40">@lang('comments::comments.there_are_no_comments')</div>
|
||||
@endif
|
||||
|
||||
<div>
|
||||
@php
|
||||
$comments = $comments->sortByDesc('created_at');
|
||||
|
||||
if (isset($perPage)) {
|
||||
$page = request()->query('page', 1) - 1;
|
||||
|
||||
$parentComments = $comments->where('child_id', '');
|
||||
|
||||
$slicedParentComments = $parentComments->slice($page * $perPage, $perPage);
|
||||
|
||||
$m = Config::get('comments.model'); // This has to be done like this, otherwise it will complain.
|
||||
$modelKeyName = (new $m)->getKeyName(); // This defaults to 'id' if not changed.
|
||||
|
||||
$slicedParentCommentsIds = $slicedParentComments->pluck($modelKeyName)->toArray();
|
||||
|
||||
// Remove parent Comments from comments.
|
||||
$comments = $comments->where('child_id', '!=', '');
|
||||
|
||||
$grouped_comments = new \Illuminate\Pagination\LengthAwarePaginator(
|
||||
$slicedParentComments->merge($comments)->groupBy('child_id'),
|
||||
$parentComments->count(),
|
||||
$perPage
|
||||
);
|
||||
|
||||
$grouped_comments->withPath(request()->url());
|
||||
} else {
|
||||
$grouped_comments = $comments->groupBy('child_id');
|
||||
}
|
||||
@endphp
|
||||
@foreach($grouped_comments as $comment_id => $comments)
|
||||
{{-- Process parent nodes --}}
|
||||
@if($comment_id == '')
|
||||
@foreach($comments as $comment)
|
||||
@include('comments::_comment', [
|
||||
'comment' => $comment,
|
||||
'grouped_comments' => $grouped_comments,
|
||||
'maxIndentationLevel' => $maxIndentationLevel ?? 3
|
||||
])
|
||||
@endforeach
|
||||
@endif
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
@isset ($perPage)
|
||||
{{ $grouped_comments->links() }}
|
||||
@endisset
|
||||
|
||||
@if ((! Illuminate\Support\Facades\Route::is('profile.comments')) && (! Illuminate\Support\Facades\Route::is('home.index')))
|
||||
@auth
|
||||
@include('comments::_form')
|
||||
@elseif(Config::get('comments.guest_commenting') == true)
|
||||
@include('comments::_form', [
|
||||
'guest_commenting' => true
|
||||
])
|
||||
@else
|
||||
<div class="block rounded-lg p-6 shadow-[0_2px_15px_-3px_rgba(0,0,0,0.07),0_10px_20px_-2px_rgba(0,0,0,0.04)] bg-white dark:bg-neutral-700/40">
|
||||
<div class="card-body">
|
||||
<h5 class="mb-2 text-xl font-medium leading-tight text-gray-800 dark:text-gray-200 w-full">@lang('comments::comments.authentication_required')</h5>
|
||||
<p class="mb-2 leading-tight text-gray-800 dark:text-gray-200 w-full">@lang('comments::comments.you_must_login_to_post_a_comment')</p>
|
||||
<br>
|
||||
<a href="{{ route('login') }}" class="relative bg-blue-700 hover:bg-blue-600 text-white font-bold px-6 h-10 rounded pt-2 pb-2" style="width: 12px">
|
||||
<i class="fa-brands fa-discord"></i> Login
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
@endauth
|
||||
@endif
|
Reference in New Issue
Block a user