View source
<?php
function views_bookmarkactivity_activity_info() {
$types = views_bookmark_get_bookmarks();
foreach ($types as $type) {
$type_admin_name = preg_replace('/\\s/', '_', drupal_strtolower($type->title));
$token_types[$type_admin_name] = $type->title;
}
return array(
'ops' => array(
'mark' => t('Mark'),
'unmark' => t('Unmark'),
),
'types' => $token_types,
'roles' => array(
'author' => array(
'#name' => t('Author'),
'#description' => t('The person who bookmarked the node.'),
'#default' => t('[author] [operation]ed the [node-type] [node-link]'),
),
'all' => array(
'#name' => t('All'),
'#description' => t('The general public.'),
'#default' => t('[author-all] [operation]ed the [node-type] [node-link]'),
),
),
);
}
function views_bookmarkactivity_activityapi(&$activity, $op) {
if ($op == 'load') {
if ($activity['data']['module'] == 'views_bookmarkactivity' && !node_access('view', node_load($activity['data']['node-id']))) {
$activity = array();
}
}
}
function views_bookmarkactivity_token_list($type = 'all') {
if ($type == 'views_bookmarkactivity') {
$tokens['views_bookmarkactivity'] = array(
'node-type' => t('The node type of the node that was bookmarked'),
'node-id' => t('Id of the node that was bookmarked'),
'node-title' => t('Title of the node that was bookmarked'),
'node-link' => t('Link to the node that was bookmarked'),
);
return $tokens;
}
}
function views_bookmarkactivity_token_values($type, $data = NULL, $options = array()) {
if ($type == 'views_bookmarkactivity' && !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 views_bookmarkactivity_views_bookmark_api($vb_name, $vbid, $vb_uid, $nid) {
$node = node_load($nid);
$types = views_bookmark_get_bookmarks();
$type = preg_replace('/\\s/', '_', drupal_strtolower($types[$vbid]->title));
if (!in_array($type, variable_get('views_bookmarkactivity_token_types', array(
$type,
)), TRUE) || !in_array($vb_name, variable_get('views_bookmarkactivity_op_types', array(
$vb_name,
)), TRUE)) {
return FALSE;
}
$user = user_load(array(
'uid' => $vb_uid,
'status' => 1,
));
if (activity_user_privacy_optout($user)) {
return FALSE;
}
$data = array(
'operation' => $vb_name,
'node-id' => $node->nid,
'node-title' => $node->title,
'node-type' => $node->type,
);
$target_users_roles = array(
ACTIVITY_ALL => 'all',
$vb_uid => 'author',
);
activity_insert($vb_uid, 'views_bookmarkactivity', $type, $vb_name, $data, $target_users_roles);
}