function pm_block_user_privatemsg_block_message in Privatemsg 6
Same name and namespace in other branches
- 6.2 pm_block_user/pm_block_user.module \pm_block_user_privatemsg_block_message()
- 7.2 pm_block_user/pm_block_user.module \pm_block_user_privatemsg_block_message()
- 7 pm_block_user/pm_block_user.module \pm_block_user_privatemsg_block_message()
Implements hook_privatemsg_block_message().
File
- pm_block_user/
pm_block_user.module, line 504 - Allows users to block other users from sending them any messages
Code
function pm_block_user_privatemsg_block_message($author, $recipients) {
$blocked = array();
// Loop through each recipient and ensure there is no rule blocking this
// author from sending them private messages. Use a reference, so when
// user_load() is needed here the array is updated, negating the need for
// further calls to user_load() later in the code.
foreach (array_keys($recipients) as $uid) {
// Ensure we have a recipient user object which includes roles.
if (!isset($recipients[$uid]->roles)) {
$recipients[$uid] = user_load($uid);
}
// Note: this is checks whether the author may send the message (see third
// parameter). Further below is a check whether the recipient may block it.
if (_pm_block_user_rule_exists($author, $recipients[$uid], PM_BLOCK_USER_DISALLOW_SENDING)) {
$blocked[] = array(
'uid' => $uid,
'message' => t('Sorry, private messaging rules forbid sending messages to !name.', array(
'!name' => $recipients[$uid]->name,
)),
);
}
}
$args = array_merge(array(
$author->uid,
), array_keys($recipients));
$result = db_query('SELECT recipient FROM {pm_block_user} WHERE author = %d AND recipient IN (' . db_placeholders($recipients) . ') GROUP BY recipient', $args);
while ($row = db_fetch_array($result)) {
$recipient = $recipients[$row['recipient']];
// If there's a rule disallowing blocking of this message, send it anyway.
if (_pm_block_user_rule_exists($author, $recipient, PM_BLOCK_USER_DISALLOW_BLOCKING)) {
continue;
}
$blocked[] = array(
'uid' => $row['recipient'],
'message' => t('%name has chosen to not recieve any more messages from you.', array(
'%name' => $recipients[$row['recipient']]->name,
)),
);
}
return $blocked;
}