BLOG:CMS :: Support Forum
Support Forum for BLOG:CMS
You are not logged in.
#1 17.08.2004 22:09
NP_Reviews
Plugin adds one field to item-table, named "irating". When template contain <%Reviews%> it will show graphics according the rating (in scale 0 to 10).
If rating is 0, nothing is shown (if your blog has some categories that don't need reviews). Handy for movie/book/game/music-reviews. My version uses graphics that are stars (from half star to full five stars). Graphics however can be anything: thermometer, your heads, numbers, dots, tires etc...
My version of graphics can be downloaded from http://www.nominaali.com/~ihra/blogcms/reviews.zip (8 Kb, zip) - save them to plugins/reviews -directory.
More ideas for graphics can be found from here: http://www.portedmods.com/modules.php?n … how=10#cat
EDITED 310804: Version 1.1 with ratings in comments.
Now the code:
Code:
<? /* ------------------ NP_Reviews ********** Plugin to show review ratings for the item. Installation: 1) download sourcecode (this file) and save it as NP_Reviews.php in nucleus/plugins directory 2) create nucleus/plugins/reviews directory and place your graphics in the directory (files should be named 1.gif to 10.gif) 3) install plugin through admin interface on blog:cms (plugins -> install new plugin) 4) put <%Reviews%> in your template (admin->templates), normally default and detailed templates and item footer box is a good place 5) edit nucleus/forms/commentform-loggedin.template and/or nucleus/forms/commentform-loggedin.template to insert dropdown-box with "crating" as a value. Example: <h4>Rating</h4> <select name="crating"> <option name="crating" value="0">Not Shown</option> <option name="crating" value="1">1</option> <option name="crating" value="2">2</option> <option name="crating" value="3">3</option> <option name="crating" value="4">4</option> <option name="crating" value="5">5</option> <option name="crating" value="6">6</option> <option name="crating" value="7">7</option> <option name="crating" value="8">8</option> <option name="crating" value="9">9</option> <option name="crating" value="10">10</option> </select> </fieldset> 6) rate your items. If rating is zero (or not between 1 to 10) nothing is shown in the item. Reviews plugin shows dropdown box with "Rating" above it in your AddItem/EditItem forms. They are in the extra-part of the wysiwyg editor. Version history: **************** 1.1 310804 Added ratings to comments also. If you don't want anyone to rate your article, set "allow only members to post comments" on in your settings. You need also insert dropdown-box or graphics bar to your comment-template (loggedin and/or notloggedin depending if you want anonymous ratings). 1.0 170804 Initial release, drop dead tired from work To-do: ****** - total rating? sum of the all ratings divided with number of ratings (average) - changeable graphics (multiple sets? only prefix is needed, like swords_ (uses swords_1.gif etc.) - admin options? (allow ratings in comments on/off) - graphic rating? like in phpNuke ("rate this article 1-5 stars") ------------------ */ class NP_Reviews extends NucleusPlugin { // name of plugin function getName() { return 'Reviews'; } // author of plugin function getAuthor() { return 'Ihra aka Jussi Josefsson'; } // Needs versio 2.0b or newer function getMinNucleusVersion() { return '200'; } // no dedicated site function getURL() { return 'http://forum.blogcms.com/'; } // version of the plugin function getVersion() { return '1.1'; } // a description to be shown on the installed plugins listing function getDescription() { return "This plugin displays current items rating, from 1-10 " ."(in graphics, uses reviews-directory with files 1.gif to 10.gif). " ."For example to rate music / movie reviews or simply just articles itself."; } function supportsFeature($feature) { switch($feature) { case 'SqlTablePrefix': return 1; default: return 0; } } // get events used function getEventList( ) { return array( 'PrepareItemForEdit','EditItemFormExtras', 'AddItemFormExtras', 'PostAddItem', 'PreUpdateItem', 'PostAddComment' ); } // when adding item, add dropdown box from 0-10 (0=dont show rating) function event_AddItemFormExtras($data){ echo "<h4>Rating</h4>"; echo "<select name=\"irating\">"; echo "<option name=\"irating\" value=0>not shown</option>"; for ($i=1; $i<11; $i++) { echo "<option name=\"irating\" value=$i>$i</option>"; }; echo "</select>"; } // inject rating-field to item and comment-database (nucleus_item) function install () { $query = 'ALTER TABLE '. sql_table('item') . ' ADD `irating` TINYINT NOT NULL DEFAULT 0'; sql_query($query); $query = 'ALTER TABLE '. sql_table('comment') . ' ADD `crating` TINYINT NOT NULL DEFAULT 0'; sql_query($query); } // remove rating-field from item and comment-database (nucleus_item) when uninstalling function uninstall () { $query = 'ALTER TABLE '. sql_table('item') .' DROP `irating`'; sql_query($query); $query = 'ALTER TABLE '. sql_table('comment') .' DROP `crating`'; sql_query($query); } // when new article is to be saved function event_PostAddItem($data) { $irating = requestVar('irating'); // if not in variables, try fetching POST-variable itself if (!$irating) { $irating=$_POST['irating']; }; $curItem = $data['itemid']; $query = "UPDATE ". sql_table('item')." SET irating=".$irating." WHERE inumber=".$curItem; $result = mysql_query($query); } // save value of crating function event_PostAddComment($data) { $crating = requestVar('crating'); // take last insert which should be our comment $commentid = mysql_insert_id(); if (!isset($crating)) { $crating=$_POST['crating']; }; if (!isset($crating)) return; $query = "UPDATE ".sql_table('comment')." SET crating=".$crating." WHERE cnumber=".$commentid; $result = mysql_query($query); } // when article is edited and saved function event_PreUpdateItem($data) { $irating = requestVar('irating'); if (!$irating) { $irating=$_POST['irating']; }; if (!$irating) return; $itemid=$data['itemid']; sql_query("UPDATE ".sql_table('item')." SET irating='$irating' WHERE inumber='$itemid'"); } // show simple dropdown box to user. 0 = no rating (for some categories etc.) function event_EditItemFormExtras($data) { $curItem = $item->itemid; $query = "SELECT irating from ". sql_table('item')." WHERE inumber=".strval($data['itemid']); $result = mysql_query($query); $row = mysql_fetch_object($result); $rating = $row->irating; echo "<h4>Rating</h4>"; echo "<select name=\"irating\">"; echo "<option name=\"irating\" value=0>not shown</option>"; for ($i=1; $i<11; $i++) { if ($i==$rating) { echo "<option name=\"irating\" value=$i selected>$i</option>"; } else { echo "<option name=\"irating\" value=$i>$i</option>"; }; }; echo "</select>"; } // show <%Reviews%> at the comments-page, where user want to show graphs (for example in comment-footer, beside time) function doTemplateCommentsVar(&$item, &$comment) { $commentId = $comment['commentid']; $query = "SELECT crating from ". sql_table('comment')." WHERE cnumber=".$commentId; $result = mysql_query($query); $row = mysql_fetch_object($result); $rating = $row->crating; $url = $this->getAdminURL( ); if (($rating>0) && (rating<=10)) { echo "<br /><img src=$url$rating.gif>"; }; } // show <%Reviews%> at the template-page, where user want to show graphs (for example in item-footer) function doTemplateVar(&$item) { global $blogid; $curItem = $item->itemid; $query = "SELECT irating from ". sql_table('item')." WHERE inumber=".$curItem." AND iblog=".$blogid; $result = mysql_query($query); $row = mysql_fetch_object($result); $rating = $row->irating; $url = $this->getAdminURL( ); if (($rating>0) && (rating<=10)) { echo "<br /><img src=$url$rating.gif>"; }; } } ?>
Plugin is in use at www.nominaali.com.
No admin section included/needed.
(For the past items (pre-plugin) in database, this plugin will insert default or "0" (which is not shown) so you can edit them too to value of your choice)
EDITED 310804: Version 1.1 with ratings in comments.
Last edited by ihra (05.09.2004 11:50)
Offline
#2 17.08.2004 22:22
- Radek Hulán
- Site Admin
- From: Prague, Czech Republic
- Registered: 17.03.2004
- Posts: 2509
- Website
Re: NP_Reviews
ihra, this is a very nice plugin!
I am also thinking, that it might be very nice if, optionally, users could :rank: items as well. What do you think? Making <a ...><img ranking /></a>?
--= BLOG:CMS developer =--
Offline
#3 18.08.2004 06:58
Re: NP_Reviews
Hmm... maybe good feature. I am personally against those "rate me" sites (phpNuke has rating system for articles) but it would be easy to put total sum of ratings and another variable review count. Then "Rating_Total / Rating_Count = Rating". Problem is, that there is no easy way to prevent multiple ratings from same user (and from search engines etc.).
However, first I will see if I will extend this to include rating in comments too (not everyone has same opinion about some movie and our older site has a lot of reviews that have multiple opinions).
Then we will have "main review, 5 stars" and "this is NOT good movie, 1 star", "I disagree, 3 stars" etc. And why with comments and not straight rating? Because site can use "only members can comment posts" and it also disables spiders setting ratings.
Last edited by ihra (18.08.2004 08:31)
Offline