You are here

function privatemsg_get_link in Privatemsg 6

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

Returns a link to send message form for a specific users.

Contains permission checks of author/recipient, blocking and if a anonymous user is involved.

Parameters

$recipient: Recipient of the message

$account: Sender of the message, defaults to the current user

Return value

Either FALSE or a URL string

Related topics

3 calls to privatemsg_get_link()
privatemsg_preprocess_author_pane in ./privatemsg.author-pane.inc
Implements hook_preprocess_author_pane().
privatemsg_user in ./privatemsg.module
views_handler_field_privatemsg_link::render in views/views_handler_field_privatemsg_link.inc
Renders our field, displays a link if the user is allowed to.

File

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

Code

function privatemsg_get_link($recipients, $account = array(), $subject = NULL) {
  if ($account == NULL) {
    global $user;
    $account = $user;
  }
  if (!is_array($recipients)) {
    $recipients = array(
      $recipients,
    );
  }
  if (!privatemsg_user_access('write privatemsg', $account) || $account->uid == 0) {
    return FALSE;
  }
  $validated = array();
  foreach ($recipients as $recipient) {
    if (!privatemsg_user_access('read privatemsg', $recipient)) {
      continue;
    }
    if (count(module_invoke_all('privatemsg_block_message', $account, array(
      $recipient->uid => $recipient,
    ))) > 0) {
      continue;
    }
    $validated[] = $recipient->uid;
  }
  if (empty($validated)) {
    return FALSE;
  }
  $url = 'messages/new/' . implode(',', $validated);
  if (!is_null($subject)) {
    $url .= '/' . $subject;
  }
  return $url;
}