From af65f9a19e34c7f1ec22aa851b6f7ec895080bc7 Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Fri, 25 Jun 2010 00:09:47 -0500
Subject: [PATCH] bug #210905 by Mikhail Khazov, matt@antinomia, marvil07: Fixed Only show 'Reset vote' link if user has voted on node/comment.

---
 vote_up_down.module |   44 ++++++++++++++++++++++++++++++++------------
 1 files changed, 32 insertions(+), 12 deletions(-)

diff --git vote_up_down.module vote_up_down.module
index 3b005de..7c136ab 100644
--- vote_up_down.module
+++ vote_up_down.module
@@ -282,13 +282,23 @@ function vote_up_down_link($type, $node = NULL, $teaser = FALSE) {
       $style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
       if ($node_type && user_access('view up/down votes')) {
         if (variable_get('vote_up_down_reset_vote', 0) && ((user_access('use vote up')) || (user_access('use vote down')))) {
-          $token = drupal_get_token("vote_up_down/$type/$node->nid/0");
-          $links['vote_up_down_reset'] = array(
-            'title' => t('Reset vote'),
-            'href' => "vote_up_down/$type/$node->nid/0",
-            'attributes' => array('title' => t('Reset your vote.')),
-            'query' => drupal_get_destination() .'&token='. $token,
+          $tag = variable_get('vote_up_down_tag', 'vote');
+          $criteria = array(
+            'content_type' => $type,
+            'content_id' => $node->nid,
+            'tag' => $tag,
           );
+          $criteria += votingapi_current_user_identifier();
+          $user_vote = votingapi_select_single_vote_value($criteria);
+          if (!is_null($user_vote)) {
+            $token = drupal_get_token("vote_up_down/$type/$node->nid/0");
+            $links['vote_up_down_reset'] = array(
+              'title' => t('Reset vote'),
+              'href' => "vote_up_down/$type/$node->nid/0",
+              'attributes' => array('title' => t('Reset your vote.')),
+              'query' => drupal_get_destination() .'&token='. $token,
+            );
+          }
         }
         if ($teaser && variable_get('vote_up_down_link_node', 0) && variable_get('vote_up_down_link_node', 0) != 2 && $style != "_alt") {
           $links['vote_up_down_points'] = array(
@@ -306,13 +316,23 @@ function vote_up_down_link($type, $node = NULL, $teaser = FALSE) {
       break;
     case 'comment':
       if (variable_get('vote_up_down_reset_vote', 0) && (user_access('use vote up') || user_access('use vote down')) && (variable_get('vote_up_down_widget_comment', 0) || variable_get('vote_up_down_link_comment', 0))) {
-        $token = drupal_get_token("vote_up_down/$type/$node->cid/0");
-        $links['vote_up_down_reset_c'] = array(
-          'title' => t('Reset vote'),
-          'href' => "vote_up_down/$type/$node->cid/0",
-          'attributes' => array('title' => t('Reset your vote.')),
-          'query' => drupal_get_destination() .'&token='. $token,
+        $tag = variable_get('vote_up_down_tag', 'vote');
+        $criteria = array(
+          'content_type' => $type,
+          'content_id' => $node->cid,
+          'tag' => $tag,
         );
+         $criteria += votingapi_current_user_identifier();
+        $user_vote = votingapi_select_single_vote_value($criteria);
+        if (!is_null($user_vote)) {
+          $token = drupal_get_token("vote_up_down/$type/$node->cid/0");
+          $links['vote_up_down_reset_c'] = array(
+            'title' => t('Reset vote'),
+            'href' => "vote_up_down/$type/$node->cid/0",
+            'attributes' => array('title' => t('Reset your vote.')),
+            'query' => drupal_get_destination() .'&token='. $token,
+          );
+        }
       }
       if (variable_get('vote_up_down_link_comment', 0) && user_access('view up/down votes')) {
         $links['vote_up_down_points_c'] = array(
-- 
1.7.1

