function privatemsg_get_link in Privatemsg 7
Same name and namespace in other branches
- 6.2 privatemsg.module \privatemsg_get_link()
- 6 privatemsg.module \privatemsg_get_link()
- 7.2 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
6 calls to privatemsg_get_link()
- PrivatemsgAPITestCase::testGetLink in ./
privatemsg.test - Test various use cases for privatemsg_get_link().
- privatemsg_comment_view in ./
privatemsg.module - Implements hook_comment_view().
- privatemsg_node_view in ./
privatemsg.module - Implements hook_node_view().
- privatemsg_preprocess_author_pane in ./
privatemsg.author-pane.inc - Implements hook_preprocess_author_pane().
- privatemsg_user_view in ./
privatemsg.module - Implements hook_user_view().
File
- ./
privatemsg.module, line 1945 - 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 = 'messages/new/' . implode(',', $validated);
if (!is_null($subject)) {
// Explicitly encode the / so that it will be encoded twice to work around
// the the menu_system.
$url .= '/' . str_replace('/', '%2F', $subject);
}
return $url;
}