Hi,

I've read this snippet:
http://www.drupalsnippets.com/snippet/type/php/custom-whos-online-block
but the problem is that it causes the need that somewhere in page.tpl, node.tpl or block.tpl
I have to call the function: print onlineuser_count()

wasn't it better if I could override the original function and simply use it instead of writing
a new function?

so, can you tell me what is the name of "Who's online block"'s function?
I want to override that function so that it doesn't show the name of online users.

thanks in advance.

Comments

ram_segal’s picture

Hi,

Search for user_block function in user.module, you have a nice example code here: http://drupal.org/node/66638

styro’s picture

http://api.drupal.org/api/function/user_block/6

The who's online block is the delta 3 one, and the code that creates it is:

<?php
case 3:
        if (user_access('access content')) {
          // Count users active within the defined period.
          $interval = 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.
          $anonymous_count = sess_count($interval);
          $authenticated_users = db_query('SELECT DISTINCT u.uid, u.name, s.timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= %d AND s.uid > 0 ORDER BY s.timestamp DESC', $interval);
          $authenticated_count = 0;
          $max_users = variable_get('user_block_max_list_count', 10);
          $items = array();
          while ($account = db_fetch_object($authenticated_users)) {
            if ($max_users > 0) {
              $items[] = $account;
              $max_users--;
            }
            $authenticated_count++;
          }

          // Format the output with proper grammar.
          if ($anonymous_count == 1 && $authenticated_count == 1) {
            $output = t('There is currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
          }
          else {
            $output = t('There are currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
          }

          // Display a list of currently online users.
          $max_users = variable_get('user_block_max_list_count', 10);
          if ($authenticated_count && $max_users) {
            $output .= theme('user_list', $items, t('Online users'));
          }

          $block['subject'] = t('Who\'s online');
          $block['content'] = $output;
        }
        return $block;
?>

There isn't a lot of scope for overriding the inner workings - but you can override the themable output eg theme('user_list', $items, t('Online users')); or the translatable strings.

see: http://api.drupal.org/api/function/theme_user_list/6 for the default theme implementation.

If you really want to alter the inner workings, either paste your altered code into a custom block or create your own module to define the block. I recommend creating a module vs pasting code into your site.