// Check that we have content to process
if (count($Forum) === 0) {
?>
No threads to display in this forum!
} else {
// forums_last_read_topics is a record of the last post a user read in a topic, and what page that was on
$DB->query("
SELECT
l.TopicID,
l.PostID,
CEIL((
SELECT COUNT(p.ID)
FROM forums_posts AS p
WHERE p.TopicID = l.TopicID
AND p.ID <= l.PostID
) / $PerPage
) AS Page
FROM forums_last_read_topics AS l
WHERE l.TopicID IN (".implode(', ', array_keys($Forum)).')
AND l.UserID = \''.$LoggedUser['ID'].'\'');
// Turns the result set into a multi-dimensional array, with
// forums_last_read_topics.TopicID as the key.
// This is done here so we get the benefit of the caching, and we
// don't have to make a database query for each topic on the page
$LastRead = $DB->to_array('TopicID');
//---------- Begin printing
foreach ($Forum as $Topic) {
list($TopicID, $Title, $AuthorID, $Locked, $Sticky, $PostCount, $LastID, $LastTime, $LastAuthorID) = array_values($Topic);
// Build list of page links
// Only do this if there is more than one page
$PageLinks = array();
$ShownEllipses = false;
$PagesText = '';
$TopicPages = ceil($PostCount / $PerPage);
if ($TopicPages > 1) {
$PagesText = ' (';
for ($i = 1; $i <= $TopicPages; $i++) {
if ($TopicPages > 4 && ($i > 2 && $i <= $TopicPages - 2)) {
if (!$ShownEllipses) {
$PageLinks[] = '-';
$ShownEllipses = true;
}
continue;
}
$PageLinks[] = "$i";
}
$PagesText .= implode(' ', $PageLinks);
$PagesText .= ')';
}
// handle read/unread posts - the reason we can't cache the whole page
if ((!$Locked || $Sticky) && ((empty($LastRead[$TopicID]) || $LastRead[$TopicID]['PostID'] < $LastID) && strtotime($LastTime) > $LoggedUser['CatchupTime'])) {
$Read = 'unread';
} else {
$Read = 'read';
}
if ($Locked) {
$Read .= '_locked';
}
if ($Sticky) {
$Read .= '_sticky';
}
?>