| [ Index ] |
PHP Cross Reference of MyBB 1.4.13 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.4 4 * Copyright © 2008 MyBB Group, All Rights Reserved 5 * 6 * Website: http://www.mybboard.net 7 * License: http://www.mybboard.net/about/license 8 * 9 * $Id: online.php 4341 2009-04-06 21:49:53Z Tikitiki $ 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 $todaycount = 0; 39 $stime = TIME_NOW-(60*60*24); 40 $todayrows = ''; 41 $query = $db->query(" 42 SELECT u.* 43 FROM ".TABLE_PREFIX."users u 44 LEFT JOIN ".TABLE_PREFIX."usergroups g ON (g.gid=u.usergroup) 45 WHERE u.lastactive > $stime 46 ORDER BY u.lastactive DESC 47 "); 48 while($online = $db->fetch_array($query)) 49 { 50 if($online['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $online['uid'] == $mybb->user['uid']) 51 { 52 if($online['invisible'] == 1) 53 { 54 $invisiblemark = "*"; 55 } 56 else 57 { 58 $invisiblemark = ""; 59 } 60 $username = $online['username']; 61 $username = format_name($username, $online['usergroup'], $online['displaygroup']); 62 $online['profilelink'] = build_profile_link($username, $online['uid']); 63 $onlinetime = my_date($mybb->settings['timeformat'], $online['lastactive']); 64 eval("\$todayrows .= \"".$templates->get("online_today_row")."\";"); 65 } 66 ++$todaycount; 67 } 68 if($todaycount == 1) 69 { 70 $onlinetoday = $lang->member_online_today; 71 } 72 else 73 { 74 $onlinetoday = $lang->sprintf($lang->members_were_online_today, $todaycount); 75 } 76 77 $plugins->run_hooks("online_today_end"); 78 79 eval("\$today = \"".$templates->get("online_today")."\";"); 80 output_page($today); 81 } 82 else 83 { 84 $plugins->run_hooks("online_start"); 85 86 // Custom sorting options 87 if($mybb->input['sortby'] == "username") 88 { 89 $sql = "u.username ASC, s.time DESC"; 90 $refresh_string = "?sortby=username"; 91 } 92 elseif($mybb->input['sortby'] == "location") 93 { 94 $sql = "s.location, s.time DESC"; 95 $refresh_string = "?sortby=location"; 96 } 97 // Otherwise sort by last refresh 98 else 99 { 100 switch($db->type) 101 { 102 case "sqlite3": 103 case "sqlite2": 104 case "pgsql": 105 $sql = "s.time DESC"; 106 break; 107 default: 108 $sql = "IF( s.uid >0, 1, 0 ) DESC, s.time DESC"; 109 break; 110 } 111 $refresh_string = ''; 112 } 113 114 $timesearch = TIME_NOW - $mybb->settings['wolcutoffmins']*60; 115 116 // Exactly how many users are currently online? 117 switch($db->type) 118 { 119 case "sqlite3": 120 case "sqlite2": 121 $sessions = array(); 122 $query = $db->simple_select("sessions", "sid", "time > {$timesearch}"); 123 while($sid = $db->fetch_field($query, "sid")) 124 { 125 $sessions[$sid] = 1; 126 } 127 $online_count = count($sessions); 128 unset($sessions); 129 break; 130 case "pgsql": 131 default: 132 $query = $db->simple_select("sessions", "COUNT(sid) as online", "time > {$timesearch}"); 133 $online_count = $db->fetch_field($query, "online"); 134 break; 135 } 136 137 // How many pages are there? 138 $perpage = $mybb->settings['threadsperpage']; 139 140 if(intval($mybb->input['page']) > 0) 141 { 142 $page = intval($mybb->input['page']); 143 $start = ($page-1) * $perpage; 144 $pages = ceil($online_count / $perpage); 145 if($page > $pages) 146 { 147 $start = 0; 148 $page = 1; 149 } 150 } 151 else 152 { 153 $start = 0; 154 $page = 1; 155 } 156 157 // Assemble page URL 158 $multipage = multipage($online_count, $perpage, $page, "online.php".$refresh_string); 159 160 // Query for active sessions 161 $query = $db->query(" 162 SELECT DISTINCT s.sid, s.ip, s.uid, s.time, s.location, u.username, s.nopermission, u.invisible, u.usergroup, u.displaygroup 163 FROM ".TABLE_PREFIX."sessions s 164 LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid) 165 WHERE s.time>'$timesearch' 166 ORDER BY $sql 167 LIMIT {$start}, {$perpage} 168 "); 169 170 // Fetch spiders 171 $spiders = $cache->read("spiders"); 172 173 while($user = $db->fetch_array($query)) 174 { 175 $plugins->run_hooks("online_user"); 176 177 // Fetch the WOL activity 178 $user['activity'] = fetch_wol_activity($user['location'], $user['nopermission']); 179 180 $botkey = my_strtolower(str_replace("bot=", '', $user['sid'])); 181 182 // Have a registered user 183 if($user['uid'] > 0) 184 { 185 if($users[$user['uid']]['time'] < $user['time'] || !$users[$user['uid']]) 186 { 187 $users[$user['uid']] = $user; 188 } 189 } 190 // Otherwise this session is a bot 191 else if(my_strpos($user['sid'], "bot=") !== false && $spiders[$botkey]) 192 { 193 $user['bot'] = $spiders[$botkey]['name']; 194 $user['usergroup'] = $spiders[$botkey]['usergroup']; 195 $guests[] = $user; 196 } 197 // Or a guest 198 else 199 { 200 $guests[] = $user; 201 } 202 } 203 204 // Now we build the actual online rows - we do this separately because we need to query all of the specific activity and location information 205 $online_rows = ''; 206 if(is_array($users)) 207 { 208 reset($users); 209 foreach($users as $user) 210 { 211 $online_rows .= build_wol_row($user); 212 } 213 } 214 if(is_array($guests)) 215 { 216 reset($guests); 217 foreach($guests as $user) 218 { 219 $online_rows .= build_wol_row($user); 220 } 221 } 222 223 // Fetch the most online information 224 $most_online = $cache->read("mostonline"); 225 $record_count = $most_online['numusers']; 226 $record_date = my_date($mybb->settings['dateformat'], $most_online['time']); 227 $record_time = my_date($mybb->settings['timeformat'], $most_online['time']); 228 229 // Set automatic refreshing if enabled 230 if($mybb->settings['refreshwol'] > 0) 231 { 232 $refresh_time = $mybb->settings['refreshwol'] * 60; 233 $refresh = "<meta http-equiv=\"refresh\" content=\"{$refresh_time};URL=online.php{$refresh_string}\" />"; 234 } 235 236 $plugins->run_hooks("online_end"); 237 238 eval("\$online = \"".$templates->get("online")."\";"); 239 output_page($online); 240 } 241 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Apr 19 19:52:21 2010 | Cross-referenced by PHPXref 0.7 |