### Eclipse Workspace Patch 1.0
#P vote_up_down
Index: vote_up_down.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vote_up_down.module,v
retrieving revision 1.20
diff -u -r1.20 vote_up_down.module
--- vote_up_down.module	19 Nov 2007 07:32:27 -0000	1.20
+++ vote_up_down.module	16 Jan 2008 23:25:13 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: vote_up_down.module,v 1.20 2007/11/19 07:32:27 frjo Exp $
+// $Id: vote_up_down.module,v 1.16.2.3 2008/01/09 15:46:33 frjo Exp $
 
 /**
  * @file
@@ -250,11 +250,12 @@
  */
 function vote_up_down_link($type, $node = NULL, $teaser = FALSE) {
   $links = array();
+  global $user;
   switch ($type) {
     case 'node':
       $node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
       if ($node_type && user_access('view up-down vote')) {
-        if (variable_get('vote_up_down_reset_vote', 0) && user_access('use up-down vote')) {
+        if (variable_get('vote_up_down_reset_vote', 0) && user_access('use up-down vote') && vote_up_down_hasvoted('node', $node->nid, $user->uid)) {
           $links['vote_up_down_reset'] = array(
             'title' => t('Reset vote'),
             'href' => "vote_up_down/$type/$node->nid/0",
@@ -271,7 +272,7 @@
       }
       break;
     case 'comment':
-      if (variable_get('vote_up_down_reset_vote', 0) && user_access('use up-down vote') && variable_get('vote_up_down_widget_comment', 0)) {
+      if (variable_get('vote_up_down_reset_vote', 0) && user_access('use up-down vote') && vote_up_down_hasvoted('comment', $node->cid, $user->uid) && (variable_get('vote_up_down_widget_comment', 0) || variable_get('vote_up_down_link_comment', 0))) {
         $links['vote_up_down_reset_c'] = array(
           'title' => t('Reset vote'),
           'href' => "vote_up_down/$type/$node->cid/0",
@@ -289,50 +290,6 @@
 }
 
 /**
- * Implementation of hook_block().
- */
-function vote_up_down_block($op = 'list', $delta = 0) {
-  if ($op == 'list') {
-    $blocks[0]['info'] = t('Who voted on it');
-    $blocks[1]['info'] = t('Details');
-    return $blocks;
-  }
-  else if ($op == 'view') {
-    if (user_access('access content')) {
-      switch ($delta) {
-        case 0:
-          if (arg(0) == 'node' & is_numeric(arg(1))) {
-            $title = t('Who voted on it');
-            $nid = arg(1);
-            $items = array();
-            $votes = votingapi_get_content_votes('node', $nid);
-            foreach ($votes as $vote) {
-              $account = user_load(array('uid' => $vote[0]->uid, 'status' => 1));
-              $items[] = theme('username', $account) .' ('. $vote[0]->value .')';
-            }
-            $output = theme('item_list', $items);
-          }
-          break;
-
-        case 1:
-          if (arg(0) == 'node' & is_numeric(arg(1))) {
-            $title = t('Details');
-            $items = array();
-            $votes = votingapi_get_content_votes('node', $node->nid);
-            $output = theme('item_list', $items);
-          }
-          break;
-      }
-
-      $block['subject'] = $title;
-      $block['content'] = $output;
-
-      return $block;
-    }
-  }
-}
-
-/**
  * Implementation of hook_userpoints().
  */
 function vote_up_down_userpoints($op, $points = 0, $uid = 0, $event = NULL, $description = NULL) {
@@ -344,7 +301,7 @@
           '#collapsed' => TRUE,
           '#title' => t('Vote up/down points'),
       );
-     
+
       $form['vote_updown_points']['userpoints_vote_up_down'] = array(
         '#type' => 'textfield',
         '#title' => t('Points for voting on a node (requires the Vote up/down module)'),
@@ -359,7 +316,7 @@
         '#size' => 5,
         '#maxlength' => 5,
       );
-      
+
       return $form;
       break;
   }
@@ -503,7 +460,7 @@
         $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.uid FROM {node} n WHERE n.nid = %d'), $cid));
       }
       else {
-        $node = db_fetch_object(db_query(db_rewrite_sql('SELECT c.uid FROM {comments} c WHERE c.cid = %d'), $cid));
+        $node = db_fetch_object(db_query(db_rewrite_sql('SELECT c.uid FROM {comments} c WHERE c.cid = %d', 'c', 'cid'), $cid));
       }
       $user_vote = votingapi_get_user_votes($type, $cid, $user->uid);
       if ($user->uid && !$user_vote && ($node->uid != $user->uid) && ($vote->value != 0)) {
@@ -555,8 +512,8 @@
         $class2 = 'vote-down-inact';
       }
 
-      $output .= '<span id="vote_up_'. $type .'_'. $cid .'" class="'. $class .'" title="'. url("vote_up_down/$type/$cid/1/1") .'">'. l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote up')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
-      $output .= '<span id="vote_down_'. $type .'_'. $cid .'" class="'. $class2 .'" title="'. url("vote_up_down/$type/$cid/-1/1") .'">'. l('', "vote_up_down/$type/$cid/-1", array('class' => $class2, 'title' => t('Vote down')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
+      $output .= '<span id="vote_up_'. $cid .'" class="'. $class .'" title="'. url("vote_up_down/$type/$cid/1/1") .'">'. l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote up')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
+      $output .= '<span id="vote_down_'. $cid .'" class="'. $class2 .'" title="'. url("vote_up_down/$type/$cid/-1/1") .'">'. l('', "vote_up_down/$type/$cid/-1", array('class' => $class2, 'title' => t('Vote down')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
     }
     else {
       $output .= '<span class="up-inact" title="'. t('You must login to vote.') .'"></span>';
@@ -587,7 +544,7 @@
         $class = 'vote-up-inact';
       }
 
-      $output .= '<span id="vote_up_'. $type .'_'. $cid .'" class="'. $class .'" title="'. url("vote_up_down/$type/$cid/1/1/1") .'">'. l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
+      $output .= '<span id="vote_up_'. $cid .'" class="'. $class .'" title="'. url("vote_up_down/$type/$cid/1/1/1") .'">'. l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
 
     }
     else {
@@ -605,23 +562,23 @@
   if ($nodelink) {
     if ($vote_result) {
       $output = array(
-        'title' => '<span id="vote_points_'. $type .'_'. $cid .'" class="vote-points">'. format_plural($vote_result->value, '1 point', '@count points') .'</span>',
+        'title' => '<span id="vote_points_'. $cid .'" class="vote-points">'. format_plural($vote_result->value, '1 point', '@count points') .'</span>',
         'html' => TRUE
       );
     }
     else {
       $output = array(
-        'title' => '<span id="vote_points_'. $type .'_'. $cid .'" class="vote-points">'. t('0 points') .'</span>',
+        'title' => '<span id="vote_points_'. $cid .'" class="vote-points">'. t('0 points') .'</span>',
         'html' => TRUE
       );
     }
   }
   else {
     if ($vote_result) {
-      $output = '<span id="vote_points_'. $type .'_'. $cid .'" class="vote-points">'. format_plural($vote_result->value, '1 point', '@count points') .'</span>';
+      $output = '<span id="vote_points_'. $cid .'" class="vote-points">'. format_plural($vote_result->value, '1 point', '@count points') .'</span>';
     }
     else {
-      $output = '<span id="vote_points_'. $type .'_'. $cid .'" class="vote-points">'. t('0 points') .'</span>';
+      $output = '<span id="vote_points_'. $cid .'" class="vote-points">'. t('0 points') .'</span>';
     }
   }
 
@@ -631,10 +588,10 @@
 function theme_vote_up_down_points_alt($cid, $type) {
   $vote_result = votingapi_get_voting_result($type, $cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum');
   if ($vote_result) {
-    $output = '<div id="vote_points_'. $type .'_'. $cid .'" class="vote-points">'. $vote_result->value;
+    $output = '<div id="vote_points_'. $cid .'" class="vote-points">'. $vote_result->value;
   }
   else {
-    $output = '<div id="vote_points_'. $type .'_'. $cid .'" class="vote-points">0';
+    $output = '<div id="vote_points_'. $cid .'" class="vote-points">0';
   }
 
   $output .= '<div class="vote-points-label">'. format_plural($vote_result->value, 'point', 'points') .'</div></div>';
@@ -666,3 +623,8 @@
 
   return $uid;
 }
+
+
+function vote_up_down_hasvoted($type = 'node', $content_id, $uid) {
+  return (db_fetch_object(db_query("SELECT uid FROM {votingapi_vote} WHERE content_type = '%s' AND content_id = %d AND uid = %d", $type, $content_id, $uid)));
+}
\ No newline at end of file
