[ Index ]

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


Generated: Sun Feb 19 19:47:08 2017 Cross-referenced by PHPXref 0.7.1