sNews Forum

Previous sNews versions => sNews 1.5 Final => Mods/addons => Topic started by: philmoz on December 21, 2006, 02:16:47 AM

Title: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on December 21, 2006, 02:16:47 AM
Version 1.00

Inspired by this original post
http://snewscms.com/forum/index.php?topic=2495.0
and my concerns about that script mentioned... so, here is my version.

Produces output showing user ratings of articles.
-- restricts voting based on first 3 blocks of ip... limits the liklihood of multiple votes.
-- stores ip numbers per article as text files which are retrieved on call.
-- quantity of ip numbers stored is configurable. Oldest is dropped from the storage file once the quantity is exceeded
-- calculations are performed at voting time only (as opposed to every time the other script is called)
-- stores results per article as an array file.

Images and naming convention.
Will require 11 images for 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5
Name the images with a prefix.. eg star_
Multiply the rating number(see above) by 10 and append to the prefix eg star_15, star_40, star_05, star_00
Don't forget to do the file extension :)  star_15.gif 

css classes in script, and use. (information only)
.snews_rate_wrap   wrapper around all rating content.
.rating            surrounds the rating image, and filler text.
.reviewcount      text and numbers inside the filler text
.rating_button      is the form button for submission.
.rate_item         for the text above the image display
.rate_article_name   for the article name when displayed as part of the rate_item area.

Onwards...
Make a new file.. eg rating.php (must have the php extension) and save.
Copy the code below, and paste into the new file and save.
Place this new file in a new directory in snews root .
Place your image set directory in this same new directory
Alter the user settings...

Code: [Select]
<?php
$ratingsOn
=1;
if(
$ratingsOn==1){
//inspired by rating application from http://www.gr0w.com/articles/code/php_5_star_rating_system_using_hreview/index.php
// Completely rewritten for use in sNews1.5 by philmoz
////////////////////////////////////////
// User settings. //
$sNews_rate_dir ='rating/';   // location of this script.
$sNews_rate_dir_images 'gnomes/';  //name of directory with the image set to use in it.
$sNews_rate_image_prefix 'gnomes-';  // name your images with a prefix, (eg, star_ for star_00.png). Allows you to swap image set quickly.
$sNews_rate_rank_descriptor "gnomes"// describes the means of voting... eg, stars, bullet, houses... whatever the images imply
$sNews_rate_image_ext 'gif';    // change to jpg, gif, png as required for your images.
$sNews_rate_button 'Please Rate'// text for rating form button
$sNews_EOL "\n";   //(may need to alter to  '\r\n' if that is what your system requires.)
$max_ip_stored 5;  // maximum ip numbers to be stored for each rating.Adjust as comfortable. Probably no more than 100
$sNews_not_rated_txt="Not rated";
// Messages -- Write as incomplete messages as they will be completed in the script.
$sNews_not_rated_msg 'No rating for '// will have the article name appended further down.
$sNews_already_rated_msg 'It appears you have already rated ';
$sNews_thank_you_msg 'Thank you for rating '// will have the article name appended further down.
$sNews_not_selected_msg ='You have not selected a rating value for ';// will have the article name appended further down.
// other text
$sNews_rate_generic_text 'this item'// in the event that the article name fails to arrive.
////*********///
// for rated articles, and for short displayed articles. Alter html only.
$sNews_rated_heading='<p class="rate_item"><span class="rate_article_name">'.$sNews_item_name.'</span> rated by viewers as:-</p>';
// for unrated full articles.  Alter html only.
$sNews_unrated_heading'<p class="rate_item">Please rate <span class="rate_article_name">'.$sNews_item_name.'</span></p>';
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//System vars //
$sNews_rate_results=$sNews_rate_dir.'results.res.php'// results file.
$sNews_rate_ipfile=$sNews_rate_dir.'item_'.$sNews_rate_id.".rating"// unique ip files.
if(!isset($sNews_rate_id)) {$sNews_rate_id='1';}
if(!isset(
$sNews_item_name)) {$sNews_item_name=$sNews_rate_generic_text;}
if (
file_exists($sNews_rate_results)){include($sNews_rate_results);}
//set vars to initial values.////////////////////
$sNews_rate_txt ='';
$sNews_stars ="";
$sNews_rate_txt="";
$rate_rating=0;
$rate_value=0;
$rater_msg="";
$sNews_rate_images=$sNews_rate_dir.$sNews_rate_dir_images.$sNews_rate_image_prefix;
////START WORKING/////
$rater_ip2 $rater_ip getenv("REMOTE_ADDR"); //voters ip
$ip_sepsexplode('.',$rater_ip);$rater_ip =$ip_seps[0].".".$ip_seps[1].".".$ip_seps[2].".";//truncate ip to first 3 blocks.
if (is_file($sNews_rate_ipfile)) {
$rate_array=explode($sNews_EOL,file_get_contents($sNews_rate_ipfile));
$count_rates=count(array_count_values($rate_array));
if (
in_array($rater_ip,$rate_array)) {
$rated='true';
$rater_msg=$sNews_already_rated_msg;
}}
// posting a rating. // voting form should be unavailable if already ip identified.
if (isset($_REQUEST["sNewsrate".$sNews_rate_id]) && !isset($_REQUEST["rating_".$sNews_rate_id])){
$rater_msg$sNews_not_selected_msg;
$rated='false';
}elseif(
$rated=='false'&& isset($_REQUEST["sNewsrate".$sNews_rate_id])){
if (!isset($rating_results[$sNews_rate_id])){$rate_value=0;$rate_numbers=0;$rate_total_score=0;
}else{
$rate_numbers $rating_results[$sNews_rate_id][0];$rate_value $rating_results[$sNews_rate_id][1];$rate_total_score$rating_results[$sNews_rate_id][2];}
$new_numbers=$rate_numbers+1;
$rater_vote $_REQUEST["rating_".$sNews_rate_id];
$new_score=$rate_total_score+$rater_vote[0];
$new_values=$new_score/$new_numbers;
if ($new_values>(intval($new_values)+0.85)) {$new_values=intval($new_values)+1;// high biased round up
}elseif ($new_values<(intval($new_values)+0.35)){$new_values=intval($new_values);// high biased round down
}else{$new_values=intval($new_values)+0.5; //if in range of  x.35>Vote>x.85 make it x.5

$rating_results[$sNews_rate_id][0]=$new_numbers;
$rating_results[$sNews_rate_id][1]=$new_values;
$rating_results[$sNews_rate_id][2]=$new_score;
//write results file.
$writer "<?php\n";
foreach (array_keys($rating_results)as $key){
$writer .= "\$rating_results[$key]=array('".$rating_results[$key][0]."','".$rating_results[$key][1]."','".$rating_results[$key][2]."');\n";}
$writer .= "?>
\n";
// file_put_contents($sNews_rate_results,$writer); // file_put_contents is php5 only...
$f=@fopen($sNews_rate_results,"w+");
   fwrite($f,$writer);
   fclose($f);
//write ip file.
if (($max_ip_stored)<=$count_rates){  // checks for max ips
array_shift($rate_array);
$count_rates=$count_rates-1;
}
$rate_array[$count_rates]=$rater_ip;
// file_put_contents($sNews_rate_ipfile, implode($sNews_EOL, $rate_array));
$f=@fopen($sNews_rate_ipfile,"w+");
$write_ips = implode($sNews_EOL, $rate_array);
   fwrite($f,$write_ips);
   fclose($f);
$rater_msg= $sNews_thank_you_msg;
$rated='true';
}

// SHOW RATING RESULT
if (!isset($rating_results[$sNews_rate_id])|| !is_file($sNews_rate_ipfile)){
$rate_value=0;$rate_numbers=0;
}else{
$rate_numbers = $rating_results[$sNews_rate_id][0];
$rate_value = $rating_results[$sNews_rate_id][1];}
if ($rate_value <= 0 || !isset($rating_results[$sNews_rate_id])){
$sNews_rate_txt=$sNews_not_rated_txt;
$digits = '00';}else{
$sNews_rate_txt = $rate_value;}
if ($rate_value>0){
if ($rate_value=='0.5' ){$digits = '05';}
else{$digits = $rate_value*10;}
}
// Assign image
$sNews_stars = $sNews_rate_images.$digits.'.'.$sNews_rate_image_ext;
// Output
$echo= $sNews_EOL.$sNews_EOL.'<div class="snews_rate_wrap">'.$sNews_EOL;
$echo.= '<form method="post" action="'.db('website').$categorySEF.'/'.$r['seftitle'].'/">';
if($rated=="true" && isset($rating_results[$sNews_rate_id])){$echo.= $sNews_rated_heading;}else{$echo.= $sNews_unrated_heading;}
$echo.= '<div>';
$echo.= '<span  class="rating"><img src="'.$sNews_stars.'?x='.uniqid((double)microtime()*1000000,1).'" alt="'.$rate_value.' stars" /> Average rating:~
</span><span class="reviewcount">'.$sNews_rate_txt.'</span>';
if ($sNews_rate_txt!=$sNews_not_rated_txt){
$echo.= ' <span class="rating">'.$sNews_rate_rank_descriptor.' from </span><span class="reviewcount">'.$rate_numbers.'</span><span class="rating"> votes.</span>
';}
$echo.= '</div>'.$sNews_EOL;
if($rater_msg=="" && $rater_msg!=$sNews_already_rated_msg && $rated=="false" ||$rater_msg==$sNews_not_selected_msg){
$echo.= '<div style="clear:both;">';
$echo.= '<label for="rate1_'.$sNews_rate_id.'"><input type="radio" value="0" name="rating_'.$sNews_rate_id.'[]" id="rate1_'.$sNews_rate_id.'" />Hmm?</label> '.$sNews_EOL;
$echo.= '<label for="rate2_'.$sNews_rate_id.'"><input type="radio" value="1" name="rating_'.$sNews_rate_id.'[]" id="rate2_'.$sNews_rate_id.'" />Poor</label> '.$sNews_EOL;
$echo.= '<label for="rate3_'.$sNews_rate_id.'"><input type="radio" value="2" name="rating_'.$sNews_rate_id.'[]" id="rate3_'.$sNews_rate_id.'" />Fair</label> '.$sNews_EOL;
$echo.= '<label for="rate4_'.$sNews_rate_id.'"><input type="radio" value="3" name="rating_'.$sNews_rate_id.'[]" id="rate4_'.$sNews_rate_id.'" />Good</label> '.$sNews_EOL;
$echo.= '<label for="rate5_'.$sNews_rate_id.'"><input type="radio" value="4" name="rating_'.$sNews_rate_id.'[]" id="rate5_'.$sNews_rate_id.'" />Very Good</label> '.$sNews_EOL;
$echo.= '<label for="rate6_'.$sNews_rate_id.'"><input type="radio" value="5" name="rating_'.$sNews_rate_id.'[]" id="rate1_'.$sNews_rate_id.'" />Excellent</label> '.$sNews_EOL;
$echo.= '<input type="hidden" name="rs_id" value="'.$sNews_rate_id.'" />'.$sNews_EOL;
$echo.= '<input class="rating_button"type="submit" name="'.'sNewsrate'.$sNews_rate_id.'" value="'.$sNews_rate_button.'" />'.$sNews_EOL;
$echo.= '</div>'.$sNews_EOL;}
if($rater_msg!="") $echo.= '<div style="clear:both;"><p class="rate_item">'.$rater_msg.'<span class="rate_article_name">'.$sNews_item_name.'</span> ('.$rater_ip2.')</p></div>'.$sNews_EOL;
$echo.= '</form>'.$sNews_EOL;
$echo.= '</div>'.$sNews_EOL.$sNews_EOL;
echo $echo;
}
?>
To plug into snews, locate
//CENTER
then find the case ($tag != 'readmore' .. after infoline
Code: [Select]
if ($infoline == true) {
foreach ($tag as $tag) {
...[snipped for brevity]...
case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
}
}
}
else if ($
and add the extra
Code: [Select]
if ($infoline == true) {
foreach ($tag as $tag) {
...[snipped for brevity]...
case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
}
/*rating script -- */ }$sNews_rate_id=$r['id'];$sNews_item_name=$r['title'];$rated="true";include("rater/rater.php"); ///place rated articles here.
}
else if ($
Alter "rater/rater.php" to your rating directory, and the name you called the file...
Then,
A bit further down,
Code: [Select]
if ($infoline == true) {
$tag = explode(',', tags('infoline'));
...[snipped for brevity]...
default: echo $tag;
}
}
}
else if ($_SESSION[db('website').'Logged_In'] == 'True') {echo '<p>'.$edit_link.'</p>';}
}
}
and alter the end bit to this...
Code: [Select]
if ($infoline == true) {
$tag = explode(',', tags('infoline'));
...[snipped for brevity]...
default: echo $tag;
}
/*rating script -- */ }$sNews_rate_id=$r['id'];$sNews_item_name=$r['title'];$rated="false";include("rater/rater.php");
}
else if ($_SESSION[db('website').'Logged_In'] == 'True') {echo '<p>'.$edit_link.'</p>';}
}
}
Again, alter "rater/rater.php" to your rating directory, and the name you called the file...

Some graphic sets can be downloaded from my site... http://www.fiddlenfolk.com/downloads/downloads/
Updates:~
Tweaked instructions -- no code change
Title: [ADDON] Article Rating [sNews 1.5]
Post by: Patric Ahlqvist on December 21, 2006, 08:34:24 AM
God almighty, Phil... You're a productive bugger :lol: Good work, and kudos to ye for making this section very much alive.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: 4Sandrix on December 21, 2006, 12:13:43 PM
Very cute mod :) thx  ;)
Title: [ADDON] Article Rating [sNews 1.5]
Post by: BBBB on December 23, 2006, 12:39:49 AM
This mod works great even in php4. Thanks! ;)
Title: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on December 23, 2006, 12:57:11 AM
Quote from: BBBB
This mod works great even in php4. Thanks! ;)
Yes, my test server is php5. When I got it working, chuffed as I was, I put it online.
It failed... online server is php4  :|
You will note in the code that there is a part I have commented out -- that bit only works for php5... ;) and is used to write to the file (php4 version directly after it).
Title: [ADDON] Article Rating [sNews 1.5]
Post by: harry on December 27, 2006, 11:51:01 AM
Phil,

Have tried playing around with this but no luck so far. Am trying to get different appearances on the category page and on the actual article page (where the user can rate.).

On the category i only want to display the stars with  rating. nothing else.
And on the article page, i want to display the whole ratings box, with heading etc.

Any help in how i can go about this. At the moment the closest i can get is just having all the information the same on both pages.

Thanks
Title: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on January 04, 2007, 11:30:28 PM
am on holidays... ;) about 1500 miles from home and test server.
Unless someone is willing to have a go, this will have to wait till late feb before I can have a look at it.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: michael kennedy on January 12, 2007, 10:12:34 PM
Are there any options that can be set with this mod?  Such as, lets say I only want the admin to be able to rate an article himself.  Or, for example, can he turn off/disable the ratings on a per-article basis?
Title: [ADDON] Article Rating [sNews 1.5]
Post by: Keyrocks on January 12, 2007, 11:03:19 PM
Quote from: philmoz
am on holidays... ;) about 1500 miles from home and test server.
Unless someone is willing to have a go, this will have to wait till late feb before I can have a look at it.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: Geox on January 20, 2007, 06:07:50 PM
I am taking this error:
Warning: fwrite(): supplied argument is not a valid stream resource in /ratings.php on line 81

Warning: fclose(): supplied argument is not a valid stream resource in /ratings.php on line 82

Warning: fwrite(): supplied argument is not a valid stream resource in /ratings.php on line 92

Warning: fclose(): supplied argument is not a valid stream resource in /ratings.php on line 93

can someone help?
Title: [ADDON] Article Rating [sNews 1.5]
Post by: Fred K on January 20, 2007, 06:45:16 PM
If I remember correctly, this error appears if the rater folder's permissions are not set to 777 -- permissions need to be 777 for the script to work correctly.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: michael kennedy on January 26, 2007, 02:12:19 AM
Thanks philmoz, this is a awesome mod.  :cool:

Check this out though, do you think it would be possible (when you get back) to make it more like this?

http://www.komodomedia.com/blog/

Most web sites allow the user to actually click on the stars and rate an article. (Like on netflix.com) the stars may also highlight a darker color on hover. Just an suggestion.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: dracko on January 26, 2007, 07:07:09 PM
hey mike, i used that tutorial and created a star rating sistem for snews, check this out

http://www.solucija.com/forum/viewtopic.php?id=3150
Title: [ADDON] Article Rating [sNews 1.5]
Post by: michael kennedy on March 09, 2007, 07:46:34 PM
This mod works with 1.5.31 yes?
Title: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on March 09, 2007, 10:00:26 PM
yes,
... but haven't looked at possile alterations that are mentioned further up this thread.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: Vinoth on May 14, 2007, 08:51:11 PM
I am using sNews 1.5.31 and the mod does not work, i have done exactly what the author has implied but no successful results.

I do not get any error, but nothing is displayed when viewing the page.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on May 14, 2007, 09:24:00 PM
Quote from: Vinoth
I am using sNews 1.5.31 and the mod does not work, i have done exactly what the author has implied but no successful results.

I do not get any error, but nothing is displayed when viewing the page.
near top of snews.php, is

Quote
//error_reporting(E_ALL ^ E_NOTICE);
error_reporting(0);
make it like the following, temporarily...
Quote
error_reporting(E_ALL ^ E_NOTICE);
//error_reporting(0);
and see if any errors are displayed.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: Vinoth on May 14, 2007, 09:36:06 PM
wonderful and thanx for the help. i did notice the errors and rectified it.

The error was i have named the directory and the filename differently from what it appears in your coding.

Thanx for the help and have u coded down any other hacks or mods.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: Vinoth on May 14, 2007, 09:42:50 PM
One more question where are the CSS files used. should the user create based on the classes and ids given or it is some where else.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on May 14, 2007, 09:55:11 PM
Quote from: Vinoth
One more question where are the CSS files used. should the user create based on the classes and ids given or it is some where else.
see first post (http://www.solucija.com/forum/viewtopic.php?pid=19651#p19651) for a list of classes used in the script, and what they affect. (I think I have them all listed there...)
It is up to the user to style however they choose.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on May 14, 2007, 09:58:52 PM
Quote from: Vinoth
Thanx for the help...
no probs...
Quote from: Vinoth
... and have u coded down any other hacks or mods.
one or two :D
Title: [ADDON] Article Rating [sNews 1.5]
Post by: Vinoth on May 14, 2007, 11:07:31 PM
I have mailed you a letter, since i cannot PM coz of some problems with my browser or software.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: snapplekid13 on June 29, 2007, 12:35:23 AM
Well I tried uploading into 1.6 and everything worked except that when I vote it gives me the message saying I did but it doesn't show up! http://towncook.com/baking/how-to-bake-a-flat-cake-and-other-tips/ is the article I'm trying.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on June 29, 2007, 01:13:46 AM
Check to make sure you have the right paths set in the top section of rater.php.

-- images didn't show for me, so I suspect this may have something to do with it.
Title: [ADDON] Article Rating [sNews 1.5]
Post by: snapplekid13 on June 29, 2007, 02:21:35 AM
I changed them and it still won't show the images...

How do I name the images?

0 stars = star_00.gif or 00.gif?
0.5 stars= star_05.gif or 05.gif

etc etc...
EDIT: Figured it out all is good everything works :)
Title: [ADDON] Article Rating [sNews 1.5]
Post by: NenadX on July 31, 2007, 12:04:53 AM
Quote from: snapplekid13
I changed them and it still won't show the images...

How do I name the images?

0 stars = star_00.gif or 00.gif?
0.5 stars= star_05.gif or 05.gif
0 stars = 00star.gif
0.5 stars= 05star.gif
1 stars= 1star.gif

I put one paragraph at the end:

Code: [Select]
include("rater/rater.php");echo '<p>..........</p>'; ///place rated articles here.instead of:

Code: [Select]
include("rater/rater.php"); ///place rated articles here.to create separator between articles.
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: line on November 10, 2007, 07:17:38 PM
I'm no good with codes.

Just an inquiry. I'm using sNews 1.6 MEMU compiled by Keyrocks..
Will this work with that release? I looked for the infoline but don't know what to do there.

Thanks in advance.
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: Keyrocks on November 10, 2007, 08:12:16 PM
I have not applied this mod at all but... after looking it over... I suggest it should work with 1.6 MEMU. All of the reference points you need to look for are the same in 1.5.31 and 1.6.0 default packages... and the the same again in the MEMU package's engine file.

Philmoz's directions say to put the new script into a new PHP file in a separate directory in the site root. Since the MEMU package uses the mods folder to contain mods and addons... I would put it in there.

Create your new folder in the mods folder and call it rater. Then add the main script to the new file and save it into the rater folder as rater.php. Your images will also go in the same folder.

Then you add the strings to the 2 locations in the center function, as shown. Notice that both mod strings have the path to the file within them - rater/rater.php. With the rater folder now in the mods folder... you need to add the mods folder to the file-path in both strings... to look like - mods/rater/rater.php. And it should work as expected.  :)
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: line on November 10, 2007, 09:00:01 PM
WoW!  :o

Thanks Keyrocks!
You made it clearer.
Got to test it.

Thanks again for the quick response. I thought I have to wait for half a day to receive a reply. And a reply in 55 minutes.

Salamat!



UPDATE:

Now working!  ;D
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: azad on December 19, 2007, 12:40:48 PM
Version 1.00

Inspired by this original post
http://snewscms.com/forum/index.php?topic=2495.0
and my concerns about that script mentioned... so, here is my version.

Produces output showing user ratings of articles.
-- restricts voting based on first 3 blocks of ip... limits the liklihood of multiple votes.
-- stores ip numbers per article as text files which are retrieved on call.
-- quantity of ip numbers stored is configurable. Oldest is dropped from the storage file once the quantity is exceeded
-- calculations are performed at voting time only (as opposed to every time the other script is called)
-- stores results per article as an array file.

Images and naming convention.
Will require 11 images for 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5
Name the images with a prefix.. eg star_
Multiply the rating number(see above) by 10 and append to the prefix eg star_15, star_40, star_05, star_00
Don't forget to do the file extension :)  star_15.gif 

css classes in script, and use. (information only)
.snews_rate_wrap   wrapper around all rating content.
.rating            surrounds the rating image, and filler text.
.reviewcount      text and numbers inside the filler text
.rating_button      is the form button for submission.
.rate_item         for the text above the image display
.rate_article_name   for the article name when displayed as part of the rate_item area.

Onwards...
Make a new file.. eg rating.php (must have the php extension) and save.
Copy the code below, and paste into the new file and save.
Place this new file in a new directory in snews root .
Place your image set directory in this same new directory
Alter the user settings...

Code: [Select]
<?php
$ratingsOn
=1;
if(
$ratingsOn==1){
//inspired by rating application from http://www.gr0w.com/articles/code/php_5_star_rating_system_using_hreview/index.php
// Completely rewritten for use in sNews1.5 by philmoz
////////////////////////////////////////
// User settings. //
$sNews_rate_dir ='rating/';   // location of this script.
$sNews_rate_dir_images 'gnomes/';  //name of directory with the image set to use in it.
$sNews_rate_image_prefix 'gnomes-';  // name your images with a prefix, (eg, star_ for star_00.png). Allows you to swap image set quickly.
$sNews_rate_rank_descriptor "gnomes"// describes the means of voting... eg, stars, bullet, houses... whatever the images imply
$sNews_rate_image_ext 'gif';    // change to jpg, gif, png as required for your images.
$sNews_rate_button 'Please Rate'// text for rating form button
$sNews_EOL "\n";   //(may need to alter to  '\r\n' if that is what your system requires.)
$max_ip_stored 5;  // maximum ip numbers to be stored for each rating.Adjust as comfortable. Probably no more than 100
$sNews_not_rated_txt="Not rated";
// Messages -- Write as incomplete messages as they will be completed in the script.
$sNews_not_rated_msg 'No rating for '// will have the article name appended further down.
$sNews_already_rated_msg 'It appears you have already rated ';
$sNews_thank_you_msg 'Thank you for rating '// will have the article name appended further down.
$sNews_not_selected_msg ='You have not selected a rating value for ';// will have the article name appended further down.
// other text
$sNews_rate_generic_text 'this item'// in the event that the article name fails to arrive.
////*********///
// for rated articles, and for short displayed articles. Alter html only.
$sNews_rated_heading='<p class="rate_item"><span class="rate_article_name">'.$sNews_item_name.'</span> rated by viewers as:-</p>';
// for unrated full articles.  Alter html only.
$sNews_unrated_heading'<p class="rate_item">Please rate <span class="rate_article_name">'.$sNews_item_name.'</span></p>';
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//System vars //
$sNews_rate_results=$sNews_rate_dir.'results.res.php'// results file.
$sNews_rate_ipfile=$sNews_rate_dir.'item_'.$sNews_rate_id.".rating"// unique ip files.
if(!isset($sNews_rate_id)) {$sNews_rate_id='1';}
if(!isset(
$sNews_item_name)) {$sNews_item_name=$sNews_rate_generic_text;}
if (
file_exists($sNews_rate_results)){include($sNews_rate_results);}
//set vars to initial values.////////////////////
$sNews_rate_txt ='';
$sNews_stars ="";
$sNews_rate_txt="";
$rate_rating=0;
$rate_value=0;
$rater_msg="";
$sNews_rate_images=$sNews_rate_dir.$sNews_rate_dir_images.$sNews_rate_image_prefix;
////START WORKING/////
$rater_ip2 $rater_ip getenv("REMOTE_ADDR"); //voters ip
$ip_sepsexplode('.',$rater_ip);$rater_ip =$ip_seps[0].".".$ip_seps[1].".".$ip_seps[2].".";//truncate ip to first 3 blocks.
if (is_file($sNews_rate_ipfile)) {
$rate_array=explode($sNews_EOL,file_get_contents($sNews_rate_ipfile));
$count_rates=count(array_count_values($rate_array));
if (
in_array($rater_ip,$rate_array)) {
$rated='true';
$rater_msg=$sNews_already_rated_msg;
}}
// posting a rating. // voting form should be unavailable if already ip identified.
if (isset($_REQUEST["sNewsrate".$sNews_rate_id]) && !isset($_REQUEST["rating_".$sNews_rate_id])){
$rater_msg$sNews_not_selected_msg;
$rated='false';
}elseif(
$rated=='false'&& isset($_REQUEST["sNewsrate".$sNews_rate_id])){
if (!isset($rating_results[$sNews_rate_id])){$rate_value=0;$rate_numbers=0;$rate_total_score=0;
}else{
$rate_numbers $rating_results[$sNews_rate_id][0];$rate_value $rating_results[$sNews_rate_id][1];$rate_total_score$rating_results[$sNews_rate_id][2];}
$new_numbers=$rate_numbers+1;
$rater_vote $_REQUEST["rating_".$sNews_rate_id];
$new_score=$rate_total_score+$rater_vote[0];
$new_values=$new_score/$new_numbers;
if ($new_values>(intval($new_values)+0.85)) {$new_values=intval($new_values)+1;// high biased round up
}elseif ($new_values<(intval($new_values)+0.35)){$new_values=intval($new_values);// high biased round down
}else{$new_values=intval($new_values)+0.5; //if in range of  x.35>Vote>x.85 make it x.5

$rating_results[$sNews_rate_id][0]=$new_numbers;
$rating_results[$sNews_rate_id][1]=$new_values;
$rating_results[$sNews_rate_id][2]=$new_score;
//write results file.
$writer "<?php\n";
foreach (array_keys($rating_results)as $key){
$writer .= "\$rating_results[$key]=array('".$rating_results[$key][0]."','".$rating_results[$key][1]."','".$rating_results[$key][2]."');\n";}
$writer .= "?>
\n";
// file_put_contents($sNews_rate_results,$writer); // file_put_contents is php5 only...
$f=@fopen($sNews_rate_results,"w+");
   fwrite($f,$writer);
   fclose($f);
//write ip file.
if (($max_ip_stored)<=$count_rates){  // checks for max ips
array_shift($rate_array);
$count_rates=$count_rates-1;
}
$rate_array[$count_rates]=$rater_ip;
// file_put_contents($sNews_rate_ipfile, implode($sNews_EOL, $rate_array));
$f=@fopen($sNews_rate_ipfile,"w+");
$write_ips = implode($sNews_EOL, $rate_array);
   fwrite($f,$write_ips);
   fclose($f);
$rater_msg= $sNews_thank_you_msg;
$rated='true';
}

// SHOW RATING RESULT
if (!isset($rating_results[$sNews_rate_id])|| !is_file($sNews_rate_ipfile)){
$rate_value=0;$rate_numbers=0;
}else{
$rate_numbers = $rating_results[$sNews_rate_id][0];
$rate_value = $rating_results[$sNews_rate_id][1];}
if ($rate_value <= 0 || !isset($rating_results[$sNews_rate_id])){
$sNews_rate_txt=$sNews_not_rated_txt;
$digits = '00';}else{
$sNews_rate_txt = $rate_value;}
if ($rate_value>0){
if ($rate_value=='0.5' ){$digits = '05';}
else{$digits = $rate_value*10;}
}
// Assign image
$sNews_stars = $sNews_rate_images.$digits.'.'.$sNews_rate_image_ext;
// Output
$echo= $sNews_EOL.$sNews_EOL.'<div class="snews_rate_wrap">'.$sNews_EOL;
$echo.= '<form method="post" action="'.db('website').$categorySEF.'/'.$r['seftitle'].'/">';
if($rated=="true" && isset($rating_results[$sNews_rate_id])){$echo.= $sNews_rated_heading;}else{$echo.= $sNews_unrated_heading;}
$echo.= '<div>';
$echo.= '<span  class="rating"><img src="'.$sNews_stars.'?x='.uniqid((double)microtime()*1000000,1).'" alt="'.$rate_value.' stars" /> Average rating:~
</span><span class="reviewcount">'.$sNews_rate_txt.'</span>';
if ($sNews_rate_txt!=$sNews_not_rated_txt){
$echo.= ' <span class="rating">'.$sNews_rate_rank_descriptor.' from </span><span class="reviewcount">'.$rate_numbers.'</span><span class="rating"> votes.</span>
';}
$echo.= '</div>'.$sNews_EOL;
if($rater_msg=="" && $rater_msg!=$sNews_already_rated_msg && $rated=="false" ||$rater_msg==$sNews_not_selected_msg){
$echo.= '<div style="clear:both;">';
$echo.= '<label for="rate1_'.$sNews_rate_id.'"><input type="radio" value="0" name="rating_'.$sNews_rate_id.'[]" id="rate1_'.$sNews_rate_id.'" />Hmm?</label> '.$sNews_EOL;
$echo.= '<label for="rate2_'.$sNews_rate_id.'"><input type="radio" value="1" name="rating_'.$sNews_rate_id.'[]" id="rate2_'.$sNews_rate_id.'" />Poor</label> '.$sNews_EOL;
$echo.= '<label for="rate3_'.$sNews_rate_id.'"><input type="radio" value="2" name="rating_'.$sNews_rate_id.'[]" id="rate3_'.$sNews_rate_id.'" />Fair</label> '.$sNews_EOL;
$echo.= '<label for="rate4_'.$sNews_rate_id.'"><input type="radio" value="3" name="rating_'.$sNews_rate_id.'[]" id="rate4_'.$sNews_rate_id.'" />Good</label> '.$sNews_EOL;
$echo.= '<label for="rate5_'.$sNews_rate_id.'"><input type="radio" value="4" name="rating_'.$sNews_rate_id.'[]" id="rate5_'.$sNews_rate_id.'" />Very Good</label> '.$sNews_EOL;
$echo.= '<label for="rate6_'.$sNews_rate_id.'"><input type="radio" value="5" name="rating_'.$sNews_rate_id.'[]" id="rate1_'.$sNews_rate_id.'" />Excellent</label> '.$sNews_EOL;
$echo.= '<input type="hidden" name="rs_id" value="'.$sNews_rate_id.'" />'.$sNews_EOL;
$echo.= '<input class="rating_button"type="submit" name="'.'sNewsrate'.$sNews_rate_id.'" value="'.$sNews_rate_button.'" />'.$sNews_EOL;
$echo.= '</div>'.$sNews_EOL;}
if($rater_msg!="") $echo.= '<div style="clear:both;"><p class="rate_item">'.$rater_msg.'<span class="rate_article_name">'.$sNews_item_name.'</span> ('.$rater_ip2.')</p></div>'.$sNews_EOL;
$echo.= '</form>'.$sNews_EOL;
$echo.= '</div>'.$sNews_EOL.$sNews_EOL;
echo $echo;
}
?>
To plug into snews, locate
//CENTER
then find the case ($tag != 'readmore' .. after infoline
Code: [Select]
if ($infoline == true) {
foreach ($tag as $tag) {
...[snipped for brevity]...
case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
}
}
}
else if ($
and add the extra
Code: [Select]
if ($infoline == true) {
foreach ($tag as $tag) {
...[snipped for brevity]...
case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
}
/*rating script -- */ }$sNews_rate_id=$r['id'];$sNews_item_name=$r['title'];$rated="true";include("rater/rater.php"); ///place rated articles here.
}
else if ($
Alter "rater/rater.php" to your rating directory, and the name you called the file...
Then,
A bit further down,
Code: [Select]
if ($infoline == true) {
$tag = explode(',', tags('infoline'));
...[snipped for brevity]...
default: echo $tag;
}
}
}
else if ($_SESSION[db('website').'Logged_In'] == 'True') {echo '<p>'.$edit_link.'</p>';}
}
}
and alter the end bit to this...
Code: [Select]
if ($infoline == true) {
$tag = explode(',', tags('infoline'));
...[snipped for brevity]...
default: echo $tag;
}
/*rating script -- */ }$sNews_rate_id=$r['id'];$sNews_item_name=$r['title'];$rated="false";include("rater/rater.php");
}
else if ($_SESSION[db('website').'Logged_In'] == 'True') {echo '<p>'.$edit_link.'</p>';}
}
}
Again, alter "rater/rater.php" to your rating directory, and the name you called the file...

Some graphic sets can be downloaded from my site... http://www.fiddlenfolk.com/downloads/downloads/
Updates:~
Tweaked instructions -- no code change



Hi,

I am using sNews 1.6 and i like your Star Rating Article but friend some thing i don't remember

there is a rate.php code:
// User settings. //
$sNews_rate_dir ='rate/';   // location of this script.
$sNews_rate_dir_images = 'gnomes/';  //name of directory with the image set to use in it.
$sNews_rate_image_prefix = 'gnomes-';  // name your images with a prefix, (eg, star_ for star_00.png). Allows you to swap image set quickly.
$sNews_rate_rank_descriptor = "gnomes"; // describes the means of voting... eg, stars, bullet, houses... whatever the images imply

you notice in this above code some area are in red color. so please tell me what will i replace in these palaces

Sorry my enlish is not well

Thank you
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on December 19, 2007, 08:28:24 PM
I am using sNews 1.6 and i like your Star Rating Article but friend some thing i don't remember

there is a rate.php code:
// User settings. //
Ok, briefly:-
Quote
$sNews_rate_dir ='rate/';   // location of this script.
Above, you enter the directory/folder name where you have placed this script, in relation to snews.php.
Quote
$sNews_rate_dir_images = 'gnomes/';  //name of directory with the image set to use in it.
The above is the directory name of the directory with the images (stars or whatever)
Quote
$sNews_rate_image_prefix = 'gnomes-';  // name your images with a prefix, (eg, star_ for star_00.png). Allows you to swap image set quickly.
This one is the prefix on the image names. If your images don't have a prefix, then leave it blank -- use 2 apostrophes like  ''
Quote
$sNews_rate_rank_descriptor = "gnome"; // describes the means of voting... eg, stars, bullet, houses... whatever the images imply
This one is what the viewer sees. For eg- This article has a 3 gnome rating
Quote
you notice in this above code some area are in red color. so please tell me what will i replace in these palaces

Sorry my enlish is not well

Thank you
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: azad on December 20, 2007, 05:12:53 AM
thank you for help friend.

==============rater.php code==================
// User settings. //
$sNews_rate_dir ='rater/';   // location of this script.
$sNews_rate_dir_images = 'img/';  //name of directory with the image set to use in it.
$sNews_rate_image_prefix = 'star_00, star_05, star_1, star_15, star_2, star_25, star_3, star_35, star_4, star_45, star_5';  // name your images with a prefix, (eg, star_ for star_00.png). Allows you to swap image set quickly.
$sNews_rate_rank_descriptor = "stars"; // describes the means of voting... eg, stars, bullet, houses... whatever the images imply
==============rater.php code==================
==============snews.php code==================
                        case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
                     }
/*rating script -- */      }$sNews_rate_id=$r['id'];$sNews_item_name=$r['title'];$rated="true";include("rating/rating.php"); ///place rated articles here.
                  }
==============snews.php code==================


friend i was made a folder on root directory called rater there i create a file name rater.php and here i create a folder name img for image.

directory:
index.php
snews.php
images/all images
rater/rater.php
rater/img/11 images of stars

waiting for quick and kindly reply  ::)
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on December 20, 2007, 09:46:41 AM
Quote
$sNews_rate_image_prefix = 'star_00, star_05, star_1, star_15, star_2, star_25, star_3, star_35, star_4, star_45, star_5';  // name your images with a prefix, (eg, star_ for star_00.png). Allows you to swap image set quickly.
From this I am assuming that your images are named star_00.gif or star_00.jpg or star_00.png.

So, for this eg, I will assume it is jpg (change as required).
You will need to name the images like this.
star_00.jpg
star_05.jpg
star_10.jpg
star_15.jpg
star_20.jpg
star_25.jpg
star_30.jpg
star_35.jpg
star_40.jpg
star_45.jpg
star_50.jpg

On the code line above, make it like
Quote
$sNews_rate_image_prefix = 'star_';
... and I think that would just about do it...
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: azad on December 25, 2007, 05:19:50 AM
thank you friend

yeah my images names are like star_00.jpg

tell me i was add my rather.php and snews.php code with images name, is that correct

==============rater.php code==================
// User settings. //
$sNews_rate_dir ='rater/';   // location of this script.
$sNews_rate_dir_images = 'img/';  //name of directory with the image set to use in it.
$sNews_rate_image_prefix = 'star_00, star_05, star_1, star_15, star_2, star_25, star_3, star_35, star_4, star_45, star_5';  // name your images with a prefix, (eg, star_ for star_00.png). Allows you to swap image set quickly.
$sNews_rate_rank_descriptor = "stars"; // describes the means of voting... eg, stars, bullet, houses... whatever the images imply
==============rater.php code==================
==============snews.php code==================
                        case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
                     }
/*rating script -- */      }$sNews_rate_id=$r['id'];$sNews_item_name=$r['title'];$rated="true";include("rating/rating.php"); ///place rated articles here.
                  }
==============snews.php code==================

you are so friendly and honest.
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: philmoz on December 26, 2007, 05:14:20 AM
it is important that the images have 2 digits.

for one star, image to be named star_10.jpg
for two star, image to be named star_20.jpg
...etc

the prefix in this case is  star_ and that is all that goes into $sNews_rate_image_prefix
that is,
 $sNews_rate_image_prefix='star_';
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: snews4me on July 09, 2010, 09:45:20 AM
Does anyone know if this works in v1.7 ?

If so is there an install guide or step for step instructions ?

Much appreciated :)
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: Charles on July 31, 2012, 04:50:35 AM
Version 1.00

Some graphic sets can be downloaded from my site... http://www.fiddlenfolk.com/downloads/downloads/
Updates:~
Tweaked instructions -- no code change


Hello Everyone;

Would like to implement this addon to v1.7MU. Does anyone have any "graphic sets"? (the link is not working.)

TIA.
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: walkie on July 31, 2012, 01:42:21 PM
Version 1.00

Some graphic sets can be downloaded from my site... http://www.fiddlenfolk.com/downloads/downloads/
Updates:~
Tweaked instructions -- no code change


Hello Everyone;

Would like to implement this addon to v1.7MU. Does anyone have any "graphic sets"? (the link is not working.)

TIA.

Hi Charles and welcome,

You can use this one :)

http://jaded.dk/ratings.gif (http://jaded.dk/ratings.gif) - just don't use the url, as i'll be removing it again when you've got it.


GL implementing it :)
Title: Re: [ADDON] Article Rating [sNews 1.5]
Post by: Charles on July 31, 2012, 07:24:41 PM
Got it... Thank you.