misuzu/public/forum/topic-priority.php

56 lines
1.3 KiB
PHP
Raw Normal View History

2019-05-08 15:46:03 +00:00
<?php
namespace Misuzu;
2020-05-25 19:58:06 +00:00
use Misuzu\Users\User;
use Misuzu\Users\UserNotFoundException;
2020-05-25 19:58:06 +00:00
2019-05-08 15:46:03 +00:00
require_once '../../misuzu.php';
2020-05-25 19:58:06 +00:00
if(!MSZ_DEBUG)
2019-05-09 15:55:06 +00:00
return;
2019-05-08 15:46:03 +00:00
$topicId = !empty($_GET['t']) && is_string($_GET['t']) ? (int)$_GET['t'] : 0;
2020-05-25 19:58:06 +00:00
$topicUser = User::getCurrent();
$topicUserId = $topicUser === null ? 0 : $topicUser->getId();
2019-05-08 15:46:03 +00:00
2019-06-10 17:04:53 +00:00
if($topicUserId < 1) {
2019-05-09 15:11:42 +00:00
echo render_error(403);
return;
}
$topic = forum_topic_get($topicId, true);
$perms = $topic
? forum_perms_get_user($topic['forum_id'], $topicUserId)[MSZ_FORUM_PERMS_GENERAL]
: 0;
2020-06-11 20:30:19 +00:00
if(isset($topicUser) && $topicUser->hasActiveWarning())
2019-05-09 15:11:42 +00:00
$perms &= ~MSZ_FORUM_PERM_SET_WRITE;
$topicIsDeleted = !empty($topic['topic_deleted']);
$canDeleteAny = perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST);
2019-06-10 17:04:53 +00:00
if(!$topic || ($topicIsDeleted && !$canDeleteAny)) {
2019-05-09 15:11:42 +00:00
echo render_error(404);
return;
}
2019-06-10 17:04:53 +00:00
if(!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM, true) // | MSZ_FORUM_PERM_PRIORITY_VOTE
2019-05-09 15:11:42 +00:00
|| !$canDeleteAny
&& (
!empty($topic['topic_locked'])
|| !empty($topic['topic_archived'])
)
) {
echo render_error(403);
return;
}
2019-06-10 17:04:53 +00:00
if(!forum_has_priority_voting($topic['forum_type'])) {
2019-05-09 15:11:42 +00:00
echo render_error(400);
return;
}
2020-05-25 19:58:06 +00:00
forum_topic_priority_increase($topicId, $topicUserId);
2019-05-08 15:46:03 +00:00
url_redirect('forum-topic', ['topic' => $topicId]);