Firefox PHP

Module for rating posts

Posted by Mensler 
All files from this thread

File Name File Size   Posted by Date  
rating.zip 11.1 KB open | download Mensler 12/04/2006 Read message
update_user_ratings.php 1.6 KB open | download Mensler 08/23/2006 Read message
french.php 519 bytes open | download momo 08/22/2006 Read message
rating_debug.php 12.6 KB open | download Mensler 08/22/2006 Read message
Module for rating posts
August 17, 2006 07:39PM
As I had nothing to do in holiday, I wrote a simple module for rating posts.
It's not as comprehensive as discussed here, but it's a start and you're welcome to contribute your ideas :-)

For now, a post can be rated as positive or negative and an indicator shows the rating. It's written as a "self-stabilizing system". It takes note about the amount of rated messages and total ratings so it can calculate the average amount of ratings per message. The goal is, that a post with hundred positive ratings looks more positive (more green :-)) than a post with only one positive rating.
I'm still not sure if this works as planned, I'll keep an eye on this in my Forum.

Only registered users can rate a post once. They are not able to rate the first post in a thread or their own posts.

To install it, unzip the file in your mods folder, enable it in the admin.
If you disable the option to add the rating elements to the message body add the following code to your read.tpl somewhere you like after {LOOP MESSAGES}:

{IF MESSAGES->mod_rating_img}
  <p>
    {IF MESSAGES->mod_rating_neg_url}
      <a class="rateNegative" href="{MESSAGES->mod_rating_neg_url}" title="{LANG->mod_rating->RateNegative}">-</a>
    {/IF}
    {IF MESSAGES->mod_rating_pos_url}
      <a class="ratePositive" href="{MESSAGES->mod_rating_pos_url}" title="{LANG->mod_rating->RatePositive}">+</a>
    {/IF}
    <img src="mods/rating/images/{MESSAGES->mod_rating_img}.png" alt="{MESSAGES->mod_rating_img_title}" title="{MESSAGES->mod_rating_img_title}" height="14" width="41" />
  </p>
{/IF}

(in my forum it's inside a <div class="readSubject"></div>)

Here's an excerpt of my stylesheet where I format this part. Of course you have to change this to fit your needs:

.readSubject p {
  margin: 0;
  float: right;
  line-height: 75%;
}

.readSubject p a {
  text-decoration: none;
  font-weight: bold;
  font-size: 85%;
}

.rateNegative {
  border: 1px solid red;
  padding: 0 0.5em;
  color: red !important;
}

.ratePositive {
  border: 1px solid green;
  padding: 0 0.3em;
  color: green !important;
}

.rateNegative:hover {
  background-color: red;
  color: black !important;
}

.ratePositive:hover {
  background-color: green;
  color: black !important;
}

Instead of the text links (+/-) for rating you can use the icons created by momo ( ). Simply change the option on the settings page or the template.

If you'd like to show the indicator image on the list page (I think this makes only sense in threaded view), add the following code to list_threads.tpl and read_threads.tpl:
The additional table head column:

<th class="PhorumTableHeader" align="center">{LANG->mod_rating->Rating}</th>

The column itself (somewhere after {LOOP ROWS}) in list_threads.tpl:

<td class="PhorumTableRow<?php echo $rclass;?>" style="text-align: center">
  {IF ROWS->mod_rating_img}
    <img src="mods/rating/images/{ROWS->mod_rating_img}.png" alt="{ROWS->mod_rating_img_title}" title="{ROWS->mod_rating_img_title}" height="14" width="41" />
  {/IF}
</td>

The column in read_threads.tpl (somewhere after {LOOP MESSAGES}):

<td class="PhorumTableRow<?php echo $rclass;?>" style="text-align: center">
  {IF MESSAGES->mod_rating_img}
    <img src="mods/rating/images/{MESSAGES->mod_rating_img}.png" alt="{MESSAGES->mod_rating_img_title}" title="{MESSAGES->mod_rating_img_title}" height="14" width="41" />
  {/IF}
</td>

If you'd like to show the indicator image on any user's profile, add the following code to profile.tpl:

{IF PROFILE->mod_rating_img}
  <tr>
    <td nowrap="nowrap">{LANG->mod_rating->UserRating}:&nbsp;</td>
    <td><img src="mods/rating/images/{PROFILE->mod_rating_img}.png" alt="{PROFILE->mod_rating_img_title}" title="{PROFILE->mod_rating_img_title}" /></td>
  </tr>
{/IF}

You can see the indicator image in my forums on [www.webplain.de]. Hopefully it was used a little bit already, I installed it a few hours ago.

Try it out if you like :-)

Greetings,
Clemens

--
Clemens Weiß
Webplain.de



Edited 12 time(s). Last edit at 12/04/2006 02:33AM by Mensler.
Attachments:
open | download - rating.zip (11.1 KB)
Re: Module for rating posts
August 18, 2006 05:39AM
I uploaded a new version. It redirects now to the message without the "rate=xxx" in the URL after rating.

--
Clemens Weiß
Webplain.de
Re: Module for rating posts
August 18, 2006 05:48AM
good idea.
it doesn't show for the first message in a thread though, is that intentional?
Maybe a good enhancement if one wants to do this ...
hide messages with a given negative store.


Thomas Seifert



Edited 1 time(s). Last edit at 08/18/2006 05:49AM by ts77.
Re: Module for rating posts
August 18, 2006 07:10AM
Thanks for taking this one of my list! It's one of the features that I had planned for my own website :-)

One idea (since I am very much in favour of real drop-in mods that do not need changes in templates at all): put the voting buttons at the bottom of the message body using the format hook. The stylesheet could go in {HEAD_DATA}. There could be an option in the settings to override this behaviour in case the webmaster wants to put it in the templates manually (this is what I did with the Forum Jumpmenu module, so maybe peek at that one to see what I mean). For most users of the mod, the defaults are probably good enough to go with.

If you don't want to put this in the mod this way, then it's no problem of course. I'll probably get around to doing this myself once I start using it.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Module for rating posts
August 18, 2006 02:20PM
This is a great mod, thanks.

I few things: I also would like to be able to vote on the first message of a thread.

I think maybe something on the 'list.tpl' page which indicates how a thread has been voted or not, maybe a 'good thread' icon that can come up when there are a certain amount of positive ratings...?
Re: Module for rating posts
August 19, 2006 02:59PM
Hi,
there's a new version. I added a settings page where you can enable the option to rate the first message, too. As Maurice suggested, I'm using the format hook now to add the rating elements. This can also be disabled in the admin.

As you can see above, I added the code to my initial post you have to add to the templates, if you want to show the indicator image on list page.

You have to disable and enable the module in the admin, if you're updating.

Greetings,
Clemens

--
Clemens Weiß
Webplain.de
Re: Module for rating posts
August 19, 2006 03:02PM
Quote
ts77
Maybe a good enhancement if one wants to do this ...
hide messages with a given negative store.

That would be cool. Maybe I'll try to implement this with some JavaScript to toggle the visibility of certain messages.

--
Clemens Weiß
Webplain.de
Re: Module for rating posts
August 19, 2006 03:07PM
Quote
M@AATW
I think maybe something on the 'list.tpl' page which indicates how a thread has been voted or not, maybe a 'good thread' icon that can come up when there are a certain amount of positive ratings...?

I could save the total amount of ratings in the whole thread in the meta data of the first post, but I don't think that would be very meaningful...
I'll think about it :-)

--
Clemens Weiß
Webplain.de
Re: Module for rating posts
August 19, 2006 04:08PM
There is something wrong with this new version. A vote of 1 negative displays

yoursite.com/phorum/mods/rating/images/rating7.png

=a positive rating.
Re: Module for rating posts
August 19, 2006 08:58PM
Quote
M@AATW
There is something wrong with this new version. A vote of 1 negative displays

yoursite.com/phorum/mods/rating/images/rating7.png

=a positive rating.

Yes, sorry. It's fixed now.

--
Clemens Weiß
Webplain.de
Sorry, only registered users may post in this forum.

Click here to login