= "4.1" ) : // thanks to: chester copperpot $bbdb->query("INSERT INTO ".$bb_table_prefix."online (user_id, activity) VALUES ('".$bb_current_user->ID."', '".time()."') ON DUPLICATE KEY UPDATE activity=VALUES(activity)"); else : if ($bbdb->get_results("SELECT * FROM ".$bb_table_prefix."online WHERE user_id = ".$bb_current_user->ID." LIMIT 1")) : $bbdb->query("UPDATE ".$bb_table_prefix."online SET activity = ".time()." WHERE user_id = ".$bb_current_user->ID.""); else : $bbdb->query("INSERT INTO ".$bb_table_prefix."online (user_id, activity) VALUES ('".$bb_current_user->ID."', '".time()."')"); endif; endif; endif; } add_action('bb_init', 'online_update'); function online_logout() { global $bbdb, $bb_current_user, $bb_table_prefix; $now = time() - 300; // 5 minutes ago if ($bbdb->get_results("SELECT * FROM ".$bb_table_prefix."online WHERE user_id = ".$bb_current_user->ID." LIMIT 1")) : $bbdb->query("UPDATE ".$bb_table_prefix."online SET activity = ".$now." WHERE user_id = ".$bb_current_user->ID.""); endif; } add_action('bb_user_logout', 'online_logout'); function setup_check() { global $bbdb, $bb_table_prefix; $bbdb->hide_errors(); $installed = $bbdb->get_results("SELECT user_id FROM ".$bb_table_prefix."online LIMIT 1"); if ( !$installed ) : $bbdb->query(" CREATE TABLE IF NOT EXISTS `".$bb_table_prefix."online` ( `user_id` INT( 11 ) NOT NULL , `activity` VARCHAR( 255 ) NOT NULL , PRIMARY KEY ( `user_id` ) )"); online_update(); // insert first data endif; $bbdb->show_errors(); } function show_online_users() { global $bbdb, $bb_table_prefix; // checks if table is created, does if not setup_check(); $now = time() - 300; // 5 minutes ago if ($online = $bbdb->get_results("SELECT * FROM ".$bb_table_prefix."online WHERE activity > ".$now." ORDER BY activity ASC")) : $counter = 0; $numrows = $bbdb->num_rows; if ($numrows == 1) : $isare = __(' Member is'); else : $isare = __(' Members are'); endif; printf(__('%1$s %2$s online.'), $numrows, $isare); echo "
"; foreach ($online as $on) : // get commas $counter++; if ( $numrows != 1 && $numrows > $counter ) : $komma = ", "; else : $komma = " "; endif; $user = bb_get_user($on->user_id); echo "user_id)."\" title=\"\">".$user->user_login."$komma"; endforeach; else : echo __('No Members around.'); endif; } function total_online_users() { global $bbdb, $bb_table_prefix; $now = time() - 300; // 5 minutes ago $total_online_users = $bbdb->get_var("SELECT COUNT(*) FROM ".$bb_table_prefix."online WHERE activity > ".$now.""); echo $total_online_users; } function profile_last_online() { global $bbdb, $bb_table_prefix, $user_id; $now = time() - 300; // 5 minutes ago echo "
\n"; echo "\t
" . __('Last Online') . "
\n"; if ($last_online = $bbdb->get_var("SELECT activity FROM ".$bb_table_prefix."online WHERE user_id=$user_id LIMIT 1")) : if ($last_online > $now) : $last_online_since = $last_online; else : $last_online_since = $last_online + 300; endif; echo "\t
" . gmdate(__('F j, Y H:i:s'), $last_online + 3600) . " (" . bb_since($last_online_since) . " ago)
\n"; else : echo "\t
" . __('Never') . "
\n"; endif; echo "
\n"; } ?>