Gossamer Forum
Home : Products : Links 2.0 : Customization :

Help - Im useless at perl!

Quote Reply
Help - Im useless at perl!
Tried taking this in 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|$rate10| if ($rec{'Rating'} =~ /(10)\.\d\d/);

$rating = qq|$rate9| if ($rec{'Rating'} =~ /(9)\.\d\d/);

$rating = qq|$rate8| if ($rec{'Rating'} =~ /(8)\.\d\d/);

$rating = qq|$rate7| if ($rec{'Rating'} =~ /(7)\.\d\d/);

$rating = qq|$rate6| if ($rec{'Rating'} =~ /(6)\.\d\d/);

$rating = qq|$rate5| if ($rec{'Rating'} =~ /(5)\.\d\d/);

$rating = qq|$rate4| if ($rec{'Rating'} =~ /(4)\.\d\d/);

$rating = qq|$rate3| if ($rec{'Rating'} =~ /(3)\.\d\d/);

$rating = qq|$rate2| if ($rec{'Rating'} =~ /(2)\.\d\d/);

$rating = qq|$rate1| if ($rec{'Rating'} =~ /(1)\.\d\d/);

$rating = qq|$rate0| 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",

title => $title,

rate_img => $rating,

%rec,

%globals

});

}




and putting it into nph-build.cgi thus

Code:


sub build_rate_page {

# --------------------------------------------------------

# Creates a Top 10 ratings page.

my (@values, $id, $votes, $rate, @top_votes, %top_votes, @top_rate, %top_rate);

local ($top_rated, $top_votes);



if ($build_ratings_path =~ m,^$build_root_path/(.*)$,) {

&build_dir ($1);

}



$total = 0;



open (LINKS, $db_links_name) or &cgierr ("unable to open links database: $db_links_name. Reason: $!");

LINE: while (<LINKS>) {

/^#/ and next LINE; # Skip comment Lines.

/^\s*$/ and next LINE; # Skip blank lines.

chomp;

@values = &split_decode ($_);

$id = $values[$db_key_pos];

$votes = $values[$db_votes];

$rate = $values[$db_rating];

next if ($votes < 10);

if (($#top_votes < 9) or ($votes > $top_votes[$#top_votes])) {

push (@{$top_votes{$votes}}, @values);

if ($#top_votes <= 10) {

push (@top_votes, $votes);

@top_votes = sort { $b <=> $a } @top_votes;

}

else {

splice (@{$top_votes{$#top_votes}}, 0, $#db_cols);

$#{$top_votes{$#top_votes}} or delete $top_votes{$#top_votes};

delete $top_votes{$top_votes[$#top_votes]-$id};

$top_votes[$#top_votes] = $votes;

@top_votes = sort { $b <=> $a } @top_votes;

}

}

if (($#top_rate < 9) or ($rate > $top_rate[$#top_rate])) {

push (@{$top_rate{$rate}}, @values);

if ($#top_rate <= 10) {

push (@top_rate, $rate);

@top_rate = sort { $b <=> $a } @top_rate;

}

else {

splice (@{$top_rate{$#top_rate}}, 0, $#db_cols);

$#{$top_rate{$#top_rate}} or delete $top_rate{$#top_rate};

delete $top_rate{$top_rate[$#top_rate]-$id};

$top_rate[$#top_rate] = $rate;

@top_rate = sort { $b <=> $a } @top_rate;

}

}

}

close LINKS;



$top_rated = ''; $top_votes = '';

$rate_img = qq|$rate10| if ($rec{'rate'} =~ /(10)\.\d\d/);

$rate_img = qq|$rate9| if ($rec{'rate'} =~ /(9)\.\d\d/);

$rate_img = qq|$rate8| if ($rec{'rate'} =~ /(8)\.\d\d/);

$rate_img = qq|$rate7| if ($rec{'rate'} =~ /(7)\.\d\d/);

$rate_img = qq|$rate6| if ($rec{'rate'} =~ /(6)\.\d\d/);

$rate_img = qq|$rate5| if ($rec{'rate'} =~ /(5)\.\d\d/);

$rate_img = qq|$rate4| if ($rec{'rate'} =~ /(4)\.\d\d/);

$rate_img = qq|$rate3| if ($rec{'rate'} =~ /(3)\.\d\d/);

$rate_img = qq|$rate2| if ($rec{'rate'} =~ /(2)\.\d\d/);

$rate_img = qq|$rate1| if ($rec{'rate'} =~ /(1)\.\d\d/);

$rate_img = qq|$rate0| if ($rec{'rate'} =~ /(0)\.\d\d/);



foreach (sort { $b <=> $a } @top_votes) {

$seen{$_}++;

%link = &array_to_hash ($seen{$_} - 1, @{$top_votes{$_}});

$top_votes .= qq~<tr><td align=center><font size="2">$link{'Rating'}</font></td><td align=center><font size="2">$link{'Votes'}</font></td><td><font size="2"><b><a href="$db_cgi_url/jump.cgi?ID=$link{'ID'}">$link{'Title'}</a></b></font></td><td><img src="$imagedir$rate_img" alt="$link{'Title'} has a rating of $link{'Rating'} for a total of $link{'Votes'}"></td></tr>\n~;

}

foreach (sort { $b <=> $a } @top_rate) {

$seen{$_}++;

%link = &array_to_hash ($seen{$_} - 1, @{$top_rate{$_}});

$top_rated .= qq~<tr><td align=center><font size="2">$link{'Rating'}</font></td><td align=center><font size="2">$link{'Votes'}</font></td><td><font size="2"><b><a href="$db_cgi_url/jump.cgi?ID=$link{'ID'}">$link{'Title'}</a></b></font></td><td><img src="$imagedir$rate_img" alt="$link{'Title'} has a rating of $link{'Rating'} for a total of $link{'Votes'}"></td></tr>\n~;

}

open (RATE, ">$build_ratings_path/$build_index") or &cgierr ("unable to open top rated page: $build_ratings_path/$build_index. Reason: $!");

print "\tVote Range: $top_votes[0] .. $top_votes[$#top_votes]\n";

print "\tRate Range: $top_rate[0] .. $top_rate[$#top_rate]\n";

print RATE &site_html_ratings;

close RATE;

}



but all I'm getting is this

http://go.roman365.com/Ratings/

Ive tried mucking around and modifying sub site_html_ratings in site_html_templates.pl with the code but am getting nowhere, can anyone give me a few pointers what I'm doing wrong?
Quote Reply
Re: [roman365] Help - Im useless at perl! In reply to
how about

http://www.gossamer-threads.com/...ting%20images;#70581


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Help - Im useless at perl! In reply to
Thanks, tried post u suggest but cant get my head round that at all.
Quote Reply
Re: [esm] Help - Im useless at perl! In reply to
Got it!

This relates to images stored at $imagedir which is set with a line in links.cfg and they are numbered rate0.gif > rate10.gif (I use them for image ratings in link display as well) and I modified the hyperlinks to go through jump.cgi instead of just the url's.

nph-build.cgi

Code:


sub build_rate_page {

# --------------------------------------------------------

# Creates a Top 10 ratings page.

my (@values, $id, $votes, $rate, @top_votes, %top_votes, @top_rate, %top_rate);

local ($top_rated, $top_votes);



if ($build_ratings_path =~ m,^$build_root_path/(.*)$,) {

&build_dir ($1);

}



$total = 0;



open (LINKS, $db_links_name) or &cgierr ("unable to open links database: $db_links_name. Reason: $!");

LINE: while (<LINKS>) {

/^#/ and next LINE; # Skip comment Lines.

/^\s*$/ and next LINE; # Skip blank lines.

chomp;

@values = &split_decode ($_);

$id = $values[$db_key_pos];

$votes = $values[$db_votes];

$rate = $values[$db_rating];

next if ($votes < 10);

if (($#top_votes < 9) or ($votes > $top_votes[$#top_votes])) {

push (@{$top_votes{$votes}}, @values);

if ($#top_votes <= 10) {

push (@top_votes, $votes);

@top_votes = sort { $b <=> $a } @top_votes;

}

else {

splice (@{$top_votes{$#top_votes}}, 0, $#db_cols);

$#{$top_votes{$#top_votes}} or delete $top_votes{$#top_votes};

delete $top_votes{$top_votes[$#top_votes]-$id};

$top_votes[$#top_votes] = $votes;

@top_votes = sort { $b <=> $a } @top_votes;

}

}

if (($#top_rate < 9) or ($rate > $top_rate[$#top_rate])) {

push (@{$top_rate{$rate}}, @values);

if ($#top_rate <= 10) {

push (@top_rate, $rate);

@top_rate = sort { $b <=> $a } @top_rate;

}

else {

splice (@{$top_rate{$#top_rate}}, 0, $#db_cols);

$#{$top_rate{$#top_rate}} or delete $top_rate{$#top_rate};

delete $top_rate{$top_rate[$#top_rate]-$id};

$top_rate[$#top_rate] = $rate;

@top_rate = sort { $b <=> $a } @top_rate;

}

}

}

close LINKS;



$top_rated = ''; $top_votes = '';



foreach (sort { $b <=> $a } @top_votes) {

$seen{$_}++;

%link = &array_to_hash ($seen{$_} - 1, @{$top_votes{$_}});

$value = int ($link{'Rating'} / 1);

$top_votes .= qq~<tr valign="top"><td align=center><font size="2">$link{'Rating'}</font></td><td align=center><font size="2">$link{'Votes'}</font></td><td><font size="2"><b><a href="$db_cgi_url/jump.cgi?ID=$link{'ID'}">$link{'Title'}</a></b></font></td><td align="right"><img src="$imagedir/rate$value.gif" alt="$link{'Title'} has a rating of $link{'Rating'} for a total of $link{'Votes'} Votes"></td></tr>\n~;

}

foreach (sort { $b <=> $a } @top_rate) {

$seen{$_}++;

%link = &array_to_hash ($seen{$_} - 1, @{$top_rate{$_}});

$value = int ($link{'Rating'} / 1);

$top_rated .= qq~<tr valign="top"><td align=center><font size="2">$link{'Rating'}</font></td><td align=center><font size="2">$link{'Votes'}</font></td><td><font size="2"><b><a href="$db_cgi_url/jump.cgi?ID=$link{'ID'}">$link{'Title'}</a></b></font></td><td align="right"><img src="$imagedir/rate$value.gif" alt="$link{'Title'} has a rating of $link{'Rating'} for a total of $link{'Votes'} Votes"></td></tr>\n~;

}

open (RATE, ">$build_ratings_path/$build_index") or &cgierr ("unable to open top rated page: $build_ratings_path/$build_index. Reason: $!");

print "\tVote Range: $top_votes[0] .. $top_votes[$#top_votes]\n";

print "\tRate Range: $top_rate[0] .. $top_rate[$#top_rate]\n";

print RATE &site_html_ratings;

close RATE;

}


Now I'm going to crash out cause my brain hurts.Crazy
Quote Reply
Re: [roman365] Help - Im useless at perl! In reply to
Oh, in rate_top.html template I added this to each table :

<th align=left>&nbsp;</th>

after

<th> Resource</th>


Heres the built page :

http://go.roman365.com/Ratings/

Last edited by:

roman365: Feb 6, 2003, 7:55 PM