misuzu/templates/forum/macros.twig

413 lines
19 KiB
Twig
Raw Normal View History

{% macro forum_category_listing(forums, title, colour, id) %}
2018-05-18 01:20:27 +00:00
{% from _self import forum_category_entry %}
2018-10-22 19:53:21 +00:00
{% from 'macros.twig' import container_title %}
2018-05-18 01:20:27 +00:00
<div class="container forum__categories"
{% if colour is not null %}style="{{ colour|html_colour('--accent-colour') }}"{% endif %}
{% if id|length > 0 %}id="{{ id }}"{% endif %}>
{{ container_title('<i class="fas fa-folder fa-fw"></i> ' ~ title) }}
2018-09-25 22:11:20 +00:00
{% if forums|length > 0 %}
<div class="forum__categories__list">
2018-05-18 01:20:27 +00:00
{% for forum in forums %}
{{ forum_category_entry(forum) }}
{% endfor %}
2018-09-25 22:11:20 +00:00
</div>
{% else %}
<div class="forum__categories__empty">
This category is empty.
</div>
{% endif %}
2018-05-18 01:20:27 +00:00
</div>
{% endmacro %}
{% macro forum_header(title, breadcrumbs, omit_last_breadcrumb, title_url) %}
<div class="container forum__header">
2018-10-15 23:00:17 +00:00
{% if breadcrumbs is iterable and breadcrumbs|length > 0 %}
<div class="forum__header__breadcrumbs">
{% for name, url in breadcrumbs %}
{% if url != breadcrumbs|first %}
<div class="forum__header__breadcrumb__separator">
<i class="fas fa-chevron-right"></i>
</div>
{% endif %}
{% if not (omit_last_breadcrumb|default(false) and url == breadcrumbs|last) %}
<a href="{{ url }}" class="forum__header__breadcrumb">{{ name }}</a>
{% endif %}
{% endfor %}
</div>
{% endif %}
{% if title|length > 0 %}
{% if title_url|length > 0 %}
<a class="forum__header__title" href="{{ title_url }}">
{{ title }}
</a>
{% else %}
<div class="forum__header__title">
{{ title }}
</div>
{% endif %}
2018-10-15 23:00:17 +00:00
{% endif %}
</div>
{% endmacro %}
2018-10-25 00:15:23 +00:00
{% macro forum_category_tools(info, perms, take, offset) %}
{% from 'macros.twig' import pagination %}
{% set can_topic = perms|perms_check(constant('MSZ_FORUM_PERM_CREATE_TOPIC')) %}
{% set pag = pagination(
info.forum_topic_count,
take,
offset,
url_construct('/forum/forum.php', {'f':info.forum_id}),
false,
null,
5
) %}
{% if can_topic or pag|trim|length > 0 %}
<div class="container forum__actions">
<div class="forum__actions__buttons">
{% if can_topic %}
<a href="{{ url_construct('/forum/posting.php', {'f':info.forum_id}) }}" class="input__button">New Topic</a>
{% endif %}
</div>
2018-10-25 00:15:23 +00:00
<div class="forum__actions__pagination">
{{ pag }}
</div>
2018-10-25 00:15:23 +00:00
</div>
{% endif %}
2018-10-25 00:15:23 +00:00
{% endmacro %}
{% macro forum_topic_tools(info, take, offset, can_reply) %}
{% from 'macros.twig' import pagination %}
{% set pag = pagination(
info.topic_post_count,
take,
offset,
url_construct('/forum/topic.php', {'t':info.topic_id}),
false,
null,
5
) %}
{% if can_reply or pag|trim|length > 0 %}
<div class="container forum__actions">
<div class="forum__actions__buttons">
{% if can_reply %}
<a href="/forum/posting.php?t={{ info.topic_id }}" class="input__button">Reply</a>
{% endif %}
</div>
2018-10-25 00:15:23 +00:00
<div class="forum__actions__pagination">
{{ pag }}
</div>
2018-10-25 00:15:23 +00:00
</div>
{% endif %}
2018-05-20 20:12:45 +00:00
{% endmacro %}
2018-09-28 16:40:41 +00:00
{% macro forum_category_entry(forum, forum_unread, forum_type) %}
2018-05-20 20:12:45 +00:00
{% set forum_type = forum_type|default(null) %}
{% set forum_unread = forum_unread|default(forum.forum_unread|default(false)) ? 'unread' : 'read' %}
2018-05-18 01:20:27 +00:00
2018-05-20 20:12:45 +00:00
{% if forum_type is null %}
2018-05-18 01:20:27 +00:00
{% if forum.forum_archived is defined and forum.forum_archived %}
2018-09-28 16:40:41 +00:00
{% set forum_type = 'fas fa-archive' %}
2018-12-30 18:58:30 +00:00
{% elseif forum.forum_type is defined and forum.forum_type != constant('MSZ_FORUM_TYPE_DISCUSSION') %}
{% if forum.forum_type == constant('MSZ_FORUM_TYPE_LINK') %}
2018-09-28 16:40:41 +00:00
{% set forum_type = 'fas fa-link' %}
2018-12-30 18:58:30 +00:00
{% elseif forum.forum_type == constant('MSZ_FORUM_TYPE_CATEGORY') %}
2018-09-28 16:40:41 +00:00
{% set forum_type = 'fas fa-folder' %}
2018-05-18 01:20:27 +00:00
{% endif %}
2018-05-20 20:12:45 +00:00
{% else %}
2018-09-28 16:40:41 +00:00
{% set forum_type = 'fas fa-comments' %}
2018-05-18 01:20:27 +00:00
{% endif %}
{% endif %}
2018-09-28 16:40:41 +00:00
<div class="forum__category">
<a href="/forum/forum.php?f={{ forum.forum_id }}" class="forum__category__link"></a>
2018-05-18 01:20:27 +00:00
2018-09-28 16:40:41 +00:00
<div class="forum__category__container">
<div class="forum__category__icon forum__category__icon--{{ forum_unread }}">
<i class="{{ forum_type }}"></i>
</div>
2018-09-28 16:40:41 +00:00
<div class="forum__category__details">
<div class="forum__category__title">
{{ forum.forum_name }}
</div>
2018-09-28 16:40:41 +00:00
<div class="forum__category__description">
{{ forum.forum_description|nl2br }}
2018-05-19 00:51:31 +00:00
</div>
2018-05-18 01:20:27 +00:00
2018-09-28 16:40:41 +00:00
{% if forum.forum_subforums is defined and forum.forum_subforums|length > 0 %}
<div class="forum__category__subforums">
{% for subforum in forum.forum_subforums %}
<a href="/forum/forum.php?f={{ subforum.forum_id }}"
class="forum__category__subforum{% if subforum.forum_unread %} forum__category__subforum--unread{% endif %}">
{{ subforum.forum_name }}
</a>
{% endfor %}
</div>
{% endif %}
</div>
2018-12-30 18:58:30 +00:00
{% if forum.forum_type == constant('MSZ_FORUM_TYPE_LINK') %}
2018-09-28 16:40:41 +00:00
{% if forum.forum_link_clicks is not null %}
<div class="forum__category__stats">
<div class="forum__category__stat" title="Clicks">{{ forum.forum_link_clicks|number_format }}</div>
</div>
{% endif %}
2018-12-30 18:58:30 +00:00
{% elseif forum.forum_type != constant('MSZ_FORUM_TYPE_CATEGORY') %}
2018-09-28 16:40:41 +00:00
<div class="forum__category__stats">
<div class="forum__category__stat" title="Topics">{{ forum.forum_topic_count|number_format }}</div>
<div class="forum__category__stat" title="Posts">{{ forum.forum_post_count|number_format }}</div>
</div>
{% endif %}
2018-12-30 18:58:30 +00:00
{% if forum.forum_type == constant('MSZ_FORUM_TYPE_DISCUSSION') or forum.forum_link_clicks is not null %}
2018-09-28 16:40:41 +00:00
<div class="forum__category__activity{% if forum.forum_link_clicks is not null %} forum__category__activity--empty{% endif %}">
2018-12-30 18:58:30 +00:00
{% if forum.forum_type != constant('MSZ_FORUM_TYPE_LINK') %}
2018-09-28 16:40:41 +00:00
{% if forum.recent_topic_id is null %}
<div class="forum__category__activity__none">
There are no posts in this forum yet.
</div>
{% else %}
<div class="forum__category__activity__details">
<a class="forum__category__activity__post"
href="/forum/topic.php?p={{ forum.recent_post_id }}#p{{ forum.recent_post_id }}">
{{ forum.recent_topic_title }}
</a>
2018-09-28 16:40:41 +00:00
<div class="forum__category__activity__info">
<time datetime="{{ forum.recent_post_created|date('c') }}"
title="{{ forum.recent_post_created|date('r') }}">{{ forum.recent_post_created|time_diff }}</time>
{% if forum.recent_post_user_id is not null %}
by
<a href="/profile.php?u={{ forum.recent_post_user_id }}" class="forum__category__username"
style="{{ forum.recent_post_user_colour|html_colour }}">
{{ forum.recent_post_username }}
</a>
{% endif %}
</div>
</div>
2018-09-28 16:40:41 +00:00
{% if forum.recent_post_user_id is not null %}
<a href="/profile.php?u={{ forum.recent_post_user_id }}"
class="avatar forum__category__avatar"
2018-09-28 16:40:41 +00:00
style="background-image:url('/profile.php?u={{ forum.recent_post_user_id }}&amp;m=avatar')">
</a>
{% endif %}
{% endif %}
{% endif %}
2018-09-28 16:40:41 +00:00
</div>
{% endif %}
</div>
2018-05-18 01:20:27 +00:00
</div>
{% endmacro %}
2018-05-23 01:41:57 +00:00
{% macro forum_topic_locked(locked, archived) %}
{% if locked is not null or archived %}
<div class="container forum__status">
2018-10-15 20:45:06 +00:00
<div class="forum__status__icon">
<i class="fas fa-{{ archived ? 'archive' : 'lock' }}"></i>
</div>
<div class="forum__status__text">
2018-05-23 01:41:57 +00:00
{% if archived %}
This topic has been <span class="forum__status__emphasis">archived</span>.
2018-05-23 01:41:57 +00:00
{% else %}
2018-10-15 20:45:06 +00:00
This topic was locked
<time class="forum__status__emphasis"
datetime="{{ locked|date('c') }}"
title="{{ locked|date('r') }}">{{ locked|time_diff }}</time>.
2018-05-23 01:41:57 +00:00
{% endif %}
</div>
</div>
{% endif %}
{% endmacro %}
2018-05-18 01:20:27 +00:00
{% macro forum_topic_listing(topics) %}
{% from _self import forum_topic_entry %}
2018-10-22 19:53:21 +00:00
{% from 'macros.twig' import container_title %}
2018-05-18 01:20:27 +00:00
<div class="container forum__topics">
{{ container_title('<i class="fas fa-comments fa-fw"></i> Topics') }}
2018-10-22 19:53:21 +00:00
2018-10-15 20:39:31 +00:00
<div class="forum__topics__list">
2018-05-18 01:20:27 +00:00
{% if topics|length > 0 %}
{% for topic in topics %}
{{ forum_topic_entry(topic) }}
{% endfor %}
{% else %}
2018-10-15 20:39:31 +00:00
<div class="forum__topics__empty">
2018-05-18 01:20:27 +00:00
There are no topics in this forum.
</div>
{% endif %}
</div>
</div>
{% endmacro %}
{% macro forum_topic_entry(topic, topic_type, topic_unread) %}
2018-05-20 01:16:29 +00:00
{% set topic_type = topic_type|default(null) %}
{% set topic_unread = topic_unread|default(topic.topic_unread|default(false)) ? 'unread' : 'read' %}
2018-05-20 01:16:29 +00:00
{% if topic_type is null %}
{% if topic.topic_deleted is defined and topic.topic_deleted is not null %}
{% set topic_type = 'fas fa-trash-alt' %}
2018-12-30 18:58:30 +00:00
{% elseif topic.topic_type is defined and topic.topic_type != constant('MSZ_TOPIC_TYPE_DISCUSSION') %}
{% if topic.topic_type == constant('MSZ_TOPIC_TYPE_ANNOUNCEMENT') or topic.topic_type == constant('MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT') %}
{% set topic_type = 'fas fa-bullhorn' %}
2018-12-30 18:58:30 +00:00
{% elseif topic.topic_type == constant('MSZ_TOPIC_TYPE_STICKY') %}
{% set topic_type = 'fas fa-thumbtack' %}
2018-05-20 01:16:29 +00:00
{% endif %}
2018-05-23 01:41:57 +00:00
{% elseif topic.topic_locked is defined and topic.topic_locked is not null %}
{% set topic_type = 'fas fa-lock' %}
2018-05-20 01:16:29 +00:00
{% else %}
{% set topic_type = 'fas fa-comment' %}
2018-05-20 01:16:29 +00:00
{% endif %}
{% endif %}
2018-05-18 01:20:27 +00:00
<div class="forum__topic{% if topic.topic_deleted is not null %} forum__topic--deleted{% endif %}">
2018-10-15 20:39:31 +00:00
<a href="/forum/topic.php?t={{ topic.topic_id }}" class="forum__topic__link"></a>
2018-05-20 01:16:29 +00:00
2018-10-15 20:39:31 +00:00
<div class="forum__topic__container">
<div class="forum__topic__icon forum__topic__icon--{{ topic_unread }}">
<i class="{{ topic_type }}"></i>
2018-05-18 01:20:27 +00:00
</div>
2018-05-21 16:37:17 +00:00
2018-10-15 20:39:31 +00:00
<div class="forum__topic__details">
<div class="forum__topic__title">
<span class="forum__topic__title__inner">
{{ topic.topic_title }}
</span>
</div>
2018-05-18 01:20:27 +00:00
2018-10-15 20:39:31 +00:00
<div class="forum__topic__info">
{% if topic.author_id is not null %}
by <a
href="/profile.php?u={{ topic.author_id }}"
class="forum__topic__username"
style="{{ topic.author_colour|html_colour }}">{{ topic.author_name }}</a>,
{% endif %}
<time datetime="{{ topic.topic_created|date('c') }}" title="{{ topic.topic_created|date('r') }}">{{ topic.topic_created|time_diff }}</time>
</div>
2018-05-20 01:16:29 +00:00
</div>
2018-10-15 20:39:31 +00:00
<div class="forum__topic__stats">
<div class="forum__topic__stat" title="Posts">{{ topic.topic_post_count|number_format }}</div>
<div class="forum__topic__stat" title="Views">{{ topic.topic_view_count|number_format }}</div>
2018-05-20 01:16:29 +00:00
</div>
2018-05-18 01:20:27 +00:00
2018-10-15 20:39:31 +00:00
<div class="forum__topic__activity">
<div class="forum__topic__activity__details">
{% if topic.respondent_id is not null %}
<a href="/profile.php?u={{ topic.respondent_id }}" class="forum__topic__username"
style="{{ topic.respondent_colour|html_colour }}">{{ topic.respondent_name }}</a>
{% endif %}
<a class="forum__topic__activity__post"
href="/forum/topic.php?p={{ topic.response_id }}#p{{ topic.response_id }}">
<time datetime="{{ topic.response_created|date('c') }}"
title="{{ topic.response_created|date('r') }}">{{ topic.response_created|time_diff }}</time>
2018-05-20 20:12:45 +00:00
</a>
</div>
2018-10-15 20:39:31 +00:00
{% if topic.respondent_id is not null %}
2018-10-15 20:39:31 +00:00
<a href="/profile.php?u={{ topic.respondent_id }}"
class="avatar forum__topic__avatar"
2018-10-15 20:39:31 +00:00
style="background-image:url('/profile.php?u={{ topic.respondent_id }}&amp;m=avatar')">
</a>
{% endif %}
</div>
2018-05-20 20:12:45 +00:00
</div>
</div>
{% endmacro %}
{% macro forum_post_listing(posts, user_id, perms) %}
2018-05-20 20:12:45 +00:00
{% from _self import forum_post_entry %}
2018-05-21 23:05:25 +00:00
{% for post in posts %}
2018-12-30 03:02:35 +00:00
{{ forum_post_entry(
post,
perms|perms_check(constant('MSZ_FORUM_PERM_CREATE_POST')),
perms|perms_check(constant(user_id == post.poster_id ? 'MSZ_FORUM_PERM_EDIT_POST' : 'MSZ_FORUM_PERM_EDIT_ANY_POST')),
perms|perms_check(constant(user_id == post.poster_id ? 'MSZ_FORUM_PERM_DELETE_POST' : 'MSZ_FORUM_PERM_DELETE_ANY_POST'))
) }}
2018-05-21 23:05:25 +00:00
{% endfor %}
2018-05-20 20:12:45 +00:00
{% endmacro %}
{% macro forum_post_entry(post, can_post, can_edit, can_delete) %}
2018-12-30 03:02:35 +00:00
{% set is_deleted = post.post_deleted is not null %}
2018-05-20 20:12:45 +00:00
2018-12-30 03:02:35 +00:00
<div class="container forum__post{% if is_deleted %} forum__post--deleted{% endif %}" id="p{{ post.post_id }}" style="{{ post.poster_colour|html_colour('--accent-colour') }}">
<div class="forum__post__info">
<div class="forum__post__info__background"></div>
<div class="forum__post__info__content">
{% if post.poster_id is not null %}
<a class="avatar forum__post__avatar"
style="background-image:url('/profile.php?u={{ post.poster_id }}&amp;m=avatar');"
href="/profile.php?u={{ post.poster_id }}">
</a>
2018-10-15 21:57:16 +00:00
<a class="forum__post__username" href="/profile.php?u={{ post.poster_id }}">{{ post.poster_name }}</a>
<div class="forum__post__icons">
<div class="flag flag--{{ post.poster_country|lower }}" title="{{ post.poster_country|country_name }}"></div>
<div class="forum__post__posts-count">{{ post.poster_post_count|number_format }} posts</div>
</div>
<div class="forum__post__joined">
joined <time datetime="{{ post.poster_joined|date('c') }}" title="{{ post.poster_joined|date('r') }}">{{ post.poster_joined|time_diff }}</time>
</div>
{% else %}
<div class="forum__post__username">Deleted User</div>
{% endif %}
</div>
2018-10-15 21:57:16 +00:00
</div>
2018-05-21 02:28:51 +00:00
<div class="forum__post__content">
2018-10-15 21:57:16 +00:00
<div class="forum__post__details">
<a class="forum__post__datetime" href="/forum/topic.php?t={{ post.topic_id }}#p{{ post.post_id }}">
<time datetime="{{ post.post_created|date('c') }}" title="{{ post.post_created|date('r') }}">{{ post.post_created|time_diff }}</time>
2018-12-30 03:02:35 +00:00
{% if post.post_edited is not null %}
(edited <time datetime="{{ post.post_edited|date('c') }}" title="{{ post.post_edited|date('r') }}">{{ post.post_edited|time_diff }}</time>)
{% endif %}
2018-05-21 02:28:51 +00:00
</a>
2018-10-15 21:57:16 +00:00
<a class="forum__post__id" href="/forum/topic.php?p={{ post.post_id }}#p{{ post.post_id }}">
2018-05-21 02:28:51 +00:00
#{{ post.post_id }}
</a>
</div>
2018-10-15 21:57:16 +00:00
2018-11-01 21:35:10 +00:00
<div class="forum__post__text{% if post.post_parse == constant('MSZ_PARSER_MARKDOWN') %} markdown{% endif %}">
{{ post.post_text|escape|parse_text(post.post_parse)|raw }}
2018-05-21 02:28:51 +00:00
</div>
2018-12-30 03:02:35 +00:00
{% if can_post or can_edit or can_delete %}
<div class="forum__post__actions">
{% if is_deleted %}
<a href="/forum/posting.php?p={{ post.post_id }}&amp;m=restore" class="forum__post__action"><i class="fas fa-magic fa-fw"></i> Restore</a>
<a href="/forum/posting.php?p={{ post.post_id }}&amp;m=nuke" class="forum__post__action"><i class="fas fa-radiation-alt fa-fw"></i> Permanently Delete</a>
{% else %}
{# if can_post %}
<a href="/forum/posting.php?p={{ post.post_id }}&amp;m=quote" class="forum__post__action"><i class="fas fa-quote-left fa-fw"></i> Quote</a>
{% endif #}
{% if can_edit %}
<a href="/forum/posting.php?p={{ post.post_id }}&amp;m=edit" class="forum__post__action"><i class="fas fa-edit fa-fw"></i> Edit</a>
{% endif %}
{# if can_delete %}
<a href="/forum/posting.php?p={{ post.post_id }}&amp;m=delete" class="forum__post__action"><i class="far fa-trash-alt fa-fw"></i> Delete</a>
{% endif #}
{% endif %}
</div>
{% endif %}
2018-05-20 20:12:45 +00:00
</div>
2018-05-18 01:20:27 +00:00
</div>
{% endmacro %}