You are here

function _drupalchat_buddylist_online in DrupalChat 7.2

Same name and namespace in other branches
  1. 6.2 drupalchat.module \_drupalchat_buddylist_online()
  2. 6 drupalchat.module \_drupalchat_buddylist_online()
  3. 7 drupalchat.module \_drupalchat_buddylist_online()
2 calls to _drupalchat_buddylist_online()
drupalchat_poll in ./drupalchat.module
Process and get messages
_drupalchat_chat in ./drupalchat.module

File

./drupalchat.module, line 924
Module code for DrupalChat.

Code

function _drupalchat_buddylist_online($buddylist) {
  global $user, $base_url;
  $users = array();
  if (check_plain(variable_get('drupalchat_enable_chatroom', 1)) == 1) {
    $users['c-0'] = array(
      'name' => t('Public Chatroom'),
      'status' => '1',
    );
    if (check_plain(variable_get('drupalchat_user_picture', 1)) == 1) {
      $users['c-0']['p'] = $base_url . '/' . drupal_get_path('module', 'drupalchat') . '/themes/' . check_plain(variable_get('drupalchat_theme', 'light')) . '/images/default_room.png';
    }
  }
  if (check_plain(variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH)) > DRUPALCHAT_REL_AUTH) {

    // Return empty on an empty buddylist
    if (empty($buddylist)) {
      $users['total'] = 0;
      return $users;
    }
    $result = db_select('drupalchat_users', 'n')
      ->fields('n', array(
      'uid',
      'name',
      'status',
    ))
      ->condition('timestamp', time() - check_plain(variable_get('drupalchat_user_latency', 2)), '>=')
      ->condition('uid', $buddylist, 'IN')
      ->execute();
  }
  else {
    if ($user->uid > 0) {
      $result = db_select('drupalchat_users', 'n')
        ->fields('n', array(
        'uid',
        'name',
        'status',
        'session',
      ))
        ->condition('timestamp', time() - check_plain(variable_get('drupalchat_user_latency', 2)), '>=')
        ->condition('uid', $user->uid, '<>')
        ->execute();
    }
    else {
      $result = db_select('drupalchat_users', 'n')
        ->fields('n', array(
        'uid',
        'name',
        'status',
        'session',
      ))
        ->condition('timestamp', time() - check_plain(variable_get('drupalchat_user_latency', 2)), '>=')
        ->condition('session', _drupalchat_get_sid(), '<>')
        ->execute();
    }
  }
  foreach ($result as $buddy) {
    if ($buddy->uid > 0) {
      $account = user_load($buddy->uid);
      $users[$buddy->uid] = array(
        'name' => check_plain(format_username($account)),
        'status' => $buddy->status,
      );
      if (check_plain(variable_get('drupalchat_user_picture', 1)) == 1) {
        $users[$buddy->uid]['p'] = drupalchat_return_pic_url_any_user(user_load($buddy->uid));
      }
    }
    else {
      $users[$buddy->uid . '-' . $buddy->session] = array(
        'name' => check_plain($buddy->name),
        'status' => $buddy->status,
      );
      if (check_plain(variable_get('drupalchat_user_picture', 1)) == 1) {
        $users[$buddy->uid . '-' . $buddy->session]['p'] = drupalchat_return_pic_url_any_user(user_load('0'));
      }
    }
  }
  $users['total'] = count($users);
  if (check_plain(variable_get('drupalchat_enable_chatroom', 1)) == 1) {
    $users['total']--;
  }
  return $users;
}