[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/ -> online.php (source)

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


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1