[ Index ]

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


Generated: Sun Feb 19 19:52:41 2017 Cross-referenced by PHPXref 0.7.1