From 5a566c55ec162b863843fa8b488273d31565718e Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 12 Aug 2004 22:12:21 +0000 Subject: - 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. --- modules/user/user.module | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'modules/user/user.module') 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) { -- cgit v1.2.3