$can_reply = $forum->canPostReply($topic->forum_id, $user->data()->group_id); if (!$can_reply) { Redirect::to('/forum/view_topic/?tid=' . $tid); die; } // Deal with inputted data if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('content' => array('required' => true, 'min' => 2, 'max' => 20480))); if ($validation->passed()) { try { $queries->create("posts", array('forum_id' => $fid, 'topic_id' => $tid, 'post_creator' => $user->data()->id, 'post_content' => htmlspecialchars(Input::get('content')), 'post_date' => date('Y-m-d H:i:s'))); // Get last post ID $last_post_id = $queries->getLastId(); $content = $mentionsParser->parse(Input::get('content'), $tid, $last_post_id, $user_language); $queries->update("posts", $last_post_id, array('post_content' => $content)); $queries->update("forums", $fid, array('last_topic_posted' => $tid, 'last_user_posted' => $user->data()->id, 'last_post_date' => date('Y-m-d H:i:s'))); $queries->update("topics", $tid, array('topic_last_user' => $user->data()->id, 'topic_reply_date' => date('U'))); Session::flash('success_post', '<div class="alert alert-info alert-dismissable"> <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span></button>' . $forum_language['post_submitted'] . '</div>'); Redirect::to('/forum/view_topic/?tid=' . $tid); die; } catch (Exception $e) { die($e->getMessage()); } } else { $error_string = ""; foreach ($validation->errors() as $error) { $error_string .= ucfirst($error) . '<br />'; } Session::flash('failure_post', '<div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span></button>' . $error_string . '</div>');
// Can the user post a reply in this topic? $can_reply = $forum->canPostReply($topic->forum_id, $user->data()->group_id); // Quick reply if (Input::exists()) { if (!$user->isLoggedIn() && !$can_reply) { Redirect::to('/forum'); die; } if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('content' => array('required' => true, 'min' => 2, 'max' => 20480))); if ($validation->passed()) { // Get last post ID and increment it $last_post_id = $queries->orderWhere('posts', 'id <> 0', 'id', 'DESC LIMIT 1'); $last_post_id = $last_post_id[0]->id + 1; $content = $mentionsParser->parse(Input::get('content'), $tid, $last_post_id); try { $queries->create("posts", array('forum_id' => $topic->forum_id, 'topic_id' => $tid, 'post_creator' => $user->data()->id, 'post_content' => htmlspecialchars($content), 'post_date' => date('Y-m-d H:i:s'))); $queries->update("forums", $topic->forum_id, array('last_topic_posted' => $tid, 'last_user_posted' => $user->data()->id, 'last_post_date' => date('Y-m-d H:i:s'))); $queries->update("topics", $tid, array('topic_last_user' => $user->data()->id, 'topic_reply_date' => date('U'))); Session::flash('success_post', '<div class="alert alert-info alert-dismissable"> <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span></button>Post submitted.</div>'); Redirect::to('/forum/view_topic/?tid=' . $tid); die; } catch (Exception $e) { die($e->getMessage()); } } else { $error_string = ""; foreach ($validation->errors() as $error) { $error_string .= ucfirst($error) . '<br />'; }