You are here

function userone_block_view in User One 7

Implements hook_block_view(). Code is identical from user_block_view() except it excludes user 1 in the count.

File

./userone.module, line 247
User One module.

Code

function userone_block_view($delta = '') {
  if ($delta == 'online') {
    if (user_access('access content')) {

      // Count users active within the defined period.
      $interval = REQUEST_TIME - variable_get('user_block_seconds_online', 900);

      // Perform database queries to gather online user lists. We use s.timestamp
      // rather than u.access because it is much faster.
      $authenticated_count = db_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 1", array(
        ':timestamp' => $interval,
      ))
        ->fetchField();
      $output = '<p>' . format_plural($authenticated_count, 'There is currently 1 user online.', 'There are currently @count users online.') . '</p>';

      // Display a list of currently online users.
      $max_users = variable_get('user_block_max_list_count', 10);
      if ($authenticated_count && $max_users) {
        $items = db_query_range('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 1 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', 0, $max_users, array(
          ':interval' => $interval,
        ))
          ->fetchAll();
        $output .= theme('user_list', array(
          'users' => $items,
        ));
      }
      $block['subject'] = t('Who\'s online');
      $block['content'] = $output;
    }
    return $block;
  }
}