You are here

function pm_send_validate in Privatemsg 6

1 string reference to 'pm_send_validate'
privatemsg_new in ./privatemsg.module

File

./privatemsg.module, line 993
Allows users to send private messages to other users.

Code

function pm_send_validate($form, &$form_state) {

  // The actual message that is being sent, we create this during validation and pass to submit to send out.
  $message = $form_state['values'];
  $message['timestamp'] = time();

  // Avoid subjects which only consist of a space as these can not be clicked.
  $message['subject'] = trim($message['subject']);
  $trimed_body = trim(truncate_utf8(strip_tags($message['body']), 50, TRUE, TRUE));
  if (empty($message['subject']) && !empty($trimed_body)) {
    $message['subject'] = $trimed_body;
  }

  // Only parse the user string for a new thread.
  if (!isset($message['thread_id'])) {
    list($message['recipients'], $invalid) = _privatemsg_parse_userstring($message['recipient']);
  }
  else {

    // Load participants.
    $message['recipients'] = _privatemsg_load_thread_participants($message['thread_id']);

    // Remove author.
    if (isset($message['recipients'][$message['author']->uid]) && count($message['recipients']) > 1) {
      unset($message['recipients'][$message['author']->uid]);
    }
  }
  $validated = _privatemsg_validate_message($message, TRUE);
  foreach ($validated['messages'] as $type => $text) {
    drupal_set_message($text, $type);
  }
  $form_state['validate_built_message'] = $message;
  if (!empty($invalid)) {
    drupal_set_message(t('The following users will not receive this private message: @invalid', array(
      '@invalid' => implode(", ", $invalid),
    )), 'error');
  }
}