function forum_access_nodeapi in Forum Access 6
Same name and namespace in other branches
- 5 forum_access.module \forum_access_nodeapi()
Implementation of hook_nodeapi().
Add ACL data to fresh forum posts.
File
- ./
forum_access.module, line 270 - forum_access.module
Code
function forum_access_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
static $old_tid = NULL;
// This is modeled after forum_nodeapi():
$vid = _forum_access_get_vid();
$vocabulary = taxonomy_vocabulary_load($vid);
if (empty($vocabulary) || !in_array($node->type, $vocabulary->nodes)) {
if ($op == 'insert' && isset($node->comment_target_nid)) {
// Set moderator on nodecomment.
$topic_node = node_load($node->comment_target_nid);
if ($topic_tid = _forum_access_get_tid($topic_node)) {
$acl_id = acl_get_id_by_number('forum_access', $topic_tid);
acl_node_add_acl($node->nid, $acl_id, 1, 1, 1);
}
}
return;
}
switch ($op) {
case 'presave':
$old_tid = db_result(db_query('SELECT tid FROM {forum} WHERE nid = %d', $node->nid));
break;
case 'update':
if (!empty($old_tid)) {
if (!empty($node->tid) && $node->tid == $old_tid) {
return;
}
acl_node_clear_acls($node->nid, 'forum_access');
if (module_exists('nodecomment')) {
_forum_access_changed_tid($node->tid);
$result = db_query('SELECT cid FROM {node_comments} WHERE nid = %d', $node->nid);
while ($row = db_fetch_object($result)) {
acl_node_clear_acls($row->cid, 'forum_access');
}
}
}
// Deliberate no break -- for changed and for previously unassigned terms we need an insert.
case 'insert':
if (!empty($node->tid)) {
$acl_id = acl_get_id_by_number('forum_access', $node->tid);
acl_node_add_acl($node->nid, $acl_id, 1, 1, 1);
if (isset($old_tid) && module_exists('nodecomment')) {
$result = db_query('SELECT cid FROM {node_comments} WHERE nid = %d', $node->nid);
while ($row = db_fetch_object($result)) {
acl_node_add_acl($row->cid, $acl_id, 1, 1, 1);
node_access_acquire_grants(node_load($row->cid));
}
}
}
$old_tid = NULL;
break;
}
}