Blame Identity/Models/Html/phpBB/3.0.4/viewonline.php

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