Index: vud.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/Attic/vud.module,v retrieving revision 1.1.2.23 diff -u -r1.1.2.23 vud.module --- vud.module 12 Mar 2010 08:06:45 -0000 1.1.2.23 +++ vud.module 21 Mar 2010 21:42:15 -0000 @@ -1,6 +1,8 @@ t('Since Vote Up/Down uses Voting API, all votes will be tagged with this term. (default: vote)
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); } Index: vud.theme.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/Attic/vud.theme.inc,v retrieving revision 1.1.2.26 diff -u -r1.1.2.26 vud.theme.inc --- vud.theme.inc 12 Mar 2010 08:10:25 -0000 1.1.2.26 +++ vud.theme.inc 21 Mar 2010 21:28:18 -0000 @@ -235,6 +235,17 @@ * Function for the main voting handler with Ajax support. */ function vud_vote($type, $cid, $value, $tag, $widget, $token) { + global $user; + + 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/$widget")) { $vote = array(); // Sanity-check the incoming values. @@ -290,3 +301,17 @@ drupal_goto($_SERVER['HTTP_REFERER']); } } + +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