Gazelle/sections/forums/functions.php

58 lines
1.7 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
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); }
2012-06-16 08:00:18 +00:00
$ThreadInfo = $DB->next_record(MYSQLI_ASSOC, false);
2011-03-28 14:21:28 +00:00
if($ThreadInfo['StickyPostID']) {
$ThreadInfo['Posts']--;
2011-03-28 14:21:28 +00:00
$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);
2011-03-28 14:21:28 +00:00
}
}
if($Return) {
return $ThreadInfo;
}
}
2011-10-11 08:00:15 +00:00
function check_forumperm($ForumID, $Perm = 'Read') {
global $LoggedUser, $Forums;
2011-10-12 08:00:15 +00:00
if ($LoggedUser['CustomForums'][$ForumID] == 1) {
return true;
}
2011-10-11 08:00:15 +00:00
if($Forums[$ForumID]['MinClass'.$Perm] > $LoggedUser['Class'] && (!isset($LoggedUser['CustomForums'][$ForumID]) || $LoggedUser['CustomForums'][$ForumID] == 0)) {
return false;
}
if(isset($LoggedUser['CustomForums'][$ForumID]) && $LoggedUser['CustomForums'][$ForumID] == 0) {
return false;
}
return true;
}