Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Re: [Andy] ajax rating system

Quote Reply
Re: [Andy] ajax rating system In reply to
Andy,

I still never could get your simple ajax rating to work using the detailed pages.

However, I did translate another program to work the GT:

http://www.masugadesign.com/...jax-star-rating-bar/

Because is all written in php, I had to create a plugin that does the same thing as a global. It still uses php for the backend, I didn't have time to translate the entire thing, nor it is really necessary.

Steps:

1.) Configure your _config-rating.php to where your Glinks tables are.
2.) Edit the js/rating.js file where it says "http://www.yoursite.com" to your actual site
3.) Edit link.html adding this:
Code:
<%stars($ID)%>

4.) Edit include_common_head.html addign this:
Code:
<script type="text/javascript" language="javascript" src="http://www.yoursite.com/js/behavior.js"></script>
<script type="text/javascript" language="javascript" src="http://www.yoursite.com/js/rating.js"></script>
<link rel="stylesheet" type="text/css" href="http://www.yoursite.com/css/default.css" />
<link rel="stylesheet" type="text/css" href="http://www.yoursite.com/css/rating.css" />
5.) Add this global, it is a direct translation of _drawrating.php

Code:
sub {
use Links qw/$DB/;
my ($id, $static) = @_;
my $db = $DB->table("Links");
my $results = $db->select({ID => $id})->fetchrow_hashref();
my $units = 5;
my $rating_unitwidth = 30;
my $ip = $ENV{REMOTE_ADDR};

my $count = $results->{Votes};
my $current_rating = $results->{Rating};

my $tense = ($count==1) ? "vote" : "votes";

if ($results->{Votes} < 1) {
$count = 0;
} else {
$count=$results->{Votes};
}
my $voted = $db->do("SELECT used_ips WHERE used_ips LIKE '%".$ip."%' AND ID='".$id."' ");
my $rating_width = ($count > 0) ? ($current_rating/$count)*$rating_unitwidth : 0;
my $rating1 = ($count > 0) ? $current_rating/$count : 0;
my $rating2 = ($count > 0) ? $current_rating/$count : 0;

if ($static) {
my $static_rater;
$static_rater .= "\n".'<div class="ratingblock">';
$static_rater .= '<div id="unit_long'.$id.'">';
$static_rater .= '<ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
$static_rater .= '<li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
$static_rater .= '</ul>';
$static_rater .= '<p class="static">'.$id.'. Rating: <strong> '.$rating1.'</strong>/'.$units.' ('.$count.' '.$tense.' cast) <em>This is \'static\'.</em></p>';
$static_rater .= '</div>';
$static_rater .= '</div>'."\n\n";
return join("\n", $static_rater);
} else {
my $rater ='';
$rater.='<div class="ratingblock">';
$rater.='<div id="unit_long'.$id.'">';
$rater.=' <ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
$rater.=' <li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
my $ncount;
for ($ncount = 1; $ncount <= $units; $ncount++) {
if(!$voted) {
$rater.='<li><a href="http://www.yoursite.com/...amp;amp;c='.$units.'" title="'.$ncount.' out of '.$units.'" class="r'.$ncount.'-unit rater" rel="nofollow">'.$ncount.'</a></li>';
}
}
$ncount=0;
$rater.=' </ul>';
$rater.=' <p';
if($voted){ $rater.=' class="voted"'; }
$rater.='>Rating: <strong> '.$rating1.'</strong>/'.$units.' ('.$count.' '.$tense.' cast)';
$rater.=' </p>';
$rater.='</div>';
$rater.='</div>';
return $rater;
}
}

- don't forget to change yoursite.com here as well

6.) upload the 3 folders to your root directory (httpdocs, public_html) whatever, unless you plan 2 change the code later

I believe that is everything. If anyone has any suggestions, improvements, or ideas for the script, let me know!






Good luck!

- Jonathan
Subject Author Views Date
Thread ajax rating system jdgamble 28762 May 26, 2009, 1:24 PM
Post Re: [jdgamble] ajax rating system
Andy 28468 May 27, 2009, 12:34 AM
Thread Re: [jdgamble] ajax rating system
Andy 28472 May 27, 2009, 12:45 AM
Thread Re: [Andy] ajax rating system
tora 12388 Apr 8, 2018, 4:02 AM
Thread Re: [tora] ajax rating system
Andy 12338 Apr 11, 2018, 12:08 AM
Post Re: [Andy] ajax rating system
tora 12332 Apr 11, 2018, 12:46 AM
Thread Re: [Andy] ajax rating system
tora 12326 Apr 11, 2018, 12:52 PM
Thread Re: [tora] ajax rating system
Andy 12317 Apr 12, 2018, 12:59 AM
Post Re: [Andy] ajax rating system
tora 12312 Apr 12, 2018, 1:21 AM
Thread Re: [jdgamble] ajax rating system
tandat 28432 May 27, 2009, 4:53 AM
Thread Re: [tandat] ajax rating system
jdgamble 28393 May 27, 2009, 8:08 AM
Thread Re: [jdgamble] ajax rating system
Andy 28379 May 27, 2009, 8:31 AM
Thread Re: [Andy] ajax rating system
jdgamble 28377 May 27, 2009, 10:38 AM
Thread Re: [jdgamble] ajax rating system
Andy 28441 May 27, 2009, 10:44 AM
Thread Re: [Andy] ajax rating system
jdgamble 28328 May 29, 2009, 11:34 AM
Thread Re: [jdgamble] ajax rating system
Matthias70 28342 May 29, 2009, 11:44 AM
Thread Re: [Matthias70] ajax rating system
jdgamble 28290 May 29, 2009, 6:55 PM
Thread Re: [jdgamble] ajax rating system
jdgamble 28281 May 29, 2009, 10:15 PM
Thread Re: [jdgamble] ajax rating system
jdgamble 28278 May 30, 2009, 7:22 PM
Thread Re: [jdgamble] ajax rating system
Andy 28393 May 31, 2009, 1:58 AM
Thread Re: [Andy] ajax rating system
jdgamble 28187 Jun 6, 2009, 10:48 AM
Thread Re: [jdgamble] ajax rating system
Andy 28277 Jun 6, 2009, 11:05 AM
Thread Re: [Andy] ajax rating system
jdgamble 28227 Jun 6, 2009, 12:42 PM
Post Re: [jdgamble] ajax rating system
Andy 28233 Jun 6, 2009, 11:58 PM