Added button to mark a forum or the entire thing as read.
This commit is contained in:
parent
9505cb1f0b
commit
624cba9d32
6 changed files with 94 additions and 35 deletions
|
@ -24,4 +24,8 @@
|
|||
display: flex;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
&__button {
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +1,49 @@
|
|||
<?php
|
||||
require_once '../../misuzu.php';
|
||||
|
||||
$categories = forum_get_root_categories(user_session_current('user_id', 0));
|
||||
$blankForum = count($categories) <= 1 && $categories[0]['forum_children'] < 1;
|
||||
switch ($_GET['m'] ?? '') {
|
||||
case 'mark':
|
||||
$forumId = (int)($_GET['f'] ?? null);
|
||||
$markEntireForum = $forumId === 0;
|
||||
$markAction = forum_mark_read($markEntireForum ? null : $forumId, user_session_current('user_id', 0));
|
||||
header('Location: /forum' . (!$markAction || $markEntireForum ? '' : url_construct('/forum.php', ['f' => $forumId])));
|
||||
break;
|
||||
|
||||
foreach ($categories as $key => $category) {
|
||||
$categories[$key]['forum_subforums'] = forum_get_children(
|
||||
$category['forum_id'],
|
||||
user_session_current('user_id', 0),
|
||||
perms_check($category['forum_permissions'], MSZ_FORUM_PERM_DELETE_TOPIC | MSZ_FORUM_PERM_DELETE_ANY_POST)
|
||||
);
|
||||
case 'new':
|
||||
break;
|
||||
|
||||
foreach ($categories[$key]['forum_subforums'] as $skey => $sub) {
|
||||
if (!forum_may_have_children($sub['forum_type'])) {
|
||||
continue;
|
||||
case 'your':
|
||||
break;
|
||||
|
||||
default:
|
||||
$categories = forum_get_root_categories(user_session_current('user_id', 0));
|
||||
$blankForum = count($categories) <= 1 && $categories[0]['forum_children'] < 1;
|
||||
|
||||
foreach ($categories as $key => $category) {
|
||||
$categories[$key]['forum_subforums'] = forum_get_children(
|
||||
$category['forum_id'],
|
||||
user_session_current('user_id', 0),
|
||||
perms_check($category['forum_permissions'], MSZ_FORUM_PERM_DELETE_TOPIC | MSZ_FORUM_PERM_DELETE_ANY_POST)
|
||||
);
|
||||
|
||||
foreach ($categories[$key]['forum_subforums'] as $skey => $sub) {
|
||||
if (!forum_may_have_children($sub['forum_type'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$categories[$key]['forum_subforums'][$skey]['forum_subforums']
|
||||
= forum_get_children(
|
||||
$sub['forum_id'],
|
||||
user_session_current('user_id', 0),
|
||||
perms_check($sub['forum_permissions'], MSZ_FORUM_PERM_DELETE_TOPIC | MSZ_FORUM_PERM_DELETE_ANY_POST),
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$categories[$key]['forum_subforums'][$skey]['forum_subforums']
|
||||
= forum_get_children(
|
||||
$sub['forum_id'],
|
||||
user_session_current('user_id', 0),
|
||||
perms_check($sub['forum_permissions'], MSZ_FORUM_PERM_DELETE_TOPIC | MSZ_FORUM_PERM_DELETE_ANY_POST),
|
||||
true
|
||||
);
|
||||
}
|
||||
echo tpl_render('forum.index', [
|
||||
'forum_categories' => $categories,
|
||||
'forum_empty' => $blankForum,
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
echo tpl_render('forum.index', [
|
||||
'forum_categories' => $categories,
|
||||
'forum_empty' => $blankForum,
|
||||
]);
|
||||
|
|
|
@ -393,3 +393,38 @@ function forum_timeout(int $forumId, int $userId): int
|
|||
|
||||
return (int)($checkTimeout->execute() ? $checkTimeout->fetchColumn() : 0);
|
||||
}
|
||||
|
||||
// $forumId == null marks all forums as read
|
||||
function forum_mark_read(?int $forumId, int $userId): bool
|
||||
{
|
||||
if (($forumId !== null && $forumId < 1) || $userId < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$entireForum = $forumId === null;
|
||||
$doMark = db_prepare(sprintf(
|
||||
'
|
||||
REPLACE INTO `msz_forum_topics_track`
|
||||
(`user_id`, `topic_id`, `forum_id`, `track_last_read`)
|
||||
SELECT u.`user_id`, t.`topic_id`, t.`forum_id`, NOW()
|
||||
FROM `msz_forum_topics` AS t
|
||||
LEFT JOIN `msz_users` AS u
|
||||
ON u.`user_id` = :user
|
||||
WHERE t.`topic_deleted` IS NULL
|
||||
AND t.`topic_bumped` >= NOW() - INTERVAL 1 MONTH
|
||||
%1$s
|
||||
GROUP BY t.`topic_id`
|
||||
HAVING ((%2$s) & %3$d) > 0
|
||||
',
|
||||
$entireForum ? '' : 'AND t.`forum_id` = :forum',
|
||||
forum_perms_get_user_sql(MSZ_FORUM_PERMS_GENERAL, 't.`forum_id`', 'u.`user_id`', 'u.`user_id`'),
|
||||
MSZ_FORUM_PERM_SET_READ
|
||||
));
|
||||
$doMark->bindValue('user', $userId);
|
||||
|
||||
if (!$entireForum) {
|
||||
$doMark->bindValue('forum', $forumId);
|
||||
}
|
||||
|
||||
return $doMark->execute();
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
{% endif %}
|
||||
|
||||
{% if forum_may_have_topics %}
|
||||
{% set category_tools = forum_category_tools(forum_info, forum_perms, forum_pagination) %}
|
||||
{% set category_tools = forum_category_tools(forum_info, forum_perms, forum_pagination, current_user|default(false)) %}
|
||||
{{ category_tools }}
|
||||
{{ forum_topic_listing(forum_topics) }}
|
||||
{{ category_tools }}
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{#
|
||||
<div class="container forum__actions">
|
||||
<a class="input__button forum__actions__button">Mark All Read</a>
|
||||
<a class="input__button forum__actions__button">Unanswered Posts</a>
|
||||
<a class="input__button forum__actions__button">New Posts</a>
|
||||
<a class="input__button forum__actions__button">Your Posts</a>
|
||||
</div>#}
|
||||
{% if current_user is defined %}
|
||||
<div class="container forum__actions">
|
||||
<a href="?m=mark" class="input__button forum__actions__button">Mark All Read</a>
|
||||
{#<a href="?m=unread" class="input__button forum__actions__button">Unread Posts</a>#}
|
||||
{#<a href="?m=your" class="input__button forum__actions__button">Your Posts</a>#}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="container">
|
||||
{{ container_title('<i class="fas fa-comment-slash fa-fw"></i> Forums') }}
|
||||
|
|
|
@ -53,18 +53,21 @@
|
|||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro forum_category_tools(info, perms, pagination_info) %}
|
||||
{% macro forum_category_tools(info, perms, pagination_info, user) %}
|
||||
{% from 'macros.twig' import pagination %}
|
||||
|
||||
{% set is_locked = info.forum_archived != 0 %}
|
||||
{% set can_topic = not is_locked and perms|perms_check(constant('MSZ_FORUM_PERM_CREATE_TOPIC')) %}
|
||||
{% set pag = pagination(pagination_info, '/forum/forum.php', null, {'f': info.forum_id}) %}
|
||||
|
||||
{% if can_topic or pag|trim|length > 0 %}
|
||||
{% if user or 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>
|
||||
<a href="{{ url_construct('/forum/posting.php', {'f':info.forum_id}) }}" class="input__button forum__actions__button">New Topic</a>
|
||||
{% endif %}
|
||||
{% if user %}
|
||||
<a href="{{ url_construct('/forum/index.php', {'m':'mark','f':info.forum_id}) }}" class="input__button forum__actions__button">Mark As Read</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue