Gossamer Forum
Home : Products : Links 2.0 : Customization :

Top 100 for Links 2.0

Quote Reply
Top 100 for Links 2.0
Hi,

i like to share this stand alone Top 100 script for Links 2.0.

In this configuration it makes a toplist sortet by hits.

Just insert your serverpath, put some html to the header an footer to match your site an start the script and youré done.

Code:
########################

#!/usr/bin/perl
use strict;
# Default Outputfile
my $outputFile = "/yourserverpath/topsites.html";
my $number_to_rank = 100; # You can put here what you want


my $htmlHeader=<<EOT;

<html>
<head></head>
<body>

<!-- Start Header -->

Your header here (plain html is ok)

<!-- End Header -->

EOT
;

my $htmlFooter=<<EOT;

<!-- Start Footer -->

Your footer here (plain html is ok)

<!-- End Footer -->

</body>
</html>

EOT
;

sub tableLine {
my $lineCnt = sprintf("%04d",shift);
my $p = shift;
my ($p0,$p1,$p2,$p3,$p4)=split(/\|/,$p);

print F <<EOT;
<tr>
<td bgcolor=#c0c0c0 align=center><b>$lineCnt</b></td>
<td bgcolor=#950000 align=center><font color="#ffffff"><b>$p0</b></font></td>
<td bgcolor=#f3f3f3><a href="http://www.yourdomain.com/...jump/jump.cgi?ID=$p2" target="_blank">$p1</a> <FONT COLOR=#0000ff><small>$p4</small></font></td>
<td bgcolor=#dfdfdf align=center><b>$p3</b></td>
</tr>

EOT
}


# this is the program

open (F, ">$outputFile");
print F $htmlHeader;
open (LINKS,"/yourserverpath/links.db")
|| die "cannot find links.db: $!\n";
flock(LINKS, 2)
|| die "cannot lock links.db: $!\n";

my @rearranged;
while (<LINKS> ) {
my @fields = split(/\|/);
push @rearranged, "$fields[8]|$fields[1]|$fields[0]|$fields[11]|$fields[16]";
}
close LINKS;


my @sorted = sort { $b <=> $a } @rearranged;
for (my $z = 0; $z < $number_to_rank; tableLine( $z,$sorted[$z++] )){};


print F $htmlFooter;
close F;


# Do this only if you dont have to much traffic on your site. It is better to use the static file topsites.html!

print "Content-type: text/html\n\n";
print `cat $outputFile`;

#####################################







I use this on my site and i will share it to the community.

cu

RSS Junkie

Last edited by:

RSS Junkie: Nov 11, 2006, 12:44 AM
Quote Reply
Re: [RSS Junkie] Top 100 for Links 2.0 In reply to
I have forgotten one thing:

In the header you need this tag <table> and in the footer you need this </table>

cu,
RSS Junkie