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();
|
2013-04-13 08:00:19 +00:00
|
|
|
foreach ($Forums as $Forum) {
|
2011-10-31 08:00:12 +00:00
|
|
|
if (!empty($Forum['LastPostTopicID'])) {
|
2013-04-13 08:00:19 +00:00
|
|
|
$TopicIDs[] = $Forum['LastPostTopicID'];
|
2011-10-31 08:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Now if we have IDs' we run the query
|
2013-04-13 08:00:19 +00:00
|
|
|
if (!empty($TopicIDs)) {
|
2013-06-04 08:00:34 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
l.TopicID,
|
|
|
|
l.PostID,
|
2013-11-17 08:00:47 +00:00
|
|
|
CEIL(
|
|
|
|
(
|
|
|
|
SELECT COUNT(p.ID)
|
|
|
|
FROM forums_posts AS p
|
|
|
|
WHERE p.TopicID = l.TopicID
|
|
|
|
AND p.ID <= l.PostID
|
|
|
|
) / $PerPage
|
|
|
|
) AS Page
|
2011-10-31 08:00:12 +00:00
|
|
|
FROM forums_last_read_topics AS l
|
2013-11-17 08:00:47 +00:00
|
|
|
WHERE l.TopicID IN(".implode(',', $TopicIDs).")
|
2013-11-19 08:00:48 +00:00
|
|
|
AND l.UserID = '$LoggedUser[ID]'");
|
2011-10-31 08:00:12 +00:00
|
|
|
$LastRead = $DB->to_array('TopicID', MYSQLI_ASSOC);
|
|
|
|
} else {
|
|
|
|
$LastRead = array();
|
|
|
|
}
|
|
|
|
|
2013-06-04 08:00:34 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT RestrictedForums
|
|
|
|
FROM users_info
|
|
|
|
WHERE UserID = ".$LoggedUser['ID']);
|
2011-10-31 08:00:12 +00:00
|
|
|
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);
|
2013-10-30 08:01:19 +00:00
|
|
|
if ($LoggedUser['CustomForums'][$ForumID] != 1
|
2013-11-19 08:00:48 +00:00
|
|
|
&& ($MinRead > $LoggedUser['Class']
|
2013-10-30 08:01:19 +00:00
|
|
|
|| array_search($ForumID, $RestrictedForums) !== false)
|
|
|
|
) {
|
2011-10-31 08:00:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$ForumDescription = display_str($ForumDescription);
|
|
|
|
|
2013-04-13 08:00:19 +00:00
|
|
|
if ($CategoryID != $LastCategoryID) {
|
2011-10-31 08:00:12 +00:00
|
|
|
if (!empty($JsonForums) && !empty($JsonCategory)) {
|
|
|
|
$JsonCategory['forums'] = $JsonForums;
|
|
|
|
$JsonCategories[] = $JsonCategory;
|
|
|
|
}
|
|
|
|
$LastCategoryID = $CategoryID;
|
|
|
|
$JsonCategory = array(
|
2013-10-30 08:01:19 +00:00
|
|
|
'categoryID' => (int)$CategoryID,
|
2011-10-31 08:00:12 +00:00
|
|
|
'categoryName' => $ForumCats[$CategoryID]
|
|
|
|
);
|
|
|
|
$JsonForums = array();
|
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-10-30 08:01:19 +00:00
|
|
|
if ((!$Locked || $Sticky)
|
|
|
|
&& $LastPostID != 0
|
|
|
|
&& ((empty($LastRead[$LastTopicID]) || $LastRead[$LastTopicID]['PostID'] < $LastPostID)
|
|
|
|
&& strtotime($LastTime) > $LoggedUser['CatchupTime'])
|
|
|
|
) {
|
2011-10-31 08:00:12 +00:00
|
|
|
$Read = 'unread';
|
|
|
|
} else {
|
|
|
|
$Read = 'read';
|
|
|
|
}
|
2012-10-11 08:00:15 +00:00
|
|
|
$UserInfo = Users::user_info($LastAuthorID);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-10-31 08:00:12 +00:00
|
|
|
$JsonForums[] = array(
|
2013-10-30 08:01:19 +00:00
|
|
|
'forumId' => (int)$ForumID,
|
2011-10-31 08:00:12 +00:00
|
|
|
'forumName' => $ForumName,
|
|
|
|
'forumDescription' => $ForumDescription,
|
2013-10-30 08:01:19 +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'],
|
2013-10-30 08:01:19 +00:00
|
|
|
'lastTopicId' => (float)$LastTopicID,
|
2011-10-31 08:00:12 +00:00
|
|
|
'lastTime' => $LastTime,
|
|
|
|
'specificRules' => $SpecificRules,
|
2012-06-16 08:00:18 +00:00
|
|
|
'lastTopic' => display_str($LastTopic),
|
2013-10-30 08:01:19 +00:00
|
|
|
'read' => $Read == 1,
|
|
|
|
'locked' => $Locked == 1,
|
|
|
|
'sticky' => $Sticky == 1
|
2011-10-31 08:00:12 +00:00
|
|
|
);
|
|
|
|
}
|
2012-07-22 08:00:16 +00:00
|
|
|
// ...And an extra one to catch the last category.
|
|
|
|
if (!empty($JsonForums) && !empty($JsonCategory)) {
|
|
|
|
$JsonCategory['forums'] = $JsonForums;
|
|
|
|
$JsonCategories[] = $JsonCategory;
|
|
|
|
}
|
2011-10-31 08:00:12 +00:00
|
|
|
|
|
|
|
print json_encode(
|
|
|
|
array(
|
|
|
|
'status' => 'success',
|
|
|
|
'response' => array(
|
|
|
|
'categories' => $JsonCategories
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|