2013-05-28 08:01:02 +00:00
|
|
|
<?php
|
2011-03-28 14:21:28 +00:00
|
|
|
/**********|| Page to show individual forums || ********************************\
|
|
|
|
|
|
|
|
Things to expect in $_GET:
|
|
|
|
ForumID: ID of the forum curently being browsed
|
|
|
|
page: The page the user's on.
|
|
|
|
page = 1 is the same as no page
|
|
|
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
//---------- Things to sort out before it can start printing/generating content
|
|
|
|
|
|
|
|
// Check for lame SQL injection attempts
|
|
|
|
$ForumID = $_GET['forumid'];
|
2013-04-19 08:00:55 +00:00
|
|
|
if (!is_number($ForumID)) {
|
2011-03-28 14:21:28 +00:00
|
|
|
error(0);
|
|
|
|
}
|
|
|
|
|
2013-08-28 23:08:41 +00:00
|
|
|
$IsDonorForum = $ForumID == DONOR_FORUM ? true : false;
|
|
|
|
$Tooltip = $ForumID == DONOR_FORUM ? "tooltip_gold" : "tooltip";
|
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
if (isset($LoggedUser['PostsPerPage'])) {
|
|
|
|
$PerPage = $LoggedUser['PostsPerPage'];
|
|
|
|
} else {
|
|
|
|
$PerPage = POSTS_PER_PAGE;
|
|
|
|
}
|
|
|
|
|
2013-05-28 08:01:02 +00:00
|
|
|
list($Page, $Limit) = Format::page_limit(TOPICS_PER_PAGE);
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
//---------- Get some data to start processing
|
|
|
|
|
2013-10-23 08:01:03 +00:00
|
|
|
// Caching anything beyond the first page of any given forum is just wasting RAM.
|
|
|
|
// Users are more likely to search than to browse to page 2.
|
2013-04-19 08:00:55 +00:00
|
|
|
if ($Page == 1) {
|
2013-07-17 08:00:52 +00:00
|
|
|
list($Forum,,,$Stickies) = $Cache->get_value("forums_$ForumID");
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-04-19 08:00:55 +00:00
|
|
|
if (!isset($Forum) || !is_array($Forum)) {
|
|
|
|
$DB->query("
|
|
|
|
SELECT
|
2013-11-17 08:00:47 +00:00
|
|
|
ID,
|
|
|
|
Title,
|
|
|
|
AuthorID,
|
|
|
|
IsLocked,
|
|
|
|
IsSticky,
|
|
|
|
NumPosts,
|
|
|
|
LastPostID,
|
|
|
|
LastPostTime,
|
|
|
|
LastPostAuthorID
|
|
|
|
FROM forums_topics
|
|
|
|
WHERE ForumID = '$ForumID'
|
|
|
|
ORDER BY Ranking = 0, Ranking ASC, IsSticky DESC, LastPostTime DESC
|
2011-03-28 14:21:28 +00:00
|
|
|
LIMIT $Limit"); // Can be cached until someone makes a new post
|
2013-07-17 08:00:52 +00:00
|
|
|
$Forum = $DB->to_array('ID', MYSQLI_ASSOC, false);
|
2013-05-16 16:15:57 +00:00
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
if ($Page == 1) {
|
2013-05-31 08:00:59 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT COUNT(ID)
|
|
|
|
FROM forums_topics
|
2013-07-17 08:00:52 +00:00
|
|
|
WHERE ForumID = '$ForumID'
|
|
|
|
AND IsSticky = '1'");
|
2011-03-28 14:21:28 +00:00
|
|
|
list($Stickies) = $DB->next_record();
|
2013-07-17 08:00:52 +00:00
|
|
|
$Cache->cache_value("forums_$ForumID", array($Forum, '', 0, $Stickies), 0);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
}
|
2013-02-10 08:00:29 +00:00
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
if (!isset($Forums[$ForumID])) {
|
|
|
|
error(404);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
// Make sure they're allowed to look at the page
|
|
|
|
if (!check_perms('site_moderate_forums')) {
|
2013-04-19 08:00:55 +00:00
|
|
|
if (isset($LoggedUser['CustomForums'][$ForumID]) && $LoggedUser['CustomForums'][$ForumID] === 0) {
|
|
|
|
error(403);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2012-03-28 08:00:20 +00:00
|
|
|
|
2013-03-24 08:00:39 +00:00
|
|
|
|
2012-06-16 08:00:18 +00:00
|
|
|
$ForumName = display_str($Forums[$ForumID]['Name']);
|
2013-08-28 23:08:41 +00:00
|
|
|
if (!Forums::check_forumperm($ForumID)) {
|
2013-04-19 08:00:55 +00:00
|
|
|
error(403);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
// Start printing
|
2013-08-28 23:08:41 +00:00
|
|
|
View::show_header('Forums > '. $Forums[$ForumID]['Name'], '', $IsDonorForum ? 'donor' : '');
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
|
|
|
<div class="thin">
|
2012-06-16 08:00:18 +00:00
|
|
|
<h2><a href="forums.php">Forums</a> > <?=$ForumName?></h2>
|
2011-03-28 14:21:28 +00:00
|
|
|
<div class="linkbox">
|
2013-08-28 23:08:41 +00:00
|
|
|
<? if (Forums::check_forumperm($ForumID, 'Write') && Forums::check_forumperm($ForumID, 'Create')) { ?>
|
2013-01-24 08:00:24 +00:00
|
|
|
<a href="forums.php?action=new&forumid=<?=$ForumID?>" class="brackets">New thread</a>
|
2011-03-28 14:21:28 +00:00
|
|
|
<? } ?>
|
2013-06-17 08:01:02 +00:00
|
|
|
<a href="#" onclick="$('#searchforum').gtoggle(); this.innerHTML = (this.innerHTML == 'Search this forum' ? 'Hide search' : 'Search this forum'); return false;" class="brackets">Search this forum</a>
|
2011-12-10 08:00:20 +00:00
|
|
|
<div id="searchforum" class="hidden center">
|
|
|
|
<div style="display: inline-block;">
|
|
|
|
<h3>Search this forum:</h3>
|
2012-09-15 08:00:25 +00:00
|
|
|
<form class="search_form" name="forum" action="forums.php" method="get">
|
2013-02-22 08:00:24 +00:00
|
|
|
<table cellpadding="6" cellspacing="1" border="0" class="layout border">
|
2011-12-10 08:00:20 +00:00
|
|
|
<tr>
|
2012-09-30 08:00:16 +00:00
|
|
|
<td>
|
|
|
|
<input type="hidden" name="action" value="search" />
|
|
|
|
<input type="hidden" name="forums[]" value="<?=$ForumID?>" />
|
2013-01-16 08:00:31 +00:00
|
|
|
<strong>Search for:</strong>
|
|
|
|
</td>
|
|
|
|
<td>
|
2014-03-23 08:00:50 +00:00
|
|
|
<input type="search" id="searchbox" name="search" size="70" />
|
2012-09-30 08:00:16 +00:00
|
|
|
</td>
|
2011-12-10 08:00:20 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Search in:</strong></td>
|
|
|
|
<td>
|
2013-02-22 08:00:24 +00:00
|
|
|
<input type="radio" name="type" id="type_title" value="title" checked="checked" />
|
2011-12-10 08:00:20 +00:00
|
|
|
<label for="type_title">Titles</label>
|
2013-02-22 08:00:24 +00:00
|
|
|
<input type="radio" name="type" id="type_body" value="body" />
|
2011-12-10 08:00:20 +00:00
|
|
|
<label for="type_body">Post bodies</label>
|
|
|
|
</td>
|
2012-09-30 08:00:16 +00:00
|
|
|
</tr>
|
2011-12-10 08:00:20 +00:00
|
|
|
<tr>
|
2014-03-23 08:00:50 +00:00
|
|
|
<td><strong>Posted by:</strong></td>
|
|
|
|
<td><input type="search" id="username" name="user" placeholder="Username" size="70" /></td>
|
2011-12-10 08:00:20 +00:00
|
|
|
</tr>
|
2012-09-30 08:00:16 +00:00
|
|
|
<tr>
|
2014-03-23 08:00:50 +00:00
|
|
|
<td colspan="2" style="text-align: center;">
|
|
|
|
<input type="submit" name="submit" value="Search" />
|
|
|
|
</td>
|
2012-09-30 08:00:16 +00:00
|
|
|
</tr>
|
2011-12-10 08:00:20 +00:00
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
<br />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2013-04-19 08:00:55 +00:00
|
|
|
<? if (check_perms('site_moderate_forums')) { ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
<div class="linkbox">
|
2013-01-24 08:00:24 +00:00
|
|
|
<a href="forums.php?action=edit_rules&forumid=<?=$ForumID?>" class="brackets">Change specific rules</a>
|
2011-03-28 14:21:28 +00:00
|
|
|
</div>
|
2013-04-19 08:00:55 +00:00
|
|
|
<? } ?>
|
|
|
|
<? if (!empty($Forums[$ForumID]['SpecificRules'])) { ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
<div class="linkbox">
|
|
|
|
<strong>Forum Specific Rules</strong>
|
2013-04-19 08:00:55 +00:00
|
|
|
<? foreach ($Forums[$ForumID]['SpecificRules'] as $ThreadIDs) {
|
2013-08-28 23:08:41 +00:00
|
|
|
$Thread = Forums::get_thread_info($ThreadIDs);
|
2013-10-01 23:08:42 +00:00
|
|
|
if ($Thread === null) {
|
|
|
|
error(404);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
|
|
|
<br />
|
2013-01-24 08:00:24 +00:00
|
|
|
<a href="forums.php?action=viewthread&threadid=<?=$ThreadIDs?>" class="brackets"><?=display_str($Thread['Title'])?></a>
|
2013-04-19 08:00:55 +00:00
|
|
|
<? } ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
</div>
|
2013-04-19 08:00:55 +00:00
|
|
|
<? } ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
<div class="linkbox pager">
|
|
|
|
<?
|
2013-05-15 08:00:54 +00:00
|
|
|
$Pages = Format::get_pages($Page, $Forums[$ForumID]['NumTopics'], TOPICS_PER_PAGE, 9);
|
2011-03-28 14:21:28 +00:00
|
|
|
echo $Pages;
|
|
|
|
?>
|
|
|
|
</div>
|
2012-11-06 08:00:20 +00:00
|
|
|
<table class="forum_index" width="100%">
|
2011-03-28 14:21:28 +00:00
|
|
|
<tr class="colhead">
|
2013-04-19 08:00:55 +00:00
|
|
|
<td style="width: 2%;"></td>
|
2011-03-28 14:21:28 +00:00
|
|
|
<td>Latest</td>
|
2013-04-19 08:00:55 +00:00
|
|
|
<td style="width: 7%;">Replies</td>
|
|
|
|
<td style="width: 14%;">Author</td>
|
2011-03-28 14:21:28 +00:00
|
|
|
</tr>
|
|
|
|
<?
|
|
|
|
// Check that we have content to process
|
2013-07-17 08:00:52 +00:00
|
|
|
if (count($Forum) === 0) {
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
|
|
|
<tr>
|
|
|
|
<td colspan="4">
|
|
|
|
No threads to display in this forum!
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?
|
|
|
|
} else {
|
|
|
|
// forums_last_read_topics is a record of the last post a user read in a topic, and what page that was on
|
2013-07-17 08:00:52 +00:00
|
|
|
$DB->query("
|
2013-04-19 08:00:55 +00:00
|
|
|
SELECT
|
|
|
|
l.TopicID,
|
|
|
|
l.PostID,
|
2013-07-17 08:00:52 +00:00
|
|
|
CEIL((
|
2013-11-17 08:00:47 +00:00
|
|
|
SELECT COUNT(p.ID)
|
|
|
|
FROM forums_posts AS p
|
|
|
|
WHERE p.TopicID = l.TopicID
|
|
|
|
AND p.ID <= l.PostID
|
2013-07-17 08:00:52 +00:00
|
|
|
) / $PerPage
|
|
|
|
) AS Page
|
2011-03-28 14:21:28 +00:00
|
|
|
FROM forums_last_read_topics AS l
|
2013-11-17 08:00:47 +00:00
|
|
|
WHERE l.TopicID IN (".implode(', ', array_keys($Forum)).')
|
|
|
|
AND l.UserID = \''.$LoggedUser['ID'].'\'');
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
$Row = 'a';
|
|
|
|
foreach ($Forum as $Topic) {
|
2012-03-28 08:00:20 +00:00
|
|
|
list($TopicID, $Title, $AuthorID, $Locked, $Sticky, $PostCount, $LastID, $LastTime, $LastAuthorID) = array_values($Topic);
|
2013-07-17 08:00:52 +00:00
|
|
|
$Row = $Row === 'a' ? 'b' : 'a';
|
|
|
|
// Build list of page links
|
2011-03-28 14:21:28 +00:00
|
|
|
// Only do this if there is more than one page
|
|
|
|
$PageLinks = array();
|
|
|
|
$ShownEllipses = false;
|
|
|
|
$PagesText = '';
|
2013-07-17 08:00:52 +00:00
|
|
|
$TopicPages = ceil($PostCount / $PerPage);
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
if ($TopicPages > 1) {
|
|
|
|
$PagesText = ' (';
|
|
|
|
for ($i = 1; $i <= $TopicPages; $i++) {
|
|
|
|
if ($TopicPages > 4 && ($i > 2 && $i <= $TopicPages - 2)) {
|
|
|
|
if (!$ShownEllipses) {
|
|
|
|
$PageLinks[] = '-';
|
2011-03-28 14:21:28 +00:00
|
|
|
$ShownEllipses = true;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2013-07-17 08:00:52 +00:00
|
|
|
$PageLinks[] = "<a href=\"forums.php?action=viewthread&threadid=$TopicID&page=$i\">$i</a>";
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-07-17 08:00:52 +00:00
|
|
|
$PagesText .= implode(' ', $PageLinks);
|
|
|
|
$PagesText .= ')';
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// handle read/unread posts - the reason we can't cache the whole page
|
2013-04-19 08:00:55 +00:00
|
|
|
if ((!$Locked || $Sticky) && ((empty($LastRead[$TopicID]) || $LastRead[$TopicID]['PostID'] < $LastID) && strtotime($LastTime) > $LoggedUser['CatchupTime'])) {
|
2011-03-28 14:21:28 +00:00
|
|
|
$Read = 'unread';
|
|
|
|
} else {
|
|
|
|
$Read = 'read';
|
|
|
|
}
|
2013-04-19 08:00:55 +00:00
|
|
|
if ($Locked) {
|
|
|
|
$Read .= '_locked';
|
|
|
|
}
|
|
|
|
if ($Sticky) {
|
|
|
|
$Read .= '_sticky';
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
|
|
|
<tr class="row<?=$Row?>">
|
2013-08-28 23:08:41 +00:00
|
|
|
<td class="<?=$Read?> <?=$Tooltip?>" title="<?=ucwords(str_replace('_', ' ', $Read))?>"></td>
|
2011-03-28 14:21:28 +00:00
|
|
|
<td>
|
2013-04-19 08:00:55 +00:00
|
|
|
<span style="float: left;" class="last_topic">
|
2011-03-28 14:21:28 +00:00
|
|
|
<?
|
2013-04-19 08:00:55 +00:00
|
|
|
$TopicLength = 75 - (2 * count($PageLinks));
|
2011-03-28 14:21:28 +00:00
|
|
|
unset($PageLinks);
|
2013-02-11 08:00:34 +00:00
|
|
|
$Title = display_str($Title);
|
|
|
|
$DisplayTitle = $Title;
|
2013-05-16 16:15:57 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
|
|
|
<strong>
|
2013-08-28 23:08:41 +00:00
|
|
|
<a href="forums.php?action=viewthread&threadid=<?=$TopicID?>" class="tooltip" data-title-plain="<?=$Title?>"><?=Format::cut_string($DisplayTitle, $TopicLength) ?></a>
|
2011-03-28 14:21:28 +00:00
|
|
|
</strong>
|
|
|
|
<?=$PagesText?>
|
|
|
|
</span>
|
2013-04-19 08:00:55 +00:00
|
|
|
<? if (!empty($LastRead[$TopicID])) { ?>
|
2013-08-28 23:08:41 +00:00
|
|
|
<span style="float: left;" class="<?=$Tooltip?> last_read" title="Jump to last read">
|
2011-03-28 14:21:28 +00:00
|
|
|
<a href="forums.php?action=viewthread&threadid=<?=$TopicID?>&page=<?=$LastRead[$TopicID]['Page']?>#post<?=$LastRead[$TopicID]['PostID']?>"></a>
|
|
|
|
</span>
|
|
|
|
<? } ?>
|
2013-04-19 08:00:55 +00:00
|
|
|
<span style="float: right;" class="last_poster">
|
2013-08-28 23:08:41 +00:00
|
|
|
by <?=Users::format_username($LastAuthorID, false, false, false, false, false, $IsDonorForum)?> <?=time_diff($LastTime,1)?>
|
2011-03-28 14:21:28 +00:00
|
|
|
</span>
|
|
|
|
</td>
|
2013-08-28 23:08:41 +00:00
|
|
|
<td class="number_column"><?=number_format($PostCount - 1)?></td>
|
|
|
|
<td><?=Users::format_username($AuthorID, false, false, false, false, false, $IsDonorForum)?></td>
|
2011-03-28 14:21:28 +00:00
|
|
|
</tr>
|
|
|
|
<? }
|
|
|
|
} ?>
|
|
|
|
</table>
|
2011-12-13 08:00:17 +00:00
|
|
|
<!--<div class="breadcrumbs">
|
2012-06-16 08:00:18 +00:00
|
|
|
<a href="forums.php">Forums</a> > <?=$ForumName?>
|
2011-12-13 08:00:17 +00:00
|
|
|
</div>-->
|
2011-03-28 14:21:28 +00:00
|
|
|
<div class="linkbox pager">
|
|
|
|
<?=$Pages?>
|
|
|
|
</div>
|
2013-01-24 08:00:24 +00:00
|
|
|
<div class="linkbox"><a href="forums.php?action=catchup&forumid=<?=$ForumID?>&auth=<?=$LoggedUser['AuthKey']?>" class="brackets">Catch up</a></div>
|
2011-03-28 14:21:28 +00:00
|
|
|
</div>
|
2012-10-11 08:00:15 +00:00
|
|
|
<? View::show_footer(); ?>
|