This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/public/posting.php

108 lines
2.9 KiB
PHP
Raw Normal View History

2015-05-06 13:42:02 +00:00
<?php
/*
* Sakura Forum Posting
*/
// Declare Namespace
namespace Sakura;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
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']) ?
Forum::getTopicIdFromPostId($_GET['p']) :
0
2015-09-14 21:41:43 +00:00
);
2015-10-18 16:48:05 +00:00
$forumId = isset($_GET['f']) ?
$_GET['f'] :
Forum::getForumIdFromTopicId($topicId);
$mode = isset($_GET['f']) ? 'f' : (isset($_GET['t']) ? 't' : (isset($_GET['p']) ? 'p' : null));
// Include emotes and bbcodes
$posting = [
'emoticons' => Main::getEmotes(),
'bbcodes' => Main::getBBcodes(),
];
// Check if we're in reply mode
if ($mode != 'f') {
// Attempt to get the topic
$topic = Forum::getTopic($topicId, true);
// Prompt an error if the topic doesn't exist
if(!$topic) {
// Add page specific things
$renderData['page'] = [
'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('FORUM_INDEX')),
'message' => 'The requested thread does not exist.',
];
// Render information page
print Templates::render('global/information.tpl', $renderData);
exit;
}
// Check if we're in quote mode
if ($mode == 'p' && isset($_GET['quote']) && $_GET['quote'] == $_GET['p'] && array_key_exists($_GET['p'], $topic['posts'])) {
// Reassign post for ease
$post = $topic['posts'][$_GET['p']];
// Add subject to render data
$posting['text'] = '[quote]' . $post['post_text'] . '[/quote]';
}
// Add subject to render data
$posting['subject'] = 'Re: '. $topic['topic']['topic_title'];
}
2015-10-18 16:48:05 +00:00
// Check if a post is being made
if (isset($_POST['post'])) {
// Set post mode
switch($_POST['parseMode']) {
// BBcode
2015-10-18 16:48:05 +00:00
case '1':
$parse = '1';
break;
// Markdown
2015-10-18 16:48:05 +00:00
case '2':
$parse = '2';
break;
// Raw
2015-10-18 16:48:05 +00:00
default:
$parse = '0';
}
// Attempt to make the post
$makePost = Forum::createPost($currentUser->data['user_id'], $_POST['subject'], $_POST['text'], $forumId, $topicId, $parse);
// 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
print isset($_REQUEST['ajax']) ?
(
$renderData['page']['message'] . '|' .
$renderData['page']['success'] . '|' .
$renderData['page']['redirect']
) :
Templates::render('global/information.tpl', $renderData);
exit;
}
2015-07-30 18:51:24 +00:00
// Set additional render data
$renderData = array_merge($renderData, [
'posting' => $posting,
2015-07-30 18:51:24 +00:00
]);
print Templates::render('forum/posting.tpl', $renderData);