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' => 'You [operation]d the [node-type] [node-title-link]',
),
'all' => array(
'#name' => t('All'),
'#description' => t('The general public.'),
'#default' => '[author] [operation]d the [node-type] [node-title-link]',
),
),
);
}
function nodeactivity_token_list($type = 'all') {
if ($type == 'nodeactivity') {
$tokens['nodeactivity'] = array(
'node-id' => t('Id of the post'),
'operation' => t('The verb of the operation that took place, eg. "create", "update", "delete"'),
'author' => t('Person who authored the node'),
'node-title' => t('Title of the post'),
'node-title-link' => t('Link to the post'),
'node-type' => t('The type of post'),
'author-name' => t('The name of the author'),
);
return $tokens;
}
}
function nodeactivity_token_values($type, $data = NULL, $options = array()) {
static $authors;
if ($type == 'nodeactivity' && !empty($data)) {
if (!isset($authors[$data['author-uid']])) {
$author = activity_user_load($data['author-uid']);
$authors[$data['author-uid']] = theme('username', $author);
}
$data['author'] = $authors[$data['author-uid']];
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;
$user = user_load(array(
'uid' => $node->uid,
));
$data = array(
'operation' => $operation,
'node-id' => $node->nid,
'author-uid' => $node->uid,
'node-title' => $node->title,
'node-type' => strtolower(node_get_types('name', $node->type)),
'node-title-link' => l($node->title, 'node/' . $node->nid),
'author-name' => $node->name,
);
$target_users_roles = array(
ACTIVITY_ALL => 'all',
$node->uid => 'author',
);
activity_insert('nodeactivity', $type, $op, $data, $target_users_roles);
}
break;
}
}