Gazelle/sections/ajax/forum/main.php

95 lines
2.8 KiB
PHP
Raw Normal View History

2011-10-31 08:00:12 +00:00
<?
2011-11-26 08:00:20 +00:00
authorize(true);
2011-10-31 08:00:12 +00:00
if (isset($LoggedUser['PostsPerPage'])) {
$PerPage = $LoggedUser['PostsPerPage'];
} else {
$PerPage = POSTS_PER_PAGE;
}
//We have to iterate here because if one is empty it breaks the query
$TopicIDs = array();
foreach($Forums as $Forum) {
if (!empty($Forum['LastPostTopicID'])) {
$TopicIDs[]=$Forum['LastPostTopicID'];
}
}
//Now if we have IDs' we run the query
if(!empty($TopicIDs)) {
$DB->query("SELECT
l.TopicID,
l.PostID,
CEIL((SELECT COUNT(ID) FROM forums_posts WHERE forums_posts.TopicID = l.TopicID AND forums_posts.ID<=l.PostID)/$PerPage) AS Page
FROM forums_last_read_topics AS l
WHERE TopicID IN(".implode(',',$TopicIDs).") AND
UserID='$LoggedUser[ID]'");
$LastRead = $DB->to_array('TopicID', MYSQLI_ASSOC);
} else {
$LastRead = array();
}
$DB->query("SELECT RestrictedForums FROM users_info WHERE UserID = ".$LoggedUser['ID']);
list($RestrictedForums) = $DB->next_record();
$RestrictedForums = explode(',', $RestrictedForums);
$PermittedForums = array_keys($LoggedUser['PermittedForums']);
$JsonCategories = array();
$JsonCategory = array();
$JsonForums = array();
foreach ($Forums as $Forum) {
2012-03-28 08:00:20 +00:00
list($ForumID, $CategoryID, $ForumName, $ForumDescription, $MinRead, $MinWrite, $MinCreate, $NumTopics, $NumPosts, $LastPostID, $LastAuthorID, $LastTopicID, $LastTime, $SpecificRules, $LastTopic, $Locked, $Sticky) = array_values($Forum);
2011-10-31 08:00:12 +00:00
if ($LoggedUser['CustomForums'][$ForumID] != 1 && ($MinRead>$LoggedUser['Class'] || array_search($ForumID, $RestrictedForums) !== FALSE)) {
continue;
}
$ForumDescription = display_str($ForumDescription);
if($CategoryID!=$LastCategoryID) {
if (!empty($JsonForums) && !empty($JsonCategory)) {
$JsonCategory['forums'] = $JsonForums;
$JsonCategories[] = $JsonCategory;
}
$LastCategoryID = $CategoryID;
$JsonCategory = array(
2011-11-26 08:00:20 +00:00
'categoryID' => (int) $CategoryID,
2011-10-31 08:00:12 +00:00
'categoryName' => $ForumCats[$CategoryID]
);
$JsonForums = array();
}
if((!$Locked || $Sticky) && $LastPostID != 0 && ((empty($LastRead[$LastTopicID]) || $LastRead[$LastTopicID]['PostID'] < $LastPostID) && strtotime($LastTime)>$LoggedUser['CatchupTime'])) {
$Read = 'unread';
} else {
$Read = 'read';
}
2012-03-28 08:00:20 +00:00
$UserInfo = user_info($LastAuthorID);
2011-10-31 08:00:12 +00:00
$JsonForums[] = array(
2011-11-26 08:00:20 +00:00
'forumId' => (int) $ForumID,
2011-10-31 08:00:12 +00:00
'forumName' => $ForumName,
'forumDescription' => $ForumDescription,
2011-11-26 08:00:20 +00:00
'numTopics' => (float) $NumTopics,
'numPosts' => (float) $NumPosts,
'lastPostId' => (float) $LastPostID,
'lastAuthorId' => (float) $LastAuthorID,
2012-03-28 08:00:20 +00:00
'lastPostAuthorName' => $UserInfo['Username'],
2011-11-26 08:00:20 +00:00
'lastTopicId' => (float) $LastTopicID,
2011-10-31 08:00:12 +00:00
'lastTime' => $LastTime,
'specificRules' => $SpecificRules,
'lastTopic' => $LastTopic,
2011-11-26 08:00:20 +00:00
'read' => $Read == 1,
'locked' => $Locked == 1,
'sticky' => $Sticky == 1
2011-10-31 08:00:12 +00:00
);
}
print json_encode(
array(
'status' => 'success',
'response' => array(
'categories' => $JsonCategories
)
)
);