if (!$topic) {
    buckys_redirect('/forum');
}
$category = BuckysForumCategory::getCategory($topic['categoryID']);
//If the topic is not published(pending or suspended), only forum moderator and administrator can see this
if ($topic['status'] != 'publish' && !buckys_is_moderator() && $TNB_GLOBALS['user']['userID'] != $topic['creatorID']) {
    buckys_redirect('/forum');
}
$orderBy = isset($_GET['orderby']) ? buckys_escape_query_string($_GET['orderby']) : 'oldest';
//Getting Replies
$page = isset($_GET['page']) ? buckys_escape_query_integer($_GET['page']) : 1;
$total = BuckysForumReply::getTotalNumOfReplies($topic['topicID'], 'publish');
$pagination = new Pagination($total, BuckysForumReply::$COUNT_PER_PAGE, $page);
$page = $pagination->getCurrentPage();
$replies = BuckysForumReply::getReplies($topic['topicID'], 'publish', $page, $orderBy);
$hierarchical = BuckysForumCategory::getCategoryHierarchical($topic['categoryID']);
//Mark Forum Notifications to read
if (buckys_check_user_acl(USER_ACL_REGISTERED)) {
    BuckysForumNotification::makeNotificationsToRead($TNB_GLOBALS['user']['userID'], null, $topic['topicID']);
}
if (buckys_check_user_acl(USER_ACL_MODERATOR)) {
    $reportID = BuckysReport::isReported($topicID, 'topic');
    $categories = BuckysForumCategory::getAllCategories();
}
buckys_enqueue_javascript('sceditor/jquery.sceditor.bbcode.js');
buckys_enqueue_javascript('uploadify/jquery.uploadify.js');
buckys_enqueue_javascript('highlight.pack.js');
buckys_enqueue_javascript('forum.js');
buckys_enqueue_stylesheet('sceditor/themes/default.css');
buckys_enqueue_stylesheet('obsidian.css');
buckys_enqueue_stylesheet('forum.css');