| 1 |
<?php |
<?php |
| 2 |
// $Id: nodeaccess.module,v 1.4.2.7.2.6 2007/04/27 18:47:54 debtman7 Exp $ |
// $Id: nodeaccess.module,v 1.4.2.7.2.7 2007/04/30 19:35:18 debtman7 Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 298 |
} |
} |
| 299 |
|
|
| 300 |
function nodeaccess_nodeapi(&$node, $op) { |
function nodeaccess_nodeapi(&$node, $op) { |
|
global $user; |
|
|
|
|
| 301 |
switch ($op) { |
switch ($op) { |
|
case 'insert': |
|
|
$grants = $user->nodeaccess_defaults ? $user->nodeaccess_defaults : variable_get('nodeaccess_'. $node->type, array()); |
|
|
|
|
|
// add author grants |
|
|
// this is duplicated below in nodeaccess_node_access_records, probably should fix that huh |
|
|
$author_prefs = variable_get('nodeaccess_authors', array()); |
|
|
$agrant = $author_prefs[$node->type]; |
|
|
if ($agrant['grant_view'] || $agrant['grant_update'] || $agrant['grant_delete']) { |
|
|
if (variable_get('nodeaccess-priority', 0)) { |
|
|
$priority = 1; |
|
|
} |
|
|
else { |
|
|
$priority = 0; |
|
|
} |
|
|
$grants[] = array( |
|
|
'realm' => 'nodeaccess_author', |
|
|
'gid' => $node->uid, |
|
|
'grant_view' => $agrant['grant_view'], |
|
|
'grant_update' => $agrant['grant_update'], |
|
|
'grant_delete' => $agrant['grant_delete'], |
|
|
'priority' => $priority |
|
|
); |
|
|
} |
|
|
|
|
|
node_access_write_grants($node, $grants, 'nodeaccess_rid'); |
|
|
break; |
|
| 302 |
case 'delete': |
case 'delete': |
| 303 |
db_query('DELETE FROM {nodeaccess} WHERE nid=%d', $node->nid); |
db_query('DELETE FROM {nodeaccess} WHERE nid=%d', $node->nid); |
| 304 |
break; |
break; |
| 442 |
$result = db_query("SELECT nid, gid, realm, grant_view, grant_update, grant_delete FROM {nodeaccess} where nid = %d", $node->nid); |
$result = db_query("SELECT nid, gid, realm, grant_view, grant_update, grant_delete FROM {nodeaccess} where nid = %d", $node->nid); |
| 443 |
if (db_num_rows($result) < 1) { |
if (db_num_rows($result) < 1) { |
| 444 |
$grants = $default; |
$grants = $default; |
| 445 |
|
foreach ($grants as $id => $grant) { |
| 446 |
|
$grants[$id]['priority'] = $priority; |
| 447 |
|
} |
| 448 |
} |
} |
| 449 |
else { |
else { |
| 450 |
// this node has a custom access set apart from the defaults, so return that |
// this node has a custom access set apart from the defaults, so return that |
| 519 |
break; |
break; |
| 520 |
} |
} |
| 521 |
} |
} |
| 522 |
|
|
| 523 |
?> |
?> |