//TODO: Normalize thread_*_info don't need to waste all that ram on things that are already in other caches /**********|| Page to show individual threads || ********************************\ Things to expect in $_GET: ThreadID: ID of the forum curently being browsed page: The page the user's on. page = 1 is the same as no page ********************************************************************************/ //---------- Things to sort out before it can start printing/generating content include(SERVER_ROOT.'/classes/class_text.php'); $Text = new TEXT; // Check for lame SQL injection attempts if(!isset($_GET['threadid']) || !is_number($_GET['threadid'])) { if(isset($_GET['topicid']) && is_number($_GET['topicid'])) { $ThreadID = $_GET['topicid']; } elseif(isset($_GET['postid']) && is_number($_GET['postid'])) { $DB->query("SELECT TopicID FROM forums_posts WHERE ID = $_GET[postid]"); list($ThreadID) = $DB->next_record(); if($ThreadID) { header("Location: forums.php?action=viewthread&threadid=$ThreadID&postid=$_GET[postid]#post$_GET[postid]"); die(); } else { error(404); } } else { error(404); } } else { $ThreadID = $_GET['threadid']; } if (isset($LoggedUser['PostsPerPage'])) { $PerPage = $LoggedUser['PostsPerPage']; } else { $PerPage = POSTS_PER_PAGE; } //---------- Get some data to start processing // Thread information, constant across all pages $ThreadInfo = get_thread_info($ThreadID, true, true); $ForumID = $ThreadInfo['ForumID']; // Make sure they're allowed to look at the page if(!check_forumperm($ForumID)) { error(403); } //Escape strings for later display $ThreadTitle = display_str($ThreadInfo['Title']); $ForumName = display_str($Forums[$ForumID]['Name']); //Post links utilize the catalogue & key params to prevent issues with custom posts per page if($ThreadInfo['Posts'] > $PerPage) { if(isset($_GET['post']) && is_number($_GET['post'])) { $PostNum = $_GET['post']; } elseif(isset($_GET['postid']) && is_number($_GET['postid'])) { $DB->query("SELECT COUNT(ID) FROM forums_posts WHERE TopicID = $ThreadID AND ID <= $_GET[postid]"); list($PostNum) = $DB->next_record(); } else { $PostNum = 1; } } else { $PostNum = 1; } list($Page,$Limit) = page_limit($PerPage, min($ThreadInfo['Posts'],$PostNum)); if(($Page-1)*$PerPage > $ThreadInfo['Posts']) { $Page = ceil($ThreadInfo['Posts']/$PerPage); } list($CatalogueID,$CatalogueLimit) = catalogue_limit($Page,$PerPage,THREAD_CATALOGUE); // Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page if(!$Catalogue = $Cache->get_value('thread_'.$ThreadID.'_catalogue_'.$CatalogueID)) { $DB->query("SELECT p.ID, p.AuthorID, p.AddedTime, p.Body, p.EditedUserID, p.EditedTime, ed.Username FROM forums_posts as p LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID WHERE p.TopicID = '$ThreadID' AND p.ID != '".$ThreadInfo['StickyPostID']."' LIMIT $CatalogueLimit"); $Catalogue = $DB->to_array(false,MYSQLI_ASSOC); if (!$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) { $Cache->cache_value('thread_'.$ThreadID.'_catalogue_'.$CatalogueID, $Catalogue, 0); } } $Thread = catalogue_select($Catalogue,$Page,$PerPage,THREAD_CATALOGUE); if($_GET['updatelastread'] != '0') { $LastPost = end($Thread); $LastPost = $LastPost['ID']; reset($Thread); if($ThreadInfo['Posts'] <= $PerPage*$Page && $ThreadInfo['StickyPostID'] > $LastPost) { $LastPost = $ThreadInfo['StickyPostID']; } //Handle last read if (!$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) { $DB->query("SELECT PostID From forums_last_read_topics WHERE UserID='$LoggedUser[ID]' AND TopicID='$ThreadID'"); list($LastRead) = $DB->next_record(); if($LastRead < $LastPost) { $DB->query("INSERT INTO forums_last_read_topics (UserID, TopicID, PostID) VALUES ('$LoggedUser[ID]', '".$ThreadID ."', '".db_string($LastPost)."') ON DUPLICATE KEY UPDATE PostID='$LastPost'"); } } } //Handle subscriptions if(($UserSubscriptions = $Cache->get_value('subscriptions_user_'.$LoggedUser['ID'])) === FALSE) { $DB->query("SELECT TopicID FROM users_subscriptions WHERE UserID = '$LoggedUser[ID]'"); $UserSubscriptions = $DB->collect(0); $Cache->cache_value('subscriptions_user_'.$LoggedUser['ID'],$UserSubscriptions,0); } if(empty($UserSubscriptions)) { $UserSubscriptions = array(); } if(in_array($ThreadID, $UserSubscriptions)) { $Cache->delete_value('subscriptions_user_new_'.$LoggedUser['ID']); } // Start printing show_header('Forums'.' > '.$Forums[$ForumID]['Name'].' > '.$ThreadInfo['Title'],'comments,subscriptions,bbcode'); ?>
#=$PostID?> =format_username($AuthorID, true, true, true, true, true)?> =time_diff($AddedTime,2)?> if(!$ThreadInfo['IsLocked'] || check_perms('site_moderate_forums')){ ?> - [Quote] } if (((!$ThreadInfo['IsLocked'] && check_forumperm($ForumID, 'Write')) && ($AuthorID == $LoggedUser['ID']) || check_perms('site_moderate_forums'))) { ?> - [Edit] } if(check_perms('site_admin_forums') && $ThreadInfo['Posts'] > 1) { ?> - [Delete] } if($PostID == $ThreadInfo['StickyPostID']) { ?> [Sticky] if(check_perms('site_moderate_forums')) { ?> - [X] } } else { if(check_perms('site_moderate_forums')) { ?> - [⇕] } } ?> [Report] ↑ | ||
if ($Avatar) { ?> } else { ?> } ?> | } ?>>
=$Text->full_format($Body) ?>
if($EditedUserID){ ?>
if(check_perms('site_admin_forums')) { ?> « } ?> Last edited by =format_username($EditedUserID, false, false, false) ?> =time_diff($EditedTime,2,true,true)?> } ?> |