diff --git a/_sakura/components/Forum.php b/_sakura/components/Forum.php index c57fc36..25142fc 100755 --- a/_sakura/components/Forum.php +++ b/_sakura/components/Forum.php @@ -277,6 +277,25 @@ class Forum } + // Get a forum ID from a topic ID + public static function getForumIdFromTopicId($id) + { + + // Get the topic + $topic = Database::fetch('topics', false, [ + 'topic_id' => [$id, '='], + ]); + + // Return false if nothing was returned + if (empty($topic)) { + return false; + } + + // Return the forum id + return $topic['forum_id']; + + } + // Get a topic ID from a post ID public static function getTopicIdFromPostId($id) { @@ -346,8 +365,55 @@ class Forum } // Creating a new post - public static function createPost($subject, $text, $enableMD, $enableSig, $forum, $type = 0, $status = 0, $topic = 0) + public static function createPost($poster, $title, $text, $forum, $topic = 0, $parse = 0, $signature = 0, $emotes = 0, $type = 0, $status = 0) { + // Check if we're replying to a thread + $getThread = Database::fetch('topics', false, ['topic_id' => [$topic, '=']]); + + // If nothing was returned create a new thread + if (!$getThread) { + // Insert the required data + Database::insert('topics', [ + 'forum_id' => $forum, + 'topic_title' => $title, + 'topic_time' => time(), + 'topic_status' => $status, + 'topic_type' => $type, + ]); + + // Fetch the last insert + $getThread = Database::fetch('topics', false, null, ['topic_id', true]); + } + + // Insert the post + Database::insert('posts', [ + 'topic_id' => $getThread['topic_id'], + 'forum_id' => $getThread['forum_id'], + 'poster_id' => $poster, + 'post_time' => time(), + 'post_parse' => $parse, + 'post_signature' => $signature, + 'post_emotes' => $emotes, + 'post_subject' => $title, + 'post_text' => $text, + ]); + + // Fetch the last insert + $getPost = Database::fetch('posts', false, null, ['post_id', true]); + + // Update the topic with the last details + Database::update('topics', [ + [ + 'topic_last_reply' => time(), + ], + [ + 'topic_id' => [$getPost['topic_id'], '='], + ], + ]); + + // Return success + return [1, 'SUCCESS', $getPost['forum_id'], $getPost['topic_id'], $getPost['post_id']]; + } } diff --git a/_sakura/templates/yuuno/forum/forumEntry.tpl b/_sakura/templates/yuuno/forum/forumEntry.tpl index 3e96e8c..8d77d0d 100755 --- a/_sakura/templates/yuuno/forum/forumEntry.tpl +++ b/_sakura/templates/yuuno/forum/forumEntry.tpl @@ -29,7 +29,7 @@
{% if forum.last_post.post_id %} - {{ forum.last_post.post_subject }}
{{ forum.last_post.elapsed }} by {% if forum.last_poster.data.user_id %}{{ forum.last_poster.data.username }}{% else %}[deleted user]{% endif %} + {{ forum.last_post.post_subject }}
{{ forum.last_post.elapsed }} by {% if forum.last_poster.data.user_id %}{{ forum.last_poster.data.username }}{% else %}[deleted user]{% endif %} {% else %} There are no posts in this forum.
  {% endif %} diff --git a/_sakura/templates/yuuno/forum/posting.tpl b/_sakura/templates/yuuno/forum/posting.tpl index 17fb6a0..aae7500 100755 --- a/_sakura/templates/yuuno/forum/posting.tpl +++ b/_sakura/templates/yuuno/forum/posting.tpl @@ -5,7 +5,7 @@ {% block content %}
-
+
Forum / Posting
@@ -44,21 +44,26 @@
- + + +

- + - +
+ {% endblock %} diff --git a/_sakura/templates/yuuno/settings/general.profile.tpl b/_sakura/templates/yuuno/settings/general.profile.tpl index d1053da..ec6faa6 100755 --- a/_sakura/templates/yuuno/settings/general.profile.tpl +++ b/_sakura/templates/yuuno/settings/general.profile.tpl @@ -54,8 +54,6 @@ diff --git a/public/authenticate.php b/public/authenticate.php index 312d653..0a5205c 100755 --- a/public/authenticate.php +++ b/public/authenticate.php @@ -281,7 +281,6 @@ if (isset($_REQUEST['mode'])) { ) : Templates::render('global/information.tpl', $renderData); exit; - } // Add page specific things diff --git a/public/content/data/yuuno/css/yuuno.css b/public/content/data/yuuno/css/yuuno.css index ee0ab84..d90e9b2 100755 --- a/public/content/data/yuuno/css/yuuno.css +++ b/public/content/data/yuuno/css/yuuno.css @@ -1704,6 +1704,15 @@ button.inputStyling:active { transition: text-shadow .2s, box-shadow .2s; } +input[type="submit"][disabled=disabled].inputStyling, +input[type="button"][disabled=disabled].inputStyling, +input[type="reset"][disabled=disabled].inputStyling, +button[disabled=disabled].inputStyling { + background: linear-gradient(180deg, #858585 0%, #858585 50%, #787878 50%) #858585 !important; + box-shadow: inset #222 0 0 1px !important; + text-shadow: #888 0 0 2px !important; +} + input[type="text"].inputStyling, input[type="password"].inputStyling, input[type="date"].inputStyling, diff --git a/public/posting.php b/public/posting.php index 6f7690e..6bc4c78 100755 --- a/public/posting.php +++ b/public/posting.php @@ -10,18 +10,56 @@ namespace Sakura; require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php'; // Set location -$locId = isset($_GET['f']) ? -$_GET['f'] : +$topicId = isset($_GET['t']) ? +$_GET['t'] : ( - isset($_GET['t']) ? - $_GET['t'] : - ( - isset($_GET['p']) ? - Forum::getTopicIdFromPostId($_GET['p']) : - 0 - ) + isset($_GET['p']) ? + Forum::getTopicIdFromPostId($_GET['p']) : + 0 ); -$locMode = isset($_GET['f']) ? 'f' : (isset($_GET['t']) || isset($_GET['p']) ? 't' : null); + +$forumId = isset($_GET['f']) ? +$_GET['f'] : +Forum::getForumIdFromTopicId($topicId); + +$mode = isset($_GET['f']) ? 'f' : (isset($_GET['t']) || isset($_GET['p']) ? 't' : null); + +// Check if a post is being made +if (isset($_POST['post'])) { + // Set post mode + switch($_POST['parseMode']) { + case '1': + $parse = '1'; + break; + case '2': + $parse = '2'; + break; + 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; +} // Set additional render data $renderData = array_merge($renderData, [