Posted By

daipratt on 09/01/10


Tagged

message drupal Online private 6 whos


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
davmorr


Drupal 6 - Custom "Who's Online" block with private message links.


 / Published in: PHP
 

URL: http://zoocha.com

Customises the \"who\'s online\" block to show what role type the user has + the links now point to private message instead of profiles.

  1. function online_block() {
  2. $localIP=$_SERVER['SERVER_ADDR'];
  3.  
  4. //Count users with activity in the past defined period.
  5. $time_period = variable_get('user_block_seconds_online', 150);
  6.  
  7. //Perform database queries to gather online user lists.
  8. $guests = sess_count(time() - $time_period);
  9.  
  10. $total_guests = db_result(db_query('SELECT COUNT(hostname) FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period));
  11. $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', time() - $time_period);
  12. $total_users = db_result(db_query('SELECT DISTINCT COUNT(u.uid) 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', time() - $time_period));
  13.  
  14. //Display a list of currently online users.
  15. $max_users = variable_get('user_block_max_list_count', 10);
  16.  
  17. if ($total_users && $max_users) {
  18. $items = array();
  19. while ($max_users-- && $account = db_fetch_object($users)) {
  20. $items[] = $account;
  21. }
  22. $output.="<div class=\"item-list\"><h4>Members online</h4><p>Within the last 150 seconds</p><ul>";
  23. for($i=0; $i<count($items); $i++) {
  24. //Add the account type.
  25. $account=user_load(array('uid'=>$items[$i]->uid));
  26. $acc = "";
  27. if (in_array("gold member", $account->roles)) {
  28. $acc = "Gold";
  29. }elseif(in_array("silver member", $account->roles)){
  30. $acc = "Silver";
  31. }elseif(in_array("site manager", $account->roles)){
  32. $acc = "Tim";
  33. }elseif(in_array("performer", $account->roles)){
  34. $acc = "Performer";
  35. }elseif(in_array("admin", $account->roles)){
  36. $acc = "Admin";
  37. }
  38. $output .= '<li><a href="/messages/new/'.$items[$i]->uid.'">'.$items[$i]->name.'</a> - ' . $acc . '</li>';
  39. }
  40. $output.="</ul><p>Lurkers online: ".$guests."</p></div>";
  41. }
  42.  
  43. return $output;
  44. }

Report this snippet  

You need to login to post a comment.