Commit 5a566c55 authored by Dries's avatar Dries

- Patch #9974 by njivi: report the number of offline users.

  I had some trouble adding this feature but realized that the "who's online" block is a geek think, and therefore it won't hurt to add some more geekiness.  If you don't know what "offline users" means, you would not have understood "online users" in the first place.  Either way, I think most people who have the block enabled, will find this an interesting addition.
parent d4a8bd58
......@@ -524,6 +524,10 @@ function user_block($op = 'list', $delta = 0) {
$users = db_query('SELECT DISTINCT(uid), MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC', time() - $time_period );
$total_users = db_num_rows($users);
// Perform database queries to count all users
$all_users = db_fetch_object(db_query('SELECT COUNT(uid) AS count FROM {users} WHERE uid != 0 AND status != 0'));
$offline_users = $all_users->count - $total_users;
// Format the output with proper grammar.
if ($total_users == 1 && $guests->count == 1) {
$output = t('There is currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests')));
......@@ -532,6 +536,14 @@ function user_block($op = 'list', $delta = 0) {
$output = t('There are currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests')));
}
// Describe how many users are offline
if ($offline_users == 1) {
$output .= ' '.t('1 user is offline.');
}
else {
$output .= ' '.t('%a are offline.', array('%a' => format_plural($offline_users, '1 user', '%count users')));
}
// Display a list of currently online users.
$max_users = variable_get('user_block_max_list_count', 10);
if ($max_users) {
......
......@@ -524,6 +524,10 @@ function user_block($op = 'list', $delta = 0) {
$users = db_query('SELECT DISTINCT(uid), MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC', time() - $time_period );
$total_users = db_num_rows($users);
// Perform database queries to count all users
$all_users = db_fetch_object(db_query('SELECT COUNT(uid) AS count FROM {users} WHERE uid != 0 AND status != 0'));
$offline_users = $all_users->count - $total_users;
// Format the output with proper grammar.
if ($total_users == 1 && $guests->count == 1) {
$output = t('There is currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests')));
......@@ -532,6 +536,14 @@ function user_block($op = 'list', $delta = 0) {
$output = t('There are currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests')));
}
// Describe how many users are offline
if ($offline_users == 1) {
$output .= ' '.t('1 user is offline.');
}
else {
$output .= ' '.t('%a are offline.', array('%a' => format_plural($offline_users, '1 user', '%count users')));
}
// Display a list of currently online users.
$max_users = variable_get('user_block_max_list_count', 10);
if ($max_users) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment