[ Index ]

PHP Cross Reference of MyBB 1.6.5

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: online.php 5638 2011-10-26 08:59:45Z Tomm $

  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,online_iplookup,mostonline";
  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      // Add pagination

  43      $perpage = $mybb->settings['threadsperpage'];
  44  
  45      if(intval($mybb->input['page']) > 0)
  46      {
  47          $page = intval($mybb->input['page']);
  48          $start = ($page-1) * $perpage;
  49          $pages = ceil($todaycount / $perpage);
  50          if($page > $pages)
  51          {
  52              $start = 0;
  53              $page = 1;
  54          }
  55      }
  56      else
  57      {
  58          $start = 0;
  59          $page = 1;
  60      }
  61  
  62      $query = $db->simple_select("users", "*", "lastactive > '{$threshold}'", array("order_by" => "lastactive", "order_dir" => "desc", "limit" => $perpage, "limit_start" => $start));
  63  
  64      $todayrows = '';
  65      $invis_count = 0;
  66      while($online = $db->fetch_array($query))
  67      {
  68          $invisiblemark = '';
  69          if($online['invisible'] == 1)
  70          {
  71              ++$invis_count;
  72              $invisiblemark = "*";
  73          }
  74  
  75          if($online['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $online['uid'] == $mybb->user['uid'])
  76          {    
  77              $username = $online['username'];
  78              $username = format_name($username, $online['usergroup'], $online['displaygroup']);
  79              $online['profilelink'] = build_profile_link($username, $online['uid']);
  80              $onlinetime = my_date($mybb->settings['timeformat'], $online['lastactive']);
  81  
  82              eval("\$todayrows .= \"".$templates->get("online_today_row")."\";");
  83          }
  84      }
  85  
  86      if($todaycount == 1)
  87      {
  88          $onlinetoday = $lang->member_online_today;
  89      }
  90      else
  91      {
  92          $onlinetoday = $lang->sprintf($lang->members_were_online_today, $todaycount);
  93      }
  94  
  95      if($invis_count)
  96      {
  97          $string = $lang->members_online_hidden;
  98  
  99          if($invis_count == 1)
 100          {
 101              $string = $lang->member_online_hidden;
 102          }
 103  
 104          $onlinetoday .= $lang->sprintf($string, $invis_count);
 105      }
 106  
 107      $multipage = multipage($todaycount, $perpage, $page, "online.php?action=today");
 108  
 109      $plugins->run_hooks("online_today_end");
 110  
 111      eval("\$today = \"".$templates->get("online_today")."\";");
 112      output_page($today);
 113  }
 114  else
 115  {
 116      $plugins->run_hooks("online_start");
 117  
 118      // Custom sorting options

 119      if($mybb->input['sortby'] == "username")
 120      {
 121          $sql = "u.username ASC, s.time DESC";
 122          $refresh_string = "?sortby=username";
 123      }
 124      elseif($mybb->input['sortby'] == "location")
 125      {
 126          $sql = "s.location, s.time DESC";
 127          $refresh_string = "?sortby=location";
 128      }
 129      // Otherwise sort by last refresh

 130      else
 131      {
 132          switch($db->type)
 133          {
 134              case "sqlite":
 135              case "pgsql":        
 136                  $sql = "s.time DESC";
 137                  break;
 138              default:
 139                  $sql = "IF( s.uid >0, 1, 0 ) DESC, s.time DESC";
 140                  break;
 141          }
 142          $refresh_string = '';
 143      }
 144      
 145      $timesearch = TIME_NOW - $mybb->settings['wolcutoffmins']*60;
 146  
 147      // Exactly how many users are currently online?

 148      switch($db->type)
 149      {
 150          case "sqlite":
 151              $sessions = array();
 152              $query = $db->simple_select("sessions", "sid", "time > {$timesearch}");
 153              while($sid = $db->fetch_field($query, "sid"))
 154              {
 155                  $sessions[$sid] = 1;
 156              }
 157              $online_count = count($sessions);
 158              unset($sessions);
 159              break;
 160          case "pgsql":
 161          default:
 162              $query = $db->simple_select("sessions", "COUNT(sid) as online", "time > {$timesearch}");
 163              $online_count = $db->fetch_field($query, "online");
 164              break;
 165      }
 166      
 167      // How many pages are there?

 168      $perpage = $mybb->settings['threadsperpage'];
 169  
 170      if(intval($mybb->input['page']) > 0)
 171      {
 172          $page = intval($mybb->input['page']);
 173          $start = ($page-1) * $perpage;
 174          $pages = ceil($online_count / $perpage);
 175          if($page > $pages)
 176          {
 177              $start = 0;
 178              $page = 1;
 179          }
 180      }
 181      else
 182      {
 183          $start = 0;
 184          $page = 1;
 185      }
 186  
 187      // Assemble page URL

 188      $multipage = multipage($online_count, $perpage, $page, "online.php".$refresh_string);
 189      
 190      // Query for active sessions

 191      $query = $db->query("
 192          SELECT DISTINCT s.sid, s.ip, s.uid, s.time, s.location, u.username, s.nopermission, u.invisible, u.usergroup, u.displaygroup
 193          FROM ".TABLE_PREFIX."sessions s
 194          LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
 195          WHERE s.time>'$timesearch'
 196          ORDER BY $sql
 197          LIMIT {$start}, {$perpage}
 198      ");
 199  
 200      // Fetch spiders

 201      $spiders = $cache->read("spiders");
 202  
 203      while($user = $db->fetch_array($query))
 204      {
 205          $plugins->run_hooks("online_user");
 206  
 207          // Fetch the WOL activity

 208          $user['activity'] = fetch_wol_activity($user['location'], $user['nopermission']);
 209  
 210          $botkey = my_strtolower(str_replace("bot=", '', $user['sid']));
 211  
 212          // Have a registered user

 213          if($user['uid'] > 0)
 214          {
 215              if($users[$user['uid']]['time'] < $user['time'] || !$users[$user['uid']])
 216              {
 217                  $users[$user['uid']] = $user;
 218              }
 219          }
 220          // Otherwise this session is a bot

 221          else if(my_strpos($user['sid'], "bot=") !== false && $spiders[$botkey])
 222          {
 223              $user['bot'] = $spiders[$botkey]['name'];
 224              $user['usergroup'] = $spiders[$botkey]['usergroup'];
 225              $guests[] = $user;
 226          }
 227          // Or a guest

 228          else
 229          {
 230              $guests[] = $user;
 231          }
 232      }
 233  
 234      // Now we build the actual online rows - we do this separately because we need to query all of the specific activity and location information

 235      $online_rows = '';
 236      if(is_array($users))
 237      {
 238          reset($users);
 239          foreach($users as $user)
 240          {
 241              $online_rows .= build_wol_row($user);
 242          }
 243      }
 244      if(is_array($guests))
 245      {
 246          reset($guests);
 247          foreach($guests as $user)
 248          {
 249              $online_rows .= build_wol_row($user);
 250          }
 251      }
 252  
 253      // Fetch the most online information

 254      $most_online = $cache->read("mostonline");
 255      $record_count = $most_online['numusers'];
 256      $record_date = my_date($mybb->settings['dateformat'], $most_online['time']);
 257      $record_time = my_date($mybb->settings['timeformat'], $most_online['time']);
 258  
 259      // Set automatic refreshing if enabled

 260      if($mybb->settings['refreshwol'] > 0)
 261      {
 262          $refresh_time = $mybb->settings['refreshwol'] * 60;
 263          $refresh = "<meta http-equiv=\"refresh\" content=\"{$refresh_time};URL=online.php{$refresh_string}\" />";
 264      }
 265      
 266      $plugins->run_hooks("online_end");
 267  
 268      eval("\$online = \"".$templates->get("online")."\";");
 269      output_page($online);
 270  }
 271  ?>


Generated: Sun Dec 11 14:16:27 2011 Cross-referenced by PHPXref 0.7.1