View source
<?php
function commentactivity_activity_info() {
return array(
'ops' => array(
'insert' => t('Insert'),
'update' => t('Update'),
'delete' => t('Delete'),
'publish' => t('Publish'),
'unpublish' => t('Unpublish'),
),
'types' => array(
'comment' => t('Comment'),
),
'roles' => array(
'author' => array(
'#name' => t('Author'),
'#description' => t('The person who created the comment.'),
'#default' => 'You left the comment [subject] on [parent-node]',
),
'parent_node_author' => array(
'#name' => t('Parent node author'),
'#description' => t('The person who created the node.'),
'#default' => '[author] commented on [parent-node]',
),
'parent_comment_author' => array(
'#name' => t('Parent comment author'),
'#description' => t('The person who wrote the comment.'),
'#default' => '[author] replied to your comment [parent-comment] with [subject]',
),
'all' => array(
'#name' => t('All'),
'#description' => t('The general public.'),
'#default' => '[author] commented on [parent-node] saying [subject]',
),
),
);
}
function commentactivity_token_list($type = 'all') {
if ($type == 'commentactivity') {
$tokens['commentactivity'] = array(
'author' => t('Person who authored the comment'),
'subject' => t('The subject of the comment'),
'parent-node' => t('Link to the parent node'),
'parent-node-author' => t('Person who authored the parent node'),
'parent-node-type' => t('The type of the parent node'),
'parent-comment-author' => t('Person who authored the parent comment'),
'parent-comment' => t('The parent comment'),
);
return $tokens;
}
}
function commentactivity_token_values($type, $data = NULL, $options = array()) {
static $authors;
if ($type == 'commentactivity' && !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 commentactivity_comment($comment, $op) {
switch ($op) {
case 'insert':
case 'update':
if ($comment['status'] == COMMENT_NOT_PUBLISHED) {
break;
}
case 'delete':
if ($comment->status == COMMENT_NOT_PUBLISHED) {
break;
}
case 'publish':
case 'unpublish':
$comment = (array) $comment;
$node = node_load($comment['nid']);
$node_author = db_fetch_object(db_query('SELECT uid, name FROM {users} WHERE uid = %d', $node->uid));
if ($comment['pid']) {
if ($parent_comment_author_uid = db_result(db_query("SELECT uid FROM {comments} WHERE cid = %d", $comment['pid']))) {
$parent_comment_author = user_load(array(
'uid' => $parent_comment_author_uid,
));
$parent_comment = db_result(db_query("SELECT subject FROM {comments} WHERE cid = %d", $comment['pid']));
}
}
$user = user_load(array(
'uid' => $comment['uid'],
));
$data = array(
'author-uid' => $user->uid,
'subject' => l($comment['subject'], 'node/' . $node->nid, array(), NULL, 'comment-' . $comment['cid']),
'parent-node' => l($node->title, 'node/' . $node->nid),
'parent-node-author' => theme('username', $node_author),
'parent-node-type' => $node->type,
);
$target_users_roles = array();
if (is_object($parent_comment_author)) {
$data['parent-comment'] = $parent_comment;
$data['parent-comment-author'] = theme('username', $parent_comment_author);
$target_users_roles[$parent_comment_author_uid] = 'parent comment author';
}
$target_users_roles = array(
ACTIVITY_ALL => 'all',
$node->uid => 'parent node author',
$comment['uid'] => 'author',
);
activity_insert('commentactivity', 'comment', $op, $data, $target_users_roles);
break;
}
}