Prevent users voting for themselves

kenwen - September 15, 2006 - 07:11
Project:Vote Up/Down
Version:HEAD
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I was just wondering - is it possible to set it up so people can't vote for themselves or it defaults to giving them a vote automatically?

Great module btw, one of the communities I'm working for are drooling at the new site :)

#1

frjo - September 15, 2006 - 12:13
Version:4.7.x-1.x-dev» HEAD
Status:active» postponed

It could be added as a setting and I may take a look at it if I have some free time :-).

#2

marcoBauli - November 9, 2006 - 00:48
Title:users voting for themselves» Prevent users voting for themselves

yep, that would make much more "par condicio" ;) +1

#3

ola90@drupal.ru - April 12, 2007 - 11:50

I used the following code in node.tpl.php to solve this issue:

    global $user;
    if ($user->uid):
     if ($user->uid!=$node->uid):
      print $vote_up_down_widget;
     else:
      print $vote_up_down_points;
     endif;
    else:
     print $vote_up_down_points;
    endif;

It shows only points to anonymous users and the author of the node, but other authorised users see the voting widget.

#4

madjr - May 2, 2007 - 02:50

umm , i can't actually get the code above to work. Dunno what i may be doing wrong.

Another strange thing is that users can also vote for themselves in the "preview" screen before posting (). After that they can still vote for themselves again once the node/comment is posted.

#5

madidus - September 5, 2007 - 04:02

Has anyone come across a fix that works for this? I'm trying to eliminate the same problem

#6

stevepurkiss - September 16, 2007 - 16:50

I've just done a hack, it works for me, YMMV ;) Also I've only done it for nodes and comments, not links, but shouldn't be hard to work out how to do it from what I've done here.

In vote_up_down.module, lines 208-246 are currently:

/**
* Implementation of hook_nodeapi().
*/
function vote_up_down_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'view':
      $node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
      if ($node_type) {
        $style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
        if ($teaser && variable_get('vote_up_down_widget_node', 0) && variable_get('vote_up_down_widget_node', 0) != 2) {
          $node->content['vote_up_down'] = array(
            '#value' => theme("vote_up_down_widget$style", $node->nid, 'node'),
            '#weight' => -10,
          );
        }
        else if (!$teaser && variable_get('vote_up_down_widget_node', 0) > 1) {
          $node->content['vote_up_down'] = array(
            '#value' => theme("vote_up_down_widget$style", $node->nid, 'node'),
            '#weight' => -10,
          );
        }
      }
      break;
  }
}

/**
* Implementation of hook_comment().
*/
function vote_up_down_comment(&$comment, $op) {
  switch ($op) {
    case 'view':
      if (variable_get('vote_up_down_widget_comment', 1)) {
        $style = variable_get('vote_up_down_widget_style_comment', 0) == 1 ? '_alt' : '';
        $comment->comment = theme("vote_up_down_widget$style", $comment->cid, 'comment') . $comment->comment;
      }
      break;
  }
}

Replace them with this:

/**
* Implementation of hook_nodeapi().
*/
function vote_up_down_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  global $user;
  switch ($op) {
    case 'view':
      $node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
      if ($node_type) {
        $style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
        if ($teaser && variable_get('vote_up_down_widget_node', 0) && variable_get('vote_up_down_widget_node', 0) != 2) {
          if ($user->uid!=$node->uid) {
            $node->content['vote_up_down'] = array(
              '#value' => theme("vote_up_down_widget$style", $node->nid, 'node'),
              '#weight' => -10,
            );
          }
          else {
            $node->content['vote_up_down'] = array(
              '#value' => theme("vote_up_down_points", $node->nid, 'node'),
              '#weight' => -10,
            );         
          }
        }
        else if (!$teaser && variable_get('vote_up_down_widget_node', 0) > 1) {
          if ($user->uid!=$node->uid) {
            $node->content['vote_up_down'] = array(
              '#value' => theme("vote_up_down_widget$style", $node->nid, 'node'),
              '#weight' => -10,
            );
          }
          else {
            $node->content['vote_up_down'] = array(
              '#value' => theme("vote_up_down_points", $node->nid, 'node'),
              '#weight' => -10,
            );         
          }
        }
      }
      break;
  }
}

/**
* Implementation of hook_comment().
*/
function vote_up_down_comment(&$comment, $op) {
  switch ($op) {
    case 'view':
      if (variable_get('vote_up_down_widget_comment', 1)) {
        $style = variable_get('vote_up_down_widget_style_comment', 0) == 1 ? '_alt' : '';

        global $user;
        if ($user->uid!=$comment->uid) {
          $comment->comment = theme("vote_up_down_widget$style", $comment->cid, 'comment') . $comment->comment;
        }
        else {
          $comment->comment = theme("vote_up_down_points", $comment->cid, 'comment') . $comment->comment;
        }
      }

      break;
  }
}

Use at your own risk ;)

#7

Ainur - May 14, 2009 - 17:11

Incredible, after 3 years of development, users still can vote on own content!
Just add more checks on vote_up_down_vote();
instead of

<?php
if ($user->uid != $content->uid && is_numeric($cid) && is_numeric($value) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], "vote_up_down/$type/$cid/$value")) {
?>

use
<?php
global $user;
$content = votingapi_load_content($cid, $type);
if (
$user->uid != $content->uid && is_numeric($cid) && is_numeric($value) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], "vote_up_down/$type/$cid/$value")) {
?>

#8

rbl - May 20, 2009 - 22:59

Ainur, what version is that code for? It doesn't match the latest 6 versions...

Ricardo

#9

Flying Drupalist - June 14, 2009 - 17:08
Status:postponed» active

I think we should unpostpone it! :)

#10

mitkoru - September 15, 2009 - 22:11

subscribe

#11

Ainur - October 15, 2009 - 10:47

rbl, it's for 5.x version

#12

rbl - October 30, 2009 - 13:34

Oh =(
Thanks!

 
 

Drupal is a registered trademark of Dries Buytaert.