Index: vud.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/vote_up_down/Attic/vud.module,v
retrieving revision 1.1.2.21
diff -u -r1.1.2.21 vud.module
--- vud.module	15 Aug 2009 21:15:45 -0000	1.1.2.21
+++ vud.module	11 Jan 2010 16:19:58 -0000
@@ -1,6 +1,6 @@
 <?php
 // $Id: vud.module,v 1.1.2.21 2009/08/15 21:15:45 lut4rp Exp $
-
+define('VUD_VOTER_OWN',  'vud_voter_own');
 /**
  * @file
  * Implements the core voting module.
@@ -30,6 +30,13 @@
     '#description'   => t('Since Vote Up/Down uses Voting API, all votes will be tagged with this term. (default: vote)<br />This tag is useful is you have deployed various modules that use Voting API. It should always be a unique value. Usually, there is NO need to change this.'),
   );
 
+   $form[VUD_VOTER_OWN] = array(
+      '#type'          => 'checkbox',
+      '#title'         => t('Vote on own content'),
+      '#description'   => t('Should a voter be allowed to vote on their own content? Check this if users are allowed to vote up their own content.'),
+      '#default_value' => variable_get(VUD_VOTER_OWN, 0),
+    );
+
   return system_settings_form($form);
 }
 
@@ -130,6 +137,22 @@
  * Function for the main voting handler with Ajax support.
  */
 function vud_vote($type, $cid, $value, $tag, $token) {
+ global $user;
+
+  if (!$user->uid) {
+    // Anonymous users can't do karma
+    exit();
+  }
+
+  if (!variable_get(VUD_VOTER_OWN, 0)) {
+    // Get the content item's uid
+    $uid = vud_get_content_uid($type, $cid);
+
+    // User cannot vote up/down their own content
+    if ($uid == $user->uid) {
+      exit();
+    }
+  }
   if (is_numeric($value) && drupal_valid_token($token, "vote/$type/$cid/$value/$tag")) {
     $vote = array();
     // Sanity-check the incoming values.
@@ -206,3 +229,17 @@
     drupal_set_message("Oops! There was an error in resetting your vote!", 'warning');
   }
 }
+
+function vud_get_content_uid($type, $cid) {
+  // Get the content item's uid.
+  // We don't do full node_load() here for performance reasons
+  if ($type == 'node') {
+    return db_result(db_query('SELECT uid FROM {node} WHERE nid = %d', $cid));
+  }
+  else if ($type == 'comment') {
+    return db_result(db_query('SELECT uid FROM {comments} WHERE cid = %d', $cid));
+  }
+  else {
+    return 0;
+  }
+}
\ No newline at end of file

