Index: votingapi.activity.inc
===================================================================
RCS file: votingapi.activity.inc
diff -N votingapi.activity.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ votingapi.activity.inc	26 Nov 2009 19:02:00 -0000
@@ -0,0 +1,82 @@
+<?php
+// $ Id: $
+/**
+ * @file
+ * Provides Activity2 integration with VotingAPI
+ */
+
+/**
+ * Implementaiton of hook_activity_type_check().
+ */
+function votingapi_activity_type_check($token_objects, $types) {
+  // @TODO: Should we use tags instead of content_types?
+  return (in_array($token_objects['vote']->content_type, $types));
+}
+
+/**
+ * Implementation of hook_activity_record_alter().
+ */
+function votingapi_activity_record_alter(&$record, $context) {
+  // Set the nid here for the node_access part of the Activity2 queries.
+  if ($context['vote']->content_type == 'node') {
+    $record->nid = $context['vote']->content_id;
+  }
+  elseif ($context['vote']->content_type == 'comment') {
+    $record->nid = db_result(db_query("SELECT nid FROM {comment} WHERE cid = %d", $context['vote']->content_id));
+  }
+}
+
+/**
+ * Implementation of hook_activity_objects_alter().
+ */
+function votingapi_activity_objects_alter(&$objects) {
+  if (isset($objects['vote'])) {
+    // We now set objects here for the various content_types.
+    if ($objects['vote']->content_type == 'node') {
+      $objects['node'] = node_load($objects['vote']->content_id);
+    }
+    elseif ($objects['vote']->content_type == 'comment') {
+      $objects['comment'] = _comment_load($objects['vote']->content_id);
+    }
+    // @TODO: figure out a solution for user voting.
+    $objects['user'] = user_load($objects['vote']->uid);
+  }
+}
+
+/**
+ * Implementation of hook_activity_grants().
+ */
+function votingapi_activity_grants($activity, $object, $type) {
+  $grants = array();
+  $content_type = NULL;
+  $content_id = NULL;
+  if ($activity->type == 'votingapi') {
+    $content_type = $object->content_type;
+    $content_id = $object->content_id;
+    $grants['votingapi_' . $object->content_type] = array($object->content_id);
+  }
+  if (isset($activity->nid)) {
+    $grants['votingapi_node'] = array($activity->nid);
+  }
+  if ($activity->type == 'comment') {
+    // With comment activity we want to grant access to those that voted on the node
+    // as well as the those that voted on the comment.
+    $grants['votingapi_comment'] = array($object->cid);
+  }
+
+  return $grants;
+}
+
+/**
+ * Implementation of hook_activity_access_grants().
+ */
+function votingapi_activity_access_grants($account) {
+  // Get all the votes by the $account and then generate the votingapi_$content_type
+  // realm using the content_id as the key
+  $votes = votingapi_select_votes(array('uid' => $account->uid));
+  $grants = array();
+  foreach ($votes as $vote) {
+    $grants['votingapi_' . $vote['content_type']][] = $vote['content_id'];
+  }
+  return $grants;
+}
\ No newline at end of file
Index: votingapi.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/votingapi/votingapi.module,v
retrieving revision 1.46.2.24
diff -u -p -r1.46.2.24 votingapi.module
--- votingapi.module	8 Jul 2009 16:09:45 -0000	1.46.2.24
+++ votingapi.module	26 Nov 2009 19:02:00 -0000
@@ -647,3 +647,57 @@ function _votingapi_query_builder($name,
   }
 }
 
+/**
+ * Implementation of hook_hook_info().
+ */
+function votingapi_hook_info() {
+  return array(
+    'votingapi' => array(
+      'votingapi' => array(
+        'insert' => array(
+          'runs when' => t('A new vote is placed'),
+        ),
+      ),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_trigger_name().
+ */
+function votingapi_votingapi_insert($votes) {
+  if (module_exists('trigger')) {
+    $aids = _trigger_get_hook_aids('votingapi', 'insert');
+    if (!empty($aids)) {
+      $context = array(
+        'hook' => 'votingapi',
+        'op' => 'insert',
+      );
+      // Hand off to each action one vote.
+      foreach ($votes as $vote_row) {
+        $vote = (object) $vote_row;
+        $context['vote'] = $vote;
+        actions_do(array_keys($aids), $vote, $context);
+      }
+    }
+  }
+}
+
+/**
+ * Implementation of hook_activity_info()
+ */
+function votingapi_activity_info() {
+  $info = new stdClass();
+  $info->api = 2.0;
+  $info->path = drupal_get_path('module', 'votingapi');
+  $info->name = 'votingapi';
+  $info->object_type = 'vote';
+  $info->objects = array('Voter' => 'vote', 'Node Author' => 'node', 'User Account' => 'user', 'Comment Author' => 'comment');
+  $info->hooks = array('votingapi' => array('insert'));
+  $info->realms = array('votingapi_node' => 'User voted on the node', 'votingapi_comment' => 'User voted for the same comment');
+  // @TODO: figure out a solution for user voting. $objects['user'] is taken up
+  // by the actual user who places the vote.
+  $info->type_options = array('node' => 'Nodes', 'comment' => 'Comments');
+  $info->eid_field = 'vote_id';
+  return $info;
+}
\ No newline at end of file
