You are here

node.inc in Activity 5

File

includes/node.inc
View source
<?php

/**
 * Activity definition file
 *
 * This defines what hooks activity module should use
 */
function node_activity_info() {
  $types = node_get_types();
  foreach ($types as $type) {
    $token_types[$type->type] = $type->name;
  }
  return array(
    'name' => 'nodeapi',
    'module' => 'node',
    'ops' => array(
      'insert',
    ),
    'types' => $token_types,
    'tokens' => array(
      'user' => 'user who did the action',
      'user-link' => 'link to the users profile',
      'node-id' => 'id of the post',
      'node-title' => 'title of the post',
      'node-title-link' => 'link to the node',
      'node-type' => 'the type of node',
      'rating' => 'rating data (if available)',
    ),
  );
}

/**
 * Implementation of hook_nodeapi()
 */
function activity_nodeapi($node, $op, $teaser, $page) {
  switch ($op) {
    case 'insert':
      if (variable_get('activity_nodeapi_' . $node->type, 0) == 1) {
        $type = $node->type;
        $action = $op;
        $tokens = array(
          'user-id' => $node->uid,
          'user-name' => $node->name,
          'node-id' => $node->nid,
          'node-title' => $node->title,
          'node-type' => $node->type,
        );

        // if comments are implemented as nodes we change the stored token data
        if (module_exists('nodecomment')) {
          $comment = node_load($node->comment_target_nid);
          $tokens['node-id'] = $node->comment_target_nid;
          $tokens['node-title'] = $comment->title;
        }
        if ($node->type == 'review') {

          // add rating data to the list of tokens
          $tokens['rating'] = $node->field_rating[0]['rating'];
        }
        activity_insert('nodeapi', $type, $action, $tokens);
      }
      break;
  }
}

Functions

Namesort descending Description
activity_nodeapi Implementation of hook_nodeapi()
node_activity_info Activity definition file