You are here

nodeactivity.module in Activity 5.4

File

contrib/nodeactivity/nodeactivity.module
View source
<?php

/**
 * Activity definition file
 *
 * This defines what hooks activity module should use
 */
function nodeactivity_activity_info() {
  $types = node_get_types();
  foreach ($types as $type) {
    $token_types[$type->type] = $type->name;
  }
  return array(
    'ops' => array(
      'insert' => t('Create'),
      'update' => t('Update'),
      'delete' => t('Delete'),
    ),
    'types' => $token_types,
    'roles' => array(
      'author' => array(
        '#name' => t('Author'),
        '#description' => t('The person who created the node.'),
        '#default' => '[author] [operation]d the [node-type] [node-link]',
      ),
      // This is what corresponds to ACTIVITY_ALL
      'all' => array(
        '#name' => t('All'),
        '#description' => t('The general public.'),
        '#default' => '[author-all] [operation]d the [node-type] [node-link]',
      ),
    ),
  );
}

/** 
 * Implementation of hook_activityapi().
 */
function nodeactivity_activityapi(&$activity, $op) {
  if ($op == 'load') {
    if ($activity['data']['module'] == 'nodeactivity' && !node_access('view', node_load($activity['data']['node-id']))) {
      $activity = array();
    }
  }
}

/**
 * Token module integration. Defines available default tokens.
 */
function nodeactivity_token_list($type = 'all') {
  if ($type == 'nodeactivity') {
    $tokens['nodeactivity'] = array(
      'node-id' => t('Id of the post'),
      'node-title' => t('Title of the post'),
      'node-link' => t('Link to the post'),
      'node-type' => t('The node type of the post'),
    );
    return $tokens;
  }
}

/**
 * Token module integration. Defines available default token values.
 */
function nodeactivity_token_values($type, $data = NULL, $options = array()) {
  if ($type == 'nodeactivity' && !empty($data)) {
    $data['node-type'] = theme('activity_node_type', $data['node-type']);
    $data['node-link'] = l($data['node-title'], 'node/' . $data['node-id']);
    return $data;
  }
}

/**
 * Implementation of hook_nodeapi().
 */
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;
        }

        // Privacy setting check
        $user = user_load(array(
          'uid' => $node->uid,
        ));
        if (activity_user_privacy_optout($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;
  }
}

Functions

Namesort descending Description
nodeactivity_activityapi Implementation of hook_activityapi().
nodeactivity_activity_info Activity definition file
nodeactivity_nodeapi Implementation of hook_nodeapi().
nodeactivity_token_list Token module integration. Defines available default tokens.
nodeactivity_token_values Token module integration. Defines available default token values.