| 73 |
return user_access('restrict content access') || ($uid == $user->uid && user_access('restrict own content access')); |
return user_access('restrict content access') || ($uid == $user->uid && user_access('restrict own content access')); |
| 74 |
} |
} |
| 75 |
|
|
| 76 |
|
/** |
| 77 |
|
* Checks if a node is restricted from the current user. |
| 78 |
|
* |
| 79 |
|
* @param $nid |
| 80 |
|
* A node ID. |
| 81 |
|
* @param $account |
| 82 |
|
* An optional user account to check, defaults to the current user. |
| 83 |
|
* @return |
| 84 |
|
* TRUE if the user has access to the node, or FALSE if the user is |
| 85 |
|
* restricted from the node. |
| 86 |
|
*/ |
| 87 |
|
function restricted_content_node_access($nid, $account = NULL) { |
| 88 |
|
global $user; |
| 89 |
|
if (!$account) { |
| 90 |
|
$account = $user; |
| 91 |
|
} |
| 92 |
|
$rids = db_result(db_query("SELECT rids FROM {restricted_content} WHERE nid = %d", $nid)); |
| 93 |
|
return !$rids || array_intersect(unserialize($rids), array_keys($account->roles)); |
| 94 |
|
} |
| 95 |
|
|
| 96 |
function restricted_content_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
function restricted_content_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
| 97 |
global $user; |
global $user; |
| 98 |
|
|
| 99 |
if ($op == 'delete') { |
if ($op == 'delete') { |
| 100 |
db_query("DELETE FROM {restricted_content} WHERE nid = %d", $node->nid); |
db_query("DELETE FROM {restricted_content} WHERE nid = %d", $node->nid); |
| 101 |
} |
} |
| 102 |
elseif ($op == 'load' && !restricted_content_form_access($node->uid)) { |
elseif ($op == 'load' && !restricted_content_form_access($node->uid) && !restricted_content_node_access($node->nid)) { |
| 103 |
$rids = db_result(db_query("SELECT rids FROM {restricted_content} WHERE nid = %d", $node->nid)); |
$message = restricted_content_var('message'); |
| 104 |
if ($rids && !array_intersect(unserialize($rids), array_keys($user->roles))) { |
$node->restricted = TRUE; |
| 105 |
|
$node->comment = COMMENT_NODE_DISABLED; |
| 106 |
$message = restricted_content_var('message'); |
|
| 107 |
$node->restricted = TRUE; |
// Add a register link of the user is anonymous and can register for an |
| 108 |
$node->comment = COMMENT_NODE_DISABLED; |
// account. |
| 109 |
|
if (!$user->uid && variable_get('user_register', 1)) { |
| 110 |
// Add a register link of the user is anonymous and can register for an |
$message .= ' '. restricted_content_var('message_anon'); |
| 111 |
// account. |
} |
|
if (!$user->uid && variable_get('user_register', 1)) { |
|
|
$message .= ' '. restricted_content_var('message_anon'); |
|
|
} |
|
|
|
|
|
// Perform token replacement if token module is available. |
|
|
if (module_exists('token')) { |
|
|
$message = token_replace($message, 'node', $node); |
|
|
} |
|
| 112 |
|
|
| 113 |
$node->teaser = $message; |
// Perform token replacement if token module is available. |
| 114 |
$node->body = $message; |
if (module_exists('token')) { |
| 115 |
|
$message = token_replace($message, 'node', $node); |
| 116 |
} |
} |
| 117 |
|
|
| 118 |
|
$node->teaser = $message; |
| 119 |
|
$node->body = $message; |
| 120 |
} |
} |
| 121 |
/*elseif ($op == 'alter' && !empty($node->restricted)) { |
/*elseif ($op == 'alter' && !empty($node->restricted)) { |
| 122 |
// Send a 403 if this is an individual page view. |
// Send a 403 if this is an individual page view. |