{% macro comments_input(category, user, reply_to) %} {% set reply_mode = reply_to is not null %} {% from 'macros.twig' import avatar %} {% from '_layout/input.twig' import input_hidden, input_csrf, input_checkbox %}
{{ input_hidden('comment[category]', category.id) }} {{ input_csrf() }} {% if reply_mode %} {{ input_hidden('comment[reply]', reply_to.id) }} {% endif %}
{{ avatar(user.id, reply_mode ? 40 : 50, user.username) }}
{% if not reply_mode %} {% if user.commentPerms.can_pin|default(false) %} {{ input_checkbox('comment[pin]', 'Pin this comment', false, 'comment__action') }} {% endif %} {% if user.commentPerms.can_lock|default(false) %} {{ input_checkbox('comment[lock]', 'Toggle locked status', false, 'comment__action') }} {% endif %} {% endif %}
{% endmacro %} {% macro comments_entry(comment, indent, category, user) %} {% from 'macros.twig' import avatar %} {% from '_layout/input.twig' import input_checkbox_raw %} {% set replies = comment.replies %} {% set poster = comment.user|default(null) %} {% if comment.post is defined %} {% set userVote = comment.vote.weight %} {% set comment = comment.post %} {% set body = comment.body %} {% set likes = comment.votesPositive %} {% set dislikes = comment.votesNegative %} {% set isReply = comment.isReply %} {% else %} {% set body = comment.text %} {% set userVote = comment.userVote %} {% set likes = comment.likes %} {% set dislikes = comment.dislikes %} {% set isReply = comment.hasParent %} {% endif %} {% set hide_details = poster is null or comment.deleted and not user.commentPerms.can_delete_any|default(false) %} {% if user.commentPerms.can_delete_any|default(false) or (not comment.deleted or replies|length > 0) %}
{% if hide_details %}
{{ avatar(0, indent > 1 ? 40 : 50) }}
{% else %} {{ avatar(poster.id, indent > 1 ? 40 : 50, poster.username) }} {% endif %}
{% if not hide_details %} {{ poster.username }} {% endif %} {% if comment.pinned %} {% apply spaceless %} Pinned {% if comment.pinnedTime != comment.createdTime %} {% endif %} {% endapply %} {% endif %}
{{ hide_details ? '(deleted)' : body|parse_comment|raw }}
{% if not comment.deleted and user is not null %} {% if user.commentPerms.can_vote|default(false) %} {% set like_vote_state = userVote > 0 ? 0 : 1 %} {% set dislike_vote_state = userVote < 0 ? 0 : -1 %} Like {% if likes > 0 %} ({{ likes|number_format }}) {% endif %} Dislike {% if dislikes > 0 %} ({{ dislikes|number_format }}) {% endif %} {% endif %} {% if user.commentPerms.can_comment|default(false) %} {% endif %} {% if user.commentPerms.can_delete_any|default(false) or (poster.id|default(0) == user.id and user.commentPerms.can_delete|default(false)) %} Delete {% endif %} {# if user is not null %} Report {% endif #} {% if not isReply and user.commentPerms.can_pin|default(false) %} {{ comment.pinned ? 'Unpin' : 'Pin' }} {% endif %} {% elseif user.commentPerms.can_delete_any|default(false) %} Restore {% endif %}
{% from _self import comments_entry, comments_input %} {% if user|default(null) is not null and category|default(null) is not null and user.commentPerms.can_comment|default(false) %} {{ input_checkbox_raw('', false, 'comment__reply-toggle', '', false, {'id':'comment-reply-toggle-' ~ comment.id}) }} {{ comments_input(category, user, comment) }} {% endif %} {% if replies|length > 0 %} {% for reply in replies %} {{ comments_entry(reply, indent + 1, category, user) }} {% endfor %} {% endif %}
{% endif %} {% endmacro %} {% macro comments_section(category, user) %} {% if category.category is defined %} {% set user = category.user %} {% set posts = category.posts %} {% set category = category.category %} {% else %} {% set posts = category.posts %} {% endif %}
{% if user|default(null) is null %}
Please login to comment.
{% elseif category|default(null) is null %}
Posting new comments here is disabled.
{% elseif not user.commentPerms.can_lock|default(false) and category.locked %}
This comment section was locked, .
{% elseif not user.commentPerms.can_comment|default(false) %}
You are not allowed to post comments.
{% else %} {% from _self import comments_input %} {{ comments_input(category, user) }} {% endif %}
{% if user.commentPerms.can_lock|default(false) and category.locked %}
This comment section was locked, .
{% endif %} {##}
{% if posts|length > 0 %} {% from _self import comments_entry %} {% for comment in posts %} {{ comments_entry(comment, 1, category, user) }} {% endfor %} {% else %}
There are no comments yet.
{% endif %}
{% endmacro %}