194 lines
12 KiB
Twig
194 lines
12 KiB
Twig
{% macro comments_input(category, user, perms, reply_to) %}
|
|
{% set reply_mode = reply_to is not null %}
|
|
|
|
{% from '_layout/input.twig' import input_hidden, input_csrf, input_checkbox %}
|
|
|
|
<form class="comment comment--input{% if reply_mode %} comment--reply{% endif %}"
|
|
method="post" action="/comments.php?m=create"
|
|
id="comment-{{ reply_mode ? 'reply-' ~ reply_to.comment_id : 'create-' ~ category.category_id }}">
|
|
{{ input_hidden('comment[category]', category.category_id) }}
|
|
{{ input_csrf('comments') }}
|
|
|
|
{% if reply_mode %}
|
|
{{ input_hidden('comment[reply]', reply_to.comment_id) }}
|
|
{% endif %}
|
|
|
|
<div class="comment__container">
|
|
<div class="avatar comment__avatar"
|
|
style="background-image:url('/profile.php?m=avatar&u={{ user.user_id }}')">
|
|
</div>
|
|
<div class="comment__content">
|
|
<textarea
|
|
class="comment__text input__textarea comment__text--input"
|
|
name="comment[text]" placeholder="Share your extensive insights..."></textarea>
|
|
<div class="comment__actions">
|
|
{% if not reply_mode %}
|
|
{% if perms.can_pin %}
|
|
{{ input_checkbox('comment[pin]', 'Pin this comment', false, 'comment__action') }}
|
|
{% endif %}
|
|
{% if perms.can_lock %}
|
|
{{ input_checkbox('comment[lock]', 'Toggle locked status', false, 'comment__action') }}
|
|
{% endif %}
|
|
{% endif %}
|
|
<button class="input__button comment__action comment__action--button comment__action--post">
|
|
{{ reply_mode ? 'Reply' : 'Post' }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
{% endmacro %}
|
|
|
|
{% macro comments_entry(comment, indent, category, user, perms) %}
|
|
{% from '_layout/input.twig' import input_checkbox_raw %}
|
|
{% set is_deleted = comment.comment_deleted is not null %}
|
|
{% set hide_details = is_deleted and not perms.can_delete_any %}
|
|
|
|
{% if perms.can_delete_any or (not is_deleted or comment.comment_replies|length > 0) %}
|
|
{% set is_pinned = comment.comment_pinned is not null %}
|
|
|
|
<div class="comment{% if is_deleted %} comment--deleted{% endif %}" id="comment-{{ comment.comment_id }}">
|
|
<div class="comment__container">
|
|
{% if hide_details %}
|
|
<div class="avatar comment__avatar" style="background-image:url('/profile.php?m=avatar')"></div>
|
|
{% else %}
|
|
<a class="avatar comment__avatar"
|
|
href="{{ url('user-profile', {'user':comment.user_id}) }}"
|
|
style="background-image:url('{{ url('user-avatar', {'user':comment.user_id}) }}')">
|
|
</a>
|
|
{% endif %}
|
|
<div class="comment__content">
|
|
<div class="comment__info">
|
|
{% if not hide_details %}
|
|
<a class="comment__user comment__user--link"
|
|
href="{{ url('user-profile', {'user':comment.user_id}) }}"
|
|
style="{{ comment.user_colour|html_colour }}">{{ comment.username }}</a>
|
|
{% endif %}
|
|
<a class="comment__link" href="#comment-{{ comment.comment_id }}">
|
|
<time class="comment__date"
|
|
title="{{ comment.comment_created|date('r') }}"
|
|
datetime="{{ comment.comment_created|date('c') }}">
|
|
{{ comment.comment_created|time_diff }}
|
|
</time>
|
|
</a>
|
|
{% if is_pinned %}
|
|
<span class="comment__pin">{% spaceless %}
|
|
Pinned
|
|
{% if comment.comment_pinned != comment.comment_created %}
|
|
<time title="{{ comment.comment_pinned|date('r') }}"
|
|
datetime="{{ comment.comment_pinned|date('c') }}">
|
|
{{ comment.comment_pinned|time_diff }}
|
|
</time>
|
|
{% endif %}
|
|
{% endspaceless %}</span>
|
|
{% endif %}
|
|
</div>
|
|
<div class="comment__text">
|
|
{{ hide_details ? '(deleted)' : (comment.comment_html is defined ? comment.comment_html|raw : comment.comment_text|nl2br) }}
|
|
</div>
|
|
<div class="comment__actions">
|
|
{% if not is_deleted and user is not null %}
|
|
{% if perms.can_vote %}
|
|
<a class="comment__action comment__action--link comment__action--vote comment__action--like{% if comment.comment_user_vote == 'Like' %} comment__action--voted{% endif %}" data-comment-id="{{ comment.comment_id }}" data-comment-vote="{{ comment.comment_user_vote == 'Like' ? '0' : '1' }}"
|
|
href="{{ url('comment-vote', {'comment':comment.comment_id,'vote':comment.comment_user_vote == 'Like' ? '0' : '1'}) }}">
|
|
<!--i class="fas fa-thumbs-up"></i-->
|
|
Like
|
|
{% if comment.comment_likes > 0 %}
|
|
({{ comment.comment_likes|number_format }})
|
|
{% endif %}
|
|
</a>
|
|
<a class="comment__action comment__action--link comment__action--vote comment__action--dislike{% if comment.comment_user_vote == 'Dislike' %} comment__action--voted{% endif %}" data-comment-id="{{ comment.comment_id }}" data-comment-vote="{{ comment.comment_user_vote == 'Dislike' ? '0' : '-1' }}"
|
|
href="{{ url('comment-vote', {'comment':comment.comment_id,'vote':comment.comment_user_vote == 'Dislike' ? '0' : '-1'}) }}">
|
|
<!--i class="fas fa-thumbs-down"></i-->
|
|
Dislike
|
|
{% if comment.comment_dislikes > 0 %}
|
|
({{ comment.comment_dislikes|number_format }})
|
|
{% endif %}
|
|
</a>
|
|
{% endif %}
|
|
{% if perms.can_comment %}
|
|
<label class="comment__action comment__action--link" for="comment-reply-toggle-{{ comment.comment_id }}">Reply</label>
|
|
{% endif %}
|
|
{% if perms.can_delete_any or (comment.user_id == user.user_id and perms.can_delete) %}
|
|
<a class="comment__action comment__action--link comment__action--hide comment__action--delete" data-comment-id="{{ comment.comment_id }}" href="{{ url('comment-delete', {'comment':comment.comment_id}) }}">Delete</a>
|
|
{% endif %}
|
|
{# if user is not null %}
|
|
<a class="comment__action comment__action--link comment__action--hide" href="#">Report</a>
|
|
{% endif #}
|
|
{% if comment.comment_reply_to is null and perms.can_pin %}
|
|
<a class="comment__action comment__action--link comment__action--hide comment__action--pin" data-comment-id="{{ comment.comment_id }}" data-comment-pinned="{{ is_pinned ? '1' : '0' }}" href="{{ url('comment-' ~ (is_pinned ? 'unpin' : 'pin'), {'comment':comment.comment_id}) }}">{{ is_pinned ? 'Unpin' : 'Pin' }}</a>
|
|
{% endif %}
|
|
{% elseif perms.can_delete_any %}
|
|
<a class="comment__action comment__action--link comment__action--restore" data-comment-id="{{ comment.comment_id }}" href="{{ url('comment-restore', {'comment':comment.comment_id}) }}">Restore</a>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="comment__replies comment__replies--indent-{{ indent }}" id="comment-{{ comment.comment_id }}-replies">
|
|
{% from _self import comments_entry, comments_input %}
|
|
{% if user|default(null) is not null and category|default(null) is not null and perms|default(null) is not null and perms.can_comment %}
|
|
{{ input_checkbox_raw('', false, 'comment__reply-toggle', '', false, {'id':'comment-reply-toggle-' ~ comment.comment_id}) }}
|
|
{{ comments_input(category, user, perms, comment) }}
|
|
{% endif %}
|
|
{% if comment.comment_replies is defined and comment.comment_replies|length > 0 %}
|
|
{% for reply in comment.comment_replies %}
|
|
{{ comments_entry(reply, indent + 1, category, user, perms) }}
|
|
{% endfor %}
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
{% macro comments_section(comments, category, user, perms) %}
|
|
<div class="comments">
|
|
<div class="comments__input">
|
|
{% if user|default(null) is null %}
|
|
<div class="comments__notice">
|
|
Please <a href="{{ url('auth-login') }}" class="comments__notice__link">login</a> to comment.
|
|
</div>
|
|
{% elseif category|default(null) is null or perms|default(null) is null %}
|
|
<div class="comments__notice">
|
|
Posting new comments here is disabled.
|
|
</div>
|
|
{% elseif not perms.can_lock and category.category_locked is not null %}
|
|
<div class="comments__notice">
|
|
This comment section was locked, <time datetime="{{ category.category_locked|date('c') }}" title="{{ category.category_locked|date('r') }}">{{ category.category_locked|time_diff }}</time>.
|
|
</div>
|
|
{% elseif not perms.can_comment %}
|
|
<div class="comments__notice">
|
|
You are not allowed to post comments.
|
|
</div>
|
|
{% else %}
|
|
{% from _self import comments_input %}
|
|
{{ comments_input(category, user, perms) }}
|
|
{% endif %}
|
|
</div>
|
|
|
|
{% if perms.can_lock and category.category_locked is not null %}
|
|
<div class="comments__notice comments__notice--staff">
|
|
This comment section was locked, <time datetime="{{ category.category_locked|date('c') }}" title="{{ category.category_locked|date('r') }}">{{ category.category_locked|time_diff }}</time>.
|
|
</div>
|
|
{% endif %}
|
|
|
|
<noscript>
|
|
<div class="comments__javascript">
|
|
While the comments work fine without Javascript, it is recommended you enable it as it has a lower bandwidth overhead.
|
|
</div>
|
|
</noscript>
|
|
|
|
<div class="comments__listing">
|
|
{% if comments|length > 0 %}
|
|
{% from _self import comments_entry %}
|
|
{% for comment in comments %}
|
|
{{ comments_entry(comment, 1, category, user, perms) }}
|
|
{% endfor %}
|
|
{% else %}
|
|
<div class="comments__none" id="_no_comments_notice_{{ category.category_id }}">
|
|
There are no comments yet.
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
{% endmacro %}
|