[ Index ]

PHP Cross Reference of phpBB-3.2.2-deutsch

title

Body

[close]

/ -> viewonline.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  define('IN_PHPBB', true);
  18  $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  19  $phpEx = substr(strrchr(__FILE__, '.'), 1);
  20  include($phpbb_root_path . 'common.' . $phpEx);
  21  
  22  // Start session management
  23  $user->session_begin();
  24  $auth->acl($user->data);
  25  $user->setup('memberlist');
  26  
  27  // Get and set some variables
  28  $mode        = $request->variable('mode', '');
  29  $session_id    = $request->variable('s', '');
  30  $start        = $request->variable('start', 0);
  31  $sort_key    = $request->variable('sk', 'b');
  32  $sort_dir    = $request->variable('sd', 'd');
  33  $show_guests    = ($config['load_online_guests']) ? $request->variable('sg', 0) : 0;
  34  
  35  // Can this user view profiles/memberlist?
  36  if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
  37  {
  38      if ($user->data['user_id'] != ANONYMOUS)
  39      {
  40          send_status_line(403, 'Forbidden');
  41          trigger_error('NO_VIEW_USERS');
  42      }
  43  
  44      login_box('', $user->lang['LOGIN_EXPLAIN_VIEWONLINE']);
  45  }
  46  
  47  /* @var $pagination \phpbb\pagination */
  48  $pagination = $phpbb_container->get('pagination');
  49  
  50  /* @var $viewonline_helper \phpbb\viewonline_helper */
  51  $viewonline_helper = $phpbb_container->get('viewonline_helper');
  52  
  53  $sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_JOINED'], 'c' => $user->lang['SORT_LOCATION']);
  54  $sort_key_sql = array('a' => 'u.username_clean', 'b' => 's.session_time', 'c' => 's.session_page');
  55  
  56  // Sorting and order
  57  if (!isset($sort_key_text[$sort_key]))
  58  {
  59      $sort_key = 'b';
  60  }
  61  
  62  $order_by = $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
  63  
  64  // Whois requested
  65  if ($mode == 'whois' && $auth->acl_get('a_') && $session_id)
  66  {
  67      if (!function_exists('user_get_id_name'))
  68      {
  69          include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  70      }
  71  
  72      $sql = 'SELECT u.user_id, u.username, u.user_type, s.session_ip
  73          FROM ' . USERS_TABLE . ' u, ' . SESSIONS_TABLE . " s
  74          WHERE s.session_id = '" . $db->sql_escape($session_id) . "'
  75              AND    u.user_id = s.session_user_id";
  76      $result = $db->sql_query($sql);
  77  
  78      if ($row = $db->sql_fetchrow($result))
  79      {
  80          $template->assign_var('WHOIS', user_ipwhois($row['session_ip']));
  81      }
  82      $db->sql_freeresult($result);
  83  
  84      // Output the page
  85      page_header($user->lang['WHO_IS_ONLINE']);
  86  
  87      $template->set_filenames(array(
  88          'body' => 'viewonline_whois.html')
  89      );
  90      make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
  91  
  92      page_footer();
  93  }
  94  
  95  $user->update_session_infos();
  96  
  97  // Forum info
  98  $sql_ary = array(
  99      'SELECT'    => 'f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.left_id, f.right_id',
 100      'FROM'        => array(
 101          FORUMS_TABLE    => 'f',
 102      ),
 103      'ORDER_BY'    => 'f.left_id ASC',
 104  );
 105  
 106  /**
 107  * Modify the forum data SQL query for getting additional fields if needed
 108  *
 109  * @event core.viewonline_modify_forum_data_sql
 110  * @var    array    sql_ary            The SQL array
 111  * @since 3.1.5-RC1
 112  */
 113  $vars = array('sql_ary');
 114  extract($phpbb_dispatcher->trigger_event('core.viewonline_modify_forum_data_sql', compact($vars)));
 115  
 116  $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary), 600);
 117  unset($sql_ary);
 118  
 119  $forum_data = array();
 120  while ($row = $db->sql_fetchrow($result))
 121  {
 122      $forum_data[$row['forum_id']] = $row;
 123  }
 124  $db->sql_freeresult($result);
 125  
 126  $guest_counter = 0;
 127  
 128  // Get number of online guests (if we do not display them)
 129  if (!$show_guests)
 130  {
 131      switch ($db->get_sql_layer())
 132      {
 133          case 'sqlite3':
 134              $sql = 'SELECT COUNT(session_ip) as num_guests
 135                  FROM (
 136                      SELECT DISTINCT session_ip
 137                          FROM ' . SESSIONS_TABLE . '
 138                          WHERE session_user_id = ' . ANONYMOUS . '
 139                              AND session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
 140                  ')';
 141          break;
 142  
 143          default:
 144              $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests
 145                  FROM ' . SESSIONS_TABLE . '
 146                  WHERE session_user_id = ' . ANONYMOUS . '
 147                      AND session_time >= ' . (time() - ($config['load_online_time'] * 60));
 148          break;
 149      }
 150      $result = $db->sql_query($sql);
 151      $guest_counter = (int) $db->sql_fetchfield('num_guests');
 152      $db->sql_freeresult($result);
 153  }
 154  
 155  // Get user list
 156  $sql_ary = array(
 157      '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',
 158      'FROM'        => array(
 159          USERS_TABLE        => 'u',
 160          SESSIONS_TABLE    => 's',
 161      ),
 162      'WHERE'        => 'u.user_id = s.session_user_id
 163          AND s.session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
 164          ((!$show_guests) ? ' AND s.session_user_id <> ' . ANONYMOUS : ''),
 165      'ORDER_BY'    => $order_by,
 166  );
 167  
 168  /**
 169  * Modify the SQL query for getting the user data to display viewonline list
 170  *
 171  * @event core.viewonline_modify_sql
 172  * @var    array    sql_ary            The SQL array
 173  * @var    bool    show_guests        Do we display guests in the list
 174  * @var    int        guest_counter    Number of guests displayed
 175  * @var    array    forum_data        Array with forum data
 176  * @since 3.1.0-a1
 177  * @changed 3.1.0-a2 Added vars guest_counter and forum_data
 178  */
 179  $vars = array('sql_ary', 'show_guests', 'guest_counter', 'forum_data');
 180  extract($phpbb_dispatcher->trigger_event('core.viewonline_modify_sql', compact($vars)));
 181  
 182  $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
 183  
 184  $prev_id = $prev_ip = $user_list = array();
 185  $logged_visible_online = $logged_hidden_online = $counter = 0;
 186  
 187  /** @var \phpbb\controller\helper $controller_helper */
 188  $controller_helper = $phpbb_container->get('controller.helper');
 189  
 190  /** @var \phpbb\group\helper $group_helper */
 191  $group_helper = $phpbb_container->get('group_helper');
 192  
 193  while ($row = $db->sql_fetchrow($result))
 194  {
 195      if ($row['user_id'] != ANONYMOUS && !isset($prev_id[$row['user_id']]))
 196      {
 197          $view_online = $s_user_hidden = false;
 198          $user_colour = ($row['user_colour']) ? ' style="color:#' . $row['user_colour'] . '" class="username-coloured"' : '';
 199  
 200          $username_full = ($row['user_type'] != USER_IGNORE) ? get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']) : '<span' . $user_colour . '>' . $row['username'] . '</span>';
 201  
 202          if (!$row['session_viewonline'])
 203          {
 204              $view_online = ($auth->acl_get('u_viewonline') || $row['user_id'] === $user->data['user_id']) ? true : false;
 205              $logged_hidden_online++;
 206  
 207              $username_full = '<em>' . $username_full . '</em>';
 208              $s_user_hidden = true;
 209          }
 210          else
 211          {
 212              $view_online = true;
 213              $logged_visible_online++;
 214          }
 215  
 216          $prev_id[$row['user_id']] = 1;
 217  
 218          if ($view_online)
 219          {
 220              $counter++;
 221          }
 222  
 223          if (!$view_online || $counter > $start + $config['topics_per_page'] || $counter <= $start)
 224          {
 225              continue;
 226          }
 227      }
 228      else if ($show_guests && $row['user_id'] == ANONYMOUS && !isset($prev_ip[$row['session_ip']]))
 229      {
 230          $prev_ip[$row['session_ip']] = 1;
 231          $guest_counter++;
 232          $counter++;
 233  
 234          if ($counter > $start + $config['topics_per_page'] || $counter <= $start)
 235          {
 236              continue;
 237          }
 238  
 239          $s_user_hidden = false;
 240          $username_full = get_username_string('full', $row['user_id'], $user->lang['GUEST']);
 241      }
 242      else
 243      {
 244          continue;
 245      }
 246  
 247      $on_page = $viewonline_helper->get_user_page($row['session_page']);
 248  
 249      switch ($on_page[1])
 250      {
 251          case 'index':
 252              $location = $user->lang['INDEX'];
 253              $location_url = append_sid("{$phpbb_root_path}index.$phpEx");
 254          break;
 255  
 256          case $phpbb_adm_relative_path . 'index':
 257              $location = $user->lang['ACP'];
 258              $location_url = append_sid("{$phpbb_root_path}index.$phpEx");
 259          break;
 260  
 261          case 'posting':
 262          case 'viewforum':
 263          case 'viewtopic':
 264              $forum_id = $row['session_forum_id'];
 265  
 266              if ($forum_id && $auth->acl_get('f_list', $forum_id))
 267              {
 268                  $location = '';
 269                  $location_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
 270  
 271                  if ($forum_data[$forum_id]['forum_type'] == FORUM_LINK)
 272                  {
 273                      $location = sprintf($user->lang['READING_LINK'], $forum_data[$forum_id]['forum_name']);
 274                      break;
 275                  }
 276  
 277                  switch ($on_page[1])
 278                  {
 279                      case 'posting':
 280                          preg_match('#mode=([a-z]+)#', $row['session_page'], $on_page);
 281                          $posting_mode = (!empty($on_page[1])) ? $on_page[1] : '';
 282  
 283                          switch ($posting_mode)
 284                          {
 285                              case 'reply':
 286                              case 'quote':
 287                                  $location = sprintf($user->lang['REPLYING_MESSAGE'], $forum_data[$forum_id]['forum_name']);
 288                              break;
 289  
 290                              default:
 291                                  $location = sprintf($user->lang['POSTING_MESSAGE'], $forum_data[$forum_id]['forum_name']);
 292                              break;
 293                          }
 294                      break;
 295  
 296                      case 'viewtopic':
 297                          $location = sprintf($user->lang['READING_TOPIC'], $forum_data[$forum_id]['forum_name']);
 298                      break;
 299  
 300                      case 'viewforum':
 301                          $location = sprintf($user->lang['READING_FORUM'], $forum_data[$forum_id]['forum_name']);
 302                      break;
 303                  }
 304              }
 305              else
 306              {
 307                  $location = $user->lang['INDEX'];
 308                  $location_url = append_sid("{$phpbb_root_path}index.$phpEx");
 309              }
 310          break;
 311  
 312          case 'search':
 313              $location = $user->lang['SEARCHING_FORUMS'];
 314              $location_url = append_sid("{$phpbb_root_path}search.$phpEx");
 315          break;
 316  
 317          case 'viewonline':
 318              $location = $user->lang['VIEWING_ONLINE'];
 319              $location_url = append_sid("{$phpbb_root_path}viewonline.$phpEx");
 320          break;
 321  
 322          case 'memberlist':
 323              $location_url = append_sid("{$phpbb_root_path}memberlist.$phpEx");
 324  
 325              if (strpos($row['session_page'], 'mode=viewprofile') !== false)
 326              {
 327                  $location = $user->lang['VIEWING_MEMBER_PROFILE'];
 328              }
 329              else if (strpos($row['session_page'], 'mode=contactadmin') !== false)
 330              {
 331                  $location = $user->lang['VIEWING_CONTACT_ADMIN'];
 332                  $location_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contactadmin');
 333              }
 334              else
 335              {
 336                  $location = $user->lang['VIEWING_MEMBERS'];
 337              }
 338          break;
 339  
 340          case 'mcp':
 341              $location = $user->lang['VIEWING_MCP'];
 342              $location_url = append_sid("{$phpbb_root_path}index.$phpEx");
 343          break;
 344  
 345          case 'ucp':
 346              $location = $user->lang['VIEWING_UCP'];
 347  
 348              // Grab some common modules
 349              $url_params = array(
 350                  'mode=register'        => 'VIEWING_REGISTER',
 351                  'i=pm&mode=compose'    => 'POSTING_PRIVATE_MESSAGE',
 352                  'i=pm&'                => 'VIEWING_PRIVATE_MESSAGES',
 353                  'i=profile&'        => 'CHANGING_PROFILE',
 354                  'i=prefs&'            => 'CHANGING_PREFERENCES',
 355              );
 356  
 357              foreach ($url_params as $param => $lang)
 358              {
 359                  if (strpos($row['session_page'], $param) !== false)
 360                  {
 361                      $location = $user->lang[$lang];
 362                      break;
 363                  }
 364              }
 365  
 366              $location_url = append_sid("{$phpbb_root_path}index.$phpEx");
 367          break;
 368  
 369          case 'download/file':
 370              $location = $user->lang['DOWNLOADING_FILE'];
 371              $location_url = append_sid("{$phpbb_root_path}index.$phpEx");
 372          break;
 373  
 374          case 'report':
 375              $location = $user->lang['REPORTING_POST'];
 376              $location_url = append_sid("{$phpbb_root_path}index.$phpEx");
 377          break;
 378  
 379          default:
 380              $location = $user->lang['INDEX'];
 381              $location_url = append_sid("{$phpbb_root_path}index.$phpEx");
 382  
 383              if ($row['session_page'] === 'app.' . $phpEx . '/help/faq' ||
 384                  $row['session_page'] === 'app.' . $phpEx . '/help/bbcode')
 385              {
 386                  $location = $user->lang['VIEWING_FAQ'];
 387                  $location_url = $controller_helper->route('phpbb_help_faq_controller');
 388              }
 389          break;
 390      }
 391  
 392      /**
 393      * Overwrite the location's name and URL, which are displayed in the list
 394      *
 395      * @event core.viewonline_overwrite_location
 396      * @var    array    on_page            File name and query string
 397      * @var    array    row                Array with the users sql row
 398      * @var    string    location        Page name to displayed in the list
 399      * @var    string    location_url    Page url to displayed in the list
 400      * @var    array    forum_data        Array with forum data
 401      * @since 3.1.0-a1
 402      * @changed 3.1.0-a2 Added var forum_data
 403      */
 404      $vars = array('on_page', 'row', 'location', 'location_url', 'forum_data');
 405      extract($phpbb_dispatcher->trigger_event('core.viewonline_overwrite_location', compact($vars)));
 406  
 407      $template_row = array(
 408          'USERNAME'             => $row['username'],
 409          'USERNAME_COLOUR'    => $row['user_colour'],
 410          'USERNAME_FULL'        => $username_full,
 411          'LASTUPDATE'        => $user->format_date($row['session_time']),
 412          'FORUM_LOCATION'    => $location,
 413          'USER_IP'            => ($auth->acl_get('a_')) ? (($mode == 'lookup' && $session_id == $row['session_id']) ? gethostbyaddr($row['session_ip']) : $row['session_ip']) : '',
 414          'USER_BROWSER'        => ($auth->acl_get('a_user')) ? $row['session_browser'] : '',
 415  
 416          'U_USER_PROFILE'    => ($row['user_type'] != USER_IGNORE) ? get_username_string('profile', $row['user_id'], '') : '',
 417          'U_USER_IP'            => append_sid("{$phpbb_root_path}viewonline.$phpEx", 'mode=lookup' . (($mode != 'lookup' || $row['session_id'] != $session_id) ? '&amp;s=' . $row['session_id'] : '') . "&amp;sg=$show_guests&amp;start=$start&amp;sk=$sort_key&amp;sd=$sort_dir"),
 418          'U_WHOIS'            => append_sid("{$phpbb_root_path}viewonline.$phpEx", 'mode=whois&amp;s=' . $row['session_id']),
 419          'U_FORUM_LOCATION'    => $location_url,
 420  
 421          'S_USER_HIDDEN'        => $s_user_hidden,
 422          'S_GUEST'            => ($row['user_id'] == ANONYMOUS) ? true : false,
 423          'S_USER_TYPE'        => $row['user_type'],
 424      );
 425  
 426      /**
 427      * Modify viewonline template data before it is displayed in the list
 428      *
 429      * @event core.viewonline_modify_user_row
 430      * @var    array    on_page            File name and query string
 431      * @var    array    row                Array with the users sql row
 432      * @var    array    forum_data        Array with forum data
 433      * @var    array    template_row    Array with template variables for the user row
 434      * @since 3.1.0-RC4
 435      */
 436      $vars = array('on_page', 'row', 'forum_data', 'template_row');
 437      extract($phpbb_dispatcher->trigger_event('core.viewonline_modify_user_row', compact($vars)));
 438  
 439      $template->assign_block_vars('user_row', $template_row);
 440  }
 441  $db->sql_freeresult($result);
 442  unset($prev_id, $prev_ip);
 443  
 444  $order_legend = ($config['legend_sort_groupname']) ? 'group_name' : 'group_legend';
 445  // Grab group details for legend display
 446  if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
 447  {
 448      $sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend
 449          FROM ' . GROUPS_TABLE . '
 450          WHERE group_legend > 0
 451          ORDER BY ' . $order_legend . ' ASC';
 452  }
 453  else
 454  {
 455      $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type, g.group_legend
 456          FROM ' . GROUPS_TABLE . ' g
 457          LEFT JOIN ' . USER_GROUP_TABLE . ' ug
 458              ON (
 459                  g.group_id = ug.group_id
 460                  AND ug.user_id = ' . $user->data['user_id'] . '
 461                  AND ug.user_pending = 0
 462              )
 463          WHERE g.group_legend > 0
 464              AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')
 465          ORDER BY g.' . $order_legend . ' ASC';
 466  }
 467  $result = $db->sql_query($sql);
 468  
 469  $legend = '';
 470  while ($row = $db->sql_fetchrow($result))
 471  {
 472      if ($row['group_name'] == 'BOTS')
 473      {
 474          $legend .= (($legend != '') ? ', ' : '') . '<span style="color:#' . $row['group_colour'] . '">' . $user->lang['G_BOTS'] . '</span>';
 475      }
 476      else
 477      {
 478          $legend .= (($legend != '') ? ', ' : '') . '<a style="color:#' . $row['group_colour'] . '" href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_helper->get_name($row['group_name']) . '</a>';
 479      }
 480  }
 481  $db->sql_freeresult($result);
 482  
 483  // Refreshing the page every 60 seconds...
 484  meta_refresh(60, append_sid("{$phpbb_root_path}viewonline.$phpEx", "sg=$show_guests&amp;sk=$sort_key&amp;sd=$sort_dir&amp;start=$start"));
 485  
 486  $start = $pagination->validate_start($start, $config['topics_per_page'], $counter);
 487  $base_url = append_sid("{$phpbb_root_path}viewonline.$phpEx", "sg=$show_guests&amp;sk=$sort_key&amp;sd=$sort_dir");
 488  $pagination->generate_template_pagination($base_url, 'pagination', 'start', $counter, $config['topics_per_page'], $start);
 489  
 490  // Send data to template
 491  $template->assign_vars(array(
 492      'TOTAL_REGISTERED_USERS_ONLINE'    => $user->lang('REG_USERS_ONLINE', (int) $logged_visible_online, $user->lang('HIDDEN_USERS_ONLINE', (int) $logged_hidden_online)),
 493      'TOTAL_GUEST_USERS_ONLINE'        => $user->lang('GUEST_USERS_ONLINE', (int) $guest_counter),
 494      'LEGEND'                        => $legend,
 495  
 496      'U_SORT_USERNAME'        => append_sid("{$phpbb_root_path}viewonline.$phpEx", 'sk=a&amp;sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a') . '&amp;sg=' . ((int) $show_guests)),
 497      'U_SORT_UPDATED'        => append_sid("{$phpbb_root_path}viewonline.$phpEx", 'sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a') . '&amp;sg=' . ((int) $show_guests)),
 498      'U_SORT_LOCATION'        => append_sid("{$phpbb_root_path}viewonline.$phpEx", 'sk=c&amp;sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a') . '&amp;sg=' . ((int) $show_guests)),
 499  
 500      'U_SWITCH_GUEST_DISPLAY'    => append_sid("{$phpbb_root_path}viewonline.$phpEx", 'sg=' . ((int) !$show_guests)),
 501      'L_SWITCH_GUEST_DISPLAY'    => ($show_guests) ? $user->lang['HIDE_GUESTS'] : $user->lang['DISPLAY_GUESTS'],
 502      'S_SWITCH_GUEST_DISPLAY'    => ($config['load_online_guests']) ? true : false,
 503      'S_VIEWONLINE'                => true,
 504  ));
 505  
 506  // We do not need to load the who is online box here. ;)
 507  $config['load_online'] = false;
 508  
 509  // Output the page
 510  page_header($user->lang['WHO_IS_ONLINE']);
 511  
 512  $template->set_filenames(array(
 513      'body' => 'viewonline_body.html')
 514  );
 515  make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
 516  
 517  page_footer();


Generated: Thu Jan 11 23:14:31 2018 Cross-referenced by PHPXref 0.7.1