You are here

function protected_node_access_callback in Protected Node 6

Same name and namespace in other branches
  1. 7 protected_node.module \protected_node_access_callback()
  2. 1.0.x protected_node.module \protected_node_access_callback()

Callback function to determine who can enter a password.

1 string reference to 'protected_node_access_callback'
protected_node_menu_array in ./protected_node.settings.inc
Actual implementation of the protected_node_menu() function.

File

./protected_node.module, line 105

Code

function protected_node_access_callback() {
  global $user;

  // super user?
  if ($user->uid == 1) {
    return TRUE;
  }
  if (!user_access('access protected content')) {
    return FALSE;
  }

  // is $nid properly defined?
  if (empty($_GET['protected_page']) || !is_numeric($_GET['protected_page'])) {
    return FALSE;
  }

  // valid node?
  $node = node_load($_GET['protected_page']);
  if (!$node) {
    return FALSE;
  }

  // editing/deleting? user has edit right?
  if (substr($_GET['destination'], 0, 5) == 'node/') {
    if (substr($_GET['destination'], -5) == '/edit') {
      if (!node_access('update', $node)) {
        return FALSE;
      }
    }
    elseif (substr($_GET['destination'], -7) == '/delete') {
      if (!node_access('delete', $node)) {
        return FALSE;
      }
    }
  }
  return TRUE;
}