You are here

function privatemsg_get_link in Privatemsg 6.2

Same name and namespace in other branches
  1. 6 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

5 calls to privatemsg_get_link()
PrivatemsgAPITestCase::testGetLink in ./privatemsg.test
Test various use cases for privatemsg_get_link().
privatemsg_link in ./privatemsg.module
Implements hook_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 1897
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 (variable_get('privatemsg_display_link_self', TRUE) == FALSE && $account->uid == $recipient->uid) {
      continue;
    }
    if (count(module_invoke_all('privatemsg_block_message', $account, array(
      privatemsg_recipient_key($recipient) => $recipient,
    ))) > 0) {
      continue;
    }
    $validated[] = $recipient->uid;
  }
  if (empty($validated)) {
    return FALSE;
  }
  $url = privatemsg_get_dynamic_url_prefix($account->uid) . '/new/' . implode(',', $validated);
  if (!is_null($subject)) {
    if (variable_get('clean_url', 0)) {

      // Encode everyting and the / twice to work around mod_rewrite and the
      // menu system.
      $url .= '/' . str_replace('%2F', '%252F', rawurlencode($subject));
    }
    else {

      // Explicitly encode the / so that it will be encoded twice to work around
      // the the menu_system.
      $url .= '/' . str_replace('/', '%2F', $subject);
    }
  }
  return $url;
}