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'];
|
|
|
|
if(!is_number($ForumID)) {
|
|
|
|
error(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($LoggedUser['PostsPerPage'])) {
|
|
|
|
$PerPage = $LoggedUser['PostsPerPage'];
|
|
|
|
} else {
|
|
|
|
$PerPage = POSTS_PER_PAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
list($Page,$Limit) = page_limit(TOPICS_PER_PAGE);
|
|
|
|
|
|
|
|
//---------- Get some data to start processing
|
|
|
|
|
|
|
|
// Caching anything beyond the first page of any given forum is just wasting ram
|
|
|
|
// users are more likely to search then to browse to page 2
|
|
|
|
if($Page==1) {
|
|
|
|
list($Forum,,,$Stickies) = $Cache->get_value('forums_'.$ForumID);
|
|
|
|
}
|
|
|
|
if(!isset($Forum) || !is_array($Forum)) {
|
|
|
|
$DB->query("SELECT
|
|
|
|
t.ID,
|
|
|
|
t.Title,
|
|
|
|
t.AuthorID,
|
|
|
|
t.IsLocked,
|
|
|
|
t.IsSticky,
|
|
|
|
t.NumPosts,
|
|
|
|
t.LastPostID,
|
|
|
|
t.LastPostTime,
|
2012-03-28 08:00:20 +00:00
|
|
|
t.LastPostAuthorID
|
2011-03-28 14:21:28 +00:00
|
|
|
FROM forums_topics AS t
|
|
|
|
WHERE t.ForumID = '$ForumID'
|
|
|
|
ORDER BY t.IsSticky DESC, t.LastPostTime DESC
|
|
|
|
LIMIT $Limit"); // Can be cached until someone makes a new post
|
2012-06-16 08:00:18 +00:00
|
|
|
$Forum = $DB->to_array('ID',MYSQLI_ASSOC, false);
|
2011-03-28 14:21:28 +00:00
|
|
|
if($Page==1) {
|
|
|
|
$DB->query("SELECT COUNT(ID) FROM forums_topics WHERE ForumID='$ForumID' AND IsSticky='1'");
|
|
|
|
list($Stickies) = $DB->next_record();
|
|
|
|
$Cache->cache_value('forums_'.$ForumID, array($Forum,'',0,$Stickies), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!isset($Forums[$ForumID])) { error(404); }
|
|
|
|
// Make sure they're allowed to look at the page
|
|
|
|
if (!check_perms('site_moderate_forums')) {
|
2011-10-11 08:00:15 +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
|
|
|
|
2012-06-16 08:00:18 +00:00
|
|
|
$ForumName = display_str($Forums[$ForumID]['Name']);
|
2011-10-11 08:00:15 +00:00
|
|
|
if($LoggedUser['CustomForums'][$ForumID] != 1 && $Forums[$ForumID]['MinClassRead'] > $LoggedUser['Class']) { error(403); }
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
// Start printing
|
|
|
|
show_header('Forums > '. $Forums[$ForumID]['Name']);
|
|
|
|
?>
|
|
|
|
<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">
|
2011-12-10 08:00:20 +00:00
|
|
|
<? if(check_forumperm($ForumID, 'Write') && check_forumperm($ForumID, 'Create')){ ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
[<a href="forums.php?action=new&forumid=<?=$ForumID?>">New Thread</a>]
|
|
|
|
<? } ?>
|
2011-12-10 08:00:20 +00:00
|
|
|
[<a href="#" onclick="$('#searchforum').toggle(); this.innerHTML = (this.innerHTML == 'Search this Forum'?'Hide Search':'Search this Forum'); return false;">Search this Forum</a>]
|
|
|
|
<div id="searchforum" class="hidden center">
|
|
|
|
<div style="display: inline-block;">
|
|
|
|
<h3>Search this forum:</h3>
|
|
|
|
<form action="forums.php" method="get">
|
2012-09-01 08:00:24 +00:00
|
|
|
<table cellpadding="6" cellspacing="1" border="0" class="layout border">
|
2011-12-10 08:00:20 +00:00
|
|
|
<input type="hidden" name="action" value="search" />
|
|
|
|
<input type="hidden" name="forums[]" value="<?=$ForumID?>" />
|
|
|
|
<tr>
|
|
|
|
<td><strong>Search for:</strong></td><td><input type="text" id="searchbox" name="search" size="70" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Search in:</strong></td>
|
|
|
|
<td>
|
|
|
|
<input type="radio" name="type" id="type_title" value="title" checked="checked" />
|
|
|
|
<label for="type_title">Titles</label>
|
|
|
|
<input type="radio" name="type" id="type_body" value="body" />
|
|
|
|
<label for="type_body">Post bodies</label>
|
|
|
|
</td>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Username:</strong></td><td><input type="text" id="username" name="user" size="70" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr><td colspan="2" style="text-align: center"><input type="submit" name="submit" value="Search" /></td></tr>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
<br />
|
|
|
|
</div>
|
|
|
|
</div>
|
2012-09-13 08:00:20 +00:00
|
|
|
<?
|
|
|
|
/*
|
2012-09-12 08:00:27 +00:00
|
|
|
if(check_perms('users_mod')) {
|
|
|
|
$DB->query("SELECT ForumID from subscribed_forums WHERE ForumID='$ForumID' AND SubscriberID='$LoggedUser[ID]'");
|
|
|
|
if($DB->record_count() == 0) { ?>
|
|
|
|
[<a href="forums.php?action=forum_subscribe&perform=add&forumid=<?=$ForumID?>&auth=<?=$LoggedUser['AuthKey']?>">Subscribe to Forum</a>]
|
|
|
|
<? } else { ?>
|
|
|
|
[<a href="forums.php?action=forum_subscribe&perform=remove&forumid=<?=$ForumID?>&auth=<?=$LoggedUser['AuthKey']?>">Unsubscribe from Forum</a>]
|
|
|
|
<? }
|
2012-09-13 08:00:20 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
?>
|
2012-09-12 08:00:27 +00:00
|
|
|
|
2011-12-10 08:00:20 +00:00
|
|
|
</div>
|
2011-03-28 14:21:28 +00:00
|
|
|
<? if(check_perms('site_moderate_forums')) { ?>
|
|
|
|
<div class="linkbox">
|
|
|
|
<a href="forums.php?action=edit_rules&forumid=<?=$ForumID?>">Change specific rules</a>
|
|
|
|
</div>
|
|
|
|
<? } ?>
|
|
|
|
<? if(!empty($Forums[$ForumID]['SpecificRules'])) { ?>
|
|
|
|
<div class="linkbox">
|
|
|
|
<strong>Forum Specific Rules</strong>
|
|
|
|
<? foreach($Forums[$ForumID]['SpecificRules'] as $ThreadIDs) {
|
|
|
|
$Thread = get_thread_info($ThreadIDs);
|
|
|
|
?>
|
|
|
|
<br />
|
2012-06-16 08:00:18 +00:00
|
|
|
[<a href="forums.php?action=viewthread&threadid=<?=$ThreadIDs?>"><?=display_str($Thread['Title'])?></a>]
|
2011-03-28 14:21:28 +00:00
|
|
|
<? } ?>
|
|
|
|
</div>
|
|
|
|
<? } ?>
|
|
|
|
<div class="linkbox pager">
|
|
|
|
<?
|
|
|
|
$Pages=get_pages($Page,$Forums[$ForumID]['NumTopics'],TOPICS_PER_PAGE,9);
|
|
|
|
echo $Pages;
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
<table class="forum_list" width="100%">
|
|
|
|
<tr class="colhead">
|
|
|
|
<td style="width:2%;"></td>
|
|
|
|
<td>Latest</td>
|
|
|
|
<td style="width:7%;">Replies</td>
|
|
|
|
<td style="width:14%;">Author</td>
|
|
|
|
</tr>
|
|
|
|
<?
|
|
|
|
// Check that we have content to process
|
|
|
|
if (count($Forum) == 0) {
|
|
|
|
?>
|
|
|
|
<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
|
|
|
|
$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(', ', array_keys($Forum)).') AND
|
|
|
|
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
|
|
|
|
|
|
|
|
$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);
|
2011-03-28 14:21:28 +00:00
|
|
|
$Row = ($Row == 'a') ? 'b' : 'a';
|
|
|
|
|
|
|
|
// 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[]='<a href="forums.php?action=viewthread&threadid='.$TopicID.'&page='.$i.'">'.$i.'</a>';
|
|
|
|
}
|
|
|
|
$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"; }
|
|
|
|
?>
|
|
|
|
<tr class="row<?=$Row?>">
|
|
|
|
<td class="<?=$Read?>" title="<?=ucwords(str_replace('_',' ',$Read))?>"></td>
|
|
|
|
<td>
|
|
|
|
<span style="float:left;" class="last_topic">
|
|
|
|
<?
|
|
|
|
$TopicLength=75-(2*count($PageLinks));
|
|
|
|
unset($PageLinks);
|
|
|
|
?>
|
|
|
|
<strong>
|
|
|
|
<a href="forums.php?action=viewthread&threadid=<?=$TopicID?>" title="<?=display_str($Title)?>"><?=display_str(cut_string($Title, $TopicLength)) ?></a>
|
|
|
|
</strong>
|
|
|
|
<?=$PagesText?>
|
|
|
|
</span>
|
|
|
|
<? if(!empty($LastRead[$TopicID])) { ?>
|
|
|
|
<span style="float: left;" class="last_read" title="Jump to last read">
|
|
|
|
<a href="forums.php?action=viewthread&threadid=<?=$TopicID?>&page=<?=$LastRead[$TopicID]['Page']?>#post<?=$LastRead[$TopicID]['PostID']?>"></a>
|
|
|
|
</span>
|
|
|
|
<? } ?>
|
|
|
|
<span style="float:right;" class="last_poster">
|
2012-03-28 08:00:20 +00:00
|
|
|
by <?=format_username($LastAuthorID, false, false, false)?> <?=time_diff($LastTime,1)?>
|
2011-03-28 14:21:28 +00:00
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
<td><?=number_format($PostCount-1)?></td>
|
2012-03-28 08:00:20 +00:00
|
|
|
<td><?=format_username($AuthorID, false, false, false)?></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>
|
|
|
|
<div class="linkbox">[<a href="forums.php?action=catchup&forumid=<?=$ForumID?>&auth=<?=$LoggedUser['AuthKey']?>">Catch up</a>]</div>
|
|
|
|
</div>
|
|
|
|
<? show_footer(); ?>
|