You are here

function access_unpublished_nodeapi in Access unpublished 6

Implements hook_nodeapi().

File

./access_unpublished.module, line 72
This module is used to allow access to unpublished nodes

Code

function access_unpublished_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  global $user;
  switch ($op) {
    case 'view':

      //When saving an unpublished node display the URL with the created hash

      //so that the author can provide direct access to the unpublished node.

      //Only display the direct URL for accessing unpublished nodes when the

      //user is allowed to do so in the permissions, and the user is not

      //already using an URL with the hash.
      if ($node->status == 0) {
        if (user_access('Generate hashed URL when saving an unpublished ' . $node->type . ' node') && $user->uid == $node->uid && user_access('Allow access to unpublished ' . $node->type . ' nodes if hash is provided') && $_GET[_access_unpublished_get_querystring()] == "") {
          drupal_set_message(t('URL to access this unpublished node: <a href="@unpublished_url">@unpublished_url</a>', array(
            '@unpublished_url' => access_unpublished_get_access_url($node),
          )));
        }
      }
      break;
  }
}