« Counter | Main | All of philosophy »
October 11, 2005
Vote Plugin
One thing I found sorely lacking in MovableType was simple voting. I switched to MovableType from Greymatter for obvious reasons (comment approval mostly), but missed the simple voting. I found an old vote plugin and fixed it up to do a bit more. Download mt-vote.zip. This new version includes a config page that allows you to view and edit votes.
Install/Uninstall
- [MTbase]/mt-vote.cgi
- [MTBase]/lib/MT/App/Vote.pm
- [MTBase]/plugins/vote/vote.pl
- [MTBase]/plugins/vote/readme.txt
- [MTBase]/plugins/vote/mt-vote-cfg.cgi
- [MTBase]/plugins/vote/tmpl/vote.tmpl
Requires that the Expressions pluggin be installed.
Putting votes onto your pages
Tags
- MTVoteNumber: gives you the number of votes submitted
- entry_id
- the id of the entry to use
- may be 0 padded
- padding does not make a difference
- defaults to the current entry
- booth
- which voting booth to use
- defaults to the empty '' booth
- MTVoteAverage: gives the average vote value of all the votes cast
- entry_id - the id of the entry to use
- booth - which voting booth to use
- places
- the number of decimal places to return
- defaults to 0
- MTVoteTotalValue: the total value of all the votes
- entry_id - the id of the entry to use
- booth - which voting booth to use
Container Tags
- MTVotes: loops over your entries, sorted highest to lowest by vote
- booth - which voting booth to use
- lastn
- the maximum number of entries to return
- defaults to 1
- current_blog_only
- when set to 1 only entries from the current blog are returned
- defaults to 0
- sortby
- 'total', sort by the total value of votes for this booth
- 'number', sort by the total number of votes for this booth
- 'average' or other, sort by the average value of votes for this booth
- minimum - the minimum vote value to be included
- maximum - the maximum vote value to be included
Examples
Add votes to the "posted" line on an index page:
| <a href="<$MTEntryPermalink archive_type="Individual"$>#votes">Votes (<$MTVoteTotalValue booth="positive" entry_id="[MTEntryID pad='1']"$>/<$MTVoteTotalValue booth="negative" entry_id="[MTEntryID pad='1']"$>)</a>
Add a "Most Popular" section to the sidebar:
<h2>Most Popular</h2>
<ul>
<MTVotes lastn="5" booth="positive" sortby="total" minimum="1">
<li><a href="<$MTEntryPermalink$>"><$MTEntryTitle$> (<$MTVoteTotalValue booth="positive" entry_id="[MTEntryID pad='1']"$>)</a></li>
</MTVotes>
</ul>
Casting Votes
mt-vote.cgi
- __mode = 'vote': allows you to vote in a booth on an entry
- entry_id
- the id of the entry to use
- may be 0 padded
- padding does not make a difference
- required
- booth
- which voting booth to use
- defaults to the empty '' booth
- value
- a number to add to the current value of this booth of this entry
- required
- url
- a redirect url, the page to load after posting the vote
- if not supplied a simple "Vote Posted" page will be displayed
- __mode = 'view': diagnostic view of the data stored in a booth on an entry
- entry_id - the id of the entry to use
- booth - which voting booth to use
Examples
Link:
A link of the form
http://www.yourdomain.com/mt-path/mt-vote.cgi?__mode=vote&entry_id=157&value=7
will add 7 to the default booth of entry 157. A Individual Entry Page Template would contain something like the following
<a name="votes"></a>
<h2>Vote</h2>
<a href="<$MTCGIPath$>mt-vote.cgi?__mode=vote&entry_id=<$MTEntryID pad='1'$>&value=1&booth=positive&url=<$MTEntryPermalink archive_type="Individual"$>><img src="<$MTBlogRelativeURL$>/images/vote/thumbsup.gif" alt="+"></a>
<span class="voteText"><$MTVoteTotalValue booth="positive" entry_id="[MTEntryID pad='1']"$> / <$MTVoteTotalValue booth="negative" entry_id="[MTEntryID pad='1']"$></span>
<a href="<$MTCGIPath$>mt-vote.cgi?__mode=vote&entry_id=<$MTEntryID pad='1'$>&value=1&booth=negative&url=<$MTEntryPermalink archive_type="Individual"$>><img src="<$MTBlogRelativeURL$>/images/vote/thumbsdown.gif" alt="-"></a>
Form:
A form created in the Individual Entry Page Template like the following will work to make two booths, "positive" and "negative"
<a name="votes"></a>
<h2>Vote</h2>
<form action="<$MTCGIPath$>mt-vote.cgi" method="post" class="inline">
<input type="image" src="<$MTBlogRelativeURL$>/images/vote/thumbsup.gif" value="+" alt="+">
<input type="hidden" name="value" value="1">
<input type="hidden" name="booth" value="positive">
<input type="hidden" name="__mode" value="vote">
<input type="hidden" name="entry_id" value="<$MTEntryID pad='1'$>">
<input type="hidden" name="url" value="<$MTEntryPermalink archive_type="Individual"$>">
</form><span class="voteText"><$MTVoteTotalValue booth="positive" entry_id="[MTEntryID pad='1']"$> / <$MTVoteTotalValue booth="negative" entry_id="[MTEntryID pad='1']"$></span><form action="<$MTCGIPath$>mt-vote.cgi" method="post" class="inline">
<input type="image" src="<$MTBlogRelativeURL$>/images/vote/thumbsdown.gif" value="-" alt="-">
<input type="hidden" name="value" value="1">
<input type="hidden" name="booth" value="negative">
<input type="hidden" name="__mode" value="vote">
<input type="hidden" name="entry_id" value="<$MTEntryID pad='1'$>">
<input type="hidden" name="url" value="<$MTEntryPermalink archive_type="Individual"$>">
</form>
The advantage of the form method is that it will never be followed by a robot crawling your site.
Posted by Bungeman at October 11, 2005 11:12 AM
Vote
180 / 6Comments
I've tested this page and I voted several times on the same post. Is there any vote protection scheme with id/ip/cookie session?
Posted by: Fred at October 24, 2005 11:26 AM
Just went and implemented this, but it needs some work. Hopefully it will be in later this week.
Posted by: Bungeman at October 24, 2005 03:21 PM
i've tested it...great work!
Posted by: wyh at October 25, 2005 10:31 PM