Gazelle/sections/forums/functions.php
World Wide Web Owner dcbc1b1af7 Don't reset search options when saving profile settings
Fix expression for cleaning up default search URL

Fix typo preventing threads from being cached

Don't include sticky post in reply count

Cast RemasterYear to int because '0' != ''

Don't compare escaped artist name to unescaped
2011-04-17 11:05:01 +00:00

44 lines
1.2 KiB
PHP

<?
function get_thread_info($ThreadID, $Return = true, $SelectiveCache = false) {
global $DB, $Cache;
if(!$ThreadInfo = $Cache->get_value('thread_'.$ThreadID.'_info')) {
$DB->query("SELECT
t.Title,
t.ForumID,
t.IsLocked,
t.IsSticky,
COUNT(fp.id) AS Posts,
t.LastPostAuthorID,
ISNULL(p.TopicID) AS NoPoll,
t.StickyPostID
FROM forums_topics AS t
JOIN forums_posts AS fp ON fp.TopicID = t.ID
LEFT JOIN forums_polls AS p ON p.TopicID=t.ID
WHERE t.ID = '$ThreadID'
GROUP BY fp.TopicID");
if($DB->record_count()==0) { error(404); }
$ThreadInfo = $DB->next_record(MYSQLI_ASSOC);
if($ThreadInfo['StickyPostID']) {
$ThreadInfo['Posts']--;
$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']."'");
list($ThreadInfo['StickyPost']) = $DB->to_array(false, MYSQLI_ASSOC);
}
if(!$SelectiveCache || !$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
$Cache->cache_value('thread_'.$ThreadID.'_info', $ThreadInfo, 0);
}
}
if($Return) {
return $ThreadInfo;
}
}