diff --git activity.module activity.module index 73d3d8c..00b938a 100644 --- activity.module +++ activity.module @@ -124,6 +124,27 @@ function user_activity_info() { return $info; } +function flag_activity_info() { + $info = _activity_activity_info(); + $info->name = 'flag'; + $info->object_type = 'flag'; + // The order of objects here matters. If a user is both the author and the + // flagging user, the flagging user message takes precedence. + $info->objects = array('node author' => 'node', 'flagging user' => 'account', 'comment author' => 'comment'); + $info->hooks = array('flag' => array('flag', 'unflag')); + + // Figure out the activity access control realms and the types. + $flags = flag_get_flags(); + foreach ($flags as $fid => $flag) { + $info->realms["flag_" . $flag->fid] = $flag->title; + // Currently, flagging a user cannot be recorded. + if ($flag->content_type != 'user') { + $info->type_options[$flag->fid] = $flag->title; + } + } + return $info; +} + /** * Implementation of hook_help(). */ diff --git modules/flag.activity.inc modules/flag.activity.inc new file mode 100644 index 0000000..c336067 --- /dev/null +++ modules/flag.activity.inc @@ -0,0 +1,65 @@ + $flag) { + // This will also work for comments as those activity records have nids. + if ($activity->nid && $flag->content_type == 'node') { + $realms['flag_' . $flag->fid] = array($activity->nid); + } + elseif ($flag->content_type == 'user') { + $realms['flag_' . $flag->fid] = array($activity->uid); + } + } + return $realms; +} + +/** + * Implementation of hook_activity_access_grants(). + */ +function flag_activity_access_grants($account) { + // Get all the user and node flags. + $user_flags = flag_get_user_flags('user', NULL, $account->uid); + $node_flags = flag_get_user_flags('node', NULL, $account->uid); + + $flag_grants = array(); + if (!empty($node_flags)) { + foreach ($node_flags as $flagged_objects) { + foreach ($flagged_objects as $nid => $flagged) { + // Tell activity to grant user $account access to those flagged with + // $fid that are $nid. + $flag_grants['flag_' . $flagged->fid][] = $nid; + } + } + } + + if (!empty($user_flags)) { + foreach ($user_flags as $flagged_objects) { + foreach ($flagged_objects as $uid => $flagged) { + // Tell Activity to grant user $account access to those flagged with + // $fid that are $uid. + $flag_grants['flag_' . $flagged->fid][] = $uid; + } + } + } + + return $flag_grants; +} + +/** + * Implementation of hook_activity_type_check(). + */ +function flag_activity_type_check($token_objects, $types) { + return (in_array($token_objects['flag']->fid, $types)); +}