root / tags / milestone_3 / phpBB / viewonline.php
History | View | Annotate | Download (10.1 kB)
| 1 | <?php
|
|---|---|
| 2 | /**
|
| 3 | * |
| 4 | * @package phpBB3 |
| 5 | * @version $Id: viewonline.php 5247 2005-10-02 18:47:06Z acydburn $ |
| 6 | * @copyright (c) 2005 phpBB Group |
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | /**
|
| 12 | */ |
| 13 | define('IN_PHPBB', true); |
| 14 | $phpbb_root_path = './'; |
| 15 | $phpEx = substr(strrchr(__FILE__, '.'), 1); |
| 16 | include($phpbb_root_path . 'common.'.$phpEx); |
| 17 | |
| 18 | // Start session management
|
| 19 | $user->session_begin();
|
| 20 | $auth->acl($user->data); |
| 21 | $user->setup();
|
| 22 | |
| 23 | // Get and set some variables
|
| 24 | $mode = request_var('mode', ''); |
| 25 | $session_id = request_var('s', ''); |
| 26 | $start = request_var('start', 0); |
| 27 | $sort_key = request_var('sk', 'b'); |
| 28 | $sort_dir = request_var('sd', 'd'); |
| 29 | $show_guests= ($config['load_online_guests']) ? request_var('sg', 0) : 0; |
| 30 | |
| 31 | $sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_LOCATION'], 'c' => $user->lang['SORT_JOINED']); |
| 32 | $sort_key_sql = array('a' => 'u.username', 'b' => 's.session_time', 'c' => 's.session_page'); |
| 33 | |
| 34 | // Sorting and order
|
| 35 | $order_by = $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC'); |
| 36 | |
| 37 | // Whois requested
|
| 38 | if ($mode == 'whois') |
| 39 | {
|
| 40 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
| 41 | |
| 42 | $sql = 'SELECT u.user_id, u.username, u.user_type, s.session_ip |
| 43 | FROM ' . USERS_TABLE . ' u, ' . SESSIONS_TABLE . " s |
| 44 | WHERE s.session_id = '" . $db->sql_escape($session_id) . "' |
| 45 | AND u.user_id = s.session_user_id";
|
| 46 | $result = $db->sql_query($sql); |
| 47 | |
| 48 | if ($row = $db->sql_fetchrow($result)) |
| 49 | {
|
| 50 | $whois = user_ipwhois($row['session_ip']); |
| 51 | |
| 52 | $whois = preg_replace('#(\s+?)([\w\-\._\+]+?@[\w\-\.]+?)(\s+?)#s', '\1<a href="mailto:\2">\2</a>\3', $whois); |
| 53 | $whois = preg_replace('#(\s+?)(http://.*?)(\s+?)#s', '\1<a href="\2" target="_blank">\2</a>\3', $whois); |
| 54 | |
| 55 | $template->assign_vars(array( |
| 56 | 'WHOIS' => trim($whois)) |
| 57 | ); |
| 58 | } |
| 59 | $db->sql_freeresult($result); |
| 60 | |
| 61 | // Output the page
|
| 62 | page_header($user->lang['WHO_IS_ONLINE']); |
| 63 | |
| 64 | $template->set_filenames(array( |
| 65 | 'body' => 'viewonline_whois.html') |
| 66 | ); |
| 67 | make_jumpbox('viewforum.'.$phpEx); |
| 68 | |
| 69 | page_footer(); |
| 70 | } |
| 71 | |
| 72 | // Forum info
|
| 73 | $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id |
| 74 | FROM ' . FORUMS_TABLE . ' |
| 75 | ORDER BY left_id ASC';
|
| 76 | $result = $db->sql_query($sql, 600); |
| 77 | |
| 78 | while ($row = $db->sql_fetchrow($result)) |
| 79 | {
|
| 80 | $forum_data[$row['forum_id']] = $row['forum_name']; |
| 81 | } |
| 82 | $db->sql_freeresult($result); |
| 83 | |
| 84 | $guest_counter = 0; |
| 85 | |
| 86 | // Get number of online guests (if we do not display them)
|
| 87 | if (!$show_guests) |
| 88 | {
|
| 89 | $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests FROM ' . SESSIONS_TABLE . ' |
| 90 | WHERE session_user_id = ' . ANONYMOUS . ' |
| 91 | AND session_time >= ' . (time() - ($config['load_online_time'] * 60)); |
| 92 | $result = $db->sql_query($sql); |
| 93 | $guest_counter = (int) $db->sql_fetchfield('num_guests', 0, $result); |
| 94 | $db->sql_freeresult($result); |
| 95 | } |
| 96 | |
| 97 | // Get user list
|
| 98 | $sql = 'SELECT u.user_id, u.username, u.user_type, u.user_allow_viewonline, u.user_colour, s.session_id, s.session_time, s.session_page, s.session_ip, s.session_viewonline |
| 99 | FROM ' . USERS_TABLE . ' u, ' . SESSIONS_TABLE . ' s |
| 100 | WHERE u.user_id = s.session_user_id |
| 101 | AND s.session_time >= ' . (time() - ($config['load_online_time'] * 60)) . |
| 102 | ((!$show_guests) ? ' AND s.session_user_id <> ' . ANONYMOUS : '') . ' |
| 103 | ORDER BY ' . $order_by; |
| 104 | $result = $db->sql_query($sql); |
| 105 | |
| 106 | $prev_id = $prev_ip = $user_list = array(); |
| 107 | $logged_visible_online = $logged_hidden_online = $counter = 0; |
| 108 | |
| 109 | while ($row = $db->sql_fetchrow($result)) |
| 110 | {
|
| 111 | if ($row['user_id'] != ANONYMOUS && !isset($prev_id[$row['user_id']])) |
| 112 | {
|
| 113 | $view_online = false; |
| 114 | |
| 115 | if ($row['user_colour']) |
| 116 | {
|
| 117 | $row['username'] = '<b style="color:#' . $row['user_colour'] . '">' . $row['username'] . '</b>'; |
| 118 | } |
| 119 | |
| 120 | if (!$row['user_allow_viewonline'] || !$row['session_viewonline']) |
| 121 | {
|
| 122 | $view_online = ($auth->acl_get('u_viewonline')) ? true : false; |
| 123 | $logged_hidden_online++;
|
| 124 | |
| 125 | $row['username'] = '<i>' . $row['username'] . '</i>'; |
| 126 | } |
| 127 | else
|
| 128 | {
|
| 129 | $view_online = true; |
| 130 | $logged_visible_online++;
|
| 131 | } |
| 132 | |
| 133 | $prev_id[$row['user_id']] = 1; |
| 134 | |
| 135 | if ($view_online) |
| 136 | {
|
| 137 | $counter++;
|
| 138 | } |
| 139 | |
| 140 | if (!$view_online || $counter > $start + $config['topics_per_page'] || $counter <= $start) |
| 141 | {
|
| 142 | continue;
|
| 143 | } |
| 144 | } |
| 145 | else if ($show_guests && $row['user_id'] == ANONYMOUS && !isset($prev_ip[$row['session_ip']])) |
| 146 | {
|
| 147 | $prev_ip[$row['session_ip']] = 1; |
| 148 | $guest_counter++;
|
| 149 | $counter++;
|
| 150 | |
| 151 | if ($counter > $start + $config['topics_per_page'] || $counter <= $start) |
| 152 | {
|
| 153 | continue;
|
| 154 | } |
| 155 | |
| 156 | $row['username'] = $user->lang['GUEST']; |
| 157 | } |
| 158 | else
|
| 159 | {
|
| 160 | continue;
|
| 161 | } |
| 162 | |
| 163 | preg_match('#^([a-z]+)#i', $row['session_page'], $on_page); |
| 164 | if (!sizeof($on_page)) |
| 165 | {
|
| 166 | $on_page[1] = ''; |
| 167 | } |
| 168 | |
| 169 | switch ($on_page[1]) |
| 170 | {
|
| 171 | case 'index': |
| 172 | $location = $user->lang['INDEX']; |
| 173 | $location_url = "index.$phpEx$SID"; |
| 174 | break;
|
| 175 | |
| 176 | case 'posting': |
| 177 | case 'viewforum': |
| 178 | case 'viewtopic': |
| 179 | preg_match('#f=([0-9]+)#', $row['session_page'], $forum_id); |
| 180 | $forum_id = (sizeof($forum_id)) ? $forum_id[1] : 0; |
| 181 | |
| 182 | if ($auth->acl_get('f_list', $forum_id)) |
| 183 | {
|
| 184 | $location = ''; |
| 185 | switch ($on_page[1]) |
| 186 | {
|
| 187 | case 'posting': |
| 188 | preg_match('#mode=([a-z]+)#', $row['session_page'], $on_page); |
| 189 | |
| 190 | switch ($on_page[1]) |
| 191 | {
|
| 192 | case 'reply': |
| 193 | $location = sprintf($user->lang['REPLYING_MESSAGE'], $forum_data[$forum_id]); |
| 194 | break;
|
| 195 | default:
|
| 196 | $location = sprintf($user->lang['POSTING_MESSAGE'], $forum_data[$forum_id]); |
| 197 | break;
|
| 198 | } |
| 199 | break;
|
| 200 | |
| 201 | case 'viewtopic': |
| 202 | $location = sprintf($user->lang['READING_TOPIC'], $forum_data[$forum_id]); |
| 203 | break;
|
| 204 | |
| 205 | case 'viewforum': |
| 206 | $location = sprintf($user->lang['READING_FORUM'], $forum_data[$forum_id]); |
| 207 | break;
|
| 208 | } |
| 209 | |
| 210 | $location_url = "viewforum.$phpEx$SID&f=$forum_id"; |
| 211 | } |
| 212 | else
|
| 213 | {
|
| 214 | $location = $user->lang['INDEX']; |
| 215 | $location_url = "index.$phpEx$SID"; |
| 216 | } |
| 217 | break;
|
| 218 | |
| 219 | case 'search': |
| 220 | $location = $user->lang['SEARCHING_FORUMS']; |
| 221 | $location_url = "search.$phpEx$SID"; |
| 222 | break;
|
| 223 | |
| 224 | case 'faq': |
| 225 | $location = $user->lang['VIEWING_FAQ']; |
| 226 | $location_url = "faq.$phpEx$SID"; |
| 227 | break;
|
| 228 | |
| 229 | case 'viewonline': |
| 230 | $location = $user->lang['VIEWING_ONLINE']; |
| 231 | $location_url = "viewonline.$phpEx$SID"; |
| 232 | break;
|
| 233 | |
| 234 | case 'memberlist': |
| 235 | $location = $user->lang['VIEWING_MEMBERS']; |
| 236 | $location_url = "memberlist.$phpEx$SID"; |
| 237 | break;
|
| 238 | |
| 239 | case 'ucp': |
| 240 | $location = $user->lang['VIEWING_UCP']; |
| 241 | $location_url = ''; |
| 242 | |
| 243 | default:
|
| 244 | $location = $user->lang['INDEX']; |
| 245 | $location_url = "index.$phpEx$SID"; |
| 246 | break;
|
| 247 | } |
| 248 | |
| 249 | $template->assign_block_vars('user_row', array( |
| 250 | 'USERNAME' => $row['username'], |
| 251 | 'LASTUPDATE' => $user->format_date($row['session_time']), |
| 252 | 'FORUM_LOCATION'=> $location, |
| 253 | 'USER_IP' => ($auth->acl_get('a_')) ? (($mode == 'lookup' && $session_id == $row['session_id']) ? gethostbyaddr($row['session_ip']) : $row['session_ip']) : '', |
| 254 | |
| 255 | 'U_USER_PROFILE' => (($row['user_type'] == USER_NORMAL || $row['user_type'] == USER_FOUNDER) && $row['user_id'] != ANONYMOUS) ? "{$phpbb_root_path}memberlist.$phpEx$SID&mode=viewprofile&u=" . $row['user_id'] : '', |
| 256 | 'U_USER_IP' => "{$phpbb_root_path}viewonline.$phpEx$SID" . (($mode != 'lookup' || $row['session_id'] != $session_id) ? '&s=' . $row['session_id'] : '') . "&mode=lookup&sg=$show_guests&start=$start&sk=$sort_key&sd=$sort_dir", |
| 257 | 'U_WHOIS' => "{$phpbb_root_path}viewonline.$phpEx$SID&mode=whois&s=" . $row['session_id'], |
| 258 | 'U_FORUM_LOCATION' => $phpbb_root_path . $location_url, |
| 259 | |
| 260 | 'S_GUEST' => ($row['user_id'] == ANONYMOUS) ? true : false, |
| 261 | 'S_USER_TYPE' => $row['user_type']) |
| 262 | ); |
| 263 | } |
| 264 | $db->sql_freeresult($result); |
| 265 | unset($prev_id, $prev_ip); |
| 266 | |
| 267 | // Generate reg/hidden/guest online text
|
| 268 | $vars_online = array( |
| 269 | 'REG' => array('logged_visible_online', 'l_r_user_s'), |
| 270 | 'HIDDEN'=> array('logged_hidden_online', 'l_h_user_s'), |
| 271 | 'GUEST' => array('guest_counter', 'l_g_user_s') |
| 272 | ); |
| 273 | |
| 274 | foreach ($vars_online as $l_prefix => $var_ary) |
| 275 | {
|
| 276 | switch ($$var_ary[0]) |
| 277 | {
|
| 278 | case 0: |
| 279 | $$var_ary[1] = $user->lang[$l_prefix . '_USERS_ZERO_ONLINE']; |
| 280 | break;
|
| 281 | |
| 282 | case 1: |
| 283 | $$var_ary[1] = $user->lang[$l_prefix . '_USER_ONLINE']; |
| 284 | break;
|
| 285 | |
| 286 | default:
|
| 287 | $$var_ary[1] = $user->lang[$l_prefix . '_USERS_ONLINE']; |
| 288 | break;
|
| 289 | } |
| 290 | } |
| 291 | unset($vars_online); |
| 292 | |
| 293 | $pagination = generate_pagination("{$phpbb_root_path}viewonline.$phpEx$SID&sg=$show_guests&sk=$sort_key&sd=$sort_dir", $counter, $config['topics_per_page'], $start); |
| 294 | |
| 295 | // Grab group details for legend display
|
| 296 | $sql = 'SELECT group_id, group_name, group_colour, group_type |
| 297 | FROM ' . GROUPS_TABLE . ' |
| 298 | WHERE group_legend = 1';
|
| 299 | $result = $db->sql_query($sql); |
| 300 | |
| 301 | $legend = ''; |
| 302 | while ($row = $db->sql_fetchrow($result)) |
| 303 | {
|
| 304 | $legend .= (($legend != '') ? ', ' : '') . '<a style="color:#' . $row['group_colour'] . '" href="' . "{$phpbb_root_path}memberlist.$phpEx$SID" . '&mode=group&g=' . $row['group_id'] . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</a>'; |
| 305 | } |
| 306 | $db->sql_freeresult($result); |
| 307 | |
| 308 | // Send data to template
|
| 309 | $template->assign_vars(array( |
| 310 | 'TOTAL_REGISTERED_USERS_ONLINE' => sprintf($l_r_user_s, $logged_visible_online) . sprintf($l_h_user_s, $logged_hidden_online), |
| 311 | 'TOTAL_GUEST_USERS_ONLINE' => sprintf($l_g_user_s, $guest_counter), |
| 312 | 'LEGEND' => $legend, |
| 313 | 'META' => '<meta http-equiv="refresh" content="60; url=viewonline.' . $phpEx . $SID . '">', |
| 314 | 'PAGINATION' => $pagination, |
| 315 | 'PAGE_NUMBER' => on_page($counter, $config['topics_per_page'], $start), |
| 316 | |
| 317 | 'U_SORT_USERNAME' => "{$phpbb_root_path}viewonline.$phpEx$SID&sk=a&sd=" . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'), |
| 318 | 'U_SORT_UPDATED' => "{$phpbb_root_path}viewonline.$phpEx$SID&sk=b&sd=" . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'), |
| 319 | 'U_SORT_LOCATION' => "{$phpbb_root_path}viewonline.$phpEx$SID&sk=c&sd=" . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'), |
| 320 | |
| 321 | 'U_SWITCH_GUEST_DISPLAY' => "{$phpbb_root_path}viewonline.$phpEx$SID&sg=" . ((int) !$show_guests), |
| 322 | 'L_SWITCH_GUEST_DISPLAY' => ($show_guests) ? $user->lang['HIDE_GUESTS'] : $user->lang['DISPLAY_GUESTS'], |
| 323 | 'S_SWITCH_GUEST_DISPLAY' => ($config['load_online_guests']) ? true : false) |
| 324 | ); |
| 325 | |
| 326 | // We do not need to load the who is online box here. ;)
|
| 327 | $config['load_online'] = false; |
| 328 | |
| 329 | // Output the page
|
| 330 | page_header($user->lang['WHO_IS_ONLINE']); |
| 331 | |
| 332 | $template->set_filenames(array( |
| 333 | 'body' => 'viewonline_body.html') |
| 334 | ); |
| 335 | make_jumpbox('viewforum.'.$phpEx); |
| 336 | |
| 337 | page_footer(); |
| 338 | |
| 339 | ?> |

