[ Index ]

PHP Cross Reference of MyBB 1.8.12

title

Body

[close]

/ -> online.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  define("IN_MYBB", 1);
  12  define('THIS_SCRIPT', 'online.php');
  13  
  14  $templatelist = "online,online_row,online_row_ip,online_today,online_today_row,online_row_ip_lookup,online_refresh,multipage,multipage_end,multipage_start";
  15  $templatelist .= ",multipage_jump_page,multipage_nextpage,multipage_page,multipage_page_current,multipage_page_link_current,multipage_prevpage";
  16  
  17  require_once  "./global.php";
  18  require_once  MYBB_ROOT."inc/functions_post.php";
  19  require_once  MYBB_ROOT."inc/functions_online.php";
  20  require_once  MYBB_ROOT."inc/class_parser.php";
  21  $parser = new postParser;
  22  
  23  // Load global language phrases
  24  $lang->load("online");
  25  
  26  if($mybb->usergroup['canviewonline'] == 0)
  27  {
  28      error_no_permission();
  29  }
  30  
  31  // Make navigation
  32  add_breadcrumb($lang->nav_online, "online.php");
  33  
  34  if($mybb->get_input('action') == "today")
  35  {
  36      add_breadcrumb($lang->nav_onlinetoday);
  37  
  38      $plugins->run_hooks("online_today_start");
  39  
  40      $threshold = TIME_NOW-(60*60*24);
  41      $query = $db->simple_select("users", "COUNT(uid) AS users", "lastactive > '{$threshold}'");
  42      $todaycount = $db->fetch_field($query, "users");
  43  
  44      $query = $db->simple_select("users", "COUNT(uid) AS users", "lastactive > '{$threshold}' AND invisible = '1'");
  45      $invis_count = $db->fetch_field($query, "users");
  46  
  47      if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
  48      {
  49          $mybb->settings['threadsperpage'] = 20;
  50      }
  51      
  52      // Add pagination
  53      $perpage = $mybb->settings['threadsperpage'];
  54  
  55      if($mybb->get_input('page', MyBB::INPUT_INT) > 0)
  56      {
  57          $page = $mybb->get_input('page', MyBB::INPUT_INT);
  58          $start = ($page-1) * $perpage;
  59          $pages = ceil($todaycount / $perpage);
  60          if($page > $pages)
  61          {
  62              $start = 0;
  63              $page = 1;
  64          }
  65      }
  66      else
  67      {
  68          $start = 0;
  69          $page = 1;
  70      }
  71  
  72      $query = $db->simple_select("users", "*", "lastactive > '{$threshold}'", array("order_by" => "lastactive", "order_dir" => "desc", "limit" => $perpage, "limit_start" => $start));
  73  
  74      $todayrows = '';
  75      while($online = $db->fetch_array($query))
  76      {
  77          $invisiblemark = '';
  78          if($online['invisible'] == 1)
  79          {
  80              $invisiblemark = "*";
  81          }
  82  
  83          if($online['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $online['uid'] == $mybb->user['uid'])
  84          {
  85              $username = format_name(htmlspecialchars_uni($online['username']), $online['usergroup'], $online['displaygroup']);
  86              $online['profilelink'] = build_profile_link($username, $online['uid']);
  87              $onlinetime = my_date($mybb->settings['timeformat'], $online['lastactive']);
  88  
  89              eval("\$todayrows .= \"".$templates->get("online_today_row")."\";");
  90          }
  91      }
  92  
  93      $todaycount = my_number_format($todaycount);
  94      $invis_count = my_number_format($invis_count);
  95  
  96      if($todaycount == 1)
  97      {
  98          $onlinetoday = $lang->member_online_today;
  99      }
 100      else
 101      {
 102          $onlinetoday = $lang->sprintf($lang->members_were_online_today, $todaycount);
 103      }
 104  
 105      if($invis_count)
 106      {
 107          $string = $lang->members_online_hidden;
 108  
 109          if($invis_count == 1)
 110          {
 111              $string = $lang->member_online_hidden;
 112          }
 113  
 114          $onlinetoday .= $lang->sprintf($string, $invis_count);
 115      }
 116  
 117      $multipage = multipage($todaycount, $perpage, $page, "online.php?action=today");
 118  
 119      $plugins->run_hooks("online_today_end");
 120  
 121      eval("\$today = \"".$templates->get("online_today")."\";");
 122      output_page($today);
 123  }
 124  else
 125  {
 126      $plugins->run_hooks("online_start");
 127  
 128      // Custom sorting options
 129      if($mybb->get_input('sortby') == "username")
 130      {
 131          $sql = "u.username ASC, s.time DESC";
 132          $refresh_string = "?sortby=username";
 133      }
 134      elseif($mybb->get_input('sortby') == "location")
 135      {
 136          $sql = "s.location, s.time DESC";
 137          $refresh_string = "?sortby=location";
 138      }
 139      // Otherwise sort by last refresh
 140      else
 141      {
 142          switch($db->type)
 143          {
 144              case "sqlite":
 145              case "pgsql":
 146                  $sql = "s.time DESC";
 147                  break;
 148              default:
 149                  $sql = "IF( s.uid >0, 1, 0 ) DESC, s.time DESC";
 150                  break;
 151          }
 152          $refresh_string = '';
 153      }
 154  
 155      $timesearch = TIME_NOW - $mybb->settings['wolcutoffmins']*60;
 156  
 157      // Exactly how many users are currently online?
 158      switch($db->type)
 159      {
 160          case "sqlite":
 161              $sessions = array();
 162              $query = $db->simple_select("sessions", "sid", "time > {$timesearch}");
 163              while($sid = $db->fetch_field($query, "sid"))
 164              {
 165                  $sessions[$sid] = 1;
 166              }
 167              $online_count = count($sessions);
 168              unset($sessions);
 169              break;
 170          case "pgsql":
 171          default:
 172              $query = $db->simple_select("sessions", "COUNT(sid) as online", "time > {$timesearch}");
 173              $online_count = $db->fetch_field($query, "online");
 174              break;
 175      }
 176      
 177      if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
 178      {
 179          $mybb->settings['threadsperpage'] = 20;
 180      }
 181  
 182      // How many pages are there?
 183      $perpage = $mybb->settings['threadsperpage'];
 184  
 185      if($mybb->get_input('page', MyBB::INPUT_INT) > 0)
 186      {
 187          $page = $mybb->get_input('page', MyBB::INPUT_INT);
 188          $start = ($page-1) * $perpage;
 189          $pages = ceil($online_count / $perpage);
 190          if($page > $pages)
 191          {
 192              $start = 0;
 193              $page = 1;
 194          }
 195      }
 196      else
 197      {
 198          $start = 0;
 199          $page = 1;
 200      }
 201  
 202      // Assemble page URL
 203      $multipage = multipage($online_count, $perpage, $page, "online.php".$refresh_string);
 204  
 205      // Query for active sessions
 206      $query = $db->query("
 207          SELECT DISTINCT s.sid, s.ip, s.uid, s.time, s.location, u.username, s.nopermission, u.invisible, u.usergroup, u.displaygroup
 208          FROM ".TABLE_PREFIX."sessions s
 209          LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
 210          WHERE s.time>'$timesearch'
 211          ORDER BY $sql
 212          LIMIT {$start}, {$perpage}
 213      ");
 214  
 215      // Fetch spiders
 216      $spiders = $cache->read("spiders");
 217  
 218      while($user = $db->fetch_array($query))
 219      {
 220          $plugins->run_hooks("online_user");
 221  
 222          // Fetch the WOL activity
 223          $user['activity'] = fetch_wol_activity($user['location'], $user['nopermission']);
 224  
 225          $botkey = my_strtolower(str_replace("bot=", '', $user['sid']));
 226  
 227          // Have a registered user
 228          if($user['uid'] > 0)
 229          {
 230              if(empty($users[$user['uid']]) || $users[$user['uid']]['time'] < $user['time'])
 231              {
 232                  $users[$user['uid']] = $user;
 233              }
 234          }
 235          // Otherwise this session is a bot
 236          else if(my_strpos($user['sid'], "bot=") !== false && $spiders[$botkey])
 237          {
 238              $user['bot'] = $spiders[$botkey]['name'];
 239              $user['usergroup'] = $spiders[$botkey]['usergroup'];
 240              $guests[] = $user;
 241          }
 242          // Or a guest
 243          else
 244          {
 245              $guests[] = $user;
 246          }
 247      }
 248  
 249      // Now we build the actual online rows - we do this separately because we need to query all of the specific activity and location information
 250      $online_rows = '';
 251      if(isset($users) && is_array($users))
 252      {
 253          reset($users);
 254          foreach($users as $user)
 255          {
 256              $online_rows .= build_wol_row($user);
 257          }
 258      }
 259      if(isset($guests) && is_array($guests))
 260      {
 261          reset($guests);
 262          foreach($guests as $user)
 263          {
 264              $online_rows .= build_wol_row($user);
 265          }
 266      }
 267  
 268      // Fetch the most online information
 269      $most_online = $cache->read("mostonline");
 270      $record_count = $most_online['numusers'];
 271      $record_date = my_date('relative', $most_online['time']);
 272  
 273      // Set automatic refreshing if enabled
 274      if($mybb->settings['refreshwol'] > 0)
 275      {
 276          $refresh_time = $mybb->settings['refreshwol'] * 60;
 277          eval("\$refresh = \"".$templates->get("online_refresh")."\";");
 278      }
 279  
 280      $plugins->run_hooks("online_end");
 281  
 282      eval("\$online = \"".$templates->get("online")."\";");
 283      output_page($online);
 284  }


2005 - 2016 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref 0.7.1