function privatemsg_get_link in Privatemsg 7.2
Same name and namespace in other branches
- 6.2 privatemsg.module \privatemsg_get_link()
- 6 privatemsg.module \privatemsg_get_link()
- 7 privatemsg.module \privatemsg_get_link()
Returns a link to the send message form for the specified users.
Contains checks for permission of the author and recipient(s), blocking, and if an anonymous user is involved.
Parameters
mixed $recipients: The user object, or an array of user objects, who will be the recipient(s) of the message.
object $account: The user object who will be the author of the message. If no object is provided, the current user will be used.
string $subject: The text for the subject of the message.
Return value
mixed 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 2029 - Allows users to send private messages to other users.
Code
function privatemsg_get_link($recipients, $account = NULL, $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;
}