Hi,
just a variation of the Top 100 Theme. The Script produces a static "Top 100", or what ever you want Page, where the Links are sortet per "hits". A static page is better, than a dynamic page, because kidies with a fast finger can crash your server if they hit fast enaugh the button or link, which produces the dynamic page.
Sample Output:
http://www.kostnixx.de/pages/topsites.html
If you have added extra fields, you maybe must change the field numbers.
Have fun,
Karl
------ Script ------
#!/usr/bin/perl
use strict;
# Default Outputfile
my $outputFile = "/home/www/yourdomain/pages/topsites.html";
my $number_to_rank = 100;
my $htmlHeader=<<EOT;
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
</head>
<body>
<center>
<table cellpadding=2 cellspacing=2 width=90%>
<tr>
<td bgcolor=#000000 align=center><font face="Verdana,Helvetica" color=#ffffff size=-1><b>Rang</b></font></td>
<td bgcolor=#000000 align=center><font face="Verdana, Helvetica" color=#ffffff size=-1><b>Hits</b></font></td>
<td bgcolor=#000000><font face="Verdana, Helvetica" color=#ffffff size=-1><b>Link</b></font></td>
<td bgcolor=#000000 align=center><font face="Verdana, Helvetica" color=#ffffff size=-1><b>Votes</b></font></td>
</tr>
EOT
;
my $htmlFooter=<<EOT;
</table></center>
</body>
</html>
EOT
;
sub tableLine {
my $lineCnt = sprintf("%04d",shift);
my $p = shift;
my ($p0,$p1,$p2,$p3)=split(/\|/,$p);
print F <<EOT;
<tr>
<td bgcolor=#c0c0c0 align=center><font face="Verdana, Helvetica" size=-1><b>$lineCnt</b></font></td>
<td bgcolor=#dfdfdf align=center><font face="Verdana, Helvetica" size=-1><b>$p0</b></font></td>
<td bgcolor=#efefef><font face="Verdana, Helvetica" size=-1><a href="http://www.yourdomain.de/cgi-bin/links/jump.cgi?ID=$p2">$p1</a></font></td>
<td bgcolor=#dfdfdf align=center><font face="Verdana, Helvetica" size=-1><b>$p3</b></font></td>
</tr>
EOT
}
open (F, ">$outputFile");
print F $htmlHeader;
open (LINKS,"/home/www/yourdomain/cgi-bin/links/admin/data/links.db")
| | die "links.db not fount: $!\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]";
}
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;
# Just for checking
print "Content-type: text/html\n\n";
print `cat $outputFile`;
[This message has been edited by Karl (edited December 01, 1999).]
just a variation of the Top 100 Theme. The Script produces a static "Top 100", or what ever you want Page, where the Links are sortet per "hits". A static page is better, than a dynamic page, because kidies with a fast finger can crash your server if they hit fast enaugh the button or link, which produces the dynamic page.
Sample Output:
http://www.kostnixx.de/pages/topsites.html
If you have added extra fields, you maybe must change the field numbers.
Have fun,
Karl
------ Script ------
Code:
#!/usr/bin/perl
use strict;
# Default Outputfile
my $outputFile = "/home/www/yourdomain/pages/topsites.html";
my $number_to_rank = 100;
my $htmlHeader=<<EOT;
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
</head>
<body>
<center>
<table cellpadding=2 cellspacing=2 width=90%>
<tr>
<td bgcolor=#000000 align=center><font face="Verdana,Helvetica" color=#ffffff size=-1><b>Rang</b></font></td>
<td bgcolor=#000000 align=center><font face="Verdana, Helvetica" color=#ffffff size=-1><b>Hits</b></font></td>
<td bgcolor=#000000><font face="Verdana, Helvetica" color=#ffffff size=-1><b>Link</b></font></td>
<td bgcolor=#000000 align=center><font face="Verdana, Helvetica" color=#ffffff size=-1><b>Votes</b></font></td>
</tr>
EOT
;
my $htmlFooter=<<EOT;
</table></center>
</body>
</html>
EOT
;
sub tableLine {
my $lineCnt = sprintf("%04d",shift);
my $p = shift;
my ($p0,$p1,$p2,$p3)=split(/\|/,$p);
print F <<EOT;
<tr>
<td bgcolor=#c0c0c0 align=center><font face="Verdana, Helvetica" size=-1><b>$lineCnt</b></font></td>
<td bgcolor=#dfdfdf align=center><font face="Verdana, Helvetica" size=-1><b>$p0</b></font></td>
<td bgcolor=#efefef><font face="Verdana, Helvetica" size=-1><a href="http://www.yourdomain.de/cgi-bin/links/jump.cgi?ID=$p2">$p1</a></font></td>
<td bgcolor=#dfdfdf align=center><font face="Verdana, Helvetica" size=-1><b>$p3</b></font></td>
</tr>
EOT
}
open (F, ">$outputFile");
print F $htmlHeader;
open (LINKS,"/home/www/yourdomain/cgi-bin/links/admin/data/links.db")
| | die "links.db not fount: $!\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]";
}
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;
# Just for checking
print "Content-type: text/html\n\n";
print `cat $outputFile`;
[This message has been edited by Karl (edited December 01, 1999).]