2015-05-06 13:42:02 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Sakura Forum Posting
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Declare Namespace
|
|
|
|
namespace Sakura;
|
|
|
|
|
|
|
|
// Include components
|
2015-09-14 20:51:23 +00:00
|
|
|
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
|
2015-07-30 18:51:24 +00:00
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Initialise templating engine
|
|
|
|
$template = new Template();
|
|
|
|
|
|
|
|
// Change templating engine
|
|
|
|
$template->setTemplate($templateName);
|
|
|
|
|
2015-07-30 18:51:24 +00:00
|
|
|
// Set location
|
2015-10-18 16:48:05 +00:00
|
|
|
$topicId = isset($_GET['t']) ?
|
|
|
|
$_GET['t'] :
|
2015-09-14 21:41:43 +00:00
|
|
|
(
|
2015-10-18 16:48:05 +00:00
|
|
|
isset($_GET['p']) ?
|
2015-11-22 22:10:23 +00:00
|
|
|
Forum\Forums::getTopicIdFromPostId($_GET['p']) :
|
2015-10-18 16:48:05 +00:00
|
|
|
0
|
2015-09-14 21:41:43 +00:00
|
|
|
);
|
2015-10-18 16:48:05 +00:00
|
|
|
|
|
|
|
$forumId = isset($_GET['f']) ?
|
|
|
|
$_GET['f'] :
|
2015-11-22 22:10:23 +00:00
|
|
|
Forum\Forums::getForumIdFromTopicId($topicId);
|
2015-10-18 16:48:05 +00:00
|
|
|
|
2015-10-20 00:49:09 +00:00
|
|
|
$mode = isset($_GET['f']) ? 'f' : (isset($_GET['t']) ? 't' : (isset($_GET['p']) ? 'p' : null));
|
|
|
|
|
|
|
|
// Include emotes and bbcodes
|
|
|
|
$posting = [
|
|
|
|
'emoticons' => Main::getEmotes(),
|
|
|
|
];
|
|
|
|
|
|
|
|
// Check if we're in reply mode
|
|
|
|
if ($mode != 'f') {
|
|
|
|
// Attempt to get the topic
|
2015-11-22 22:10:23 +00:00
|
|
|
$thread = Forum\Forums::getTopic($topicId, true);
|
2015-10-20 00:49:09 +00:00
|
|
|
|
|
|
|
// Prompt an error if the topic doesn't exist
|
2015-11-15 14:29:26 +00:00
|
|
|
if (!$thread) {
|
2015-10-20 00:49:09 +00:00
|
|
|
// Add page specific things
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('FORUM_INDEX')),
|
2015-10-22 14:24:18 +00:00
|
|
|
'message' => 'The requested post does not exist.',
|
2015-10-20 00:49:09 +00:00
|
|
|
];
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Set parse variables
|
|
|
|
$template->setVariables($renderData);
|
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
echo $template->render('global/information.tpl');
|
2015-10-20 00:49:09 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we're in quote mode
|
2015-11-15 14:29:26 +00:00
|
|
|
if ($mode == 'p' && isset($_GET['quote']) && $_GET['quote'] == $_GET['p'] && array_key_exists($_GET['p'], $thread['posts'])) {
|
2015-10-20 00:49:09 +00:00
|
|
|
// Reassign post for ease
|
2015-11-15 14:29:26 +00:00
|
|
|
$post = $thread['posts'][$_GET['p']];
|
2015-10-20 00:49:09 +00:00
|
|
|
|
|
|
|
// Add subject to render data
|
2015-12-02 14:38:40 +00:00
|
|
|
$posting['text'] = '[quote]' . (new BBcode($post['post_text']))->toEditor() . '[/quote]';
|
2015-10-22 14:24:18 +00:00
|
|
|
|
2015-10-24 08:55:45 +00:00
|
|
|
// Post editing
|
2015-11-15 14:29:26 +00:00
|
|
|
} elseif ($mode == 'p' && isset($_GET['edit']) && $_GET['edit'] == $_GET['p'] && array_key_exists($_GET['p'], $thread['posts'])) {
|
2015-10-22 14:24:18 +00:00
|
|
|
// Checks
|
2015-11-15 14:29:26 +00:00
|
|
|
if ($thread['posts'][$_GET['p']]['poster_id'] != $currentUser->id()) {
|
2015-10-22 14:24:18 +00:00
|
|
|
// Add page specific things
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('FORUM_INDEX')),
|
|
|
|
'message' => 'You can only edit your own posts!',
|
|
|
|
];
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Set parse variables
|
|
|
|
$template->setVariables($renderData);
|
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
echo $template->render('global/information.tpl');
|
2015-10-22 14:24:18 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reassign post for ease
|
2015-11-15 14:29:26 +00:00
|
|
|
$post = $thread['posts'][$_GET['p']];
|
2015-10-22 14:24:18 +00:00
|
|
|
|
|
|
|
// Set variables
|
|
|
|
$posting = array_merge($posting, [
|
|
|
|
'subject' => $post['post_subject'],
|
2015-12-02 14:38:40 +00:00
|
|
|
'text' => (new BBcode($post['post_text']))->toEditor(),
|
2015-10-24 08:55:45 +00:00
|
|
|
'id' => $post['post_id'],
|
2015-10-22 14:24:18 +00:00
|
|
|
]);
|
2015-10-24 08:55:45 +00:00
|
|
|
// Post deletion
|
2015-11-15 14:29:26 +00:00
|
|
|
} elseif ($mode == 'p' && isset($_GET['delete']) && $_GET['delete'] == $_GET['p'] && array_key_exists($_GET['p'], $thread['posts'])) {
|
2015-10-22 14:24:18 +00:00
|
|
|
// Checks
|
2015-11-15 14:29:26 +00:00
|
|
|
if ($thread['posts'][$_GET['p']]['poster_id'] != $currentUser->id()) {
|
2015-10-22 14:24:18 +00:00
|
|
|
// Add page specific things
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('FORUM_INDEX')),
|
|
|
|
'message' => 'You can only delete your own posts!',
|
|
|
|
];
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Set parse variables
|
|
|
|
$template->setVariables($renderData);
|
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
echo $template->render('global/information.tpl');
|
2015-10-22 14:24:18 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Submit mode
|
|
|
|
if (isset($_POST['timestamp'], $_POST['sessionid'], $_POST['post_id'])) {
|
|
|
|
// Post deletion code
|
|
|
|
if (isset($_POST['yes'])) {
|
|
|
|
// Delete the post
|
|
|
|
Database::delete('posts', [
|
|
|
|
'post_id' => [$_POST['post_id'], '='],
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Reload the topic
|
2015-11-22 22:10:23 +00:00
|
|
|
$thread = Forum\Forums::getTopic($topicId, true);
|
2015-10-22 14:24:18 +00:00
|
|
|
|
|
|
|
// If there's no more posts left in the topic delete it as well
|
2015-11-15 14:29:26 +00:00
|
|
|
if (!count($thread['posts'])) {
|
2015-10-22 14:24:18 +00:00
|
|
|
Database::delete('topics', [
|
2015-11-15 14:29:26 +00:00
|
|
|
'topic_id' => [$thread['topic']['topic_id'], '='],
|
2015-10-22 14:24:18 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add page specific things
|
|
|
|
$renderData['page'] = [
|
2015-11-15 14:29:26 +00:00
|
|
|
'redirect' => (count($thread['posts']) ? $urls->format('FORUM_THREAD', [$thread['topic']['topic_id']]) : $urls->format('FORUM_INDEX')),
|
2015-10-22 14:24:18 +00:00
|
|
|
'message' => 'Your post has been deleted!',
|
|
|
|
];
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Set parse variables
|
|
|
|
$template->setVariables($renderData);
|
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
echo $template->render('global/information.tpl');
|
2015-10-22 14:24:18 +00:00
|
|
|
exit;
|
2015-10-24 08:55:45 +00:00
|
|
|
// Return to previous page
|
2015-10-22 14:24:18 +00:00
|
|
|
} else {
|
2015-10-24 08:55:45 +00:00
|
|
|
header('Location: ' . $urls->format('FORUM_POST', [$_POST['post_id']]));
|
2015-10-22 14:24:18 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Form mode
|
|
|
|
$renderData = array_merge($renderData, [
|
2015-11-15 14:29:26 +00:00
|
|
|
'message' => 'Are you sure you want to delete your reply to ' . $thread['topic']['topic_title'] . '?',
|
2015-10-22 14:24:18 +00:00
|
|
|
'conditions' => [
|
2015-11-15 14:29:26 +00:00
|
|
|
'post_id' => $thread['posts'][$_GET['p']]['post_id'],
|
2015-10-24 08:55:45 +00:00
|
|
|
],
|
2015-10-22 14:24:18 +00:00
|
|
|
]);
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Set parse variables
|
|
|
|
$template->setVariables($renderData);
|
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
echo $template->render('global/confirm.tpl');
|
2015-10-22 14:24:18 +00:00
|
|
|
exit;
|
2015-10-20 00:49:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add subject to render data
|
2015-10-24 08:55:45 +00:00
|
|
|
if (!isset($posting['subject'])) {
|
2015-11-15 14:29:26 +00:00
|
|
|
$posting['subject'] = 'Re: ' . $thread['topic']['topic_title'];
|
2015-10-22 14:24:18 +00:00
|
|
|
}
|
2015-10-20 00:49:09 +00:00
|
|
|
}
|
2015-10-18 16:48:05 +00:00
|
|
|
|
|
|
|
// Check if a post is being made
|
|
|
|
if (isset($_POST['post'])) {
|
|
|
|
// Attempt to make the post
|
2015-11-22 22:10:23 +00:00
|
|
|
$makePost = Forum\Forums::createPost($currentUser->id(), $_POST['subject'], $_POST['text'], $forumId, $topicId, 1, 1, 1);
|
2015-10-18 16:48:05 +00:00
|
|
|
|
|
|
|
// Add page specific things
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $urls->format('FORUM_THREAD', [$makePost[3]]),
|
|
|
|
'message' => 'Made the post!',
|
|
|
|
'success' => $makePost[0],
|
|
|
|
];
|
|
|
|
|
|
|
|
// Print page contents or if the AJAX request is set only display the render data
|
2015-11-06 22:30:37 +00:00
|
|
|
if (isset($_REQUEST['ajax'])) {
|
|
|
|
echo $renderData['page']['message'] . '|' .
|
|
|
|
$renderData['page']['success'] . '|' .
|
|
|
|
$renderData['page']['redirect'];
|
|
|
|
} else {
|
|
|
|
// Set parse variables
|
|
|
|
$template->setVariables($renderData);
|
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
echo $template->render('global/information.tpl');
|
|
|
|
}
|
2015-10-18 16:48:05 +00:00
|
|
|
exit;
|
|
|
|
}
|
2015-07-30 18:51:24 +00:00
|
|
|
|
|
|
|
// Set additional render data
|
|
|
|
$renderData = array_merge($renderData, [
|
2015-10-20 00:49:09 +00:00
|
|
|
'posting' => $posting,
|
2015-07-30 18:51:24 +00:00
|
|
|
]);
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Set parse variables
|
|
|
|
$template->setVariables($renderData);
|
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
echo $template->render('forum/posting.tpl');
|