You are here

function protected_node_load in Protected Node 6

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

Load the node extension fields.

@param[in] object $node The node to complement with the protected node parameters.

Return value

An array with the node extended fields or FALSE.

1 call to protected_node_load()
protected_node_nodeapi in ./protected_node.module
Implementation of hook_nodeapi(). @link http://api.drupal.org/api/function/hook_nodeapi/6

File

./protected_node.module, line 678

Code

function protected_node_load($node) {

  // valid input parameters?
  if (!is_object($node) || !is_numeric($node->nid)) {
    return FALSE;
  }

  // default fields for protected nodes
  static $default_fields = array(
    'protected_node_is_protected' => FALSE,
    'protected_node_passwd' => '',
    'protected_node_passwd_changed' => 0,
    'protected_node_show_title' => 0,
    'protected_node_hint' => '',
  );

  // can the node be protected at all?
  $protection = variable_get('protected_node_protection_' . $node->type, PROTECTED_NODE_PROTECTION_PROTECTABLE);
  if ($protection == PROTECTED_NODE_PROTECTION_NEVER) {

    // by default the node is not protected, return that
    return $default_fields;
  }
  $sql = "SELECT protected_node_is_protected, protected_node_passwd, protected_node_passwd_changed," . " protected_node_show_title, protected_node_hint FROM {protected_nodes} WHERE nid = %d";
  $result = db_fetch_array(db_query($sql, $node->nid));
  if (!is_array($result)) {

    // the SELECT failed, use the defaults
    $result = $default_fields;
  }
  else {

    // define any missing field
    $result += $default_fields;
  }

  // the password is a CHAR(40) and when empty it's all spaces
  // (this is possible when the global password is used)
  $result['protected_node_passwd'] = trim($result['protected_node_passwd']);

  // if the user changed the mode to "always protected" then we force that here
  // it means the node may not be accessible to people without administration
  // privileges since it may not have a default password
  if ($protection == PROTECTED_NODE_PROTECTION_ALWAYS) {
    $result['protected_node_is_protected'] = TRUE;
  }
  return $result;
}