Gossamer Forum
Home : Products : Links 2.0 : Customization :

New 5 Star Image for Rating Mod

Quote Reply
New 5 Star Image for Rating Mod
Hi,

Someone I know needed an image for rating mod and as the "Amazon Fix" one didn't seem to work then I made my own.
So thought I'd share the code with you (the person I wrote it for doesn't mind).

It may not be the shortest or prettiest mod but it works and that is what mattters.

In site_html_templates.pl replace sub site_html_link with:

Code:
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;

$rating = qq|<img src="$build_root_url/images/clr.gif">| x '5' if ($rec{'Rating'} =~ /(9|10)\.\d\d/);
$rating = qq|<img src="$build_root_url/images/clr.gif">| x '4' if ($rec{'Rating'} =~ /(7|8)\.\d\d/);
$rating = qq|<img src="$build_root_url/images/clr.gif">| x '3' if ($rec{'Rating'} =~ /(5|6)\.\d\d/);
$rating = qq|<img src="$build_root_url/images/clr.gif">| x '2' if ($rec{'Rating'} =~ /(3|4)\.\d\d/);
$rating = qq|<img src="$build_root_url/images/clr.gif">| x '1' if ($rec{'Rating'} =~ /(1|2)\.\d\d/);
$rating = qq|<small>No Rating</small>| if ($rec{'Rating'} =~ /0\.\d\d/);

# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});

return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
rate_img => $rating,
%rec,
%globals
});
}
Then add <%rate_img%> in link.html

You can obviously change the img tag to point to wherever you have the image.
You only need one image that could be a star or whatever.
The mod will duplicate the img tag automatically to show the correct number of stars.

Alternatively you can remove the x '5', x '4', x '3', x '2', x '1' from the variable and use an image that contains all the stars.

So you'd use something like:

Code:
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;

$rating = qq|<img src="$build_root_url/images/5stars.gif">| if ($rec{'Rating'} =~ /(9|10)\.\d\d/);
$rating = qq|<img src="$build_root_url/images/4stars.gif">| if ($rec{'Rating'} =~ /(7|8)\.\d\d/);
$rating = qq|<img src="$build_root_url/images/3stars.gif">| if ($rec{'Rating'} =~ /(5|6)\.\d\d/);
$rating = qq|<img src="$build_root_url/images/2stars.gif">| if ($rec{'Rating'} =~ /(3|4)\.\d\d/);
$rating = qq|<img src="$build_root_url/images/1stars.gif">| if ($rec{'Rating'} =~ /(1|2)\.\d\d/);
$rating = qq|<small>No Rating</small>| if ($rec{'Rating'} =~ /0\.\d\d/);

# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});

return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
rate_img => $rating,
%rec,
%globals
});
}
Hope I made sense then - if not just ask away...


Installations:http://www.wiredon.net/gt/
Favicon:http://www.wiredon.net/favicon/

Quote Reply
Re: [RedRum] New 5 Star Image for Rating Mod In reply to
Hello RedRum,

I've read almost ever posting concerning this mod. I have tried everything possible. Yet, I still receive this error: Unknow Tag: rate_img. I have the following code in my link.html <%rate_img%>

I have the following code in my site_html_templates.pl

Code:


sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;

$rating = qq|<img src="$build_root_url/clr.gif">| x '5' if ($rec{'Rating'} =~ /(9|10)\.\d\d/);
$rating = qq|<img src="$build_root_url/clr.gif">| x '4' if ($rec{'Rating'} =~ /(7|8)\.\d\d/);
$rating = qq|<img src="$build_root_url/clr.gif">| x '3' if ($rec{'Rating'} =~ /(5|6)\.\d\d/);
$rating = qq|<img src="$build_root_url/clr.gif">| x '2' if ($rec{'Rating'} =~ /(3|4)\.\d\d/);
$rating = qq|<img src="$build_root_url/clr.gif">| x '1' if ($rec{'Rating'} =~ /(1|2)\.\d\d/);
$rating = qq|<small>No Rating</small>| if ($rec{'Rating'} =~ /0\.\d\d/);



# Set new and pop to either 1 or 0 for templates.



($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});

return &load_template ('link.html', {

detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
rate_img => $rating,
%rec,
%globals
});
}


What am I doing wrong?
Quote Reply
Re: [luvlynspiration] New 5 Star Image for Rating Mod In reply to
I don't know about you but this is what I have and it works great.

sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.


my %rec = @_;

$rating = qq|<img src="$build_root_url/images/clr.gif">| x int(($rec{'Rating'}/2) + .5);
$rating = qq|<small>No Rating</small>| if ($rec{'Rating'} < 1);


# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});


return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
rate_img => $rating,
%rec,
%globals
});
}

rexxx webmaster
Quote Reply
Re: [luvlynspiration] New 5 Star Image for Rating Mod In reply to
Hi,

That was the old version, try what rexxx provided and let me know how that goes.
Quote Reply
Re: [RedRum] New 5 Star Image for Rating Mod In reply to
Hello RedRum,

I tried what Rexxx provided, it still doesn't work. Crazy Perhaps, I'll doing something wrong inside my link.html

This is what I have:

Code:

<ul><img src=<%build_root_url%>/dot.gif> <a class="link" href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a> <%if Description%>
<span class="descript">- <%Description%></span>
<%endif%> <%if new_mod_img%>
<%new_mod_img%>
<%endif%> <%if isPopular%>
<sup class="new"><img src="<%build_root_url%>/hot.gif" alt="hot" border="0"></sup>
<%endif%> <small class="date">(Added: <%Date%> Hits: <%Hits%> Rating: <%Rating%> Votes: <%Votes%>) <a href="<%db_cgi_url%>/rate.cgi?ID=<%ID%>">Rate It</a> | <a href="<%db_cgi_url%>/review.cgi?function=display&LID=<%ID%>">Review It</a> | <a href="<%db_cgi_url%>/info.cgi?ID=<%ID%>">Info</a> | <a href="<%db_cgi_url%>/sendlink.cgi?ID=<%ID%>">Send This Link</a></small> </ul>
Quote Reply
Re: [luvlynspiration] New 5 Star Image for Rating Mod In reply to
You need to add if you did it as I showed you:

<%rate_img%> next to were you have Rating: like this

(Added: <%Date%> Hits: <%Hits%> Rating: <%rate_img%> Votes: <%Votes%>)

You can also keep <%rating%> there it would just show you the numbers also.
rexxx webmaster
Quote Reply
Re: [rexxx] New 5 Star Image for Rating Mod In reply to
Hello, first time using this system, I'm going to throw my 2 cents in I think, not that it will matter seeing all the threads to this quizee, anyways here we go.......

In regards to the 5 star mod, and a top mod it is, and with all the posts with changes, and modifications to it, super lateral thinking guys. Beleive me I tested them all out.
However, stick to the basics that work, WeirdOn got it right the first time, if you want five star rating images use the original mod. Don't get confused.

Before doing anything to your code, backup the file you are going to tweak. Highly recommended, will save you lots of time if you do something wrong. Particularly if on rebuild it tries to download the rebuild file, I bet lots have experienced that beauty!

If you want 10 rated images to display just change the /2 to /1
I know some are getting funky with half images, though keep the code as short as possible. And the use of 1 image will speed the page load 10 times over, than 3 images plus a half image, see what I mean.

star examples:
  • 5 star mod by WeirdOn


$rating = qq|<img src="/images/rate.gif">| x int(($rec{'Rating'}/2) + .5);
  • Now for 10 star change the /2 to /1


$rating = qq|<img src="/images/rate.gif">| x int(($rec{'Rating'}/1) + .5);

Open: site_html_template.pl, in this file look for sub site_html_link {
paste the code as is from the mod file you downloaded from WeirdOn's pages. And your done.
Check chmod and rebuild, if it trys to download on rebuild, you stuffed up somewhere, upload the backup of site_html_templates.pl and try again.

But don't forget to upload an image to the location specified in the img src= tag.

And again your done.

Also it depends on your templates aswell, cause if you are downloading templates from the resources section of gt, some have the mods already, so linking to it with <%rate_img%> in link.html is faster than trying to re-code. See what happens, you may only need to change the img location.

ERRORS:
If you see no result, check if it has a rating at all, if not give the link a test rating of say 5, if the img src is correct and you uploaded the image in binary not ASCii or Auto it should work showing 5 stars for 10 star rating code and 3 stars for 5 star rating code. Or 2 stars and a half if you have a long code for a 5 star rating.
  • For the last reply to display in link.html:
    You need to add if you did it as I showed you:

    <%rate_img%> next to were you have Rating: like this

    (Added: <%Date%> Hits: <%Hits%> Rating: <%rate_img%> Votes: <%Votes%>)

    You can also keep <%rating%> there it would just show you the numbers also.
    rexxx webmaster


SOME MORE SOLUTIONS
You can have
(Added: <%Date%> Hits: <%Hits%><%if Rating%>Rated:<%rate_img%> Votes: <%Votes%><%endif%>) in link.html
no rating no display at all, makes page load faster in stead of loading a no rating image or having a tag in the .pl in question.

the shorter the code the faster the output. if your site is a search engine a high % of surfers want fast loading pages not graphic heavy, but if you are a graphic person like I can be sometimes do it if it pleases you, just remember some surfers get bored waiting for images to load if they have slow connections. Don't loose traffic to an extra 3 - 8 seconds of image loading, keep your site alive.

Tweak the Weirdon mod with /2 or /1 it's that simple!



Skippy (australia)
Team ET


Hat of to Paul, nice script tuning of links.
Quote Reply
Re: [Paul] New 5 Star Image for Rating Mod In reply to
Paul and Rexxx:

Very cool mod. Thanks for posting it.

Charlie
Quote Reply
Re: [cvance] New 5 Star Image for Rating Mod In reply to
I believe that I did everything correctly, however, I get this error: Unkown Tag: rate_img

Anyone else have this problem?
Quote Reply
Re: [Ames] New 5 Star Image for Rating Mod In reply to
Have you replaced your temple.pm file with the one from the resource center?


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] New 5 Star Image for Rating Mod In reply to
hmm, no, but it didn't say so in the instructions above...unless I completely missed it. Where or what exactly in the resource center? Is it the Amazon Amazon Style Image for Rating fix?
Quote Reply
Re: [Ames] New 5 Star Image for Rating Mod In reply to
Well, it may not be the problem, but it's a good idea to use it anyway. Look here: http://www.gossamer-threads.com/...es/Detailed/877.html

You didn't know about the resource center? Use the breadcrumb nav on the page above and hit 'Links.'


Leonard
aka PerlFlunkie
Quote Reply
Re: [rexxx] New 5 Star Image for Rating Mod In reply to
Hello,

I've been trying to get this image mod to work for a while now with no luck. I have edited the site_html_templates but every time I click on Build in the admin page it starts to download the nph-build.cgi file. Any clue about what may be wrong? Do I have to edit any other files other than site_html_templates.pl? Also I have previously added the category title mod. Could this be the problem?

Thanks,Bill
http://www.free4everyone.com/
Quote Reply
Re: [billpavNJ] New 5 Star Image for Rating Mod In reply to
The clue will be in the download.... Open it, and there will be an error message, telling you what's wrong on which line. Of course, sometimes the actual error is further up the code than the message says...


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] New 5 Star Image for Rating Mod In reply to
Hi All,

I have managed to get the "image to replace ratings" mod to work fine on the links.htm page....but when I try and add it to the detaild page template (i.e. <%rate_img%>) I get a "Rating: Unkown Tag: rate_img" error. Any idea why it would work on the links page and not the detailed page....is there something else I need to do??

Thanks
Hamsterpants
Quote Reply
Re: [Hamsterpants] New 5 Star Image for Rating Mod In reply to
Add the red part to this sub, in site_html_templates.pl:



sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
my %rec = @_;
return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
rate_img => $rate_img,
%rec,
%globals
} );
}


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] New 5 Star Image for Rating Mod In reply to
Hi Leonard,



Thanks for the reply,

Tried what you suggested but didn't work... You did give me a clue though and so I tried added the top rate image source to that sub aswell (see below) and that worked.

sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
my %rec = @_;
$rating = qq|<img src="$build_root_url/images/clr.gif">| x int(($rec{'Rating'}/2) + .5);
$rating = qq|<small>No Rating</small>| if ($rec{'Rating'} < 1);


return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
%rec,
rate_img => $rating,
%globals
} );

Thanks
Hamsterpants