comment.html.twig 10.1 KB
Newer Older
Emma's avatar
Emma committed
1
{%- block comment -%}
2
  {%- from '_macros/time.html.twig' import relative_time, relative_time_diff -%}
Emma's avatar
Emma committed
3 4 5 6
  {%- from 'vote/_macros.html.twig' import vote -%}
  <article class="comment
                  comment--{{ level > 1 ? 'nested' : 'top-level' }}
                  {{ show_context ? 'comment--with-context' }}
Emma's avatar
Emma committed
7
                  {{ comment.softDeleted ? 'comment--soft-deleted' }}"
Emma's avatar
Emma committed
8 9 10 11 12 13
           id="comment_{{ comment.id }}"
           data-level="{{ level }}">
    {% if show_context %}
      {{- block('comment_context') -}}
    {% endif %}

Emma's avatar
Emma committed
14 15
    <div class="comment__row">
      <div class="comment__main">
Emma's avatar
Emma committed
16 17 18 19
        <h1 class="comment__info break-text unheaderize">
          <span class="fg-muted text-sm">
            {{ 'comments.info'|trans({
              '%user%': block('comment_info_user'),
20
              '%timestamp%': relative_time(comment.timestamp, { natural: true }),
Emma's avatar
Emma committed
21
            })|raw }}
Emma's avatar
Emma committed
22

Emma's avatar
Emma committed
23
            {% if comment.editedAt %}
24
              <span class="comment__edited-at {{ comment.moderated ? 'comment__moderated' }} fg-muted text-sm">
Emma's avatar
Emma committed
25
                {{ (comment.moderated ? 'comments.moderator_info' : 'comments.edit_info')|trans({
26
                  '%edited_at%': relative_time_diff(comment.editedAt, comment.timestamp, { natural: true }),
Emma's avatar
Emma committed
27 28 29 30
                })|raw }}
              </span>
            {% endif %}
          </span>
Emma's avatar
Emma committed
31 32
        </h1>

Emma's avatar
Emma committed
33
        <div class="comment__body break-text">
Emma's avatar
Emma committed
34 35 36 37 38
          {%- if raw_body is not null -%}
            {{ raw_body|raw }}
          {%- elseif comment.body is not null -%}
            {{ comment.body|cached_markdown({ context: 'comment', comment: comment })|raw }}
          {%- endif -%}
Emma's avatar
Emma committed
39 40
        </div>

Emma's avatar
Emma committed
41
        <nav class="comment__nav">
Emma's avatar
Emma committed
42 43 44
          <ul class="fg-muted nav nav--guttered no-margin unlistify">
            {{- block('comment_nav') -}}
          </ul>
Emma's avatar
Emma committed
45 46 47 48 49 50 51
        </nav>

        {% if show_form and is_granted('ROLE_USER') %}
          {% from 'comment/_macros.html.twig' import comment_form %}
          {{ comment_form(comment.submission, comment) }}
        {% endif %}
      </div>
Emma's avatar
Emma committed
52 53 54 55

      <div class="comment__vote">
        {{ vote(comment, 'comment_vote') }}
      </div>
Emma's avatar
Emma committed
56 57 58
    </div>

    {% if recurse and comment.children|length > 0 %}
Emma's avatar
Emma committed
59
      <div class="comment__replies">
Emma's avatar
Emma committed
60
        {%- for reply in comment.children -%}
Emma's avatar
Emma committed
61
          {%- with { comment: reply, level: level + 1, show_form: false } -%}
Emma's avatar
Emma committed
62 63 64 65 66 67 68 69 70 71
            {{- block('comment') -}}
          {%- endwith -%}
        {%- endfor -%}
      </div>
    {% endif %}
  </article>
{%- endblock comment -%}

{% block comment_context %}
  {% with { submission: comment.submission, forum: comment.submission.forum } %}
Emma's avatar
Emma committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    <div class="comment__context break-text text-sm">
      <p class="fg-muted">
        {{ (comment.parent ? 'comments.context.comment_reply' : 'comments.context.top_level_reply')|trans({
          '%comment_author%': block('comment_context_link_format')|format(
            path('user', { username: comment.user.username })|e,
            comment.user.username|e
          ),
          '%submission_title%': block('comment_context_link_format')|format(
            path('submission', {forum_name: forum.name, submission_id: submission.id})|e,
            submission.title|e
          ),
          '%submission_author%': block('comment_context_link_format')|format(
            path('user', { username: submission.user.username })|e,
            submission.user.username|e
          ),
        })|raw }}
Emma's avatar
Emma committed
88 89 90 91
    </div>
  {% endwith %}
{% endblock comment_context %}

Emma's avatar
Emma committed
92 93 94 95
{%- block comment_context_link_format -%}
  <a href="%s" class="fg-inherit"><strong>%s</strong></a>
{%- endblock -%}

Emma's avatar
Emma committed
96
{%- block comment_info_user -%}
Emma's avatar
Emma committed
97
  {%- from 'user/_macros.html.twig' import user_flag -%}
Emma's avatar
Emma committed
98

Emma's avatar
Emma committed
99 100 101 102 103 104
  {% filter spaceless %}
    {%- if not comment.softDeleted -%}
      <a href="{{ path('user', { username: comment.user.username }) }}" class="fg-inherit">
        <strong>{{ comment.user.username }}</strong>
      </a>
    {%- else -%}
105
      {{- 'placeholder.deleted'|trans -}}
Emma's avatar
Emma committed
106 107 108
    {%- endif -%}
  {% endfilter %}

109
  {% if not comment.softDeleted and comment.user is same as(comment.submission.user) %}
Emma's avatar
Emma committed
110 111 112 113 114 115 116 117
    <small class="comment__op-text text-sm user-flag"
           title="{{ 'item.op'|trans }}"
           aria-label="{{ 'item.op'|trans }}">
      {{- 'item.op_abbr'|trans -}}
    </small>
  {% endif %}

  {{ user_flag(comment.userFlag) }}
Emma's avatar
Emma committed
118 119
{%- endblock comment_info_user -%}

Emma's avatar
Emma committed
120 121 122 123 124 125 126
{% block comment_nav %}
  {{ block('comment_nav_reply') }}
  {{ block('comment_nav_permalink') }}
  {{ block('comment_nav_parent') }}

  {% if comment.user is same as(self) %}
    {% set comment_nav_classes = 'fg-inherit text-sm' %}
127 128 129 130
    {% if comment.children|length == 0 %}
      {{ block('comment_nav_delete_thread') }}
    {% endif %}
    {{- block('comment_nav_softdelete') -}}
Emma's avatar
Emma committed
131
    {{- block('comment_nav_edit') }}
132 133 134 135 136
  {% endif %}

  {% set menu_actions = block('comment_nav_menu_actions')|trim %}

  {% if menu_actions is not empty %}
Emma's avatar
Emma committed
137 138 139 140 141 142
    <li class="dropdown">
      <button class="dropdown__toggle fg-inherit no-underline text-sm unbuttonize">
        <span class="no-underline__exempt">{{ 'nav.actions'|trans }}</span>
        <span class="dropdown__arrow" aria-hidden="true"></span>
      </button>

Emma's avatar
Emma committed
143
      <ul class="dropdown__menu dropdown-card unlistify no-margin">
144
        {{ menu_actions|raw }}
Emma's avatar
Emma committed
145 146 147 148
      </ul>
    </li>
  {% endif %}
{% endblock comment_nav %}
Emma's avatar
Emma committed
149

150 151 152 153 154 155 156 157 158 159 160 161 162
{% block comment_nav_menu_actions %}
  {% set comment_nav_classes = 'menu-item no-wrap' %}
  {% if comment.user is not same as(self) %}
    {{ block('comment_nav_softdelete') }}
    {{ block('comment_nav_delete_thread') }}
    {{ block('comment_nav_edit') }}
    {{ block('comment_nav_ban') }}
    {{ block('comment_nav_ip_ban') }}
  {% elseif comment.children|length > 0 %}
    {{ block('comment_nav_delete_thread') }}
  {% endif %}
{% endblock %}

Emma's avatar
Emma committed
163
{%- block comment_nav_reply -%}
Emma's avatar
Emma committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
  {% if is_granted('ROLE_USER') %}
    <li>
      <a href="{{ path('comment', {
        forum_name: comment.submission.forum.name,
        submission_id: comment.submission.id,
        comment_id: comment.id
      }) }}" data-form-url="{{ path('comment_form', {
        forumName: comment.submission.forum.name,
        submissionId: comment.submission.id,
        commentId: comment.id
      }) }}" class="comment__reply-link text-sm">
        <strong>{{ 'comments.reply'|trans }}</strong>
      </a>
    </li>
  {% endif %}
Emma's avatar
Emma committed
179 180 181 182 183 184 185 186 187
{%- endblock comment_nav_reply -%}

{%- block comment_nav_permalink -%}
  {%- filter spaceless -%}
    <li>
      <a href="{{ path('comment', {
        forum_name: comment.submission.forum.name,
        submission_id: comment.submission.id,
        comment_id: comment.id
Emma's avatar
Emma committed
188
      }) }}" class="comment__permalink fg-inherit text-sm">{{ 'comments.permalink'|trans }}</a>
Emma's avatar
Emma committed
189 190 191 192 193 194 195 196 197 198 199 200
    </li>
  {%- endfilter -%}
{%- endblock comment_nav_permalink -%}

{%- block comment_nav_parent -%}
  {%- filter spaceless -%}
    {%- if comment.parent -%}
      <li>
        <a href="{{ path('comment', {
          forum_name: comment.submission.forum.name,
          submission_id: comment.submission.id,
          comment_id: comment.parent.id
Emma's avatar
Emma committed
201
        }) }}" class="comment__parent-link fg-inherit text-sm">{{ 'comments.parent'|trans }}</a>
Emma's avatar
Emma committed
202 203 204 205 206
      </li>
    {%- endif -%}
  {%- endfilter -%}
{%- endblock comment_nav_parent -%}

207
{% block comment_nav_softdelete %}
Emma's avatar
Emma committed
208
  {% from '_macros/icon.html.twig' import icon %}
209 210 211
  {% if is_granted('softdelete', comment) %}
    <li>
      <form action="{{ path('softdelete_comment', {
Emma's avatar
Emma committed
212 213 214
        forum_name: comment.submission.forum.name,
        submission_id: comment.submission.id,
        comment_id: comment.id,
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
      }) }}" method="POST">
        <input type="hidden" name="token" value="{{ csrf_token('softdelete_comment') }}">
        <button type="submit"
                class="unbuttonize comment__soft-delete-button {{ comment_nav_classes }} js-confirm-comment-delete">
          {{- 'menu-item' in comment_nav_classes ? icon('trash') }}
          {{ 'comments.delete'|trans -}}
        </button>
      </form>
    </li>
  {% endif %}
{% endblock comment_nav_softdelete %}

{%- block comment_nav_delete_thread -%}
  {% from '_macros/icon.html.twig' import icon %}
  {% if is_granted('delete_thread', comment) %}
    <li>
      <form action="{{ path('delete_comment_thread', {
          forum_name: comment.submission.forum.name,
          submission_id: comment.submission.id,
          comment_id: comment.id,
      }) }}" method="POST">
        <input type="hidden" name="token" value="{{ csrf_token('delete_comment') }}">
        <button type="submit"
                class="unbuttonize comment__thread-delete-button {{ comment_nav_classes }} js-confirm-comment-delete">
          {{- 'menu-item' in comment_nav_classes ? icon('trash') }}
          {{ comment.children|length > 0 ? 'comments.delete_thread'|trans : 'comments.delete'|trans -}}
        </button>
      </form>
    </li>
  {% endif %}
Emma's avatar
Emma committed
245
{%- endblock comment_nav_delete_thread -%}
Emma's avatar
Emma committed
246

Emma's avatar
Emma committed
247 248 249
{%- block comment_nav_edit -%}
  {% from '_macros/icon.html.twig' import icon %}
  {% if is_granted('edit', comment) %}
Emma's avatar
Emma committed
250
    <li>
Emma's avatar
Emma committed
251
      <a href="{{ path('edit_comment', {
Emma's avatar
Emma committed
252 253 254
        forum_name: comment.submission.forum.name,
        submission_id: comment.submission.id,
        comment_id: comment.id,
Emma's avatar
Emma committed
255
      }) }}" class="comment__edit-link {{ comment_nav_classes }}">
256
        {{- 'menu-item' in comment_nav_classes ? icon('pencil') }}
Emma's avatar
Emma committed
257 258
        {{ 'comments.edit'|trans -}}
      </a>
Emma's avatar
Emma committed
259
    </li>
Emma's avatar
Emma committed
260 261
  {% endif -%}
{% endblock comment_nav_edit %}
Emma's avatar
Emma committed
262

Emma's avatar
Emma committed
263 264 265 266 267
{% block comment_nav_ban %}
  {% from '_macros/icon.html.twig' import icon %}
  {% if is_granted('moderator', comment.submission.forum) %}
    <li>
      <a href="{{ path('forum_ban', {forum_name: comment.submission.forum.name, username: comment.user.username}) }}"
268
         class="comment__ban-link menu-item no-wrap">
Emma's avatar
Emma committed
269 270 271 272 273 274
        {{- icon('user-times') }}
        {{ 'action.ban'|trans -}}
      </a>
    </li>
  {% endif %}
{% endblock comment_nav_ban %}
Emma's avatar
Emma committed
275

Emma's avatar
Emma committed
276 277 278 279 280
{%- block comment_nav_ip_ban %}
  {% from '_macros/icon.html.twig' import icon %}
  {% if is_granted('ROLE_ADMIN') %}
    <li>
      <a href="{{ path('ban_user', {'username': comment.user.username}) }}"
281
         class="comment__ip-ban-link menu-item no-wrap">
Emma's avatar
Emma committed
282 283 284 285 286 287
        {{- icon('hammer') }}
        {{ 'action.global_ban'|trans -}}
      </a>
    </li>
  {% endif -%}
{% endblock comment_nav_ip_ban -%}