Index: vud.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud.module,v retrieving revision 1.2 diff -u -r1.2 vud.module --- vud.module 31 May 2010 03:59:39 -0000 1.2 +++ vud.module 23 Jun 2010 17:13:34 -0000 @@ -5,6 +5,8 @@ * @file * Implements the core voting module on top of Voting API. */ + +define('VUD_VOTER_OWN', 'vud_voter_own');//need it for option to disallow voting on own content module_load_include('inc', 'vud', 'vud.theme'); // Include the theme.inc file. @@ -29,6 +31,12 @@ '#default_value' => variable_get('vud_tag', 'vote'), '#description' => 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), + ); $form['vud_message_on_deny'] = array( '#type' => 'checkbox', '#title' => t('Message on denied permission'), Index: vud.theme.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud.theme.inc,v retrieving revision 1.3 diff -u -r1.3 vud.theme.inc --- vud.theme.inc 20 Jun 2010 17:44:32 -0000 1.3 +++ vud.theme.inc 23 Jun 2010 17:26:02 -0000 @@ -301,6 +301,18 @@ * Function for the main voting handler with Ajax support. */ function vud_vote($type, $content_id, $value, $tag, $widget, $token) { + ctools_include('ajax'); + global $user; + + if (!variable_get(VUD_VOTER_OWN, 0)) { + // Get the content item's uid + $uid = vud_get_content_uid($type, $content_id); + + // User cannot vote up/down their own content + if ($uid == $user->uid) { + ctools_ajax_render_error('Users cannot vote up/down their own content.'); + } + } if (is_numeric($value) && drupal_valid_token($token, "vote/$type/$content_id/$value/$tag/$widget")) { $vote = array(); // Sanity-check the incoming values. @@ -356,3 +368,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; + } +}