You are here

function nodeactivity_nodeapi in Activity 6

Same name and namespace in other branches
  1. 5.4 contrib/nodeactivity/nodeactivity.module \nodeactivity_nodeapi()
  2. 5.2 contrib/nodeactivity.module \nodeactivity_nodeapi()
  3. 5.3 contrib/nodeactivity/nodeactivity.module \nodeactivity_nodeapi()

Implementation of hook_nodeapi().

File

contrib/nodeactivity/nodeactivity.module, line 72

Code

function nodeactivity_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'insert':
    case 'update':
    case 'delete':
      if ($node->status == 1) {
        $operation = $op == 'insert' ? t('create') : t($op);
        $type = $node->type;

        // Check if both type and operation are
        // enabled for activity. If not then stop here
        if (!in_array($node->type, variable_get('nodeactivity_token_types', array(
          $node->type,
        )), TRUE) || !in_array($op, variable_get('nodeactivity_op_types', array(
          $op,
        )), TRUE)) {
          return FALSE;
        }
        $user = user_load(array(
          'uid' => $node->uid,
        ));

        // Privacy setting check
        if (activity_user_privacy_optout($user)) {
          return FALSE;
        }

        // User hide activity permission check
        if (user_access('hide activity', $user)) {
          return FALSE;
        }
        $data = array(
          'operation' => $operation,
          'node-id' => $node->nid,
          'node-title' => $node->title,
          'node-type' => $node->type,
        );

        // This determines who sees messages based on this data.
        // This implementation will ensure that the activity is shown
        // to the special group ACTIVITY_ALL (everybody, basically),
        // as well as to the person who inserted, updated or deleted the node.
        // The use of the role (all and author) ensures that we know later how
        // to address the person... ie "You" or "Bob".
        $target_users_roles = array(
          ACTIVITY_ALL => 'all',
          $node->uid => 'author',
        );
        activity_insert($node->uid, 'nodeactivity', $type, $op, $data, $target_users_roles);
      }
      break;
  }
}