function drupalchat_init in DrupalChat 6.2
Same name and namespace in other branches
- 6 drupalchat.module \drupalchat_init()
- 7.2 drupalchat.module \drupalchat_init()
- 7 drupalchat.module \drupalchat_init()
File
- ./
drupalchat.module, line 372 - Module code for DrupalChat.
Code
function drupalchat_init() {
global $user, $base_url;
if (variable_get('drupalchat_polling_method', DRUPALCHAT_COMMERCIAL) == DRUPALCHAT_COMMERCIAL) {
if (user_access('access drupalchat') && drupalchat_verify_access()) {
$iflychat_auth_url = url('drupalchat/auth', array(
'query' => array(
't' => time(),
),
));
if (variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH) == "0") {
if (isset($_SESSION['token']) && !empty($_SESSION['token'])) {
drupal_add_js('var iflychat_auth_token = "' . $_SESSION['token'] . '";', 'inline', 'footer');
}
}
if ($user->uid) {
drupal_add_js('var iflychat_auth_url = "' . $iflychat_auth_url . '";', 'inline', 'footer');
}
// if(varibale_get('drupalchat_path_visibility') == '1'){ // show popup chat everywhere
// drupal_add_js('var drupalchat_popup=document.createElement("DIV"); drupalchat_popup.className="iflychat-popup";document.body.appendChild(drupalchat_popup);', 'inline', 'footer');
// }else if(varibale_get('drupalchat_path_visibility') == '2' && !path_is_admin(current_path())){ // show popup chat on frontend only
// drupal_add_js('var drupalchat_popup=document.createElement("DIV"); drupalchat_popup.className="iflychat-popup";document.body.appendChild(drupalchat_popup);', 'inline', 'footer');
// }else if((varibale_get('drupalchat_path_visibility') == '3' || variable_get('drupalchat_show_popup_chat') == '4') && drupalchat_verify_access()){
// drupal_add_js('var drupalchat_popup=document.createElement("DIV"); drupalchat_popup.className="iflychat-popup";document.body.appendChild(drupalchat_popup);', 'inline', 'footer');
// }
if (drupalchat_verify_access()) {
drupal_add_js('var drupalchat_popup=document.createElement("DIV"); drupalchat_popup.className="iflychat-popup";document.body.appendChild(drupalchat_popup);', 'inline', 'footer');
}
drupal_add_js('var drupalchat_bundle = document.createElement("SCRIPT"); drupalchat_bundle.src = "//' . DRUPALCHAT_EXTERNAL_A_PORT . '/js/iflychat-v2.min.js?app_id=' . variable_get('drupalchat_app_id', NULL) . '"' . '; drupalchat_bundle.async = "async";document.body.appendChild(drupalchat_bundle)', 'inline', 'footer');
}
}
else {
if (drupalchat_verify_access()) {
if (variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX) != DRUPALCHAT_COMMERCIAL) {
if ($user->uid > 0) {
$user_name = _drupalchat_get_username($user->uid);
$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);
}
}
else {
$sid = _drupalchat_get_sid();
if (!$sid || $sid == -1) {
return;
}
else {
$check = db_result(db_query('SELECT COUNT(*) FROM {drupalchat_users} WHERE uid = %d AND session = \'%s\'', $user->uid, $sid));
$status = db_result(db_query('SELECT status FROM {drupalchat_users} WHERE uid = %d AND session = \'%s\'', $user->uid, $sid));
if (!$check) {
$status = DRUPALCHAT_USER_ONLINE;
if (variable_get('drupalchat_anon_use_name', 1) == 1) {
$user_name = variable_get('drupalchat_anon_prefix', 'Guest') . ' ' . drupalchat_get_random_name();
}
else {
$user_name = check_plain(variable_get('drupalchat_anon_prefix', 'Guest') . time());
}
$current_user = (object) array(
'uid' => $user->uid,
'session' => $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 AND session=\'%s\'', time(), $status == DRUPALCHAT_USER_OFFLINE ? DRUPALCHAT_USER_ONLINE : $status, $user->uid, $sid);
}
}
}
}
// else {
// if($user->uid) {
// $user_name = _drupalchat_get_username($user->uid);
// }
// else {
// $a_name = drupalchat_get_current_guest_name();
// }
// }
$theme = variable_get('drupalchat_theme', 'light');
$polling_method = variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX);
if (!$user->uid && variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX) != DRUPALCHAT_COMMERCIAL) {
$a_name = db_result(db_query('SELECT name FROM {drupalchat_users} WHERE uid = %d AND session = \'%s\'', $user->uid, $sid));
}
$my_settings = array(
'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',
'soundFile' => base_path() . drupal_get_path('module', 'drupalchat') . '/wav/notification.mp3',
'noUsers' => theme('item_list', array(
t('No users online'),
)),
'smileyURL' => base_path() . drupal_get_path('module', 'drupalchat') . '/smileys/very_emotional_emoticons-png/png-32x32/',
'profilePath' => url('user', array(
'absolute' => TRUE,
)),
'notificationSound' => variable_get('drupalchat_notification_sound', 1),
'version' => '6',
'exurl' => url('drupalchat/auth', array(
'query' => array(
't' => time(),
),
)),
'chat_type' => variable_get('drupalchat_show_admin_list', 2),
'guestPrefix' => variable_get('drupalchat_anon_prefix', 'Guest') . " ",
'changeurl' => url('drupalchat/change-guest-name', array(
'query' => array(
't' => time(),
),
)),
//addURL is missing, have to add
'allowSmileys' => variable_get('drupalchat_enable_smiley', 1),
);
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);
}
if ($polling_method != DRUPALCHAT_COMMERCIAL) {
$my_settings['username'] = $user->uid ? $user_name : $a_name;
$my_settings['uid'] = $user->uid ? $user->uid : '0-' . _drupalchat_get_sid();
}
$my_settings['iup'] = variable_get('drupalchat_user_picture', 1);
if (variable_get('drupalchat_user_picture', 1) == 1) {
if ($polling_method != DRUPALCHAT_COMMERCIAL) {
$my_settings['up'] = drupalchat_return_pic_url();
}
$my_settings['default_up'] = $base_url . '/' . drupal_get_path('module', 'drupalchat') . '/themes/' . $theme . '/images/default_avatar.png';
$my_settings['default_cr'] = $base_url . '/' . drupal_get_path('module', 'drupalchat') . '/themes/' . $theme . '/images/default_room.png';
$my_settings['default_team'] = $base_url . '/' . drupal_get_path('module', 'drupalchat') . '/themes/' . $theme . '/images/default_team.png';
}
/*drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/swfobject.js', 'module');
if ((variable_get('drupalchat_yui_use_cdn', 1) == 2)) {
drupal_add_js(drupalchat_yui_path() . '/yui-min.js');
}
else {
drupal_set_html_head('<script type="text/javascript" src="http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js"></script>');
}
drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/storage-lite.js', 'module');*/
//
if ($polling_method != DRUPALCHAT_COMMERCIAL) {
/*if ((variable_get('drupalchat_yui_use_cdn', 1) == 2)) {
drupal_add_js(drupalchat_yui_path() . '/yui-min.js');
}
else {
drupal_set_html_head('<script type="text/javascript" src="http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js"></script>');
}
*/
drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/jquery.titlealert.min.js', 'module');
drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/ba-emotify.js', 'module');
drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/swfobject.js', 'module');
drupal_add_css(drupal_get_path('module', 'drupalchat') . '/themes/' . $theme . '/' . $theme . '.css', 'module');
drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/drupalchat-jstorage.js', 'module');
drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/drupalchat.js', 'module');
}
// drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/ba-emotify.js');
drupal_add_js(array(
'drupalchat' => $my_settings,
), "setting");
}
}
}