You are here

function drupalchat_send in DrupalChat 7.2

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

Send messages via ajax

2 string references to 'drupalchat_send'
drupalchat_init in ./drupalchat.module
@todo Please document this function.
drupalchat_menu in ./drupalchat.module
Implements hook_menu().

File

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

Code

function drupalchat_send() {
  global $user;
  $formToken = check_plain($_POST['form_token']);
  $formID = check_plain($_POST['form_id']);
  $form_token = !empty($formToken) ? $formToken : '';
  $form_id = !empty($formID) ? $formID : '';
  if (!drupal_valid_token($form_token, $form_id)) {
    return;
  }
  $message = (object) array(
    'message_id' => check_plain($_POST['drupalchat_message_id']),
    'uid1' => $user->uid ? $user->uid : '0-' . _drupalchat_get_sid(),
    'uid2' => check_plain($_POST['drupalchat_uid2']),
    'message' => $_POST['drupalchat_message'],
    'timestamp' => time(),
  );
  drupal_write_record('drupalchat_msg', $message);
  foreach (module_implements('drupalchat_send') as $module) {
    $function = $module . '_drupalchat_send';
    $function($message);
  }
  drupal_json_output(array());
}