function spaces_announce_nodeapi in Spaces 5.2
Same name and namespace in other branches
- 5 spaces_announce/spaces_announce.module \spaces_announce_nodeapi()
Implementation of hook_nodeapi
Log viewing on view, and save primary gid relation on update and insert.
File
- spaces_announce/
spaces_announce.module, line 38
Code
function spaces_announce_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
if (variable_get('spaces_announce_' . $node->type, false)) {
switch ($op) {
case 'view':
$space = spaces_get_space();
if ($gid = spaces_announce_primary_gid($node->nid)) {
if ($space->sid != $gid) {
if ($page) {
// If this is not the primary group than then node is being
// recieved, so we do two things; log the view, and set context.
db_query("UPDATE {spaces_announce_log} a SET a.count = a.count + 1, a.viewed = %d WHERE a.nid = %d", time(), $node->nid);
context_set('spaces', 'annoucement', $node->type);
// If a ' NODETYPE_announcement' feature is defined give it the chance to
// become the active feature.
$context = new StdClass();
$context->space = 'spaces';
$context->key = 'feature';
$context->value = $node->type . '_announcement';
if ($context = context_ui_context('load', $context)) {
context_set($context->space, $context->key, $context->value);
}
}
// Add "from" text to content.
$group = node_load($gid);
$group_name = spaces_is_member($gid) ? l($group->title, 'node/' . $gid) : $group->title;
$node->content['announce_primary_group'] = array(
'#value' => theme('announce_group_label', $group_name),
'#weight' => -100,
);
}
}
break;
case 'update':
// If the annoucement settings have been changed for a root book page
// push those changes to the rest of the book.
if ($node->type == 'book' && $node->parent == 0) {
_spaces_announce_apply_book_perms($node);
}
// Check to see if the post has a primary_gid, if it doesn't cascade
// into the 'insert' case so that the primary_gid is silently corrected.
if (spaces_announce_primary_gid($node->nid)) {
break;
}
case 'insert':
$space = spaces_get_space();
db_query('INSERT INTO {spaces_announce} (nid, gid) VALUES (%d, %d)', $node->nid, $space->sid);
db_query('INSERT INTO {spaces_announce_log} (nid) VALUES (%d)', $node->nid);
break;
case 'delete':
db_query('DELETE FROM {spaces_announce} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {spaces_announce_log} WHERE nid = %d', $node->nid);
break;
}
}
}