2011-03-28 14:21:28 +00:00
|
|
|
<?
|
2013-06-10 08:01:05 +00:00
|
|
|
function get_thread_info($ThreadID, $Return = true, $SelectiveCache = false, $ApiCall = false) {
|
2011-03-28 14:21:28 +00:00
|
|
|
global $DB, $Cache;
|
2013-04-17 08:00:58 +00:00
|
|
|
if ((!$ThreadInfo = $Cache->get_value('thread_'.$ThreadID.'_info')) || !isset($ThreadInfo['OP'])) {
|
2013-06-04 08:00:34 +00:00
|
|
|
$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,
|
2013-07-01 08:01:00 +00:00
|
|
|
t.AuthorID as OP,
|
|
|
|
t.Ranking
|
2013-04-17 08:00:58 +00:00
|
|
|
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
|
2011-03-28 14:21:28 +00:00
|
|
|
WHERE t.ID = '$ThreadID'
|
|
|
|
GROUP BY fp.TopicID");
|
2013-04-17 08:00:58 +00:00
|
|
|
if ($DB->record_count() == 0) {
|
2013-06-10 08:01:05 +00:00
|
|
|
if (!$ApiCall) {
|
|
|
|
error(404);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-04-17 08:00:58 +00:00
|
|
|
}
|
2012-06-16 08:00:18 +00:00
|
|
|
$ThreadInfo = $DB->next_record(MYSQLI_ASSOC, false);
|
2013-04-17 08:00:58 +00:00
|
|
|
if ($ThreadInfo['StickyPostID']) {
|
2011-04-17 11:05:01 +00:00
|
|
|
$ThreadInfo['Posts']--;
|
2013-06-04 08:00:34 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
p.ID,
|
|
|
|
p.AuthorID,
|
|
|
|
p.AddedTime,
|
|
|
|
p.Body,
|
|
|
|
p.EditedUserID,
|
|
|
|
p.EditedTime,
|
|
|
|
ed.Username
|
2011-03-28 14:21:28 +00:00
|
|
|
FROM forums_posts as p
|
2013-04-17 08:00:58 +00:00
|
|
|
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
|
2013-06-04 08:00:34 +00:00
|
|
|
WHERE p.TopicID = '$ThreadID'
|
|
|
|
AND p.ID = '".$ThreadInfo['StickyPostID']."'");
|
2011-03-28 14:21:28 +00:00
|
|
|
list($ThreadInfo['StickyPost']) = $DB->to_array(false, MYSQLI_ASSOC);
|
|
|
|
}
|
2013-04-17 08:00:58 +00:00
|
|
|
if (!$SelectiveCache || !$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
|
2011-04-17 11:05:01 +00:00
|
|
|
$Cache->cache_value('thread_'.$ThreadID.'_info', $ThreadInfo, 0);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-17 08:00:58 +00:00
|
|
|
if ($Return) {
|
2011-03-28 14:21:28 +00:00
|
|
|
return $ThreadInfo;
|
|
|
|
}
|
|
|
|
}
|
2011-05-15 12:06:04 +00:00
|
|
|
|
2011-10-11 08:00:15 +00:00
|
|
|
function check_forumperm($ForumID, $Perm = 'Read') {
|
2011-05-15 12:06:04 +00:00
|
|
|
global $LoggedUser, $Forums;
|
2011-10-12 08:00:15 +00:00
|
|
|
if ($LoggedUser['CustomForums'][$ForumID] == 1) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-17 08:00:58 +00:00
|
|
|
if ($Forums[$ForumID]['MinClass'.$Perm] > $LoggedUser['Class'] && (!isset($LoggedUser['CustomForums'][$ForumID]) || $LoggedUser['CustomForums'][$ForumID] == 0)) {
|
2011-05-15 12:06:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-04-17 08:00:58 +00:00
|
|
|
if (isset($LoggedUser['CustomForums'][$ForumID]) && $LoggedUser['CustomForums'][$ForumID] == 0) {
|
2011-05-15 12:06:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-14 08:00:19 +00:00
|
|
|
|
|
|
|
// Function to get basic information on a forum
|
|
|
|
// Uses class CACHE
|
|
|
|
function get_forum_info($ForumID) {
|
|
|
|
global $DB, $Cache;
|
|
|
|
$Forum = $Cache->get_value('ForumInfo_'.$ForumID);
|
2013-04-17 08:00:58 +00:00
|
|
|
if (!$Forum) {
|
2013-06-04 08:00:34 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
Name,
|
|
|
|
MinClassRead,
|
|
|
|
MinClassWrite,
|
|
|
|
MinClassCreate,
|
|
|
|
COUNT(forums_topics.ID) AS Topics
|
2012-11-14 08:00:19 +00:00
|
|
|
FROM forums
|
2013-04-17 08:00:58 +00:00
|
|
|
LEFT JOIN forums_topics ON forums_topics.ForumID=forums.ID
|
2012-11-14 08:00:19 +00:00
|
|
|
WHERE forums.ID='$ForumID'
|
|
|
|
GROUP BY ForumID");
|
2013-04-17 08:00:58 +00:00
|
|
|
if ($DB->record_count() == 0) {
|
2012-11-14 08:00:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Makes an array, with $Forum['Name'], etc.
|
|
|
|
$Forum = $DB->next_record(MYSQLI_ASSOC);
|
|
|
|
|
|
|
|
$Cache->cache_value('ForumInfo_'.$ForumID, $Forum, 86400); // Cache for a day
|
|
|
|
}
|
|
|
|
return $Forum;
|
2013-04-17 08:00:58 +00:00
|
|
|
}
|