You are here

function _drupalchat_get_auth in DrupalChat 6.2

Same name and namespace in other branches
  1. 7.2 drupalchat.module \_drupalchat_get_auth()
  2. 7 drupalchat.module \_drupalchat_get_auth()
3 calls to _drupalchat_get_auth()
drupalchat_app_settings in ./drupalchat.admin.inc
@file Administrative functions to configure DrupalChat.
drupalchat_ex_auth in ./drupalchat.module
drupalchat_settings_form_validate in ./drupalchat.admin.inc

File

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

Code

function _drupalchat_get_auth($name, $formValues) {
  global $user, $base_url;
  $theme = variable_get('drupalchat_theme', 'light');
  if (user_access('administer drupalchat')) {
    $role = "admin";
  }
  else {
    $role = $user->roles;
  }

  // print_r("formValues");
  // print_r($formValues);
  if (array_key_exists('api_key', $formValues)) {

    //print_r("form");
    $api_key = $formValues['api_key'];
  }
  else {

    //print_r("db");
    $api_key = variable_get('drupalchat_external_api_key', NULL);
  }
  if (array_key_exists('app_id', $formValues)) {

    //print_r("form");
    $app_id = $formValues['app_id'];
  }
  else {

    //print_r("db");
    $app_id = variable_get('drupalchat_app_id', NULL);
  }
  if ($user->uid) {
    $data = array(
      'user_name' => $name,
      'user_id' => $user->uid,
      'api_key' => $api_key,
      'app_id' => $app_id,
      'user_roles' => $role,
      'version' => 'D6',
      'user_status' => TRUE,
      'user_list_filter' => 'all',
    );
  }

  //if(variable_get('drupalchat_user_picture', 1) == 1) {
  $data['user_avatar_url'] = drupalchat_return_pic_url();

  //}
  $data['user_profile_url'] = drupalchat_return_profile_url();

  //  if(variable_get('drupalchat_user_picture', 1) == 1) {
  // if(isset($user->picture) && ($user->picture)) {
  //   $data['up'] = base_path() . $user->picture;
  //    }
  //    else {
  //   global $base_url;
  //      $data['up'] = $base_url . '/' . drupal_get_path('module', 'drupalchat') . '/themes/' . $theme . '/images/default_avatar.png';
  //    }
  //  }
  if (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;
    }
  }

  //print_r($data);
  $data = json_encode($data);
  $options = array(
    'method' => 'POST',
    'data' => $data,
    'timeout' => 15,
    'headers' => array(
      'Content-Type' => 'application/json',
    ),
  );

  //print_r($data);
  $result = drupal_http_request(DRUPALCHAT_EXTERNAL_A_HOST . ':' . DRUPALCHAT_EXTERNAL_A_PORT . '/api/1.1/token/generate', array(
    'Content-Type' => 'application/json',
  ), 'POST', $data, 15);

  // print_r(gettype($result));
  // print_r($result);
  if ($result->code == 200) {
    $result = json_decode($result->data);

    //drupal_set_html_head('<link type="text/css" rel="stylesheet" media="all" href="' . DRUPALCHAT_EXTERNAL_A_HOST . ':' . DRUPALCHAT_EXTERNAL_A_PORT .  '/i/' . $result->css . '/cache.css' . '" />');

    // if(isset($result->_i) && ($result->_i!=variable_get('drupalchat_ext_d_i',''))) {
    //   variable_set('drupalchat_ext_d_i',$result->_i);
    // }
    if ($user->uid) {
      $_SESSION['token'] = $result->key;
    }

    // print_r(gettype($result));
    // print_r($result);
    if (array_key_exists('app_id', $result)) {
      variable_set('drupalchat_app_id', $result->app_id);
    }
    return $result;
  }
  else {
    return $result;

    //return null;
  }
}