diff options
author | Dries Buytaert <dries@buytaert.net> | 2004-08-12 22:12:21 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2004-08-12 22:12:21 +0000 |
commit | 5a566c55ec162b863843fa8b488273d31565718e (patch) | |
tree | 9342f528ae07f23c3bccaa56e61b521857410e17 /modules | |
parent | d4a8bd587707a7c0d99b27c16164b2cb22e8c905 (diff) | |
download | brdo-5a566c55ec162b863843fa8b488273d31565718e.tar.gz brdo-5a566c55ec162b863843fa8b488273d31565718e.tar.bz2 |
- 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.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/user.module | 12 | ||||
-rw-r--r-- | modules/user/user.module | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/modules/user.module b/modules/user.module index 9ffed462f..d9b5ff76e 100644 --- a/modules/user.module +++ b/modules/user.module @@ -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) { diff --git a/modules/user/user.module b/modules/user/user.module index 9ffed462f..d9b5ff76e 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -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) { |