1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Up Down Voting 1.0

Discussion in 'Plugins' started by Nick, Mar 2, 2010.

  1. Nick

    Nick Well-Known Member

    Up Down Voting
    Version: 1.0
    Author: Nick Ramsay
    Created: 2010/05/07
    Last Updated:
    Tested on: Hotaru 1.5.2
    Plugins Required: Submit, Users
    Plug & Play: Yes
    Supported: No

    An alternative to the original "Vote" plugin. This one allows users to vote up or down.

    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.

    You'll need Activity 0.7 or above to record the up and down votes in the activity stream.

    Revision History
    v.1.0 2013/06/22 - shibuya246 - reorganize jquery and function libs
    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.

    Attached Files:

    noreplay, ipodtouch, chilllin and 5 others like this.
  2. carlo75

    carlo75 Design & Development

    Nick you are a vulcan of plugins!
    I think this plugin really like so much...
  3. Nick

    Nick Well-Known Member


    Dif-tor heh smusma, Spohkh.
  4. nothingman

    nothingman Active Member

    Hi Nick, do we need to uninstall the Vote plugin first?
  5. Nick

    Nick Well-Known Member

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

    Gunaxin Well-Known Member


    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.

    Attached Files:

  7. Gunaxin

    Gunaxin Well-Known Member

    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 :
    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.
  8. Nick

    Nick Well-Known Member

    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.
  9. Gunaxin

    Gunaxin Well-Known Member

    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 :

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

    - 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.

    Attached Files:

    Last edited: Mar 16, 2010
    mabujo and Nick like this.
  10. Nick

    Nick Well-Known Member

    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.
    Gunaxin likes this.
  11. Gunaxin

    Gunaxin Well-Known Member

    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.
  12. mabujo

    mabujo Designer

    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.
  13. Gunaxin

    Gunaxin Well-Known Member

    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.
  14. Nick

    Nick Well-Known Member

    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 for making these customizations available to the community.
  15. Gunaxin

    Gunaxin Well-Known Member

    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)
  16. Nick

    Nick Well-Known Member

    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 likes this.
  17. Gunaxin

    Gunaxin Well-Known Member

    That worked, Thanks. I didn't realize those "Remove Settings" things were there. Good stuff.
    Nick likes this.
  18. Gunaxin

    Gunaxin Well-Known Member

    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.
  19. Nick

    Nick Well-Known Member

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

    Gunaxin Well-Known Member

    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.
    Last edited: Apr 3, 2010

Share This Page