You are here

function _drupalchat_get_user_details in DrupalChat 7.2

2 calls to _drupalchat_get_user_details()
drupalchat_init in ./drupalchat.module
@todo Please document this function.
_drupalchat_get_auth in ./drupalchat.module

File

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

Code

function _drupalchat_get_user_details() {
  global $user;
  $account = user_load($user->uid);
  if (user_access('administer drupalchat')) {
    $chat_role = "admin";
  }
  else {
    if (user_access('moderate drupalchat')) {
      $chat_role = "moderator";
    }
    else {
      $chat_role = "participant";
    }
  }
  $hook_user_name = '';
  $hook_user_avatar_url = '';
  $hook_user_profile_url = '';
  $hook_user_roles = array();
  drupal_alter('drupalchat_get_username', $hook_user_name, $user->uid);
  drupal_alter('drupalchat_get_user_avatar_url', $hook_user_avatar_url, $user->uid);
  drupal_alter('drupalchat_get_user_profile_url', $hook_user_profile_url, $user->uid);
  drupal_alter('drupalchat_get_user_roles', $hook_user_roles, $user->uid);
  if (!empty($hook_user_name)) {
    $user_name = $hook_user_name;
  }
  else {
    $user_name = check_plain(format_username($account));
  }
  if (!empty($hook_user_roles)) {
    $role = $hook_user_roles;
  }
  else {
    $role = $user->roles;
  }
  $data = array(
    'user_name' => $user_name,
    'user_id' => $user->uid,
    'user_roles' => $role,
    'chat_role' => $chat_role,
    'user_status' => '1',
    'user_list_filter' => 'all',
  );

  //Added allRoles if role is admin.
  if ($chat_role == 'admin' || $chat_role == 'moderator') {
    $data['user_site_roles'] = user_roles();
  }
  if (!empty($hook_user_avatar_url)) {
    $data['user_avatar_url'] = $hook_user_avatar_url;
  }
  else {
    $data['user_avatar_url'] = drupalchat_return_pic_url();
  }
  if (!empty($hook_user_profile_url)) {
    $data['user_profile_url'] = $hook_user_profile_url;
  }
  else {
    $data['user_profile_url'] = drupalchat_return_profile_url();
  }
  $hook_user_friends = _drupalchat_get_friends($user->uid);
  $hook_user_groups = array();
  drupal_alter('drupalchat_get_groups', $hook_user_groups, $user->uid);
  if (variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH) == DRUPALCHAT_REL_OG) {
    $user_groups = _drupalchat_get_groups($user->uid);
    if (!empty($user_groups)) {
      $data['user_list_filter'] = 'group';
      $data['user_groups'] = $user_groups;
    }
  }
  else {
    if (check_plain(variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH)) > DRUPALCHAT_REL_AUTH) {
      $data['user_list_filter'] = 'friend';
      $new_valid_uids = _drupalchat_get_buddylist($user->uid);
      if (!isset($_SESSION['drupalchat_user_roster_list']) || $_SESSION['drupalchat_user_roster_list'] != $new_valid_uids) {
        $data['user_relationships'] = $new_valid_uids;
        $_SESSION['drupalchat_user_roster_list'] = $new_valid_uids;
      }
      else {
        $data['user_relationships'] = $new_valid_uids;
      }
    }
    else {
      if (!empty($hook_user_friends)) {
        $data['user_list_filter'] = 'friend';
        $final_list = array();
        $final_list['1']['name'] = 'friend';
        $final_list['1']['plural'] = 'friends';
        $final_list['1']['valid_uids'] = $hook_user_friends;
        $data['user_relationships'] = $final_list;
      }
      else {
        if (!empty($hook_user_groups)) {
          $data['user_list_filter'] = 'group';
          $data['user_groups'] = $hook_user_groups;
        }
      }
    }
  }
  return $data;
}