2018-05-21 23:05:25 +00:00
|
|
|
<?php
|
|
|
|
use Misuzu\Database;
|
|
|
|
|
2018-10-04 20:30:55 +00:00
|
|
|
require_once '../../misuzu.php';
|
2018-05-21 23:05:25 +00:00
|
|
|
|
2018-10-02 22:34:05 +00:00
|
|
|
if (!user_session_active()) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(403);
|
2018-05-21 23:05:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$postRequest = $_SERVER['REQUEST_METHOD'] === 'POST';
|
|
|
|
|
|
|
|
if ($postRequest) {
|
|
|
|
$topicId = max(0, (int)($_POST['post']['topic'] ?? 0));
|
|
|
|
$forumId = max(0, (int)($_POST['post']['forum'] ?? 0));
|
|
|
|
} else {
|
|
|
|
$postId = max(0, (int)($_GET['p'] ?? 0));
|
|
|
|
$topicId = max(0, (int)($_GET['t'] ?? 0));
|
|
|
|
$forumId = max(0, (int)($_GET['f'] ?? 0));
|
|
|
|
}
|
|
|
|
|
2018-05-22 02:09:53 +00:00
|
|
|
if (empty($postId) && empty($topicId) && empty($forumId)) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(404);
|
2018-05-22 02:09:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-21 23:05:25 +00:00
|
|
|
if (!empty($postId)) {
|
2018-07-15 22:59:14 +00:00
|
|
|
$getPost = Database::prepare('
|
2018-05-22 01:26:47 +00:00
|
|
|
SELECT `post_id`, `topic_id`
|
2018-05-21 23:05:25 +00:00
|
|
|
FROM `msz_forum_posts`
|
|
|
|
WHERE `post_id` = :post_id
|
|
|
|
');
|
|
|
|
$getPost->bindValue('post_id', $postId);
|
|
|
|
$post = $getPost->execute() ? $getPost->fetch() : false;
|
|
|
|
|
|
|
|
if (isset($post['topic_id'])) { // should automatic cross-quoting be a thing? if so, check if $topicId is < 1 first
|
|
|
|
$topicId = (int)$post['topic_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($topicId)) {
|
2018-07-15 22:59:14 +00:00
|
|
|
$getTopic = Database::prepare('
|
2018-05-23 01:41:57 +00:00
|
|
|
SELECT `topic_id`, `forum_id`, `topic_title`, `topic_locked`
|
2018-05-21 23:05:25 +00:00
|
|
|
FROM `msz_forum_topics`
|
|
|
|
WHERE `topic_id` = :topic_id
|
|
|
|
');
|
|
|
|
$getTopic->bindValue('topic_id', $topicId);
|
|
|
|
$topic = $getTopic->execute() ? $getTopic->fetch() : false;
|
|
|
|
|
|
|
|
if (isset($topic['forum_id'])) {
|
|
|
|
$forumId = (int)$topic['forum_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($forumId)) {
|
2018-07-15 22:59:14 +00:00
|
|
|
$getForum = Database::prepare('
|
2018-05-23 01:41:57 +00:00
|
|
|
SELECT `forum_id`, `forum_name`, `forum_type`, `forum_archived`
|
2018-05-21 23:05:25 +00:00
|
|
|
FROM `msz_forum_categories`
|
|
|
|
WHERE `forum_id` = :forum_id
|
|
|
|
');
|
|
|
|
$getForum->bindValue('forum_id', $forumId);
|
|
|
|
$forum = $getForum->execute() ? $getForum->fetch() : false;
|
|
|
|
}
|
|
|
|
|
2018-05-22 02:09:53 +00:00
|
|
|
if (empty($forum)) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(404);
|
2018-05-22 02:09:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-02 22:34:05 +00:00
|
|
|
$perms = forum_perms_get_user(MSZ_FORUM_PERMS_GENERAL, $forum['forum_id'], user_session_current('user_id', 0));
|
2018-08-23 20:06:48 +00:00
|
|
|
|
|
|
|
if ($forum['forum_archived']
|
|
|
|
|| !empty($topic['topic_locked'])
|
|
|
|
|| !perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM | MSZ_FORUM_PERM_CREATE_POST)
|
|
|
|
|| (empty($topic) && !perms_check($perms, MSZ_FORUM_PERM_CREATE_TOPIC))) {
|
|
|
|
echo render_error(403);
|
2018-05-22 02:09:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-23 20:06:48 +00:00
|
|
|
if (!forum_may_have_topics($forum['forum_type'])) {
|
|
|
|
echo render_error(400);
|
2018-05-23 01:41:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-21 23:05:25 +00:00
|
|
|
if ($postRequest) {
|
2018-10-02 22:34:05 +00:00
|
|
|
if (!csrf_verify('forum_post', $_POST['csrf'] ?? '')) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo 'Could not verify request.';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-23 01:41:57 +00:00
|
|
|
$topicTitle = $_POST['post']['title'] ?? '';
|
|
|
|
$topicTitleValidate = forum_validate_title($topicTitle);
|
|
|
|
$postText = $_POST['post']['text'] ?? '';
|
|
|
|
$postTextValidate = forum_validate_post($postText);
|
|
|
|
|
|
|
|
switch ($postTextValidate) {
|
|
|
|
case 'too-short':
|
|
|
|
echo 'Post content was too short.';
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'too-long':
|
|
|
|
echo 'Post content was too long.';
|
|
|
|
return;
|
|
|
|
}
|
2018-05-21 23:05:25 +00:00
|
|
|
|
|
|
|
if (isset($topic)) {
|
2018-05-23 01:41:57 +00:00
|
|
|
forum_topic_bump($topic['topic_id']);
|
2018-05-21 23:05:25 +00:00
|
|
|
} else {
|
2018-05-23 01:41:57 +00:00
|
|
|
switch ($topicTitleValidate) {
|
|
|
|
case 'too-short':
|
|
|
|
echo 'Topic title was too short.';
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'too-long':
|
|
|
|
echo 'Topic title was too long.';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-02 22:34:05 +00:00
|
|
|
$topicId = forum_topic_create($forum['forum_id'], user_session_current('user_id', 0), $topicTitle);
|
2018-05-21 23:05:25 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 01:41:57 +00:00
|
|
|
$postId = forum_post_create(
|
|
|
|
$topicId,
|
|
|
|
$forum['forum_id'],
|
2018-10-02 22:34:05 +00:00
|
|
|
user_session_current('user_id', 0),
|
2018-09-27 08:32:43 +00:00
|
|
|
ip_remote_address(),
|
2018-05-24 19:31:48 +00:00
|
|
|
$postText,
|
2018-09-21 08:56:52 +00:00
|
|
|
MSZ_PARSER_BBCODE
|
2018-05-23 01:41:57 +00:00
|
|
|
);
|
2018-10-02 22:34:05 +00:00
|
|
|
forum_topic_mark_read(user_session_current('user_id', 0), $topicId, $forum['forum_id']);
|
2018-05-21 23:05:25 +00:00
|
|
|
|
|
|
|
header("Location: /forum/topic.php?p={$postId}#p{$postId}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-22 00:54:20 +00:00
|
|
|
if (!empty($topic)) {
|
2018-08-15 01:12:58 +00:00
|
|
|
tpl_var('posting_topic', $topic);
|
2018-05-22 00:54:20 +00:00
|
|
|
}
|
2018-05-21 23:05:25 +00:00
|
|
|
|
2018-08-15 01:12:58 +00:00
|
|
|
echo tpl_render('forum.posting', [
|
2018-05-23 01:41:57 +00:00
|
|
|
'posting_breadcrumbs' => forum_get_breadcrumbs($forumId),
|
2018-05-22 00:54:20 +00:00
|
|
|
'posting_forum' => $forum,
|
|
|
|
]);
|