#!/usr/bin/perl -w # n.b. will need updating before 2007! use CGI qw/:standard/;; $theyear = `date +%Y`; $thismonth = `date +%m`; chomp $thismonth; chomp $theyear; # print "current mon: $thismonth\n"; print "Content-type:text/html\n\n"; if (param()) { $name = param('name'); } else { print "I need a name parameter, bozo!"; exit; } # start HTML output &HTML_header($name); # generate current year for ($month=$thismonth-1;$month>=1;$month--) { $themonth = sprintf("%02d", $month); $filename = $theyear . $themonth . ".html"; ($rank, $posts, $percent) = &findposter($name,$filename); &HTML_row($themonth,$theyear,$rank,$posts,$percent); } # generate 2005 $theyear = 2005; for ($month=12;$month>=1;$month--) { $themonth = sprintf("%02d", $month); $filename = $theyear . $themonth . ".html"; ($rank, $posts, $percent) = &findposter($name,$filename); &HTML_row($themonth,$theyear,$rank,$posts,$percent); } # generate 2004 $theyear = 2004; for ($month=12;$month>=1;$month--) { $themonth = sprintf("%02d", $month); $filename = $theyear . $themonth . ".html"; ($rank, $posts, $percent) = &findposter($name,$filename); &HTML_row($themonth,$theyear,$rank,$posts,$percent); } # generate 2003 $theyear = 2003; for ($month=12;$month>=1;$month--) { $themonth = sprintf("%02d", $month); $filename = $theyear . $themonth . ".html"; ($rank, $posts, $percent) = &findposter($name,$filename); &HTML_row($themonth,$theyear,$rank,$posts,$percent); } # generate 2002 $theyear = 2002; for ($month=12;$month>=1;$month--) { $themonth = sprintf("%02d", $month); $filename = $theyear . $themonth . ".html"; ($rank, $posts, $percent) = &findposter($name,$filename); &HTML_row($themonth,$theyear,$rank,$posts,$percent); } # generate 2001 $theyear = 2001; for ($month=12;$month>=3;$month--) { $themonth = sprintf("%02d", $month); $filename = $theyear . $themonth . ".html"; ($rank, $posts, $percent) = &findposter($name,$filename); &HTML_row($themonth,$theyear,$rank,$posts,$percent); } &HTML_footer; sub findposter { my $name = shift; my $filename = shift; my $rank = 0; # read file and create hash open (FILE, "<$filename"); $match = 0; while (<FILE>) { chomp; if (m/>(\d+)</) { $rank = $1; } if (m/($name.*)/) { $match = 1; } if ($match == 1 && m/\((.*) posts, (.*)\%/) { close FILE; # print "RAANK $rank"; return ($rank,$1,$2); } } # print "NO match"; close FILE; return (0,0,0); } ####################################################################### # Add your own HTML in to the print blocks of the three functions below ####################################################################### sub HTML_header { my $name = shift; print <<END <html> <head> <title>Posting history for $name</title> <style type="text/css"> body {background-color:white; font-family:sans-serif;} #stats { text-align:left; position:absolute; top:140px; width:100%; } #totalstats { position:absolute; top:50px; text-align:left; width:100%; } </style> </head> <body> <h2><acronym title="Brighton New Media">BNM</acronym> posting history for $name</h2> <div id="stats"> <table border="1"> END } sub HTML_row { my ($month, $year, $rank, $posts, $percentage) = @_; $total_posts += $posts; my $mwidth = sprintf( "%f", $percentage*$posts/100) * 3; my $pwidth = ($posts * 3) - $mwidth; # print "<tr><td>$month/$year</td><td>$posts</td></tr>\n"; if ($rank) { $total_rank += $rank; $total_months += 1; print <<END; <tr> <td><a href="$year$month.html">$month/$year</a></td> <td align="left"><img src="images/redbar.png" height="10" width="$mwidth" hspace="0"><img src="images/greenbar.png" height="10" width="$pwidth" hspace="0"><br>(rank $rank: $posts posts, $percentage% off-topic)</td> </tr> END } else { print <<END; <tr> <td><a href="$year$month.html">$month/$year</a></td> <td align="left">No postings</td> </tr> END } } sub HTML_footer { my $average_rank = sprintf("%1.1f", $total_rank / $total_months); my $average_posts = sprintf("%1.1f", $total_posts / $total_months); print <<END; </table> <p><a href="./">Back to rankings</a></p> <p><a href="../">Back to my BNM area</a></p> END my $back = referer(); if ($back) { print "<p><a href=\"$back\">Back to the ranking page you were looking at</a></p>"; } print "</div><div id='totalstats'><p>Total posts to date: $total_posts<br>Average posts/month: $average_posts<br>Average rank: $average_rank</p></body></html></div>"; }