Posted by kenwen on September 15, 2006 at 7:11am
Jump to:
| Project: | Vote Up/Down |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (duplicate) |
Issue Summary
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 :)
Comments
#1
It could be added as a setting and I may take a look at it if I have some free time :-).
#2
yep, that would make much more "par condicio" ;) +1
#3
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
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
Has anyone come across a fix that works for this? I'm trying to eliminate the same problem
#6
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
Incredible, after 3 years of development, users still can vote on own content!
Just add more checks on vote_up_down_vote();
instead of
<?phpif ($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
<?phpglobal $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
Ainur, what version is that code for? It doesn't match the latest 6 versions...
Ricardo
#9
I think we should unpostpone it! :)
#10
subscribe
#11
rbl, it's for 5.x version
#12
Oh =(
Thanks!
#13
Hi, for 6.x-version please check this issue: http://drupal.org/node/554360
#14
like mentioned in #13, this is now tracked on #554360: Disallow Voting on Your Own Content