Gazelle/sections/forums/main.php

112 lines
3.8 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +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();
}
show_header('Forums');
?>
<div class="thin">
<h2>Forums</h2>
<?
$Row = 'a';
$LastCategoryID=0;
$OpenTable = false;
$DB->query("SELECT RestrictedForums FROM users_info WHERE UserID = ".$LoggedUser['ID']);
list($RestrictedForums) = $DB->next_record();
$RestrictedForums = explode(',', $RestrictedForums);
2011-10-11 08:00:15 +00:00
$PermittedForums = array_keys($LoggedUser['PermittedForums']);
2011-03-28 14:21:28 +00:00
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-11 08:00:15 +00:00
if ($LoggedUser['CustomForums'][$ForumID] != 1 && ($MinRead>$LoggedUser['Class'] || array_search($ForumID, $RestrictedForums) !== FALSE)) {
2011-03-28 14:21:28 +00:00
continue;
}
$Row = ($Row == 'a') ? 'b' : 'a';
$ForumDescription = display_str($ForumDescription);
if($CategoryID!=$LastCategoryID) {
2012-02-13 08:00:23 +00:00
$Row = 'b';
2011-03-28 14:21:28 +00:00
$LastCategoryID=$CategoryID;
if($OpenTable) { ?>
</table>
<? } ?>
<h3><?=$ForumCats[$CategoryID]?></h3>
<table class="forum_index">
<tr class="colhead">
<td style="width:2%;"></td>
<td style="width:25%;">Forum</td>
<td>Last Post</td>
<td style="width:7%;">Topics</td>
<td style="width:7%;">Posts</td>
</tr>
<?
$OpenTable = true;
}
if((!$Locked || $Sticky) && $LastPostID != 0 && ((empty($LastRead[$LastTopicID]) || $LastRead[$LastTopicID]['PostID'] < $LastPostID) && strtotime($LastTime)>$LoggedUser['CatchupTime'])) {
$Read = 'unread';
} else {
$Read = 'read';
}
/* Removed per request, as distracting
if($Locked) { $Read .= "_locked"; }
if($Sticky) { $Read .= "_sticky"; }
*/
?>
<tr class="row<?=$Row?>">
<td class="<?=$Read?>" title="<?=ucfirst($Read)?>"></td>
<td>
<h4 class="min_padding">
<a href="forums.php?action=viewforum&amp;forumid=<?=$ForumID?>" title="<?=display_str($ForumDescription)?>"><?=display_str($ForumName)?></a>
</h4>
</td>
<? if ($NumPosts == 0) { ?>
<td colspan="3">
There are no topics here<?=($MinCreate<=$LoggedUser['Class']) ? ', <a href="forums.php?action=new&amp;forumid='.$ForumID.'">'.'create one'.'</a>' : ''?>.
</td>
<? } else { ?>
<td>
<span style="float:left;" class="last_topic">
<a href="forums.php?action=viewthread&amp;threadid=<?=$LastTopicID?>" title="<?=display_str($LastTopic)?>"><?=display_str(cut_string($LastTopic, 50, 1))?></a>
</span>
<? if (!empty($LastRead[$LastTopicID])) { ?>
<span style="float: left;" class="last_read" title="Jump to last read">
<a href="forums.php?action=viewthread&amp;threadid=<?=$LastTopicID?>&amp;page=<?=$LastRead[$LastTopicID]['Page']?>#post<?=$LastRead[$LastTopicID]['PostID']?>"></a>
</span>
<? } ?>
2012-03-28 08:00:20 +00:00
<span style="float:right;" class="last_poster">by <?=format_username($LastAuthorID, false, false, false)?> <?=time_diff($LastTime,1)?></span>
2011-03-28 14:21:28 +00:00
</td>
<td><?=number_format($NumTopics)?></td>
<td><?=number_format($NumPosts)?></td>
<? } ?>
</tr>
<? } ?>
</table>
<div class="linkbox"><a href="forums.php?action=catchup&amp;forumid=all&amp;auth=<?=$LoggedUser['AuthKey']?>">Catch up</a></div>
</div>
<? show_footer();