You are here

function node_authlink_node_access in Node authorize link 7

Same name and namespace in other branches
  1. 8 node_authlink.module \node_authlink_node_access()

Implements hook_node_access().

File

./node_authlink.module, line 203
Provides functionality for the node_authlink module.

Code

function node_authlink_node_access($node, $op, $account) {

  // Ignore if just creating node.
  if ($op == 'create') {
    return NODE_ACCESS_IGNORE;
  }

  // Ignore if node type is not enabled.
  if (!variable_get('node_authlink_enable_' . $node->type, FALSE)) {
    return NODE_ACCESS_IGNORE;
  }

  // Check key if:
  // authkey param is set and in node is set.
  if (isset($_GET['authkey']) && isset($node->authkey)) {
    if ($node->authkey == $_GET['authkey']) {

      // Start session.
      if (!isset($_SESSION)) {
        drupal_session_initialize();
      }

      // Save allowed grants to session.
      $_SESSION['node_authlink_nodes'][$node->nid] = variable_get('node_authlink_grants_' . $node->type, array());
    }
  }

  // Permit if checked.
  if (isset($_SESSION['node_authlink_nodes'][$node->nid]) && in_array($op, $_SESSION['node_authlink_nodes'][$node->nid])) {
    return NODE_ACCESS_ALLOW;
  }
}