PDA

View Full Version : Up Down Voting 0.9



Nick
03-02-2010, 02:17 PM
Up Down Voting
Version: 0.9
Author: Nick Ramsay
Created: 2010/05/07
Last Updated: 2010/06/04
Tested on: Hotaru 1.3.0
Plugins Required: Submit, Users
Plug & Play: Yes
Supported: No

Description
An alternative to the original "Vote (http://hotarucms.org/showthread.php?78-Vote-1.4)" plugin. This one allows users to vote up or down.

Instructions
1. Upload the "updown_voting" folder to your plugins folder.
2. Install it from Plugin Management in Admin.
3. Edit settings in Admin -> Up Down Voting

Future Plans
Add an option to automatically bury a post if it receives X down votes. Until then, you can still auto-bury it with X number of flags.

Notes
You'll need Activity 0.7 (http://hotarucms.org/showthread.php?227-Activity-0.7) or above to record the up and down votes in the activity stream.

Revision History
v.0.9 2010/05/23 - Nick - Removed the requirement to have SB Base installed.
v.0.8 2010/05/17 - Nick - Fix for undefined variable
v.0.7 2010/05/14 - Nick - Fix for auto-votes being assigned to the current user when cron runs AutoReader
v.0.6 2010/05/05 - Nick - Fix for user id 0 assign to auto-vote when using AutoReader
v.0.5 2010/04/04 - Nick - Fix for updating the post_pub_date field
v.0.4 2010/04/03 - Gunaxin - Fix for missing $undo variable
v.0.3 2010/03/28 - Nick - Updates the new post_pub_date field in Hotaru 1.1.4 when a story is promoted
v.0.2 2010/03/17 - Fix for settings bug, plus ability to both undo and reverse your vote
v.0.1 2010/03/03 - Nick - Released first version

Please click "Rate Thread" and give this plugin a rating. Thank you.

carlo75
03-02-2010, 02:21 PM
Nick you are a vulcan of plugins!
I think this plugin really like so much...

Nick
03-02-2010, 03:10 PM
Nick you are a vulcan of plugins!

642

Dif-tor heh smusma, Spohkh.

nothingman
03-03-2010, 05:49 AM
Hi Nick, do we need to uninstall the Vote plugin first?

Nick
03-03-2010, 06:12 AM
Hi Nick, do we need to uninstall the Vote plugin first?

Yes, it's an alternative, not an extension.

Gunaxin
03-15-2010, 07:47 PM
Nick,

I've been messing with this plugin some on my site, as I definitely want this functionality. However the text buttons aren't doing it for me. So I'm working on implementing GIF backgrounds, that shift up and down on mouseover and voting. The code doesn't really seem setup to work that way, so its been a challenge for my limited abilities. I have a few hurdles left to solve, but assuming I can get it to work, I'll send you the code and you can see how easy it would be to implement for everyone. Hopefully you don't look at the code and tell me that I did it a crazy way, or else I just wasted a couple of hours. =)

Wanted to tease you with a screenshot.

Gunaxin
03-15-2010, 09:45 PM
One of the last things I was trying to get to work with this, I realized was actually a problem in your original code (I think).

If User A submits something, and then User B comes and votes up, it registers +1 (so 2 total)
If User B then decides to remove the vote, the only way to do that is to vote down, -1 (so 1 total)
Now if User B wants to vote down, he can't because that button isn't available to him, he can only vote up again.

So basically once you vote one direction, you aren't able to vote the other direction.

With the arrows that I am using, it would make sense if you've already voted up, that a vote down would then give you a -2, or hitting the up arrow again would give you -1 and reset everything to where you could then vote either direction again.

I have everything else working with the arrows, hovers, live switching of colors, etc. I think this bug I mentioned is probably beyond my ability to fix based on the code I looked at and the way it was designed.

As it stands now, I've already rewritten significant portions of :
updown_voting_button.php
updown_voting.js
and of course... updown_voting.css

I'll email those three files along with the arrow gifs to you Nick, to see if you want to implement, or what to do with it to share with other people.

Nick
03-16-2010, 07:39 AM
Hi Gunaxin, your use of images instead of text looks good. I got the email you sent, but I think you should attach them to your posts here so other people can refer to them if they want to make the same changes or an improved version of this plugin.

I checked out what you said about users only being able to undo votes as opposed to reversing their votes. I agree it's a bit odd, but not really a bug. I might have a look at changing it but these things tend to be much more fiddly than they look on the surface, so I can't make any promises.

Gunaxin
03-16-2010, 03:10 PM
Ok, so as Nick suggested, I'm attaching my modified files to this post. I don't claim to be a coder, so my code may not be perfect, or documented, but it does at least seem to function. Essentially I took the Up Down Voting plugin and modified it to use images instead of text for the voting. I changed around the way it works some, in order to use links with a background image, that shifts when you hover or vote. So it utilizes two Gif images (up and down) that have three arrows each in it. So you can customize those arrows, or even change the size if you want, you'll just have to change the css that goes along with it. I've only included the files in the zip that I modified :

updown_voting.css
- Includes styles for the new buttons - you'll need to edit it for your image path.

updown_voting_button.php
- modified as links with id and class to allow for style changes

updown_voting.js - Modified
- modified to change class upon voting

up.gif, down.gif
- samples files

I needed to make these changes for my own purposes, so I figured I would share them with everyone, in case someone else is looking for something similar. I suggest comparing my files to the originals, so that you can see and understand what I did. No warranties, mileage may vary, do whatever you want with it, and have fun.

Nick
03-17-2010, 04:04 AM
Updated: v.0.2 2010/03/17 - Fix for settings bug, plus ability to both undo and reverse your vote. No template or css changes necessary.

There was a bug in v.0.1 that used the original Vote settings in some cases instead the Updown Voting settings. That has been fixed, and while I was there, I managed to solve the issue posted above about users not being able to reverse a vote. I admit it's not exactly been tested much, but seems to work.

@Gunaxin, the settings problem was caused by getSerializedSettings('vote') instead of getSerializedSettings('updown_voting') on lines 95 and 122 or Updown Voting 0.1. The "reverse vote" fix required quite extensive changes to updown_voting_functions.php and javascript/updown_voting.js. Unfortunately I never committed version 0.1 to the SVN so I can't point out the differences, though you can view the files here (http://my-trac.assembla.com/HotaruCMS/browser/branches/1.2/content/plugins/updown_voting).

Gunaxin
03-17-2010, 03:10 PM
Updated: v.0.2 2010/03/17 - Fix for settings bug, plus ability to both undo and reverse your vote. No template or css changes necessary.

Implemented and tested, and I believe the changes you describe above are working for me. Thanks!

I need to do some additional testing to sort out my questions about Popular, Latest, and Recent which I asked in that other thread.

mabujo
03-21-2010, 11:00 AM
Glad I came to this thread now - I was trying to get image/arrow voting working like Gunaxin has (but using only CSS replacement) and was derailed by the fact that the arrows have the same class whether they have been actioned or not.
Surely it would make sense to have the different states have different classes by default? Then if you didn't want to change to an image you could define .vote_button_top,.voted_button top { } (giving both classes the same style) and still leave it open to modification?
I'm going to have a go with Gunaxin's mod now anyway.

Gunaxin
03-22-2010, 04:53 AM
I'm going to have a go with Gunaxin's mod now anyway.

I updated it slightly based on Nick's most recent version (with bug fixes). Let me know if you want the updated files, I'll have to pull them together and re-upload tomorrow.

Nick
04-01-2010, 02:12 PM
Updated: v.0.3 2010/03/28 - Nick - Updates the new post_pub_date field in Hotaru 1.1.4 when a story is promoted.

Thanks to Gunaxin Links (http://links.gunaxin.com) for making these customizations available to the community.

Gunaxin
04-01-2010, 05:19 PM
There was a bug in v.0.1 that used the original Vote settings in some cases instead the Updown Voting settings. That has been fixed, and while I was there, I managed to solve the issue posted above about users not being able to reverse a vote. I admit it's not exactly been tested much, but seems to work.


I probably should have told you this before you came out with 0.3, but I think I found another bug. It appears that you have fixed number of votes needed to get to the front page, but the next two options don't seem to work if previously set in the other voting plugin :

Number of days a new post can sit on the Upcoming page: (Default: 5)
Deadline for new posts to hit the front page (days): (Default: 5)

Nick
04-02-2010, 01:40 AM
It appears that you have fixed number of votes needed to get to the front page, but the next two options don't seem to work if previously set in the other voting plugin :

Number of days a new post can sit on the Upcoming page: (Default: 5)
Deadline for new posts to hit the front page (days): (Default: 5)

To avoid any conflicts, try Admin -> Maintenance -> Plugin Settings and click "Remove Vote Settings". Otherwise, please help me find where those settings have been "fixed" because it all looks okay to me.

Gunaxin
04-03-2010, 01:03 AM
To avoid any conflicts, try Admin -> Maintenance -> Plugin Settings and click "Remove Vote Settings". Otherwise, please help me find where those settings have been "fixed" because it all looks okay to me.

That worked, Thanks. I didn't realize those "Remove Settings" things were there. Good stuff.

Gunaxin
04-03-2010, 01:05 AM
Updated: v.0.3 2010/03/28 - Nick - Updates the new post_pub_date field in Hotaru 1.1.4 when a story is promoted.

Are the only changes here in updown_voting_functions.php? I replaced just that file, and this functionality seems to work. However now I seem to have a problem with my updating arrows. When I vote, the number updates, but the arrow does not. However once I reload the arrow is the correct color. Since I made those mods myself, I guess I'll have to figure out where the hell that went wrong. I never edited updown_voting_functions though, and everything else is my old files, so I'm confused with this one.

Nick
04-03-2010, 01:26 AM
Are the only changes here in updown_voting_functions.php?

Yes, except for the version number and readme.txt file.

Gunaxin
04-03-2010, 03:49 AM
Hmmmm, ok, so I preface this by saying I don't know what I'm doing. However, I went back to the previous version of the functions, and my arrows work just dandy. So comparing the old and new file, I see that you split some stuff out into a new vote function. It looks like you didn't pass the function the status of $undo, which seems to be needed to update the arrows automatically.

So I changed those lines to :

vote($h, $post_id, $vote_rating, $user_ip, $updown_voting_settings, $undo);
}

function vote($h, $post_id, $vote_rating, $user_ip, $updown_voting_settings, $undo) {

And magically the arrows auto-update on voting again. However they don't seem to automatically remove themselves on a vote removal, so I'll have to figure that one out now. I could be completely wrong here, but that little change seems to have worked at least partially for me.

Nick
04-03-2010, 04:07 AM
Updated: v.0.4 2010/04/03 - Gunaxin - Fix for missing $undo variable (#1452 (http://my-trac.assembla.com/HotaruCMS/changeset/1452))

@Gunaxin, Sorry about that. Thanks for the fix. :o

Nick
04-04-2010, 04:31 AM
Updated: v.0.5 2010/04/04 - Nick - Fix for updating the post_pub_date field (no template or css changes necessary) (#1453) (http://my-trac.assembla.com/HotaruCMS/changeset/1453#file2).

shibuya246
05-06-2010, 03:50 PM
Updated v.0.6 2010/05/05 - Nick - Fix for user id 0 assign to auto-vote when using AutoReader [Hotaru 1.2]

Nick
05-14-2010, 05:51 AM
Updated: v.0.7 2010/05/14 - Nick - Fix for auto-votes being assigned to the current user when cron runs AutoReader

Nick
05-17-2010, 04:09 AM
UPdated: v.0.8 2010/05/17 - Nick - Fix for undefined variable [IMPORTANT FIX (http://hotarucms.showthread.php?764-Undefined-variable-voter_id-in-vote.php)]

Nick
08-09-2010, 03:02 PM
Guys, I'm ending my support for this plugin. It's too time consuming to update two vote plugins in parallel. Plus I really can't see why you'd want to use a plugin that keeps vote counts down. I mean, if 5 people like a post and 5 people don't, you'd have +5 if using the Vote plugin, but 0 if using this Up Down Voting plugin. Unless you've got Reddit-sized traffic, this plugin would just make your site look less active than it really is.... in my opinion.

If someone would like to maintain this plugin, that's great! Just follow the changes in the Vote plugin and apply them into this one. Let me know and I'll give you forum permissions to update the first post.

Shorel
08-18-2010, 03:43 PM
Hello, I need this plugin, so I will try to make it work again.

Can you offer any help if I can't make it work ?

Anewuser
11-30-2010, 07:21 PM
i love this plugin ,
can you please tell me how to create a style for it ?
thanks

petsagouris
11-30-2010, 09:12 PM
i love this plugin ,
can you please tell me how to create a style for it ?
thanks

In the plugin folder you'll find
updown_voting/templates/updown_voting_button.php for the HTML
updown_voting/templates/updown_voting.css for the CSS

Leka74
12-10-2010, 04:03 PM
Hello,
I designed a few buttons with photoshop but for some reason the vote_up.gif is bugged. However if I hover on it, it will get fixed. And then when I remove the mouse from the vote_up.gif, it gets bugged again.

Here is a picture:
http://i.solidfiles.net/f5dbd.png

Hopefully someone can help me with this problem.
Thanks

Leka74
12-11-2010, 08:29 AM
I just noticed that if I'm logged out then the vote_up picture works fine. Wierd.

mabujo
12-11-2010, 08:36 AM
It's been a while since I used this plugin, but in the template there should be references to various button states - logged in and already voted, logged in and not voted, logged out and voted e.t.c.

Pay careful attention these states and test how they work. If you're stuck, the Yonda theme I made uses custom images for the buttons, so you can take a peek out how it works in that theme.

jerryisrockin
02-06-2011, 08:02 PM
Hi, I searched this thread, but didnt find the answer I was looking for. Is there a way to allow unregistered users to vote, without registering. Please help, I am trying to get more people voting and I think more people will vote if they are not required to register.

Nick
02-07-2011, 04:38 AM
Anonymous voting is in the Vote plugin, but not this Up Down Voting plugin.

krankdroid
02-24-2011, 01:19 PM
when not using description in admin settings, i think that it is this plug in that messes up alignment..

can that be fixed ?

sithburns
05-03-2011, 07:49 PM
So no one supports this plugin anymore?

mabujo
05-04-2011, 08:18 PM
So no one supports this plugin anymore?

I'll take it that you are volunteering?

sithburns
05-04-2011, 09:34 PM
no, i need someone to support it, lol. Need the requirement of adding a comment whenever someone down votes actually? You want to do it if I pay you? :)

mabujo
05-05-2011, 09:49 AM
no, i need someone to support it, lol. Need the requirement of adding a comment whenever someone down votes actually? You want to do it if I pay you? :)

Given that last time you offered money for a feature which I then implemented you didn't pay, no.

krankdroid
05-05-2011, 11:04 AM
well.. i would have just entered "burn"..

but that was too short..

:)

scopolamine
06-17-2011, 12:08 PM
Number of days a new post can sit on the Upcoming page: (Default: 5)
There is no point of this feature. It should be "number of hours" instead of "number of days".

yudhis97
06-18-2011, 06:57 AM
So I was wondering if there is any update for this plugin ?

skorpyo
11-07-2011, 06:18 PM
okay...so I've changed the style of my vote widget but every time I vote up or down, I think the java clears the vote count css style I applied...is that possible? how can I make this work, please help!

PuckRobin
11-08-2011, 03:57 AM
Did you try to clear the server side css cache and also your browser cache?

skorpyo
11-08-2011, 01:09 PM
I'm not that new to Hotaru as you probably think...so yeah, I did that long before this happened. Something just clears the css style I applied to the vote counts and don't know what or where...

PuckRobin
11-08-2011, 02:50 PM
Then, using chrome's "inspect element" feature, check which css classes are active before and after the click. Search for this class the codes and make necessary changes.

skorpyo
11-08-2011, 03:44 PM
that doesn't help at all...because I already know what class is in cause and just disappears after I vote either up or down...although its present on template

PuckRobin
11-08-2011, 03:51 PM
Do you mean you have already changed updown_voting.css and those styles disappear?

skorpyo
11-08-2011, 04:01 PM
Actually I applied css style from the styles.css file of my custom theme to it, and cleared the updown_voting.css located in the css folder of the same custome theme...and I think maybe I should do the same for the updown_voting.css located at the css plugin folder...

Edit: or put the custom css code on the updown_voting.css located on the custom theme...
A bit later edit: you can check out the dev site (http://beta6.web-mee.com) and see it for your selfs.

skorpyo
11-09-2011, 11:25 AM
This is the custom code that resets after voting either up or down:


<div id='votes_<?php echo $h->post->id; ?>' class='vote_button_count'><a href="#" class="disabled"><span><em><?php echo $h->vars['votesUp']; ?></em></span></a></div>

and this is after voting:


<div id='votes_<?php echo $h->post->id; ?>' class='vote_button_count'><?php echo $h->vars['votesUp']; ?></div>

that means the "a", "span" and "em" tags disappear...after voting, but WHY? I just can't figure this out...this is insane! Please someone help me.

UsupNew
12-17-2011, 03:53 AM
Thanks i need this.....

valMETNG
04-13-2012, 02:40 AM
Granted, I'm still learning the Hotaru code base, but I think I might have found a bug in this plugin. The potential offending line is 110 within the function updown_voting_remove_vote of updown_voting_functions.php:


function updown_voting_remove_vote($h, $post_id, $user_id, $voted, $vote_rating)
{
// Update Postvotes table
$sql = "DELETE FROM " . TABLE_POSTVOTES . " WHERE vote_post_id = %d AND vote_user_id = %d AND vote_rating = %d";
$h->db->query($h->db->prepare($sql, $post_id, $user_id, $voted, $vote_rating));

// Update Posts table
if ($vote_rating > 0) {
$sql = "UPDATE " . TABLE_POSTS . " SET post_votes_up = post_votes_up + 1 WHERE post_id = %d";
$h->db->query($h->db->prepare($sql, $post_id));
} else {
$sql = "UPDATE " . TABLE_POSTS . " SET post_votes_up = post_votes_up - 1 WHERE post_id = %d";
$h->db->query($h->db->prepare($sql, $post_id));
}
}

I haven't fully traced the implications, but the code $h->db->query($h->db->prepare($sql, $post_id, $user_id, $voted, $vote_rating)); seems to be wrong as it's passing four variables to a WHERE that only wants three. Seems like $voted shouldn't be there. Or am I missing something?

PuckRobin
04-13-2012, 06:13 AM
Well, it depends on the definition of "bug" :) When a post is voted, $voted=$vote_rating, so there will be no implications of this.

valMETNG
04-13-2012, 01:28 PM
Well, it depends on the definition of "bug" :) When a post is voted, $voted=$vote_rating, so there will be no implications of this.
Never a bug unless a user sees it, eh? ;)