function protected_node_init in Protected Node 6
Same name and namespace in other branches
- 7 protected_node.module \protected_node_init()
- 1.0.x protected_node.module \protected_node_init()
Implementation of hook_init(). @link http://api.drupal.org/api/function/hook_init/6
File
- ./
protected_node.module, line 148
Code
function protected_node_init() {
global $user;
// are we about to display a node?
// can user see all nodes anyway?
if (user_access('bypass password protection')) {
return;
}
$nid = FALSE;
$param2 = arg(2);
if (arg(0) == 'node' && is_numeric(arg(1))) {
if ($param2 === NULL) {
$nid = protected_node_is_locked(arg(1), 'view');
if ($nid === -1) {
return;
}
}
elseif ($param2 == 'edit' || $param2 == 'delete') {
$nid = protected_node_is_locked(arg(1), $param2);
}
else {
// any access right?
$nid = protected_node_is_locked(arg(1));
}
if ($nid === TRUE || $nid === -1) {
drupal_access_denied();
exit;
}
}
elseif (arg(0) == 'system' && arg(1) == 'files') {
if (!empty($param2)) {
// $param2 is a filename in this case
$nid = protected_node_and_attachment($param2);
}
}
if ($nid) {
$query = drupal_get_destination();
if (!empty($_SERVER['HTTP_REFERER'])) {
$query .= '&back=' . urlencode($_SERVER['HTTP_REFERER']);
}
$query .= '&protected_page=' . $nid;
drupal_goto('protected-node', $query);
}
}