".__('Members Online')."
".__('now').' : '; members_online_now();
echo "
".__('today').' : '; members_online_today();
echo "
";
}
function members_online($action='') {
global $bbdb,$bb_current_user, $bb_user_cache, $members_online;
if (empty($bb_current_user->ID)) {return;}
$time=time(); $id=$bb_current_user->ID; $user=bb_get_user($id);
if (isset($user->last_online)) {
$since=$time - intval($user->last_online);
if (!empty($action) || $since >$members_online['timeout']) { // user's previous session has expired, update total online time before we lose track
(int) $user->time_online=intval($user->time_online)+( intval($user->last_online)-intval($user->first_online));
$bbdb->query("UPDATE $bbdb->usermeta SET meta_value='$user->time_online' WHERE user_id='$id' AND meta_key='time_online' LIMIT 1");
if (empty($action)) {
$user->first_online=$user->last_online=$time;
$bbdb->query("UPDATE $bbdb->usermeta SET meta_value='$time' WHERE user_id='$id' AND (meta_key='first_online' OR meta_key='last_online') LIMIT 2");
} else { // logout, trick first_online to be higher than last_online to indicate
$user->first_online=(int) $user->last_online+1;
$bbdb->query("UPDATE $bbdb->usermeta SET meta_value='$user->first_online' WHERE user_id='$id' AND meta_key='first_online' LIMIT 1");
}
} elseif ($since>60) { // regular update, save queries by not bothering to update unless it's been over a minute
$bbdb->query("UPDATE $bbdb->usermeta SET meta_value='$time' WHERE user_id='$id' AND meta_key='last_online' LIMIT 1");
$user->last_online=$time;
}
} else { // plugin has never seen this member before
$bbdb->query("INSERT INTO $bbdb->usermeta ( user_id , meta_key , meta_value) VALUES ('$id', 'last_online', '$time') , ('$id', 'first_online', '$time') , ('$id', 'time_online', '1')");
$user->first_online=$user->last_online=$time; $user->time_online=1;
}
if (function_exists('wp_cache_add')) {wp_cache_set($user->ID, $user, 'users' );} else {$bb_user_cache[$user->ID]=$user;}
}
function members_online_update() {members_online('logout');}
function members_online_now($time=0) {
global $bbdb, $members_online; $members_online['footer']=false;
if (empty($members_online['show_anyone']) && !bb_is_user_logged_in()) {return;}
if (empty($time)) {$time=time()-$members_online['timeout'];}
$results=$bbdb->get_results("SELECT ID,user_login FROM $bbdb->users LEFT JOIN $bbdb->usermeta ON ID=user_id WHERE meta_key='last_online' AND cast(meta_value AS unsigned)>'$time' ORDER BY meta_value DESC");
if (!empty($results)) {
$output=""; $rewrite = bb_get_option( 'mod_rewrite' ); $bb_uri=bb_get_option('uri');
if (empty($rewrite)) {$uri=$bb_uri."profile.php?id=";} else {$uri=$bb_uri."profile/"; }
foreach ($results as $result) { $key=$result->ID; $value=$result->user_login;
if (empty($rewrite) || $rewrite !== 'slugs' ) {$stub=$key;} else {$stub= bb_user_nicename_sanitize($value);}
$output.="