#!/usr/bin/perl #------------------------------------------------------------------------------ # mwForum - Web-based discussion forum # Copyright (c) 1999-2002 Markus Wichitill # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. #------------------------------------------------------------------------------ use strict; # Imports use DBI; use MwfConfig; use MwfMain; #------------------------------------------------------------------------------ # Init init(); # Get CGI parameters my $msg = cgiStr('msg'); my $markRead = cgiBool('markRead'); # Print header printHeader($msg); # Check if access should be denied checkBlock(); # "?markRead=1" is obsolete, user has wrong bookmark !$markRead or userError($lng->{'errWrongBkm'}); # Print title bar my @titleBar = ( !$user->{'default'} && $cfg{'linkShowNew'} ? ("post_shownew.pl", "frmShowNew", 1) : (), !$user->{'default'} ? ("post_showreplies.pl", "frmShowRpl", 1) : (), "forum_info.pl", "frmInfo", 1, ); printBar($cfg{'forumName'}, "", \@titleBar, 0); print "
\n\n"; # Get categories my $query = " SELECT id, title FROM categories ORDER BY pos"; my $sth = query($query); my $categs = $sth->fetchall_arrayref({}); my $categIds = "0"; for my $categ (@$categs) { $categIds .= "," . $categ->{'id'}; } # Get boards $query = " SELECT boards.* FROM boards LEFT JOIN boardHiddenFlags ON boardHiddenFlags.userId = $user->{'id'} AND boardHiddenFlags.boardId = boards.id WHERE boards.categoryId IN ($categIds) AND boardHiddenFlags.boardId IS NULL ORDER BY boards.pos"; $sth = query($query); my $fetchedBoards = $sth->fetchall_arrayref({}); my $boards = []; my %boards = (); my $boardIds = "0"; for my $board (@$fetchedBoards) { next if !boardVisible($board); push @$boards, $board; $boards{$board->{'id'}} = $board; $boardIds .= "," . $board->{'id'}; } # New posts/read posts statistics my $now = time(); if (!$user->{'default'}) { if (!$cfg{'skipNewCheck'}) { # Get new post numbers my $approvedStr = $user->{'admin'} ? "" : "AND approved = 1"; $query = " SELECT boardId, COUNT(*) AS newNum FROM posts WHERE boardId IN ($boardIds) AND postTime > $user->{'lastReadTime'} $approvedStr GROUP BY boardId"; $sth = query($query); while (my ($boardId, $newNum) = $sth->fetchrow_array()) { $boards{$boardId}{'newNum'} = $newNum; } } # Check whether there's at least one unread topic for my $board (@$boards) { if ($cfg{'skipUnreadCheck'}) { $board->{'hasUnread'} = 1 } else { my $lowestUnreadTime = $now - ($cfg{'maxUnreadDays'} || 30) * 86400; $query = " SELECT topics.id IS NOT NULL AS hasUnread FROM topics LEFT JOIN topicReadTimes ON topicReadTimes.userId = $user->{'id'} AND topicReadTimes.topicId = topics.id WHERE topics.boardId = $board->{'id'} AND topics.lastPostTime > $lowestUnreadTime AND (topics.lastPostTime > topicReadTimes.lastReadTime OR topicReadTimes.topicId IS NULL) LIMIT 1"; $sth = query($query); $board->{'hasUnread'} = $sth->fetchrow_array(); } } } # Print table header print tableStart(); # Determine fixed icon attributes my $imgAlign = browserAttr('middleImgAlign'); my $imgFixAttr = "WIDTH=$cfg{'iconSize'} HEIGHT=$cfg{'iconSize'} BORDER=0 $imgAlign"; # Print categories/boards my $boardsPrinted = 0; for my $categ (@$categs) { my $isFirstBoard = 1; for my $board (@$boards) { # Skip boards not in current category next if $board->{'categoryId'} != $categ->{'id'}; # Format output my $lastPostTimeStr = $board->{'lastPostTime'} > 0 ? formatTime($board->{'lastPostTime'}, $user->{'timezone'}) : " - "; # Format "new" number string my $newNumStr = ""; if ($board->{'newNum'} && $cfg{'linkShowNew'}) { $newNumStr = "" . "($board->{'newNum'} $lng->{'frmNew'})"; } elsif ($board->{'newNum'}) { $newNumStr = "($board->{'newNum'} $lng->{'frmNew'})"; } # Determine variable board icon attributes my $imgSrc; my $imgTitle = ""; my $imgAlt = ""; if ($user->{'default'}) { $imgSrc = "board_ou" } else { if ($board->{'newNum'} && $board->{'hasUnread'}) { $imgSrc = "board_nu"; $imgTitle = $lng->{'comNewUnrdTT'}; $imgAlt = $lng->{'comNewUnrd'}; } elsif ($board->{'newNum'}) { $imgSrc = "board_nr"; $imgTitle = $lng->{'comNewReadTT'}; $imgAlt = $lng->{'comNewRead'}; } elsif ($board->{'hasUnread'}) { $imgSrc = "board_ou"; $imgTitle = $lng->{'comOldUnrdTT'}; $imgAlt = $lng->{'comOldUnrd'}; } else { $imgSrc = "board_or"; $imgTitle = $lng->{'comOldReadTT'}; $imgAlt = $lng->{'comOldRead'}; } } my $imgVarAttr = "SRC='$cfg{'nonCgiPath'}/$imgSrc.gif' TITLE='$imgTitle' ALT='$imgAlt'"; # If first board in category, print category if ($isFirstBoard) { print "\n", "$categ->{'title'}\n", "$lng->{'frmPosts'}\n", "$lng->{'frmLastPost'}\n", "\n\n"; $isFirstBoard = 0; } # Print board print "\n", "\n", "\n", "\n", "$board->{'title'}\n", "$board->{'postNum'} $newNumStr\n", "$lastPostTimeStr\n", "\n"; print "\n", "$board->{'shortDesc'}\n", "\n" if $user->{'boardDescs'} && $board->{'shortDesc'}; print "\n"; # At least one board has been printed $boardsPrinted++; } } # Print notification that there were no visible boards print "\n", "$lng->{'frmNoBoards'}\n", "\n" if !$boardsPrinted; print tableEnd(); # Print statistics box if ($cfg{'forumStats'} == 1 && !$user->{'default'} || $cfg{'forumStats'} == 2) { my $limit = $cfg{'forumStatRanks'} || 5; print "

\n\n", tableStart($lng->{'frmStsTtl'}, 4), "", "\n"; # Most active topics my $extraLimit = $limit + 5; # Hack to make up for private topics $query = " SELECT id, boardId, subject, postNum * 2 + hitNum - ROUND(($now - topics.lastPostTime) / 86400) AS score FROM topics WHERE boardId IN ($boardIds) HAVING score > 0 ORDER BY score DESC LIMIT $extraLimit"; $sth = query($query); my $activeTopics = $sth->fetchall_arrayref({}); print "\n", "", "\n"; my $rank = 1; for my $actTopic (@$activeTopics) { my $subject = escHtml(abbr(deescHtml($actTopic->{'subject'}), 20)); print "", "\n"; $rank++; last if $rank > $limit; } print "
$lng->{'frmStsActTpc'}$lng->{'frmStsScore'}
$rank. $subject$actTopic->{'score'}
\n"; # Most active users print "\n"; $query = " SELECT id, userName, ROUND(postNum * 10 / (($now - regTime) / 86400) + postNum / 10) AS score FROM users WHERE ($now - regTime) / 86400 > 1 ORDER BY score DESC LIMIT $limit"; $sth = query($query); my $activeUsers = $sth->fetchall_arrayref({}); print "\n", "", "\n"; $rank = 1; for my $actUser (@$activeUsers) { my $userName = abbr($actUser->{'userName'}); print "", "\n"; $rank++; } print "
$lng->{'frmStsActUsr'}$lng->{'frmStsScore'}
$rank. $userName$actUser->{'score'}
\n"; # Newest users print "\n"; $query = " SELECT id, userName FROM users ORDER BY regTime DESC LIMIT $limit"; $sth = query($query); my $newestUsers = $sth->fetchall_arrayref({}); print "\n", ""; $rank = 1; for my $newUser (@$newestUsers) { my $userName = abbr($newUser->{'userName'}); print "\n"; $rank++; } print "
$lng->{'frmStsNewUsr'}
$rank. $userName
\n"; # Last online users print "\n"; $query = " SELECT id, userName FROM users WHERE $now - lastOnTime < 300 AND id != $user->{'id'} AND lastOnTime != regTime ORDER BY lastOnTime DESC LIMIT $limit"; $sth = query($query); my $onlineUsers = $sth->fetchall_arrayref({}); print "\n", ""; $rank = 1; for my $onlUser (@$onlineUsers) { my $userName = abbr($onlUser->{'userName'}); print "\n"; $rank++; } print "
$lng->{'frmStsOnlUsr'}
$rank. $userName
\n"; print "\n", tableEnd(); } # Print admin bar if ($user->{'admin'}) { my @adminBar = ( $cfg{'linkShowNew'} ? () : ("post_shownew.pl", "New Posts", 1), "user_admin.pl", "Users", 1, "board_admin.pl", "Boards", 1, "categ_admin.pl", "Categories", 1, "cron_admin.pl", "Cronjobs", 1, ); printBar("Admin", "", \@adminBar); } # Update user if (!$user->{'default'}) { $query = " UPDATE users SET lastOnTime = $now, lastIp = '$ENV{'REMOTE_ADDR'}' WHERE id = $user->{'id'}"; $dbh->do($query) or dbError(); } # Log action logAction(2, 'forum', 'show', $user->{'id'}); # Print footer printFooter();