особенности
1. показывает всех пользователей форума за день и текущий час
2. показывает только тех пользователей, которые разрешили себя показывать (опция "Скрывать ваше пребывание на форуме" отключена)
3. админы видят всех пользователей, "скрывающиеся" юзеры отображаются курсивом
4. пребывание админов скрыто от всех пользователей
5. админы видят IP пользователей и их время последнего пребывания на форуме во всплывающей подсказке
возможные минусы
1. видимостью админов не возможно манипулировать (хотя можно настроить)
2. в отличии от аналогов выполняется 2 более структурированных запроса к БД (возможно это недостаток, однако при генерации страниц в среднем на форуме выполняется около 12-17 запросов. но главная страница запрашивается по отношению к другим в соотношении примерно 1:10. то есть лишним запросом можно пренебречь)
Код: Выделить всё
##############################################################
## MOD Title: Users Of The Day
## MOD Author: quazi < nomail@nospam.com > ( N/A ) N/A
## MOD Description: This modification allows to see users who visited forum at the recent day and last hour (if actual user turn on feature 'View online' in his own profile. In other hand admin see all users always however himself stays invisible. If You want show admins for all users comment the condition marked by line // admin is not visible anywhere
## MOD Version: 1.1.0
##
## Installation Level: Easy
## Installation Time: 5 Minutes
## Files To Edit: (5) includes/functions.php, includes/page_header.php, templates/subSilver/index_body.tpl, language/lang_russian/lang_main.php, language/lang_english/lang_main.php
## Included Files: n/a
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum.
##############################################################
## Author Notes: Previous idea of the mod had been generated by WingLion
## at the Russian phpBB community http://phpbbguru.net/community/viewtopic.php?p=26942
##
##############################################################
## MOD History:
##
## 2005-07-14 10:26:00 - The first release
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#
#----[ OPEN ]-------------------------------------------------------------
#
includes/functions.php
#
#----[ FIND ]--------------------------------------------------------------
#
function create_date($format, $gmepoch, $tz)
{
global $board_config, $lang;
static $translate;
if ( empty($translate) && $board_config['default_lang'] != 'english' )
{
@reset($lang['datetime']);
while ( list($match, $replace) = @each($lang['datetime']) )
{
$translate[$match] = $replace;
}
}
return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : @gmdate($format, $gmepoch + (3600 * $tz));
}
#
#----[ REPLACE WITH ]--------------------------------------------------
#
function create_date($format, $gmepoch, $tz, $skipDelta=true)
{
global $board_config, $lang;
static $translate;
if ( !$gmepoch )
{
return $lang['datetime']['Hidden_time'];
}
preg_match('/([\+\-])?(\d\d)(\d\d)/', date('O'), $matches);
$h = (int)($matches[1] . $matches[2]);
$m = (int)($matches[1] . $matches[3]);
$tz_delta = ($h + $m / 60 - $tz) * 3600;
$time = $gmepoch - $tz_delta;
if ( $skipDelta ) {
$midnight = mktime(0, 0, 0) - $tz_delta;
$delta = $time - $midnight;
if ($delta >= 0 && $delta < 86400)
{
return $lang['datetime']['Today'] . date('H:i', $time);
}
else
if ($delta < 0 && $delta > -86400)
{
return $lang['datetime']['Yesterday'] . date('H:i', $time);
}
}
$pre_format = @date($format, $time);
if ( empty($translate) && $board_config['default_lang'] != 'english' )
{
@reset($lang['datetime']);
while ( list($match, $replace) = @each($lang['datetime']) )
{
$translate[$match] = $replace;
}
}
return ( !empty($translate) ) ? strtr($pre_format, $translate) : $pre_format;
//return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : @gmdate($format, $gmepoch + (3600 * $tz));
}
#
#----[ OPEN ]-------------------------------------------------------------
#
includes/page_header.php
#
#----[ FIND ]-------------------------------------------------------------
#
//
// Obtain number of new private messages
// if user is logged in
//
#
#----[ ADD, BEFORE ]------------------------------------------------------
#
// +Users of the day MOD
$userdata_time = 3600 * ( floatval($userdata['user_timezone']) ? $userdata['user_timezone'] : @$board_config['board_timezone'] );
$day_guest_userlist = $day_userlist = array();
$day_users = array('reg' => 0, 'hidden' => 0, 'guest' => 0, 'hour' => 0);
$sql = "SELECT u.user_id, u.username, u.user_level, u.user_lastvisit, u.user_session_time, s.session_time, s.session_ip, s.session_logged_in, u.user_allow_viewonline
FROM " . USERS_TABLE . " u
LEFT JOIN " . SESSIONS_TABLE . " s
ON u.user_id = s.session_user_id
WHERE u.user_session_time >= " . mktime(0, 0, 0) . "
GROUP BY u.username
ORDER BY u.username ASC, u.user_session_time ASC";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain user/day information', '', __LINE__, __FILE__, $sql);
}
while( $row = $db->sql_fetchrow($result) )
{
// all users visible by admin (including their IP)
$user_tooltip = '';
if ($userdata['user_level'] == ADMIN)
{
$user_tooltip = ' title="' . @$row['username'] . ' [' . decode_ip(@$row['session_ip']) . '] ' . create_date($userdata['date_format'], @$row['user_session_time'], $board_config['board_timezone'], true) . '"';
}
// color definition
$style_color = '';
if ( $row['user_level'] == ADMIN )
{
// admin is not visible anywhere
if ($userdata['user_level'] != ADMIN)
{
continue;
}
$row['username'] = '<b>' . $row['username'] . '</b>';
$style_color = 'style="color:#' . $theme['fontcolor3'] . '"';
}
else if ( $row['user_level'] == MOD )
{
$row['username'] = '<b>' . $row['username'] . '</b>';
$style_color = 'style="color:#' . $theme['fontcolor2'] . '"';
}
if ( $row['user_allow_viewonline'] )
{
$day_users['reg']++;
}
else
{
$day_users['hidden']++;
$row['username'] = '<i>' . $row['username'] . '</i>';
}
// Users at last hour
if ( $row['user_session_time'] >= mktime(date("H"), 0, 0) )
{
$day_users['hour']++;
}
// all users visible for admin
if ( $userdata['user_level'] == ADMIN || $row['user_allow_viewonline'] )
{
$day_userlist[] = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color . $user_tooltip . '>' . $row['username'] . '</a>';
}
}
$sql = "SELECT s.session_ip, MAX(s.session_time) AS session_time
FROM " . USERS_TABLE . " u
LEFT JOIN " . SESSIONS_TABLE . " s
ON u.user_id = s.session_user_id
WHERE u.user_id = " . ANONYMOUS . "
AND s.session_time >= " . mktime(0, 0, 0) . "
GROUP BY s.session_ip
ORDER BY session_time ASC";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain guest user/day information', '', __LINE__, __FILE__, $sql);
}
while( $row = $db->sql_fetchrow($result) )
{
// guests per last hour
if ( $row['session_time'] >= gmmktime(date("H"), 0, 0) - $userdata_time )
{
$day_users['hour']++;
}
// guests per day
$day_users['guest']++;
// guest IP visible by admin
if ($userdata['user_level'] == ADMIN)
{
$day_guest_userlist[$row['user_session_time']][] = '<span class="guest" title="[' . decode_ip($row['session_ip']) . '] ' . create_date($userdata['date_format'], $row['session_time'], $board_config['board_timezone'], true) . '">' . decode_ip($row['session_ip']) . '</span>';
}
}
// logged, hidden and guest users counts and list of logged users
$day_userlist = ( isset($forum_id) ) ? '' : sprintf($lang['Users_Stat'], $day_users['reg'] + $day_users['hidden'] + $day_users['guest'], $day_users['reg'], $day_users['hidden'], $day_users['guest'], $day_users['hour'], implode(', ', $day_userlist));
// admin collected guests' ips and times and resort by time
if ($userdata['user_level'] == ADMIN)
{
foreach ($day_guest_userlist as $k => $v)
{
$day_guest_userlist[$k] = implode('', $day_guest_userlist[$k]);
}
$day_userlist .= '<br /><hr />' . "\n";
$day_userlist .= '<style type="text/css">.guest{border: 1px solid #CCC; display: block; float: left; margin: 1px; padding: 0; text-align: center; width: 100px;}</style>';
$day_userlist .= implode('', $day_guest_userlist);
}
// -Users of the day MOD
#
#----[ FIND ]-------------------------------------------------------------------
#
'LOGGED_IN_USER_LIST' => $online_userlist,
#
#----[ ADD, AFTER ]-------------------------------------------------------------
#
// +Users Of The Day
'USERS_OF_THE_DAY_LIST' => $day_userlist,
// -Users Of The Day
#
#----[ OPEN ]-------------------------------------------------------------------
#
templates/subSilver/index_body.tpl
#
#----[ FIND ]-------------------------------------------------------------------
#
<tr>
<td class="row1" align="left"><span class="gensmall">{TOTAL_USERS_ONLINE} [ {L_WHOSONLINE_ADMIN} ] [ {L_WHOSONLINE_MOD} ]<br />{RECORD_USERS}<br />{LOGGED_IN_USER_LIST}</span></td>
</tr>
#
#----[ ADD, BEFORE ]------------------------------------------------------------
#
<tr>
<td class="row1" align="left"><span class="gensmall">{USERS_OF_THE_DAY_LIST}</span></td>
</tr>
#
#----[ OPEN ]------------------------------------------------------------------
#
language/lang_russian/lang_main.php
#
#----[ FIND ]------------------------------------------------------------------
#
?>
#
#----[ ADD, BEFORE ]------------------------------------------------------------
#
$lang['Users_Stat'] = 'Сегодня наш форум поcетило пользователей: <b>%d</b><br />Зарегистрированных: %d, скрытых: %d и гостей: %d, из них <b>%d</b> в течение последнего часа<br />Зарегистрированные пользователи: %s';
#
#----[ OPEN ]------------------------------------------------------------------
#
language/lang_english/lang_main.php
#
#----[ FIND ]------------------------------------------------------------------
#
?>
#
#----[ ADD, BEFORE ]------------------------------------------------------------
#
$lang['Users_Stat'] = 'In total <b>%d</b> user have visited this site today <br />%d Registered, %d Hidden and %d Guests, <b>%d</b> of them within the last hour <br />Registered Users: %s';
# EoM