mirror of
https://github.com/OPSnet/Gazelle.git
synced 2026-09-30 07:13:20 -04:00
75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|
authorize();
|
|
|
|
/* Creating a new thread
|
|
* Form variables:
|
|
* $_POST['forum']
|
|
* $_POST['title']
|
|
* $_POST['body']
|
|
* optional for a poll:
|
|
* $_POST['question']
|
|
* $_POST['answers'] (array of answers)
|
|
*/
|
|
|
|
if ($LoggedUser['DisablePosting']) {
|
|
error('Your posting privileges have been removed.');
|
|
}
|
|
|
|
if (isset($_POST['forum'])) {
|
|
$ForumID = (int)$_POST['forum'];
|
|
if (!$Forums[$ForumID]) {
|
|
error(404);
|
|
}
|
|
if (!Forums::check_forumperm($ForumID, 'Write') || !Forums::check_forumperm($ForumID, 'Create')) {
|
|
error(403);
|
|
}
|
|
}
|
|
|
|
// If you're not sending anything, go back
|
|
if (empty($_POST['body']) || empty($_POST['title'])) {
|
|
header("Location: " . $_SERVER['HTTP_REFERER'] ?? "forums.php?action=viewforum&forumid={$_POST['forum']}");
|
|
exit;
|
|
}
|
|
$Title = shortenString(trim($_POST['title']), 150, true, false);
|
|
$Body = trim($_POST['body']);
|
|
|
|
if (empty($_POST['question']) || empty($_POST['answers']) || !check_perms('forums_polls_create')) {
|
|
$needPoll = false;
|
|
} else {
|
|
$needPoll = true;
|
|
$Question = trim($_POST['question']);
|
|
$Answers = [];
|
|
$Votes = [];
|
|
|
|
// Step over empty answer fields to avoid gaps in the answer IDs
|
|
foreach ($_POST['answers'] as $i => $Answer) {
|
|
if ($Answer == '') {
|
|
continue;
|
|
}
|
|
$Answers[$i + 1] = $Answer;
|
|
$Votes[$i + 1] = 0;
|
|
}
|
|
|
|
if (count($Answers) < 2) {
|
|
error('You cannot create a poll with only one answer.');
|
|
} elseif (count($Answers) > 25) {
|
|
error('You cannot create a poll with greater than 25 answers.');
|
|
}
|
|
}
|
|
|
|
$forum = new \Gazelle\Forum($ForumID);
|
|
$threadId = $forum->addThread($LoggedUser['ID'], $Title, $Body);
|
|
|
|
if ($needPoll) {
|
|
$forum->addPoll($threadId, $Question, $Answers, $Votes);
|
|
if ($ForumID == STAFF_FORUM_ID) {
|
|
send_irc('PRIVMSG '.MOD_CHAN.' :Poll created by '.$LoggedUser['Username'].": \"$Question\" ".SITE_URL."/forums.php?action=viewthread&threadid=$threadId");
|
|
}
|
|
}
|
|
|
|
if (isset($_POST['subscribe'])) {
|
|
(new Gazelle\Manager\Subscription($LoggedUser['ID']))->subscribe($threadId);
|
|
}
|
|
|
|
header("Location: forums.php?action=viewthread&threadid=$threadId");
|