Index: activity/contrib/pollactivity/pollactivity.info
===================================================================
--- activity/contrib/pollactivity/pollactivity.info	(revision 0)
+++ activity/contrib/pollactivity/pollactivity.info	(revision 0)
@@ -0,0 +1,7 @@
+; $Id: $
+name = Poll activity
+description = "Enable activity notifications for polls."
+core = 6.x
+dependencies[] = activity
+dependencies[] = poll
+package = Activity
Index: activity/contrib/pollactivity/pollactivity.install
===================================================================
--- activity/contrib/pollactivity/pollactivity.install	(revision 0)
+++ activity/contrib/pollactivity/pollactivity.install	(revision 0)
@@ -0,0 +1,34 @@
+<?php
+// $Id: $
+
+/**
+ * Implementation of hook_install().
+ */
+function pollactivity_install() {
+  if (!module_exists('activity')) {
+    module_load_include('module', 'activity');
+  }
+  activity_install_activity_defaults('pollactivity');
+  drupal_set_message(t('Activity integration with Poll module installed. Go to <a href="@settings">Poll Activity settings</a> to customize ', array('@settings' => url('admin/settings/activity/pollactivity'))));
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function pollactivity_uninstall() {
+  // Remove any activity entries from the votingapiactivity module
+  if (module_exists('activityhistory')) {
+    db_query("DELETE FROM {activity_history} WHERE aid IN (SELECT aid FROM {activity} WHERE module = '%s')", 'pollactivity');
+  }
+  db_query("DELETE FROM {activity_targets} WHERE aid IN (SELECT aid FROM {activity} WHERE module = '%s')", 'pollactivity');
+  db_query("DELETE FROM {activity_comments} WHERE aid IN (SELECT aid FROM {activity} WHERE module = '%s')", 'pollactivity');
+  db_query("DELETE FROM {activity} WHERE module = '%s'", 'pollactivity');
+
+  // Delete any variables that have been set.
+  // We don't just DELETE FROM {variable}, even though we could.
+  $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'pollactivity%'");
+  // Instead we use the API, because API's can change!
+  while ($row = db_fetch_object($result)) {
+    variable_del($row->name);
+  }
+}
Index: activity/contrib/pollactivity/pollactivity.module
===================================================================
--- activity/contrib/pollactivity/pollactivity.module	(revision 0)
+++ activity/contrib/pollactivity/pollactivity.module	(revision 0)
@@ -0,0 +1,144 @@
+<?php
+// $Id: $
+
+/**
+ * Activity definition file
+ *
+ * This defines what hooks activity module should use
+ */
+function pollactivity_activity_info() {
+  return array(
+    'ops' => array('vote' => t('Vote')),
+    'types' => array('poll' => node_get_types('name', 'poll')),
+    'roles' => array(
+      'author' => array(
+        '#name' => t('Author'),
+        '#description' => t('The person who voted'),
+        '#default' => t('[author] voted on the [content-type] [content-link]'),
+      ),
+      'all' => array(
+        '#name' => t('All'),
+        '#description' => t('The general public.'),
+        '#default' => t('[author-all] voted on the [content-type] [content-link]'),
+      ),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_activityapi().
+ */
+function pollactivity_activityapi(&$activity, $op) {
+  if ($op == 'load') {
+    if ($activity['data']['module'] == 'pollactivity' && !node_access('view', node_load($activity['data']['content-nid']))) {
+      $activity = array();
+    }
+  }
+}
+
+/**
+ * Token module integration. Defines available default tokens.
+ */
+function pollactivity_token_list($type = 'all') {
+  if ($type == 'pollactivity') {
+    $tokens['pollactivity'] = array(
+      'author-vote' 	=> t('Value of the author\'s vote'),
+      'content-type' 	=> t('Content type that was voted on such as "story" or "image" or "comment"'),
+      'content-nid'  	=> t('Id of the node that was voted upon'),
+      'content-title'  	=> t('Title of the content that was voted upon'),
+      'content-link' 	=> t('Link to the content that was voted upon'),
+      //'content-vote-avg' => t('Average of all votes for this content'),
+      'content-vote-count' => t('Count of all votes for this content'),
+    );
+    return $tokens;
+  }
+}
+
+/**
+ * Token module integration. Defines available default token values.
+ */
+function pollactivity_token_values($type, $data = NULL, $options = array()) {
+  if ($type == 'pollactivity' && !empty($data)) {
+    $author_vote = db_fetch_object(db_query('SELECT chorder FROM {poll_votes} WHERE uid = %d AND nid = %d', $data['uid'], $data['content-nid']));
+    $data['author-vote'] = $author_vote->chorder;
+    $content_votes = db_fetch_object(db_query('SELECT count(*) as count_value FROM {poll_votes} WHERE nid = %d', $data['content-nid']));
+    $data['content-vote-count'] = $content_votes->count_value;
+    $data['content-type'] = theme('activity_node_type', $data['content-type']);
+
+    $data['content-link'] = l($data['content-title'], 'node/'. $data['content-nid']);
+    return $data;
+  }
+}
+
+function pollactivity_form_alter(&$form, $form_state, $form_id) {
+  if ($form_id == 'poll_view_voting') {
+    $form['vote']['#submit'][] = 'pollactivity_poll_voting_submit';
+  }
+}
+
+/**
+ * Form submission callback for a poll voting form.
+ */
+function pollactivity_poll_voting_submit($form, &$form_state) {
+  $node = $form['#node'];
+
+  $vote = array();
+  global $user;
+  $vote['uid'] = $user->uid;
+  $vote['content_type'] = 'node';
+  $vote['content_id'] = $node->nid;
+
+  pollactivity_poll_insert(array($vote));
+}
+
+/**
+ * Implementation of hook_poll_insert()
+ */
+function pollactivity_poll_insert($votes) {
+  foreach ($votes as $vote) {
+
+    // Check if both type and operation are
+    // enabled for activity. If not then stop here
+    if (!in_array('poll', variable_get('pollactivity_token_types', array('poll')), TRUE) ||
+      !in_array('vote', variable_get('pollactivity_op_types', array('vote')), TRUE)) {
+      return FALSE;
+    }
+
+    // let's not write a record if the voter is
+    // anonymous or otherwise not valid
+    if ($vote['uid'] == 0 || (!$user = user_load(array('uid' => $vote['uid'])))) {
+      return FALSE;
+    }
+
+    // Privacy setting check
+    if (activity_user_privacy_optout($user)) {
+      return FALSE;
+    }
+
+    // User hide activity permission check
+    if (user_access('hide activity', $user)) {
+      return FALSE;
+    }
+
+    // Only handle votes on nodes:
+    if ($vote['content_type'] == 'node') {
+      $content = node_load($vote['content_id']);
+    }
+    else {
+      return FALSE;
+    }
+
+    $data = array(
+      'content-nid'		=> $content->nid,
+      'content-type' 	=> $content->type,
+      'content-title' 	=> $content->title,
+    );
+
+    $target_users_roles = array(
+      ACTIVITY_ALL => 'all',
+      $user->uid => 'author'
+    );
+
+    activity_insert($user->uid, 'pollactivity', 'poll', 'vote', $data, $target_users_roles);
+  }
+}
