Blame Extras/phpBB/3.0.4/viewonline.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package phpBB3
4c79b5
* @version $Id: viewonline.php 8705 2008-07-28 16:55:00Z Kellanved $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
define('IN_PHPBB', true);
4c79b5
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
4c79b5
$phpEx = substr(strrchr(__FILE__, '.'), 1);
4c79b5
include($phpbb_root_path . 'common.' . $phpEx);
4c79b5
4c79b5
// Start session management
4c79b5
$user->session_begin();
4c79b5
$auth->acl($user->data);
4c79b5
$user->setup('memberlist');
4c79b5
4c79b5
// Get and set some variables
4c79b5
$mode		= request_var('mode', '');
4c79b5
$session_id	= request_var('s', '');
4c79b5
$start		= request_var('start', 0);
4c79b5
$sort_key	= request_var('sk', 'b');
4c79b5
$sort_dir	= request_var('sd', 'd');
4c79b5
$show_guests= ($config['load_online_guests']) ? request_var('sg', 0) : 0;
4c79b5
4c79b5
// Can this user view profiles/memberlist?
4c79b5
if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
4c79b5
{
4c79b5
	if ($user->data['user_id'] != ANONYMOUS)
4c79b5
	{
4c79b5
		trigger_error('NO_VIEW_USERS');
4c79b5
	}
4c79b5
4c79b5
	login_box('', $user->lang['LOGIN_EXPLAIN_VIEWONLINE']);
4c79b5
}
4c79b5
4c79b5
$sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_JOINED'], 'c' => $user->lang['SORT_LOCATION']);
4c79b5
$sort_key_sql = array('a' => 'u.username_clean', 'b' => 's.session_time', 'c' => 's.session_page');
4c79b5
4c79b5
// Sorting and order
4c79b5
if (!isset($sort_key_text[$sort_key]))
4c79b5
{
4c79b5
	$sort_key = 'b';
4c79b5
}
4c79b5
4c79b5
$order_by = $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
4c79b5
4c79b5
// Whois requested
4c79b5
if ($mode == 'whois' && $auth->acl_get('a_') && $session_id)
4c79b5
{
4c79b5
	include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
	$sql = 'SELECT u.user_id, u.username, u.user_type, s.session_ip
4c79b5
		FROM ' . USERS_TABLE . ' u, ' . SESSIONS_TABLE . " s
4c79b5
		WHERE s.session_id = '" . $db->sql_escape($session_id) . "'
4c79b5
			AND	u.user_id = s.session_user_id";
4c79b5
	$result = $db->sql_query($sql);
4c79b5
4c79b5
	if ($row = $db->sql_fetchrow($result))
4c79b5
	{
4c79b5
		$template->assign_var('WHOIS', user_ipwhois($row['session_ip']));
4c79b5
	}
4c79b5
	$db->sql_freeresult($result);
4c79b5
4c79b5
	// Output the page
4c79b5
	page_header($user->lang['WHO_IS_ONLINE']);
4c79b5
4c79b5
	$template->set_filenames(array(
4c79b5
		'body' => 'viewonline_whois.html')
4c79b5
	);
4c79b5
	make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
4c79b5
4c79b5
	page_footer();
4c79b5
}
4c79b5
4c79b5
// Forum info
4c79b5
$sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
4c79b5
	FROM ' . FORUMS_TABLE . '
4c79b5
	ORDER BY left_id ASC';
4c79b5
$result = $db->sql_query($sql, 600);
4c79b5
4c79b5
$forum_data = array();
4c79b5
while ($row = $db->sql_fetchrow($result))
4c79b5
{
4c79b5
	$forum_data[$row['forum_id']] = $row;
4c79b5
}
4c79b5
$db->sql_freeresult($result);
4c79b5
4c79b5
$guest_counter = 0;
4c79b5
4c79b5
// Get number of online guests (if we do not display them)
4c79b5
if (!$show_guests)
4c79b5
{
4c79b5
	switch ($db->sql_layer)
4c79b5
	{
4c79b5
		case 'sqlite':
4c79b5
			$sql = 'SELECT COUNT(session_ip) as num_guests
4c79b5
				FROM (
4c79b5
					SELECT DISTINCT session_ip
4c79b5
						FROM ' . SESSIONS_TABLE . '
4c79b5
						WHERE session_user_id = ' . ANONYMOUS . '
4c79b5
							AND session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
4c79b5
				')';
4c79b5
		break;
4c79b5
4c79b5
		default:
4c79b5
			$sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests
4c79b5
				FROM ' . SESSIONS_TABLE . '
4c79b5
				WHERE session_user_id = ' . ANONYMOUS . '
4c79b5
					AND session_time >= ' . (time() - ($config['load_online_time'] * 60));
4c79b5
		break;
4c79b5
	}
4c79b5
	$result = $db->sql_query($sql);
4c79b5
	$guest_counter = (int) $db->sql_fetchfield('num_guests');
4c79b5
	$db->sql_freeresult($result);
4c79b5
}
4c79b5
4c79b5
// Get user list
4c79b5
$sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_type, u.user_colour, s.session_id, s.session_time, s.session_page, s.session_ip, s.session_browser, s.session_viewonline, s.session_forum_id
4c79b5
	FROM ' . USERS_TABLE . ' u, ' . SESSIONS_TABLE . ' s
4c79b5
	WHERE u.user_id = s.session_user_id
4c79b5
		AND s.session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
4c79b5
		((!$show_guests) ? ' AND s.session_user_id <> ' . ANONYMOUS : '') . '
4c79b5
	ORDER BY ' . $order_by;
4c79b5
$result = $db->sql_query($sql);
4c79b5
4c79b5
$prev_id = $prev_ip = $user_list = array();
4c79b5
$logged_visible_online = $logged_hidden_online = $counter = 0;
4c79b5
4c79b5
while ($row = $db->sql_fetchrow($result))
4c79b5
{
4c79b5
	if ($row['user_id'] != ANONYMOUS && !isset($prev_id[$row['user_id']]))
4c79b5
	{
4c79b5
		$view_online = $s_user_hidden = false;
4c79b5
		$user_colour = ($row['user_colour']) ? ' style="color:#' . $row['user_colour'] . '" class="username-coloured"' : '';
4c79b5
		
4c79b5
		$username_full = ($row['user_type'] != USER_IGNORE) ? get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']) : '<span' . $user_colour . '>' . $row['username'] . '';
4c79b5
4c79b5
		if (!$row['session_viewonline'])
4c79b5
		{
4c79b5
			$view_online = ($auth->acl_get('u_viewonline')) ? true : false;
4c79b5
			$logged_hidden_online++;
4c79b5
4c79b5
			$username_full = '' . $username_full . '';
4c79b5
			$s_user_hidden = true;
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$view_online = true;
4c79b5
			$logged_visible_online++;
4c79b5
		}
4c79b5
4c79b5
		$prev_id[$row['user_id']] = 1;
4c79b5
4c79b5
		if ($view_online)
4c79b5
		{
4c79b5
			$counter++;
4c79b5
		}
4c79b5
4c79b5
		if (!$view_online || $counter > $start + $config['topics_per_page'] || $counter <= $start)
4c79b5
		{
4c79b5
			continue;
4c79b5
		}
4c79b5
	}
4c79b5
	else if ($show_guests && $row['user_id'] == ANONYMOUS && !isset($prev_ip[$row['session_ip']]))
4c79b5
	{
4c79b5
		$prev_ip[$row['session_ip']] = 1;
4c79b5
		$guest_counter++;
4c79b5
		$counter++;
4c79b5
4c79b5
		if ($counter > $start + $config['topics_per_page'] || $counter <= $start)
4c79b5
		{
4c79b5
			continue;
4c79b5
		}
4c79b5
4c79b5
		$s_user_hidden = false;
4c79b5
		$username_full = get_username_string('full', $row['user_id'], $user->lang['GUEST']);
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		continue;
4c79b5
	}
4c79b5
4c79b5
	preg_match('#^([a-z/]+)#i', $row['session_page'], $on_page);
4c79b5
	if (!sizeof($on_page))
4c79b5
	{
4c79b5
		$on_page[1] = '';
4c79b5
	}
4c79b5
4c79b5
	switch ($on_page[1])
4c79b5
	{
4c79b5
		case 'index':
4c79b5
			$location = $user->lang['INDEX'];
4c79b5
			$location_url = append_sid("{$phpbb_root_path}index.$phpEx");
4c79b5
		break;
4c79b5
4c79b5
		case 'adm/index':
4c79b5
			$location = $user->lang['ACP'];
4c79b5
			$location_url = append_sid("{$phpbb_root_path}index.$phpEx");
4c79b5
		break;
4c79b5
4c79b5
		case 'posting':
4c79b5
		case 'viewforum':
4c79b5
		case 'viewtopic':
4c79b5
			$forum_id = $row['session_forum_id'];
4c79b5
4c79b5
			if ($forum_id && $auth->acl_get('f_list', $forum_id))
4c79b5
			{
4c79b5
				$location = '';
4c79b5
				$location_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
4c79b5
4c79b5
				if ($forum_data[$forum_id]['forum_type'] == FORUM_LINK)
4c79b5
				{
4c79b5
					$location = sprintf($user->lang['READING_LINK'], $forum_data[$forum_id]['forum_name']);
4c79b5
					break;
4c79b5
				}
4c79b5
4c79b5
				switch ($on_page[1])
4c79b5
				{
4c79b5
					case 'posting':
4c79b5
						preg_match('#mode=([a-z]+)#', $row['session_page'], $on_page);
4c79b5
						$posting_mode = (!empty($on_page[1])) ? $on_page[1] : '';
4c79b5
4c79b5
						switch ($posting_mode)
4c79b5
						{
4c79b5
							case 'reply':
4c79b5
							case 'quote':
4c79b5
								$location = sprintf($user->lang['REPLYING_MESSAGE'], $forum_data[$forum_id]['forum_name']);
4c79b5
							break;
4c79b5
4c79b5
							default:
4c79b5
								$location = sprintf($user->lang['POSTING_MESSAGE'], $forum_data[$forum_id]['forum_name']);
4c79b5
							break;
4c79b5
						}
4c79b5
					break;
4c79b5
4c79b5
					case 'viewtopic':
4c79b5
						$location = sprintf($user->lang['READING_TOPIC'], $forum_data[$forum_id]['forum_name']);
4c79b5
					break;
4c79b5
4c79b5
					case 'viewforum':
4c79b5
						$location = sprintf($user->lang['READING_FORUM'], $forum_data[$forum_id]['forum_name']);
4c79b5
					break;
4c79b5
				}
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$location = $user->lang['INDEX'];
4c79b5
				$location_url = append_sid("{$phpbb_root_path}index.$phpEx");
4c79b5
			}
4c79b5
		break;
4c79b5
4c79b5
		case 'search':
4c79b5
			$location = $user->lang['SEARCHING_FORUMS'];
4c79b5
			$location_url = append_sid("{$phpbb_root_path}search.$phpEx");
4c79b5
		break;
4c79b5
4c79b5
		case 'faq':
4c79b5
			$location = $user->lang['VIEWING_FAQ'];
4c79b5
			$location_url = append_sid("{$phpbb_root_path}faq.$phpEx");
4c79b5
		break;
4c79b5
4c79b5
		case 'viewonline':
4c79b5
			$location = $user->lang['VIEWING_ONLINE'];
4c79b5
			$location_url = append_sid("{$phpbb_root_path}viewonline.$phpEx");
4c79b5
		break;
4c79b5
4c79b5
		case 'memberlist':
4c79b5
			$location = (strpos($row['session_page'], 'mode=viewprofile') !== false) ? $user->lang['VIEWING_MEMBER_PROFILE'] : $user->lang['VIEWING_MEMBERS'];
4c79b5
			$location_url = append_sid("{$phpbb_root_path}memberlist.$phpEx");
4c79b5
		break;
4c79b5
4c79b5
		case 'mcp':
4c79b5
			$location = $user->lang['VIEWING_MCP'];
4c79b5
			$location_url = append_sid("{$phpbb_root_path}index.$phpEx");
4c79b5
		break;
4c79b5
4c79b5
		case 'ucp':
4c79b5
			$location = $user->lang['VIEWING_UCP'];
4c79b5
4c79b5
			// Grab some common modules
4c79b5
			$url_params = array(
4c79b5
				'mode=register'		=> 'VIEWING_REGISTER',
4c79b5
				'i=pm&mode=compose'	=> 'POSTING_PRIVATE_MESSAGE',
4c79b5
				'i=pm&'				=> 'VIEWING_PRIVATE_MESSAGES',
4c79b5
				'i=profile&'		=> 'CHANGING_PROFILE',
4c79b5
				'i=prefs&'			=> 'CHANGING_PREFERENCES',
4c79b5
			);
4c79b5
4c79b5
			foreach ($url_params as $param => $lang)
4c79b5
			{
4c79b5
				if (strpos($row['session_page'], $param) !== false)
4c79b5
				{
4c79b5
					$location = $user->lang[$lang];
4c79b5
					break;
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			$location_url = append_sid("{$phpbb_root_path}index.$phpEx");
4c79b5
		break;
4c79b5
4c79b5
		case 'download/file':
4c79b5
			$location = $user->lang['DOWNLOADING_FILE'];
4c79b5
			$location_url = append_sid("{$phpbb_root_path}index.$phpEx");
4c79b5
		break;
4c79b5
4c79b5
		case 'report':
4c79b5
			$location = $user->lang['REPORTING_POST'];
4c79b5
			$location_url = append_sid("{$phpbb_root_path}index.$phpEx");
4c79b5
		break;
4c79b5
4c79b5
		default:
4c79b5
			$location = $user->lang['INDEX'];
4c79b5
			$location_url = append_sid("{$phpbb_root_path}index.$phpEx");
4c79b5
		break;
4c79b5
	}
4c79b5
4c79b5
	$template->assign_block_vars('user_row', array(
4c79b5
		'USERNAME' 			=> $row['username'],
4c79b5
		'USERNAME_COLOUR'	=> $row['user_colour'],
4c79b5
		'USERNAME_FULL'		=> $username_full,
4c79b5
		'LASTUPDATE'		=> $user->format_date($row['session_time']),
4c79b5
		'FORUM_LOCATION'	=> $location,
4c79b5
		'USER_IP'			=> ($auth->acl_get('a_')) ? (($mode == 'lookup' && $session_id == $row['session_id']) ? gethostbyaddr($row['session_ip']) : $row['session_ip']) : '',
4c79b5
		'USER_BROWSER'		=> ($auth->acl_get('a_user')) ? $row['session_browser'] : '',
4c79b5
4c79b5
		'U_USER_PROFILE'	=> ($row['user_type'] != USER_IGNORE) ? get_username_string('profile', $row['user_id'], '') : '',
4c79b5
		'U_USER_IP'			=> append_sid("{$phpbb_root_path}viewonline.$phpEx", 'mode=lookup' . (($mode != 'lookup' || $row['session_id'] != $session_id) ? '&s=' . $row['session_id'] : '') . "&sg=$show_guests&start=$start&sk=$sort_key&sd=$sort_dir"),
4c79b5
		'U_WHOIS'			=> append_sid("{$phpbb_root_path}viewonline.$phpEx", 'mode=whois&s=' . $row['session_id']),
4c79b5
		'U_FORUM_LOCATION'	=> $location_url,
4c79b5
		
4c79b5
		'S_USER_HIDDEN'		=> $s_user_hidden,
4c79b5
		'S_GUEST'			=> ($row['user_id'] == ANONYMOUS) ? true : false,
4c79b5
		'S_USER_TYPE'		=> $row['user_type'],
4c79b5
	));
4c79b5
}
4c79b5
$db->sql_freeresult($result);
4c79b5
unset($prev_id, $prev_ip);
4c79b5
4c79b5
// Generate reg/hidden/guest online text
4c79b5
$vars_online = array(
4c79b5
	'REG'	=> array('logged_visible_online', 'l_r_user_s'),
4c79b5
	'HIDDEN'=> array('logged_hidden_online', 'l_h_user_s'),
4c79b5
	'GUEST'	=> array('guest_counter', 'l_g_user_s')
4c79b5
);
4c79b5
4c79b5
foreach ($vars_online as $l_prefix => $var_ary)
4c79b5
{
4c79b5
	switch ($$var_ary[0])
4c79b5
	{
4c79b5
		case 0:
4c79b5
			$$var_ary[1] = $user->lang[$l_prefix . '_USERS_ZERO_ONLINE'];
4c79b5
		break;
4c79b5
4c79b5
		case 1:
4c79b5
			$$var_ary[1] = $user->lang[$l_prefix . '_USER_ONLINE'];
4c79b5
		break;
4c79b5
4c79b5
		default:
4c79b5
			$$var_ary[1] = $user->lang[$l_prefix . '_USERS_ONLINE'];
4c79b5
		break;
4c79b5
	}
4c79b5
}
4c79b5
unset($vars_online);
4c79b5
4c79b5
$pagination = generate_pagination(append_sid("{$phpbb_root_path}viewonline.$phpEx", "sg=$show_guests&sk=$sort_key&sd=$sort_dir"), $counter, $config['topics_per_page'], $start);
4c79b5
4c79b5
// Grab group details for legend display
4c79b5
if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
4c79b5
{
4c79b5
	$sql = 'SELECT group_id, group_name, group_colour, group_type
4c79b5
		FROM ' . GROUPS_TABLE . '
4c79b5
		WHERE group_legend = 1
4c79b5
		ORDER BY group_name ASC';
4c79b5
}
4c79b5
else
4c79b5
{
4c79b5
	$sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type
4c79b5
		FROM ' . GROUPS_TABLE . ' g
4c79b5
		LEFT JOIN ' . USER_GROUP_TABLE . ' ug
4c79b5
			ON (
4c79b5
				g.group_id = ug.group_id
4c79b5
				AND ug.user_id = ' . $user->data['user_id'] . '
4c79b5
				AND ug.user_pending = 0
4c79b5
			)
4c79b5
		WHERE g.group_legend = 1
4c79b5
			AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')
4c79b5
		ORDER BY g.group_name ASC';
4c79b5
}
4c79b5
$result = $db->sql_query($sql);
4c79b5
4c79b5
$legend = '';
4c79b5
while ($row = $db->sql_fetchrow($result))
4c79b5
{
4c79b5
	if ($row['group_name'] == 'BOTS')
4c79b5
	{
4c79b5
		$legend .= (($legend != '') ? ', ' : '') . '' . $user->lang['G_BOTS'] . '';
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$legend .= (($legend != '') ? ', ' : '') . '' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '';
4c79b5
	}
4c79b5
}
4c79b5
$db->sql_freeresult($result);
4c79b5
4c79b5
// Refreshing the page every 60 seconds...
4c79b5
meta_refresh(60, append_sid("{$phpbb_root_path}viewonline.$phpEx", "sg=$show_guests&sk=$sort_key&sd=$sort_dir&start=$start"));
4c79b5
4c79b5
// Send data to template
4c79b5
$template->assign_vars(array(
4c79b5
	'TOTAL_REGISTERED_USERS_ONLINE'	=> sprintf($l_r_user_s, $logged_visible_online) . sprintf($l_h_user_s, $logged_hidden_online),
4c79b5
	'TOTAL_GUEST_USERS_ONLINE'		=> sprintf($l_g_user_s, $guest_counter),
4c79b5
	'LEGEND'						=> $legend,
4c79b5
	'PAGINATION'					=> $pagination,
4c79b5
	'PAGE_NUMBER'					=> on_page($counter, $config['topics_per_page'], $start),
4c79b5
4c79b5
	'U_SORT_USERNAME'		=> append_sid("{$phpbb_root_path}viewonline.$phpEx", 'sk=a&sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a') . '&sg=' . ((int) $show_guests)),
4c79b5
	'U_SORT_UPDATED'		=> append_sid("{$phpbb_root_path}viewonline.$phpEx", 'sk=b&sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a') . '&sg=' . ((int) $show_guests)),
4c79b5
	'U_SORT_LOCATION'		=> append_sid("{$phpbb_root_path}viewonline.$phpEx", 'sk=c&sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a') . '&sg=' . ((int) $show_guests)),
4c79b5
4c79b5
	'U_SWITCH_GUEST_DISPLAY'	=> append_sid("{$phpbb_root_path}viewonline.$phpEx", 'sg=' . ((int) !$show_guests)),
4c79b5
	'L_SWITCH_GUEST_DISPLAY'	=> ($show_guests) ? $user->lang['HIDE_GUESTS'] : $user->lang['DISPLAY_GUESTS'],
4c79b5
	'S_SWITCH_GUEST_DISPLAY'	=> ($config['load_online_guests']) ? true : false)
4c79b5
);
4c79b5
4c79b5
// We do not need to load the who is online box here. ;)
4c79b5
$config['load_online'] = false;
4c79b5
4c79b5
// Output the page
4c79b5
page_header($user->lang['WHO_IS_ONLINE']);
4c79b5
4c79b5
$template->set_filenames(array(
4c79b5
	'body' => 'viewonline_body.html')
4c79b5
);
4c79b5
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
4c79b5
4c79b5
page_footer();
4c79b5
4c79b5
?>