vote_up_down module anonymous user
use up-down vote X

Comments

frjo’s picture

Version: 4.7.x-1.x-dev »
Category: bug » feature

Anonymous voting is not yet supported, I need to add that to the README.

frjo’s picture

Status: Active » Fixed
lennart’s picture

Status: Fixed » Active

anonymous user still cannot vote even when granted access under access control. There is no mention of this in the readme file.

jackdaw’s picture

yes, I have this problem too

frjo’s picture

Status: Active » Postponed

Line 23 in the README.txt in cvs "Anonymous voting is not supported, not yet at least."

rousehouse’s picture

Looking forward to this feature (when it's ready). ;-)

xamox’s picture

Looking forwards to it as well.

marcoBauli’s picture

+1 to the coire for this feat

shadyman@erroraccessdenied.com’s picture

+1 looking forward

shadyman@erroraccessdenied.com’s picture

Title: anonymouse user cannot vote even if it's enabled in access control » Allow Anonymous Users to Vote
summit’s picture

Does this feature of anonymous voting get enabled please?
I really would like it!

Thanks for your response in advance!

greetings,
Martijn
www.ontwikkelingswerk.net

shadyman@erroraccessdenied.com’s picture

Martijn:

No, the feature is postponed until it can be implemented.

aw05’s picture

I am working on this right now because our site needs anonymous voting asap. Hopefully, we'll have a patch available in the next few days, but no promises.

Blackwolf’s picture

aw05: you'd be my hero if you could pull this off :)

summit’s picture

My hero also.
thanks in advance!

greetings,
Martijn

frjo’s picture

The Fivestar module supports anonymous voters and many other nice things. It is developed by Eaton as a showcase what you can do with Voting API. I intend to implement many things from Fivestar in to the next version of Vote up/down.

If possibel I might even simply build on top of Fivestar, just as I already build on top of Links, Voting API etc. I would also like to make more use of CCK and Views.

I will start with this when I retun from my travels in a couple of weeks.

Lityi’s picture

"couple of weeks"!? :)

Come back and do this NOW! No fun until you statisfy our request! :)

(I'd sponsor it a little bit if it speeds up the developing process...)

Then you can have your travel around the world, hehehe.

j0rd’s picture

i'm going to attempt to get this going tonight. We'll see how far i get. If i can't figure it out easy, i'll probably just switch to 5 star.

j0rd’s picture

Quick and dirty anonymous voting. 1 per IP.

Download here: http://mholman.com/vote_up_down.module.diff

Please rank some of the portfolio work as well.

Is this a permanent fix? No.

Does it work? Yes.

What does it do? Enabled the voting system for anonymous users. Stores the votes under the uid ip2long(sprintf("%u",$_SERVER['REMOTE_ADDR']));

Is this a good idea? Not really, but it works for me for now.

--- vote_up_down/vote_up_down.module   2007-02-16 01:11:17.000000000 -0800
+++ modules/vote_up_down/vote_up_down.module 2007-02-16 01:07:48.000000000 -0800
@@ -455,7 +455,16 @@


     // do the voting via voting api.
-    votingapi_set_vote($type, $cid, $vote);
+    global $user;
+    if($user->uid) {
+       votingapi_set_vote($type, $cid, $vote);
+    }
+    else {
+       $long = ip2long($_SERVER['REMOTE_ADDR']);
+       if($long != -1 && $long != FALSE) {
+          votingapi_set_vote($type, $cid, $vote, sprintf("%u", ip2long($_SERVER['REMOTE_ADDR'])));
+       }
+    }

     if ($ajax) {
       $style = ($alt == TRUE ? '_alt' : '');
@@ -475,7 +484,7 @@

     $output = '<div class="vote-up-down-widget">';

-    if (user_access('use up-down vote')) {
+    if (user_access('use up-down vote') && $user->uid) {
       $user_vote = votingapi_get_user_votes($type, $cid);

       if ($user_vote[0]->value > 0) {
@@ -513,7 +522,7 @@
     $output = '<div class="vote-up-down-widget-alt">';
     $output .= theme('vote_up_down_points_alt', $cid, $type);

-    if (user_access('use up-down vote')) {
+    if (user_access('use up-down vote') && $user->uid) {
       $user_vote = votingapi_get_user_votes($type, $cid);

       if ($user_vote[0]->value > 0) {
guschnit’s picture

hi
I'm not an expert
Where do we have to insert that code?
is it for version 5?
regards

frjo’s picture

Assigned: Unassigned » frjo
Status: Postponed » Active

The HEAD version, http://drupal.org/node/96075, now has support for anonymous voting. OBS! HEAD only supports Drupal 5. Thanks for the comments and code on this issue.

I'm very interested in comments on the implementation, and bug reports of course.

By using the ip address plus the day of the year as "uid" I'm allowing one vote per IP and day. Does that sounds reasonable? I took that from the fivestar module.

Here is how I generate a "uid" for anonymous voters, does it look OK?

    if ($long = ip2long($_SERVER['REMOTE_ADDR'])) {
      $uid = sprintf("%u", $long) . date('z');
    }
j0rd’s picture

that's exactly how i did the UID in my code diff posted above. My code is for 5.1, but i'm sure it can be applied to other versions of drupal.

You'll also need to remove the tests for && $user->uid in the theme functions for vote_up_down to allow them to vote.

My diff above has all the code changes needed. If you don't know how to read a diff....i'll explain it below.

find this line in vote_up_down.module

votingapi_set_vote($type, $cid, $vote);

and replace it with

    global $user;
    if($user->uid) {
       votingapi_set_vote($type, $cid, $vote);
    }
    else {
       $long = ip2long($_SERVER['REMOTE_ADDR']);
       if($long != -1 && $long != FALSE) {
          votingapi_set_vote($type, $cid, $vote, sprintf("%u", ip2long($_SERVER['REMOTE_ADDR'])));
       }
    }

This allows users who are logged in to get tracked under their UID and users who are not logged in to get tracked under a fake UID which is their IP. This will cause conflicts in the ip2long conversion is the same as a UID, but i believe you'll need a server with a load of members to have these two start conflicting.

Then find the two instances of this code

    if (user_access('use up-down vote') && $user->uid) {

and replace it with the following

    if (user_access('use up-down vote')) {

This allows users who are not logged in to vote. Remember, there are two instances of this.

Thanks for committing the code to HEAD, although i believe you should create a more permanent solution.

j0rd’s picture

i just took a look at the nightly snap shot and i would recommend using that. It's more robust that my hack as it includes administrative features as well.

j0rd’s picture

There's a bug in the HEADs implementation.

I noticed that when i'm anonymous and vote, then refresh the page, usually it would show the Up arrow highlighted, but it's not anymore.

Could we please get this fixed. It did not happen in my implementation.

frjo’s picture

When I vote as a anonymous user on my test site and then refresh the page the vote arrow is active, just like when I vote as a logged in user. I guess something is different in our setups. Have you tried it on a fresh install of Drupal 5.1?

If you as a anonymous user come back the next day, or rather after midnight, the system will treat you as a new anonymous user and you can make a new vote.

Blackwolf’s picture

Thanks frjo for your update. But I think there is a problem somewhere.
Because when I vote anonymously from machine/IP-address "A", machine/IP-address "B" wil no longer be able to vote, and the "has voted"-icon will appear, even though no vote has been casted from "B". Also the vote won't get resetted after 24 hours+.

Do I have something seriously wrong in my setup or can this be reproduced elsewere?

frjo’s picture

I can reproduce this. The uid field in the tabell votingapi_vote is int(10). The uid I generated for anonymous users was not a integer value and to long.

I have just committed a new attempt to HEAD that seems to fix this on my test site. Please try it out and report any problems with this approche here.

    if ($long = ip2long($_SERVER['REMOTE_ADDR'])) {
      $uid = abs($long) + date('z');
    }
frjo’s picture

Status: Active » Fixed
shadyman@erroraccessdenied.com’s picture

Status: Fixed » Needs work

I'm still getting "You must login to vote" when hovering over the + as an anonymous user with the Alternative +1 vote style.

Everyone has permission to use/view/access up-down vote.

shadyman@erroraccessdenied.com’s picture

I should add that I installed the HEAD, and cleared my cache.

shadyman@erroraccessdenied.com’s picture

Status: Needs work » Fixed

Ignore that, Turns out I had "Allow anonymous users to vote" set to Off in the voteupdown 'advanced' settings. My bad :)

Anonymous’s picture

Status: Fixed » Closed (fixed)