function _drupalchat_get_auth in DrupalChat 7
Same name and namespace in other branches
- 6.2 drupalchat.module \_drupalchat_get_auth()
- 7.2 drupalchat.module \_drupalchat_get_auth()
3 calls to _drupalchat_get_auth()
- drupalchat_ex_auth in ./
drupalchat.module - drupalchat_init in ./
drupalchat.module - @todo Please document this function.
- drupalchat_mobile_auth in ./
drupalchat.mobileauth.inc
File
- ./
drupalchat.module, line 1255 - Module code for DrupalChat.
Code
function _drupalchat_get_auth($name) {
global $user;
global $base_url;
if (user_access('administer drupalchat')) {
$role = "admin";
}
else {
$role = $user->roles;
}
$data = array(
'uname' => $name,
'uid' => $user->uid ? $user->uid : '0-' . _drupalchat_get_sid(),
'api_key' => variable_get('drupalchat_external_api_key', NULL),
'image_path' => $base_url . '/' . drupal_get_path('module', 'drupalchat') . '/themes/' . variable_get('drupalchat_theme', 'light') . '/images',
'isLog' => TRUE,
'whichTheme' => 'blue',
'enableStatus' => TRUE,
'role' => $role,
'validState' => array(
'available',
'offline',
'busy',
'idle',
),
'rel' => variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH),
);
//Added allRoles if role is admin.
if ($role == 'admin') {
$data['allRoles'] = user_roles();
}
if (variable_get('drupalchat_user_picture', 1) == 1) {
$data['up'] = drupalchat_return_pic_url();
}
$data['upl'] = drupalchat_return_profile_url();
$hook_user_friends = _drupalchat_get_friends($user->uid);
if (variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH) == DRUPALCHAT_REL_OG) {
$data['rel'] = '0';
$user_groups = _drupalchat_get_groups($user->uid);
if (!empty($user_groups)) {
$data['valid_groups'] = $user_groups;
}
}
else {
if (variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH) > DRUPALCHAT_REL_AUTH) {
$new_valid_uids = _drupalchat_get_buddylist($user->uid);
if (!isset($_SESSION['drupalchat_valid_uids']) || $_SESSION['drupalchat_valid_uids'] != $new_valid_uids) {
$data['valid_uids'] = $new_valid_uids;
$_SESSION['drupalchat_valid_uids'] = $new_valid_uids;
}
else {
$data['valid_uids'] = $new_valid_uids;
}
}
else {
if (!empty($hook_user_friends)) {
$data['rel'] = '1';
$final_list = array();
$final_list['1']['name'] = 'friend';
$final_list['1']['plural'] = 'friends';
$final_list['1']['valid_uids'] = $hook_user_friends;
$data['valid_uids'] = $final_list;
}
}
}
$data = json_encode($data);
$options = array(
'method' => 'POST',
'data' => $data,
'timeout' => 15,
'headers' => array(
'Content-Type' => 'application/json',
),
);
$result = drupal_http_request(DRUPALCHAT_EXTERNAL_A_HOST . ':' . DRUPALCHAT_EXTERNAL_A_PORT . '/p/', $options);
if ($result->code == 200) {
$result = drupal_json_decode($result->data);
//drupal_add_css(DRUPALCHAT_EXTERNAL_A_HOST . ':' . DRUPALCHAT_EXTERNAL_A_PORT . '/i/' . $result['css'] . '/cache.css', 'external');
if (isset($result['_i']) && $result['_i'] != variable_get('drupalchat_ext_d_i', '3')) {
variable_set('drupalchat_ext_d_i', $result['_i']);
}
return $result;
}
else {
return null;
}
}