2018-08-06 22:19:35 +00:00
{% macro comments_input ( category , user , perms , reply_to ) %}
{% set reply_mode = reply_to is not null %}
2018-10-27 14:29:13 +00:00
{% from '_layout/input.twig' import input_hidden , input_csrf , input_checkbox %}
2018-10-25 01:35:53 +00:00
2018-08-08 01:53:33 +00:00
<form class="comment comment--input {% if reply_mode %} comment--reply {% endif %} "
2019-02-28 21:52:39 +00:00
method="post" action=" {{ url ( 'comment-create' ) }} "
2018-08-06 22:19:35 +00:00
id="comment- {{ reply_mode ? 'reply-' ~ reply_to .comment_id : 'create-' ~ category .category_id }} ">
2018-10-25 01:35:53 +00:00
{{ input_hidden ( 'comment[category]' , category .category_id ) }}
2019-06-10 15:21:53 +00:00
{{ input_csrf ( ) }}
2018-08-08 01:53:33 +00:00
2018-08-06 22:19:35 +00:00
{% if reply_mode %}
2018-10-25 01:35:53 +00:00
{{ input_hidden ( 'comment[reply]' , reply_to .comment_id ) }}
2018-08-06 22:19:35 +00:00
{% endif %}
2018-08-08 01:53:33 +00:00
2018-08-06 22:19:35 +00:00
<div class="comment__container">
<div class="avatar comment__avatar"
2019-03-25 20:11:31 +00:00
style="background-image:url(' {{ url ( 'user-avatar' , { 'user' : user .user_id , 'res' : ( reply_mode ? 8 0 : 1 0 0 ) } ) }} ')">
2018-08-06 22:19:35 +00:00
</div>
<div class="comment__content">
<textarea
class="comment__text input__textarea comment__text--input"
2018-08-10 21:21:39 +00:00
name="comment[text]" placeholder="Share your extensive insights..."></textarea>
2018-08-06 22:19:35 +00:00
<div class="comment__actions">
{% if not reply_mode %}
{% if perms .can_pin %}
2018-10-27 14:29:13 +00:00
{{ input_checkbox ( 'comment[pin]' , 'Pin this comment' , false , 'comment__action' ) }}
2018-08-06 22:19:35 +00:00
{% endif %}
{% if perms .can_lock %}
2018-10-27 14:29:13 +00:00
{{ input_checkbox ( 'comment[lock]' , 'Toggle locked status' , false , 'comment__action' ) }}
2018-08-06 22:19:35 +00:00
{% endif %}
{% endif %}
2018-10-22 19:53:21 +00:00
<button class="input__button comment__action comment__action--button comment__action--post">
2018-08-10 21:21:39 +00:00
{{ reply_mode ? 'Reply' : 'Post' }}
</button>
2018-08-06 22:19:35 +00:00
</div>
</div>
</div>
</form>
{% endmacro %}
2018-08-10 21:21:39 +00:00
{% macro comments_entry ( comment , indent , category , user , perms ) %}
2018-10-27 18:50:34 +00:00
{% from '_layout/input.twig' import input_checkbox_raw %}
2018-12-16 19:40:50 +00:00
{% set is_deleted = comment .comment_deleted is not null %}
{% set hide_details = is_deleted and not perms .can_delete_any %}
2018-10-27 18:50:34 +00:00
2018-12-16 19:40:50 +00:00
{% if perms .can_delete_any or ( not is_deleted or comment .comment_replies | length > 0 ) %}
2018-12-30 20:42:01 +00:00
{% set is_pinned = comment .comment_pinned is not null %}
2018-12-16 19:40:50 +00:00
<div class="comment {% if is_deleted %} comment--deleted {% endif %} " id="comment- {{ comment .comment_id }} ">
2018-08-10 21:21:39 +00:00
<div class="comment__container">
2018-12-16 19:40:50 +00:00
{% if hide_details %}
2019-03-25 20:11:31 +00:00
<div class="avatar comment__avatar" style="background-image:url(' {{ url ( 'user-avatar' , { 'res' : indent > 1 ? 8 0 : 1 0 0 } ) }} ')"></div>
2018-12-16 19:40:50 +00:00
{% else %}
<a class="avatar comment__avatar"
2019-01-24 20:54:24 +00:00
href=" {{ url ( 'user-profile' , { 'user' : comment .user_id } ) }} "
2019-03-25 20:11:31 +00:00
style="background-image:url(' {{ url ( 'user-avatar' , { 'user' : comment .user_id , 'res' : indent > 1 ? 8 0 : 1 0 0 } ) }} ')">
2018-12-16 19:40:50 +00:00
</a>
{% endif %}
2018-08-10 21:21:39 +00:00
<div class="comment__content">
<div class="comment__info">
2018-12-16 19:40:50 +00:00
{% if not hide_details %}
<a class="comment__user comment__user--link"
2019-01-24 20:54:24 +00:00
href=" {{ url ( 'user-profile' , { 'user' : comment .user_id } ) }} "
2018-12-16 19:40:50 +00:00
style=" {{ comment .user_colour | html_colour }} "> {{ comment .username }} </a>
{% endif %}
2018-08-10 21:21:39 +00:00
<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>
2018-12-30 20:42:01 +00:00
{% if is_pinned %}
2018-08-10 21:21:39 +00:00
<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>
2018-12-15 22:15:35 +00:00
<div class="comment__text">
2018-12-16 19:40:50 +00:00
{{ hide_details ? '(deleted)' : ( comment .comment_html is defined ? comment .comment_html | raw : comment .comment_text | nl2br ) }}
2018-08-10 21:21:39 +00:00
</div>
2018-12-15 22:15:35 +00:00
<div class="comment__actions">
2018-12-16 19:40:50 +00:00
{% if not is_deleted and user is not null %}
2018-08-10 21:21:39 +00:00
{% if perms .can_vote %}
2019-03-10 19:00:10 +00:00
{% set like_vote_state = comment .comment_user_vote == constant ( 'MSZ_COMMENTS_VOTE_LIKE' )
? constant('MSZ_COMMENTS_VOTE_INDIFFERENT')
: constant('MSZ_COMMENTS_VOTE_LIKE') %}
{% set dislike_vote_state = comment .comment_user_vote == constant ( 'MSZ_COMMENTS_VOTE_DISLIKE' )
? constant('MSZ_COMMENTS_VOTE_INDIFFERENT')
: constant('MSZ_COMMENTS_VOTE_DISLIKE') %}
<a class="comment__action comment__action--link comment__action--vote comment__action--like {% if comment .comment_user_vote == constant ( 'MSZ_COMMENTS_VOTE_LIKE' ) %} comment__action--voted {% endif %} " data-comment-id=" {{ comment .comment_id }} " data-comment-vote=" {{ like_vote_state }} "
href=" {{ url ( 'comment-vote' , { 'comment' : comment .comment_id , 'vote' : like_vote_state } ) }} ">
2018-12-11 20:42:59 +00:00
<!--i class="fas fa-thumbs-up"></i-->
2018-08-10 21:21:39 +00:00
Like
{% if comment .comment_likes > 0 %}
( {{ comment .comment_likes | number_format }} )
{% endif %}
</a>
2019-03-10 19:00:10 +00:00
<a class="comment__action comment__action--link comment__action--vote comment__action--dislike {% if comment .comment_user_vote == constant ( 'MSZ_COMMENTS_VOTE_DISLIKE' ) %} comment__action--voted {% endif %} " data-comment-id=" {{ comment .comment_id }} " data-comment-vote=" {{ dislike_vote_state }} "
href=" {{ url ( 'comment-vote' , { 'comment' : comment .comment_id , 'vote' : dislike_vote_state } ) }} ">
2018-12-11 20:42:59 +00:00
<!--i class="fas fa-thumbs-down"></i-->
2018-08-10 21:21:39 +00:00
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 ) %}
2019-01-24 20:54:24 +00:00
<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>
2018-08-10 21:21:39 +00:00
{% endif %}
{ # if user is not null %}
<a class="comment__action comment__action--link comment__action--hide" href="#">Report</a>
{% endif # }
2018-12-30 20:42:01 +00:00
{% if comment .comment_reply_to is null and perms .can_pin %}
2019-01-24 20:54:24 +00:00
<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>
2018-12-30 20:42:01 +00:00
{% endif %}
2018-12-15 22:15:35 +00:00
{% elseif perms .can_delete_any %}
2019-01-24 20:54:24 +00:00
<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>
2018-12-15 22:15:35 +00:00
{% endif %}
</div>
2018-08-10 21:21:39 +00:00
</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 %}
2018-10-27 18:50:34 +00:00
{{ input_checkbox_raw ( '' , false , 'comment__reply-toggle' , '' , false , { 'id' :'comment-reply-toggle-' ~ comment .comment_id } ) }}
2018-08-10 21:21:39 +00:00
{{ 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 %}
2018-08-06 22:19:35 +00:00
{% macro comments_section ( comments , category , user , perms ) %}
<div class="comments">
<div class="comments__input">
{% if user | default ( null ) is null %}
<div class="comments__notice">
2019-01-24 20:54:24 +00:00
Please <a href=" {{ url ( 'auth-login' ) }} " class="comments__notice__link">login</a> to comment.
2018-08-06 22:19:35 +00:00
</div>
{% elseif category | default ( null ) is null or perms | default ( null ) is null %}
<div class="comments__notice">
Posting new comments here is disabled.
</div>
2018-08-10 21:21:39 +00:00
{% 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>
2018-08-06 22:19:35 +00:00
{% 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>
2018-08-10 21:21:39 +00:00
{% 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 %}
2018-08-06 22:19:35 +00:00
<noscript>
<div class="comments__javascript">
2018-08-10 21:21:39 +00:00
While the comments work fine without Javascript, it is recommended you enable it as it has a lower bandwidth overhead.
2018-08-06 22:19:35 +00:00
</div>
</noscript>
2018-08-10 21:21:39 +00:00
<div class="comments__listing">
{% if comments | length > 0 %}
2018-08-06 22:19:35 +00:00
{% from _self import comments_entry %}
{% for comment in comments %}
{{ comments_entry ( comment , 1 , category , user , perms ) }}
{% endfor %}
2018-08-10 21:21:39 +00:00
{% else %}
2018-10-08 13:28:19 +00:00
<div class="comments__none" id="_no_comments_notice_ {{ category .category_id }} ">
2018-08-10 21:21:39 +00:00
There are no comments yet.
</div>
{% endif %}
</div>
2018-08-06 22:19:35 +00:00
</div>
{% endmacro %}