I'd like to change how the "Who's online" block looks.

I would like it to read like this:

There are currently 8543 members and 58 people are online right now, including: Member 1, Member 2, Member 3

Instead of this:

Who's online

There are currently 3 users and 55 guests online.
Online users:

  • Member 1
  • Member 2
  • Member 3

Is this possible - and if so, how do I go about making the changes?

Comments

boris mann’s picture

It's part of the code of the user module -- here is the source from CVS. You have two choices -- either hack the code for generating the Who's Online block, or just copy that code into a new, custom PHP block, and edit it to be formatted however you like.

cre8d’s picture

Will try making it into a custom block so I don't muck with the source :)

sungkhum’s picture

Is there a way someone could post the code I should place in the block? I'm a little confused as to what sections of that code need to be included in a custom "Who's Online" block (I want to add how many total members exist to the block).

Thanks,
Nathan

http://www.sbbic.org

sungkhum’s picture

Ok, I think I got it - put this in a block with php enabled:

<?php
$number = db_result(db_query('SELECT COUNT(uid) AS number FROM {users} WHERE status=1'));



        if (user_access('access content')) {
          // Count users with activity in the past defined period.
          $time_period = variable_get('user_block_seconds_online', 900);

          // Perform database queries to gather online user lists.
          $guests = db_fetch_object(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period));
          $users = db_query('SELECT uid, name, access FROM {users} WHERE access >= %d AND uid != 0 ORDER BY access DESC', time() - $time_period);
          $total_users = db_num_rows($users);

          // Format the output with proper grammar.
echo "Out of $number registered users ";
          if ($total_users == 1 && $guests->count == 1) {
            $output = t('%members and %visitors online.', array('%members' => format_plural($total_users, 'there is currently 1 user', 'there are currently %count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests')));
          }
          else {
            $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')));
          }

          // Display a list of currently online users.
          $max_users = variable_get('user_block_max_list_count', 10);
          if ($total_users && $max_users) {
            $items = array();

            while ($max_users-- && $account = db_fetch_object($users)) {
              $items[] = $account;
            }

            $output .= theme('user_list', $items, t('Online users'));
          }

        }
        return $output;
   

?>

That adds the total number of users and then tells how many are currently online

-Nathan

desm0n’s picture

That works perfectly, thanks nathan,

sungkhum’s picture

Glad to help :)

-Nathan

adammichaelroach’s picture

Thanks, worked great for me!

RMDTech’s picture

Okay so I tried this on Drupal 5 and not sure if it's because it's a new version or what but when the online count comes up it comes up as:

"Out of 4 registered users there are currently %count users and %count guests online." rather than stating the numbers (It will say there is 1 user on or 1 guest but when there is neither one the other or both it will still say %count)

Secondly is there anyway to make certain members Admin, Moderator, Etc) different colors?

vm’s picture

If you used the code posted in the thread and didnt pull new code out of the user.module in the cvs link that would be why it did not work. The code in the post is for Drupal 4.x.x.

Check out the cvs link and pull the proper code for Drupal 5.

Secondly is there anyway to make certain members Admin, Moderator, Etc) different colors?

neat idea, may be able to be done with some .css magic. I don't have a recipe for it off the top of my head though.

RMDTech’s picture

Yeah I kind-of figured that. Unfortunately not the coding king (know basic html) so I will probably have to wait to get it fixed. Thanks though will try and look through it and see if I can guesstimate or figure something out.

sepeck’s picture

Zen theme has some css class selectors for comments. Not sure if it is tied to user or role but it should be adaptable for it.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

psr’s picture

i popped this in to a new block just to see what it would do and it completely disabled my drupal4.7 website and its been a real pain to get the site running again. avoid.

sepeck’s picture

This thread is from 2005 so probably Drupal 4.5
Note this link in the Best Practices section on testing php code.

I am locking this thread due to age.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide