You are here

function _privatemsg_send in Privatemsg 5

Same name and namespace in other branches
  1. 5.3 privatemsg.module \_privatemsg_send()
  2. 6.2 privatemsg.module \_privatemsg_send()
  3. 6 privatemsg.module \_privatemsg_send()
  4. 7.2 privatemsg.module \_privatemsg_send()
  5. 7 privatemsg.module \_privatemsg_send()
3 calls to _privatemsg_send()
privatemsg_new_form_submit in ./privatemsg.module
privatemsg_send_privatemsg in ./privatemsg.module
Send private message. Sender is the current user.
privatemsg_user in ./privatemsg.module
Implementation of hook_user().

File

./privatemsg.module, line 1641

Code

function _privatemsg_send($sender, $recipient, $subject, $body, $format, $thread = 0, $type = 'private-message', $original_variables = array()) {
  if (!privatemsg_message_allowed($recipient->uid, $sender->uid)) {
    drupal_set_message(t('You cannot contact %recipient', array(
      '%recipient' => $recipient->name,
    )));
    return;
  }

  // Hook to allow other modules to alter any aspect of a privatemsg by
  // accepting these params by reference. Any module can cancel a privatemsg by
  // returning false here
  foreach (module_implements('privatemsg_alter') as $name) {
    $function = $name . '_privatemsg_alter';
    if (!$function($sender, $recipient, $subject, $body, $format, $thread, $type)) {
      return FALSE;
    }
  }
  $message_id = db_next_id('{privatemsg}_id');
  if (!$thread) {
    $thread = db_next_id('{privatemsg}_thread');
  }
  $variables = array();
  foreach ($original_variables as $name => $value) {
    $variables[str_replace('!', '!original_', $name)] = $value;
  }
  $result = db_query("INSERT INTO {privatemsg} (id, author, recipient, subject, message, timestamp, newmsg, hostname, format, thread, type, variables) VALUES (%d, %d, %d, '%s', '%s', %d, %d, '%s', %d, %d, '%s', '%s')", $message_id, $sender->uid, $recipient->uid, $subject, $body, time(), 1, getenv('REMOTE_ADDR'), $format, $thread, $type, serialize($variables));
  if ($points = variable_get('privatemsg_userpoints', 0)) {
    module_invoke('userpoints', 'userpointsapi', 'points', $points, $sender->uid, 'privatemsg');
  }
  module_invoke('pm_subscriptions', 'subscriptions_handle', privatemsg_load($message_id));
  return $result ? $message_id : $result;
}