You are here

function drupalchat_init in DrupalChat 6

Same name and namespace in other branches
  1. 6.2 drupalchat.module \drupalchat_init()
  2. 7.2 drupalchat.module \drupalchat_init()
  3. 7 drupalchat.module \drupalchat_init()

File

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

Code

function drupalchat_init() {
  if (user_access('access drupalchat')) {
    global $user;
    $status = db_result(db_query('SELECT status FROM {drupalchat_users} WHERE uid = %d', $user->uid));
    if (!$status) {
      $status = DRUPALCHAT_USER_ONLINE;
      $current_user = (object) array(
        'uid' => $user->uid,
        'session' => $user->sid,
        'name' => $user->name,
        'status' => $status,
        'timestamp' => time(),
      );
      drupal_write_record('drupalchat_users', $current_user);
    }
    else {
      db_query('UPDATE {drupalchat_users} SET timestamp = %d, status = %d WHERE uid = %d', time(), $status == DRUPALCHAT_USER_OFFLINE ? DRUPALCHAT_USER_ONLINE : $status, $user->uid);
    }
    $theme = variable_get('drupalchat_theme', 'light');
    $polling_method = variable_get('drupalchat_polling_method', DRUPALCHAT_LONGPOLL);
    $my_settings = array(
      'username' => $user->name,
      'uid' => $user->uid,
      'current_timestamp' => time(),
      'polling_method' => $polling_method,
      'pollUrl' => url('drupalchat/poll', array(
        'absolute' => TRUE,
      )),
      'sendUrl' => url('drupalchat/send', array(
        'absolute' => TRUE,
      )),
      'statusUrl' => url('drupalchat/status', array(
        'absolute' => TRUE,
      )),
      'status' => $status,
      'goOnline' => t('Go Online'),
      'goIdle' => t('Go Idle'),
      'newMessage' => t('New chat message!'),
      'images' => base_path() . drupal_get_path('module', 'drupalchat') . '/themes/' . $theme . '/images/',
      'sound' => base_path() . drupal_get_path('module', 'drupalchat') . '/swf/sound.swf',
      'noUsers' => theme('item_list', array(
        l(t('No users online'), 'user'),
      )),
      'smileyURL' => base_path() . drupal_get_path('module', 'drupalchat') . '/smileys/very_emotional_emoticons-png/png-32x32/',
    );
    if ($polling_method == DRUPALCHAT_AJAX) {
      $my_settings['refresh_rate'] = variable_get('drupalchat_refresh_rate', 2);
      $my_settings['send_rate'] = variable_get('drupalchat_send_rate', 2);
    }
    drupal_add_js(array(
      'drupalchat' => $my_settings,
    ), "setting");
    drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/swfobject.js', 'module');
    if (variable_get('drupalchat_yui_path', NULL)) {
      drupal_add_js(drupalchat_yui_path() . '/yui-min.js', 'module');
    }
    drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/storage-lite.js', 'module');
    drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/jquery.titlealert.min.js', 'module');
    drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/drupalchat-min.js', 'module');
    drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/ba-emotify.js', 'module');
    drupal_add_css(drupal_get_path('module', 'drupalchat') . '/themes/' . $theme . '/' . $theme . '.css', 'module');

    //    drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/ba-emotify.js');
  }
}