You are here

function _pm_block_user_rule_exists in Privatemsg 7.2

Same name and namespace in other branches
  1. 6.2 pm_block_user/pm_block_user.module \_pm_block_user_rule_exists()
  2. 6 pm_block_user/pm_block_user.module \_pm_block_user_rule_exists()
  3. 7 pm_block_user/pm_block_user.module \_pm_block_user_rule_exists()

Checks whether a rule exists for a given author, recipient and action.

For example: if this is passed User A (who has the admin role), User B (who has the authenticated user role) and PM_BLOCK_USER_DISALLOW_BLOCKING parameters, and a rule is configured that disallows authenticated users blocking admins then this function will return TRUE.

Parameters

$author: Author user object to check.

$recipient: Receiver user object to check.

$action: The action to be taken, defaults to PM_BLOCK_USER_DISALLOW_BLOCKING.

Return value

TRUE if a rule exists for the combination of author recipient and action.

4 calls to _pm_block_user_rule_exists()
pm_block_user_block_validate in pm_block_user/pm_block_user.pages.inc
Validate user names.
pm_block_user_privatemsg_block_message in pm_block_user/pm_block_user.module
Implements hook_privatemsg_block_message.
pm_block_user_privatemsg_message_view_alter in pm_block_user/pm_block_user.module
Implements hook_privatemsg_message_view_alter.
_pm_block_user_access in pm_block_user/pm_block_user.module
Provides access argument for blocking user menu item.

File

pm_block_user/pm_block_user.module, line 224
Allows users to block other users from sending them any messages

Code

function _pm_block_user_rule_exists($author, $recipient, $action = PM_BLOCK_USER_DISALLOW_BLOCKING) {
  $block_actions = variable_get('pm_block_user_actions', array());
  foreach ($block_actions as $details) {

    // If this rule doesn't relate to $action, or it's disabled
    // ignore it and go to next loop iteration.
    if ($details['action'] != $action || !$details['enabled']) {
      continue;
    }

    // There are no rules governing user one, but user one may have roles that
    // affect other users, so these exceptions are narrow in scope.
    // Disallow sending affects private message authors.
    if ($author->uid == 1 && $action == PM_BLOCK_USER_DISALLOW_SENDING) {
      continue;
    }

    // Disallow blocking affects private message recipients.
    if ($recipient->uid == 1 && $action == PM_BLOCK_USER_DISALLOW_BLOCKING) {
      continue;
    }

    // The author has a role matching the rule and so does the recipient.
    if (isset($author->roles[$details['author']]) && isset($recipient->roles[$details['recipient']])) {
      return TRUE;
    }
  }
  return FALSE;
}