function _privatemsg_get_allowed_recipients in Privatemsg 6.2
Same name and namespace in other branches
- 7.2 privatemsg.pages.inc \_privatemsg_get_allowed_recipients()
Check if the current user is allowed to write these recipients.
Parameters
$recipients: Array of recipient objects.
Return value
Array of allowed recipient objects.
2 calls to _privatemsg_get_allowed_recipients()
- privatemsg_form_reply in ./
privatemsg.pages.inc - Form builder function; Write a reply to a thread.
- privatemsg_new in ./
privatemsg.pages.inc - Form builder function; Write a new private message.
File
- ./
privatemsg.pages.inc, line 426 - User menu callbacks for Privatemsg.
Code
function _privatemsg_get_allowed_recipients($recipients, $thread_id = NULL) {
global $user;
$usercount = 0;
$valid = array();
$blocked_messages =& _privatemsg_blocked_messages();
$blocked_messages = array();
foreach ($recipients as $recipient) {
// Allow to pass in normal user objects.
if (empty($recipient->type)) {
$recipient->type = 'user';
$recipient->recipient = $recipient->uid;
}
if ($recipient->type == 'hidden') {
continue;
}
if (isset($valid[privatemsg_recipient_key($recipient)])) {
// We already added the recipient to the list, skip him.
continue;
}
if (!privatemsg_recipient_access($recipient->type, 'write', $recipient)) {
// User does not have access to write to this recipient, continue.
continue;
}
if ($recipient->type == 'user' && $recipient->recipient == $user->uid) {
// Skip putting author in the recipients list for now.
// Will be added if he is the only recipient.
$usercount++;
continue;
}
$valid[privatemsg_recipient_key($recipient)] = $recipient;
}
foreach (module_invoke_all('privatemsg_block_message', $user, $valid, array(
'thread_id' => $thread_id,
)) as $blocked) {
// Unset the recipient.
unset($valid[$blocked['recipient']]);
// Store blocked messages. These are only displayed if all recipients
// are blocked.
$blocked_messages[] = $blocked['message'];
}
if (empty($valid) && $usercount >= 1 && empty($blocked_messages)) {
// Assume the user sent message to own account as if the usercount is one or
// less, then the user sent a message but not to self.
$valid['user_' . $user->uid] = $user;
}
return $valid;
}