Gazelle/sections/ajax/forum/index.php

108 lines
2.8 KiB
PHP
Raw Normal View History

2011-10-31 08:00:12 +00:00
<?
// Already done in /sections/ajax/index.php
//enforce_login();
if (!empty($LoggedUser['DisableForums'])) {
print json_encode(array('status' => 'failure'));
2012-02-09 08:00:20 +00:00
die();
2011-10-31 08:00:12 +00:00
}
else {
include(SERVER_ROOT.'/sections/forums/functions.php');
2012-02-14 08:00:22 +00:00
// Replace the old hard-coded forum categories
unset($ForumCats);
$ForumCats = $Cache->get_value('forums_categories');
if ($ForumCats === false) {
$DB->query("SELECT ID, Name FROM forums_categories");
$ForumCats = array();
while (list($ID, $Name) = $DB->next_record()) {
$ForumCats[$ID] = $Name;
}
$Cache->cache_value('forums_categories', $ForumCats, 0); //Inf cache.
}
2011-10-31 08:00:12 +00:00
//This variable contains all our lovely forum data
2013-05-05 08:00:31 +00:00
if (!$Forums = $Cache->get_value('forums_list')) {
$DB->query("
SELECT
f.ID,
f.CategoryID,
f.Name,
f.Description,
f.MinClassRead,
f.MinClassWrite,
f.MinClassCreate,
f.NumTopics,
f.NumPosts,
f.LastPostID,
f.LastPostAuthorID,
f.LastPostTopicID,
f.LastPostTime,
COUNT(sr.ThreadID) AS SpecificRules,
t.Title,
t.IsLocked,
t.IsSticky
2011-10-31 08:00:12 +00:00
FROM forums AS f
2013-05-05 08:00:31 +00:00
JOIN forums_categories AS fc ON fc.ID = f.CategoryID
LEFT JOIN forums_topics as t ON t.ID = f.LastPostTopicID
LEFT JOIN forums_specific_rules AS sr ON sr.ForumID = f.ID
2011-10-31 08:00:12 +00:00
GROUP BY f.ID
2012-02-14 08:00:22 +00:00
ORDER BY fc.Sort, fc.Name, f.CategoryID, f.Sort");
2011-10-31 08:00:12 +00:00
$Forums = $DB->to_array('ID', MYSQLI_ASSOC, false);
2013-05-05 08:00:31 +00:00
foreach ($Forums as $ForumID => $Forum) {
if (count($Forum['SpecificRules'])) {
2011-10-31 08:00:12 +00:00
$DB->query("SELECT ThreadID FROM forums_specific_rules WHERE ForumID = ".$ForumID);
$ThreadIDs = $DB->collect('ThreadID');
$Forums[$ForumID]['SpecificRules'] = $ThreadIDs;
}
}
unset($ForumID, $Forum);
$Cache->cache_value('forums_list', $Forums, 0); //Inf cache.
}
2013-02-22 08:00:24 +00:00
2013-05-05 08:00:31 +00:00
if (empty($_GET['type']) || $_GET['type'] == 'main') {
2011-10-31 08:00:12 +00:00
include(SERVER_ROOT.'/sections/ajax/forum/main.php');
} else {
2013-05-01 08:00:16 +00:00
switch ($_GET['type']) {
2011-10-31 08:00:12 +00:00
case 'viewforum':
include(SERVER_ROOT.'/sections/ajax/forum/forum.php');
break;
case 'viewthread':
include(SERVER_ROOT.'/sections/ajax/forum/thread.php');
break;
default:
print json_encode(array('status' => 'failure'));
break;
}
}
}
// 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-05-05 08:00:31 +00:00
if (!$Forum) {
$DB->query("
SELECT
Name,
MinClassRead,
MinClassWrite,
MinClassCreate,
COUNT(forums_topics.ID) AS Topics
2011-10-31 08:00:12 +00:00
FROM forums
2013-05-05 08:00:31 +00:00
LEFT JOIN forums_topics ON forums_topics.ForumID=forums.ID
2011-10-31 08:00:12 +00:00
WHERE forums.ID='$ForumID'
GROUP BY ForumID");
2013-05-05 08:00:31 +00:00
if ($DB->record_count() == 0) {
2011-10-31 08:00:12 +00:00
return false;
}
// Makes an array, with $Forum['Name'], etc.
$Forum = $DB->next_record(MYSQLI_ASSOC);
2013-02-22 08:00:24 +00:00
2011-10-31 08:00:12 +00:00
$Cache->cache_value('ForumInfo_'.$ForumID, $Forum, 86400); // Cache for a day
}
return $Forum;
}
?>