You are here

function redirect_access in Redirect 7

Same name and namespace in other branches
  1. 7.2 redirect.module \redirect_access()

Determine whether the current user may perform the given operation on the specified redirect.

Parameters

$op: The operation to be performed on the redirect. Possible values are:

  • "create"
  • "update"
  • "delete"

$redirect: The redirect object on which the operation is to be performed, or redirect type (e.g. 'feedburner') for the "create" operation.

$account: Optional, a user object representing the user for whom the operation is to be performed. Determines access for a user other than the current user.

Return value

TRUE if the operation may be performed, FALSE otherwise.

7 calls to redirect_access()
redirect_404_list in ./redirect.admin.inc
redirect_field_attach_form in ./redirect.module
Implements hook_field_attach_form().
redirect_handler_field_redirect_link_delete::render in views/redirect_handler_field_redirect_link_delete.inc
Render the field.
redirect_handler_field_redirect_link_edit::render in views/redirect_handler_field_redirect_link_edit.inc
Render the field.
redirect_handler_field_redirect_operations::render in views/redirect_handler_field_redirect_operations.inc
Render the field.

... See full list

3 string references to 'redirect_access'
redirect_hook_info in ./redirect.module
Implements hook_hook_info().
redirect_list_form in ./redirect.admin.inc
@file Administrative page callbacks for the redirect module.
redirect_menu in ./redirect.module
Implements hook_menu().

File

./redirect.module, line 702

Code

function redirect_access($op, $redirect, $account = NULL) {
  global $user;
  $rights =& drupal_static(__FUNCTION__, array());
  if (!$redirect || !in_array($op, array(
    'create',
    'update',
    'delete',
    'list',
  ), TRUE)) {

    // If there was no redirect to check against, or the $op was not one of the
    // supported ones, we return access denied.
    return FALSE;
  }

  // If no user object is supplied, the access check is for the current user.
  if (empty($account)) {
    $account = $user;
  }
  $cid = isset($redirect->rid) ? $redirect->rid : $redirect;

  // Return cached value if access already checked for this redirect, user and op.
  if (isset($rights[$account->uid][$cid][$op])) {
    return $rights[$account->uid][$cid][$op];
  }

  // Initialize the array value
  $rights[$account->uid][$cid][$op] = FALSE;
  if (user_access('administer redirects', $account)) {

    // Can access all redirects.
    $rights[$account->uid][$cid][$op] = TRUE;
  }
  elseif (user_access('administer own redirects')) {

    // Redirect needs to be the user's redirect
    $rights[$account->uid][$cid][$op] = $op == 'create' || $op == 'list' || $redirect->uid == $account->uid;
  }

  // We grant access to the redirect if both of the following conditions are met:
  // - No modules say to deny access.
  // - At least one module says to grant access.
  $access = module_invoke_all('redirect_access', $op, $redirect, $account);
  if (in_array(REDIRECT_ACCESS_DENY, $access, TRUE)) {
    $rights[$account->uid][$cid][$op] = FALSE;
  }
  elseif (in_array(REDIRECT_ACCESS_ALLOW, $access, TRUE)) {
    $rights[$account->uid][$cid][$op] = TRUE;
  }
  return $rights[$account->uid][$cid][$op];
}