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 45221 May 26, 2009, 1:24 PM
Post Re: [jdgamble] ajax rating system
Andy 44697 May 27, 2009, 12:34 AM
Thread Re: [jdgamble] ajax rating system
Andy 44720 May 27, 2009, 12:45 AM
Thread Re: [Andy] ajax rating system
tora 28638 Apr 8, 2018, 4:02 AM
Thread Re: [tora] ajax rating system
Andy 28577 Apr 11, 2018, 12:08 AM
Post Re: [Andy] ajax rating system
tora 28534 Apr 11, 2018, 12:46 AM
Thread Re: [Andy] ajax rating system
tora 28581 Apr 11, 2018, 12:52 PM
Thread Re: [tora] ajax rating system
Andy 28557 Apr 12, 2018, 12:59 AM
Post Re: [Andy] ajax rating system
tora 28516 Apr 12, 2018, 1:21 AM
Thread Re: [jdgamble] ajax rating system
tandat 44665 May 27, 2009, 4:53 AM
Thread Re: [tandat] ajax rating system
jdgamble 44651 May 27, 2009, 8:08 AM
Thread Re: [jdgamble] ajax rating system
Andy 44628 May 27, 2009, 8:31 AM
Thread Re: [Andy] ajax rating system
jdgamble 44637 May 27, 2009, 10:38 AM
Thread Re: [jdgamble] ajax rating system
Andy 44687 May 27, 2009, 10:44 AM
Thread Re: [Andy] ajax rating system
jdgamble 44560 May 29, 2009, 11:34 AM
Thread Re: [jdgamble] ajax rating system
Matthias70 44584 May 29, 2009, 11:44 AM
Thread Re: [Matthias70] ajax rating system
jdgamble 44555 May 29, 2009, 6:55 PM
Thread Re: [jdgamble] ajax rating system
jdgamble 44519 May 29, 2009, 10:15 PM
Thread Re: [jdgamble] ajax rating system
jdgamble 44506 May 30, 2009, 7:22 PM
Thread Re: [jdgamble] ajax rating system
Andy 44619 May 31, 2009, 1:58 AM
Thread Re: [Andy] ajax rating system
jdgamble 44431 Jun 6, 2009, 10:48 AM
Thread Re: [jdgamble] ajax rating system
Andy 44521 Jun 6, 2009, 11:05 AM
Thread Re: [Andy] ajax rating system
jdgamble 44484 Jun 6, 2009, 12:42 PM
Post Re: [jdgamble] ajax rating system
Andy 44458 Jun 6, 2009, 11:58 PM