View source
<?php
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' => t('[author] [operation]d the [node-type] [node-link]'),
),
'all' => array(
'#name' => t('All'),
'#description' => t('The general public.'),
'#default' => t('[author-all] [operation]d the [node-type] [node-link]'),
),
),
);
}
function nodeactivity_activityapi(&$activity, $op) {
if ($op == 'load') {
if ($activity['data']['module'] == 'nodeactivity' && !node_access('view', node_load($activity['data']['node-id']))) {
$activity = array();
}
}
}
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;
}
}
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;
}
}
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;
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,
));
if (activity_user_privacy_optout($user)) {
return FALSE;
}
if (user_access('hide activity', $user)) {
return FALSE;
}
$data = array(
'operation' => $operation,
'node-id' => $node->nid,
'node-title' => $node->title,
'node-type' => $node->type,
);
$target_users_roles = array(
ACTIVITY_ALL => 'all',
$node->uid => 'author',
);
activity_insert($node->uid, 'nodeactivity', $type, $op, $data, $target_users_roles);
}
break;
}
}