package Pisg::HTMLGenerator; use strict; $^W = 1; my ($conf, $debug, $parser, $stats, $users, %T); sub new { my $self = shift; $conf = shift; $debug = shift; $stats = shift; $users = shift; %T = @_; # Load the Common module from wherever it's configured to be. push(@INC, $conf->{modules_dir}); require Pisg::Common; Pisg::Common->import(); return bless {}; } sub create_html { # This is where all subroutines get executed, you can actually design # your own layout here, the lines should be self-explainable print "Now generating HTML($conf->{outputfile})...\n"; open (OUTPUT, "> $conf->{outputfile}") or die("$0: Unable to open outputfile($conf->{outputfile}): $!\n"); if ($conf->{show_time}) { $conf->{tablewidth} += 40; } if ($conf->{show_words}) { $conf->{tablewidth} += 40; } if ($conf->{show_wpl}) { $conf->{tablewidth} += 40; } if ($conf->{show_cpl}) { $conf->{tablewidth} += 40; } $conf->{headwidth} = $conf->{tablewidth} - 4; htmlheader($stats); pageheader($stats); activetimes($stats); activenicks($stats); headline(template_text('bignumtopic')); html("{tablewidth}\">\n"); # Needed for sections questions($stats); shoutpeople($stats); capspeople($stats); violent($stats); mostsmiles($stats); mostsad($stats); linelengths($stats); mostwords($stats); mostwordsperline($stats); html("
"); # Needed for sections mostusedword($stats); mostreferencednicks($stats); mosturls($stats); headline(template_text('othernumtopic')); html("{tablewidth}\">\n"); # Needed for sections gotkicks($stats); mostkicks($stats); mostop($stats); mostactions($stats); mostmonologues($stats); mostjoins($stats); mostfoul($stats); html("
"); # Needed for sections headline(template_text('latesttopic')); html("{tablewidth}\">\n"); # Needed for sections lasttopics($stats); html("
"); # Needed for sections my %hash = ( lines => $stats->{totallines} ); html(template_text('totallines', %hash) . "

"); htmlfooter($stats); close(OUTPUT); } # Some HTML subs sub htmlheader { my ($stats) = @_; my $bgpic = ""; if ($conf->{bgpic}) { $bgpic = " background=\"$conf->{bgpic}\""; } print OUTPUT < $conf->{channel} @ $conf->{network} channel statistics
HTML my %hash = ( network => $conf->{network}, maintainer => $conf->{maintainer}, days => $stats->{days}, nicks => scalar keys %{ $stats->{lines} } ); print OUTPUT "" . template_text('pagetitle1', %hash) . "
"; print OUTPUT "
"; print OUTPUT template_text('pagetitle2', %hash); sub timefix { my ($timezone, $sec, $min, $hour, $mday, $mon, $year, $wday, $month, $day, $tday, $wdisplay, @month, @day, $timefixx, %hash); $month = template_text('month', %hash); $day = template_text('day', %hash); @month=split / /, $month; @day=split / /, $day; # Get the Date from the users computer $timezone = $conf->{timeoffset} * 3600; ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+$timezone); $year += 1900; # Y2K Patch $min =~ s/^(.)$/0$1/; # Fixes the display of mins/secs below $sec =~ s/^(.)$/0$1/; # it displays 03 instead of 3 if($hour > '23') { # Checks to see if it Midnight $hour = 12; # Makes it display the hour 12 $tday = "AM"; # Display AM } elsif($hour > '12') { # Get rid of the Military time and $hour -= 12; # put it into normal time $tday = "PM"; # If past Noon and before Midnight set } # the time as PM else { $tday = "AM"; # If it's past Midnight and before Noon } # set the time as AM # Use 24 hours pr. day if($tday eq "PM" && $hour < '12') { $hour += 12; } print OUTPUT "$day[$wday] $mday $month[$mon] $year - $hour:$min:$sec\n"; } timefix(); print OUTPUT "
" . template_text('pagetitle3', %hash) . "

"; } sub htmlfooter { my ($stats) = @_; print OUTPUT < Stats generated by pisg $conf->{version}
pisg by Morten "LostStar" Brix Pedersen and others
Stats generated in $stats->{processtime}
HTML } sub headline { my ($title) = @_; print OUTPUT <
$title
HTML } sub pageheader { if ($conf->{pagehead} ne 'none') { open(PAGEHEAD, $conf->{pagehead}) or die("$0: Unable to open $conf->{pagehead} for reading: $!\n"); while () { html($_); } } } sub activetimes { # The most actives times on the channel my ($stats) = @_; my (%output, $tbgcolor); &headline(template_text('activetimestopic')); my @toptime = sort { $stats->{times}{$b} <=> $stats->{times}{$a} } keys %{ $stats->{times} }; my $highest_value = $stats->{times}{$toptime[0]}; my @now = localtime($conf->{timestamp}); my $image; for my $hour (sort keys %{ $stats->{times} }) { $debug->("Time: $hour => ". $stats->{times}{$hour}); my $size = ($stats->{times}{$hour} / $highest_value) * 100; my $percent = ($stats->{times}{$hour} / $stats->{totallines}) * 100; $percent =~ s/(\.\d)\d+/$1/; if ($size < 1 && $size != 0) { # Opera doesn't understand '0.xxxx' in the height="xx" attr, # so we simply round up to 1.0 here. $size = 1.0; } if ($conf->{timeoffset} =~ /\+(\d+)/) { # We must plus some hours to the time $hour += $1; $hour = $hour % 24; if ($hour < 10) { $hour = "0" . $hour; } } elsif ($conf->{timeoffset} =~ /-(\d+)/) { # We must remove some hours from the time $hour -= $1; $hour = $hour % 24; if ($hour < 10) { $hour = "0" . $hour; } } $image = "pic_v_".(int($hour/6)*6); $image = $conf->{$image}; $debug->("Image: $image"); $output{$hour} = "$percent%
\"$percent\"\n"; } html("{tablewidth}\">\n"); for ($b = 0; $b < 24; $b++) { if ($b < 10) { $a = "0" . $b; } else { $a = $b; } if (!defined($output{$a}) || $output{$a} eq "") { html(""); } else { html($output{$a}); } } html(""); for ($b = 0; $b < 24; $b++) { if ($now[2] == $b) { $tbgcolor = "\#AAAAAA"; } else { $tbgcolor = "\#CCCCCC"; } html(""); } html("
0%
$b
"); if($conf->{show_legend} == 1) { &legend(); } } sub activenicks { # The most active nicks (those who wrote most lines) my ($stats) = @_; headline(template_text('activenickstopic')); html("{tablewidth}\">"); html(""); if (scalar keys %{$users->{userpics}} > 0) { html(""); } html(""); my @active = sort { $stats->{lines}{$b} <=> $stats->{lines}{$a} } keys %{ $stats->{lines} }; my $nicks = scalar keys %{ $stats->{lines} }; if ($conf->{activenicks} > $nicks) { $conf->{activenicks} = $nicks; print "Note: There were fewer nicks in the logfile than your specificied there to be in most active nicks...\n"; } my ($nick, $visiblenick, $randomline, %hash); my $i = 1; for (my $c = 0; $c < $conf->{activenicks}; $c++) { $nick = $active[$c]; $visiblenick = $active[$c]; if (not defined $stats->{sayings}{$nick}) { $randomline = ""; } else { $randomline = htmlentities($stats->{sayings}{$nick}); } # Convert URLs and e-mail addys to links $randomline = replace_links($randomline); # Add a link to the nick if there is any if ($users->{userlinks}{$nick}) { $visiblenick = replace_links($users->{userlinks}{$nick}, $nick); } my $h = $conf->{hicell}; $h =~ s/^#//; $h = hex $h; my $h2 = $conf->{hicell2}; $h2 =~ s/^#//; $h2 = hex $h2; my $f_b = $h & 0xff; my $f_g = ($h & 0xff00) >> 8; my $f_r = ($h & 0xff0000) >> 16; my $t_b = $h2 & 0xff; my $t_g = ($h2 & 0xff00) >> 8; my $t_r = ($h2 & 0xff0000) >> 16; my $col_b = sprintf "%0.2x", abs int(((($t_b - $f_b) / $conf->{activenicks}) * +$c) + $f_b); my $col_g = sprintf "%0.2x", abs int(((($t_g - $f_g) / $conf->{activenicks}) * +$c) + $f_g); my $col_r = sprintf "%0.2x", abs int(((($t_r - $f_r) / $conf->{activenicks}) * +$c) + $f_r); html("" . ($conf->{show_linetime} ? "" : "") . ($conf->{show_time} ? "" : "") . ($conf->{show_words} ? "" : "") . ($conf->{show_wpl} ? "" : "") . ($conf->{show_cpl} ? "" : "") .""); if ($users->{userpics}{$nick}) { html(""); } html(""); $i++; } html("
 {tdtop}\">" . template_text('nick') . "{tdtop}\">" . template_text('numberlines') . "{tdtop}\">" . ($conf->{show_time} ? template_text('show_time')."{tdtop}\">" : "") . ($conf->{show_words} ? template_text('show_words')."{tdtop}\">" : "") . ($conf->{show_wpl} ? template_text('show_wpl')."{tdtop}\">" : "") . ($conf->{show_cpl} ? template_text('show_cpl')."{tdtop}\">" : "") . template_text('randquote') ."{tdtop}\">" . template_text('userpic') ."
{rankc}\" align=\"left\">"); my $line = $stats->{lines}{$nick}; my $w = $stats->{words}{$nick}; my $ch = $stats->{lengths}{$nick}; html("$i$visiblenick".user_linetimes($stats,$nick,$active[0])."$line".user_times($stats,$nick)."$w".sprintf("%.1f",$w/$line)."".sprintf("%.1f",$ch/$line).""); html("\"$randomline\"{imagepath}$users->{userpics}{$nick}\">

"); # Almost as active nicks ('These didn't make it to the top..') my $nickstoshow = $conf->{activenicks} + $conf->{activenicks2}; $hash{totalnicks} = $nicks - $nickstoshow; unless ($nickstoshow > $nicks) { html("
" . template_text('nottop') . ""); for (my $c = $conf->{activenicks}; $c < $nickstoshow; $c++) { unless ($c % 5) { unless ($c == $conf->{activenicks}) { html(""); } } html(""); } html("
{rankc}\" class=\"small\">"); my $nick = $active[$c]; my $lines = $stats->{lines}{$nick}; html("$nick ($lines)
"); } if($hash{totalnicks} > 0) { html("
" . template_text('totalnicks', %hash) . "
"); } } sub html { my $html = shift; print OUTPUT "$html\n"; } sub questions { # Persons who asked the most questions my ($stats) = @_; my %qpercent; foreach my $nick (sort keys %{ $stats->{questions} }) { if ($stats->{lines}{$nick} > 100) { $qpercent{$nick} = ($stats->{questions}{$nick} / $stats->{lines}{$nick}) * 100; $qpercent{$nick} =~ s/(\.\d)\d+/$1/; } } my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent; if (@question) { my %hash = ( nick => $question[0], per => $qpercent{$question[0]} ); my $text = template_text('question1', %hash); html("{hicell}\">$text"); if (@question >= 2) { my %hash = ( nick => $question[1], per => $qpercent{$question[1]} ); my $text = template_text('question2', %hash); html("
$text"); } html(""); } else { html("{hicell}\">" . template_text('question3') . ""); } } sub shoutpeople { # The ones who speak with exclamation points! my ($stats) = @_; my %spercent; foreach my $nick (sort keys %{ $stats->{shouts} }) { if ($stats->{lines}{$nick} > 100) { $spercent{$nick} = ($stats->{shouts}{$nick} / $stats->{lines}{$nick}) * 100; $spercent{$nick} =~ s/(\.\d)\d+/$1/; } } my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent; if (@shout) { my %hash = ( nick => $shout[0], per => $spercent{$shout[0]} ); my $text = template_text('shout1', %hash); html("{hicell}\">$text"); if (@shout >= 2) { my %hash = ( nick => $shout[1], per => $spercent{$shout[1]} ); my $text = template_text('shout2', %hash); html("
$text"); } html(""); } else { my $text = template_text('shout3'); html("{hicell}\">$text"); } } sub capspeople { # The ones who speak ALL CAPS. my ($stats) = @_; my %cpercent; foreach my $nick (sort keys %{ $stats->{allcaps} }) { if ($stats->{lines}{$nick} > 100) { $cpercent{$nick} = $stats->{allcaps}{$nick} / $stats->{lines}{$nick} * 100; $cpercent{$nick} =~ s/(\.\d)\d+/$1/; } } my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent; if (@caps) { my %hash = ( nick => $caps[0], per => $cpercent{$caps[0]}, line => htmlentities($stats->{allcaplines}{$caps[0]}) ); my $text = template_text('allcaps1', %hash); if($conf->{show_shoutline}) { my $exttext = template_text('allcapstext', %hash); html("{hicell}\">$text
$exttext
"); } else { html("{hicell}\">$text"); } if (@caps >= 2) { my %hash = ( nick => $caps[1], per => $cpercent{$caps[1]} ); my $text = template_text('allcaps2', %hash); html("
$text"); } html(""); } else { my $text = template_text('allcaps3'); html("{hicell}\">$text"); } } sub violent { # They attacked others my ($stats) = @_; my @aggressors; @aggressors = sort { $stats->{violence}{$b} <=> $stats->{violence}{$a} } keys %{ $stats->{violence} }; if(@aggressors) { my %hash = ( nick => $aggressors[0], attacks => $stats->{violence}{$aggressors[0]}, line => htmlentities($stats->{violencelines}{$aggressors[0]}) ); my $text = template_text('violent1', %hash); if($conf->{show_violentlines}) { my $exttext = template_text('violenttext', %hash); html("{hicell}\">$text
$exttext
"); } else { html("{hicell}\">$text"); } if (@aggressors >= 2) { my %hash = ( nick => $aggressors[1], attacks => $stats->{violence}{$aggressors[1]} ); my $text = template_text('violent2', %hash); html("
$text"); } html(""); } else { my $text = template_text('violent3'); html("{hicell}\">$text"); } # They got attacked my @victims; @victims = sort { $stats->{attacked}{$b} <=> $stats->{attacked}{$a} } keys %{ $stats->{attacked} }; if(@victims) { my %hash = ( nick => $victims[0], attacks => $stats->{attacked}{$victims[0]}, line => htmlentities($stats->{attackedlines}{$victims[0]}) ); my $text = template_text('attacked1', %hash); if($conf->{show_violentlines}) { my $exttext = template_text('attackedtext', %hash); html("{hicell}\">$text
$exttext
"); } else { html("{hicell}\">$text"); } if (@victims >= 2) { my %hash = ( nick => $victims[1], attacks => $stats->{attacked}{$victims[1]} ); my $text = template_text('attacked2', %hash); html("
$text"); } html(""); } } sub gotkicks { # The persons who got kicked the most my ($stats) = @_; my @gotkick = sort { $stats->{gotkicked}{$b} <=> $stats->{gotkicked}{$a} } keys %{ $stats->{gotkicked} }; if (@gotkick) { my %hash = ( nick => $gotkick[0], kicks => $stats->{gotkicked}{$gotkick[0]}, line => $stats->{kicklines}{$gotkick[0]} ); my $text = template_text('gotkick1', %hash); if ($conf->{show_kickline}) { my $exttext = template_text('kicktext', %hash); html("{hicell}\">$text
$exttext
"); } else { html("{hicell}\">$text"); } if (@gotkick >= 2) { my %hash = ( nick => $gotkick[1], kicks => $stats->{gotkicked}{$gotkick[1]} ); my $text = template_text('gotkick2', %hash); html("
$text"); } html(""); } } sub mostjoins { my ($stats) = @_; my @joins = sort { $stats->{joins}{$b} <=> $stats->{joins}{$a} } keys %{ $stats->{joins} }; if (@joins) { my %hash = ( nick => $joins[0], joins => $stats->{joins}{$joins[0]} ); my $text = template_text('joins', %hash); html("{hicell}\">$text"); } } sub mostwords { # The person who got words the most my ($stats) = @_; my @words = sort { $stats->{words}{$b} <=> $stats->{words}{$a} } keys %{ $stats->{words} }; if (@words) { my %hash = ( nick => $words[0], words => $stats->{words}{$words[0]} ); my $text = template_text('words1', %hash); html("{hicell}\">$text"); if (@words >= 2) { my %hash = ( oldnick => $words[0], nick => $words[1], words => $stats->{words}{$words[1]} ); my $text = template_text('words2', %hash); html("
$text"); } html(""); } else { my $text = template_text('kick3'); html("{hicell}\">$text"); } } sub mostkicks { # The person who got kicked the most my ($stats) = @_; my @kicked = sort { $stats->{kicked}{$b} <=> $stats->{kicked}{$a} } keys %{ $stats->{kicked} }; if (@kicked) { my %hash = ( nick => $kicked[0], kicked => $stats->{kicked}{$kicked[0]} ); my $text = template_text('kick1', %hash); html("{hicell}\">$text"); if (@kicked >= 2) { my %hash = ( oldnick => $kicked[0], nick => $kicked[1], kicked => $stats->{kicked}{$kicked[1]} ); my $text = template_text('kick2', %hash); html("
$text"); } html(""); } else { my $text = template_text('kick3'); html("{hicell}\">$text"); } } sub mostmonologues { # The person who had the most monologues (speaking to himself) my ($stats) = @_; my @monologue = sort { $stats->{monologues}{$b} <=> $stats->{monologues}{$a} } keys %{ $stats->{monologues} }; if (@monologue) { my %hash = ( nick => $monologue[0], monos => $stats->{monologues}{$monologue[0]} ); my $text = template_text('mono1', %hash); html("{hicell}\">$text"); if (@monologue >= 2) { my %hash = ( nick => $monologue[1], monos => $stats->{monologues}{$monologue[1]} ); my $text = template_text('mono2', %hash); html("
$text"); } html(""); } } sub linelengths { # The person(s) who wrote the longest lines my ($stats) = @_; my %len; foreach my $nick (sort keys %{ $stats->{lengths} }) { if ($stats->{lines}{$nick} > 100) { $len{$nick} = $stats->{lengths}{$nick} / $stats->{lines}{$nick}; $len{$nick} =~ s/(\.\d)\d+/$1/; } } my @len = sort { $len{$b} <=> $len{$a} } keys %len; my $all_lines; my $totallength; foreach my $nick (keys %{ $stats->{lines} }) { $all_lines += $stats->{lines}{$nick}; $totallength += $stats->{lengths}{$nick}; } my $totalaverage; if ($all_lines > 0) { $totalaverage = $totallength / $all_lines; $totalaverage =~ s/(\.\d)\d+/$1/; } if (@len) { my %hash = ( nick => $len[0], letters => $len{$len[0]} ); my $text = template_text('long1', %hash); html("{hicell}\">$text
"); if (@len >= 2) { %hash = ( avg => $totalaverage ); $text = template_text('long2', %hash); html("$text"); } } # The person(s) who wrote the shortest lines if (@len) { my %hash = ( nick => $len[$#len], letters => $len{$len[$#len]} ); my $text = template_text('short1', %hash); html("{hicell}\">$text
"); if (@len >= 2) { %hash = ( nick => $len[$#len - 1], letters => $len{$len[$#len - 1]} ); $text = template_text('short2', %hash); html("$text"); } } } sub mostfoul { my ($stats) = @_; my %spercent; foreach my $nick (sort keys %{ $stats->{foul} }) { if ($stats->{lines}{$nick} > 15) { $spercent{$nick} = $stats->{foul}{$nick} / $stats->{lines}{$nick} * 100; $spercent{$nick} =~ s/(\.\d)\d+/$1/; } } my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent; if (@foul) { my %hash = ( nick => $foul[0], per => $spercent{$foul[0]} ); my $text = template_text('foul1', %hash); html("{hicell}\">$text"); if (@foul >= 2) { my %hash = ( nick => $foul[1], per => $spercent{$foul[1]} ); my $text = template_text('foul2', %hash); html("
$text"); } html(""); } else { my $text = template_text('foul3'); html("{hicell}\">$text"); } } sub mostsad { my ($stats) = @_; my %spercent; foreach my $nick (sort keys %{ $stats->{frowns} }) { if ($stats->{lines}{$nick} > 100) { $spercent{$nick} = $stats->{frowns}{$nick} / $stats->{lines}{$nick} * 100; $spercent{$nick} =~ s/(\.\d)\d+/$1/; } } my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent; if (@sadface) { my %hash = ( nick => $sadface[0], per => $spercent{$sadface[0]} ); my $text = template_text('sad1', %hash); html("{hicell}\">$text"); if (@sadface >= 2) { my %hash = ( nick => $sadface[1], per => $spercent{$sadface[1]} ); my $text = template_text('sad2', %hash); html("
$text"); } html(""); } else { my $text = template_text('sad3'); html("{hicell}\">$text"); } } sub mostop { my ($stats) = @_; my @ops = sort { $stats->{gaveops}{$b} <=> $stats->{gaveops}{$a} } keys %{ $stats->{gaveops} }; my @deops = sort { $stats->{tookops}{$b} <=> $stats->{tookops}{$a} } keys %{ $stats->{tookops} }; if (@ops) { my %hash = ( nick => $ops[0], ops => $stats->{gaveops}{$ops[0]} ); my $text = template_text('mostop1', %hash); html("{hicell}\">$text"); if (@ops >= 2) { my %hash = ( nick => $ops[1], ops => $stats->{gaveops}{$ops[1]} ); my $text = template_text('mostop2', %hash); html("
$text"); } html(""); } else { my $text = template_text('mostop3'); html("{hicell}\">$text"); } if (@deops) { my %hash = ( nick => $deops[0], deops => $stats->{tookops}{$deops[0]} ); my $text = template_text('mostdeop1', %hash); html("{hicell}\">$text"); if (@deops >= 2) { my %hash = ( nick => $deops[1], deops => $stats->{tookops}{$deops[1]} ); my $text = template_text('mostdeop2', %hash); html("
$text"); } html(""); } else { my $text = template_text('mostdeop3'); html("{hicell}\">$text"); } } sub mostactions { # The person who did the most /me's my ($stats) = @_; my @actions = sort { $stats->{actions}{$b} <=> $stats->{actions}{$a} } keys %{ $stats->{actions} }; if (@actions) { my %hash = ( nick => $actions[0], actions => $stats->{actions}{$actions[0]}, line => htmlentities($stats->{actionlines}{$actions[0]}) ); my $text = template_text('action1', %hash); if($conf->{show_actionline}) { my $exttext = template_text('actiontext', %hash); html("{hicell}\">$text
$exttext
"); } else { html("{hicell}\">$text"); } if (@actions >= 2) { my %hash = ( nick => $actions[1], actions => $stats->{actions}{$actions[1]} ); my $text = template_text('action2', %hash); html("
$text"); } html(""); } else { my $text = template_text('action3'); html("{hicell}\">$text"); } } sub mostsmiles { # The person(s) who smiled the most :-) my ($stats) = @_; my %spercent; foreach my $nick (sort keys %{ $stats->{smiles} }) { if ($stats->{lines}{$nick} > 100) { $spercent{$nick} = $stats->{smiles}{$nick} / $stats->{lines}{$nick} * 100; $spercent{$nick} =~ s/(\.\d)\d+/$1/; } } my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent; if (@smiles) { my %hash = ( nick => $smiles[0], per => $spercent{$smiles[0]} ); my $text = template_text('smiles1', %hash); html("{hicell}\">$text"); if (@smiles >= 2) { my %hash = ( nick => $smiles[1], per => $spercent{$smiles[1]} ); my $text = template_text('smiles2', %hash); html("
$text"); } html(""); } else { my $text = template_text('smiles3'); html("{hicell}\">$text"); } } sub lasttopics { my ($stats) = @_; if ($stats->{topics}) { $debug->("Total number of topics: " . scalar @{ $stats->{topics} }); my %hash = ( total => scalar @{ $stats->{topics} } ); my $ltopic = $#{ $stats->{topics} }; my $tlimit = 0; $conf->{topichistory} -= 1; if ($ltopic > $conf->{topichistory}) { $tlimit = $ltopic - $conf->{topichistory}; } for (my $i = $ltopic; $i >= $tlimit; $i--) { my $topic = htmlentities($stats->{topics}[$i]{topic}); $topic = replace_links($stats->{topics}[$i]{topic}); # Strip off the quotes (') $topic =~ s/^\'(.*)\'$/$1/; my $nick = $stats->{topics}[$i]{nick}; my $hour = $stats->{topics}[$i]{hour}; my $min = $stats->{topics}[$i]{min}; html("{hicell}\">$topic"); html("{hicell}\">By $nick at $hour:$min"); } html("" . template_text('totaltopic', %hash) . ""); } else { html("{hicell}\">" . template_text('notopic') .""); } } sub template_text { # This function is for the homemade template system. It receives a name # of a template and a hash with the fields in the template to update to # its corresponding value my $template = shift; my %hash = @_; my $text; unless ($text = $T{$conf->{lang}}{$template}) { # Fall back to English if the language template doesn't exist if ($text = $T{EN}{$template}) { print "Note: There was no translation in $conf->{lang} for '$template' - falling back to English..\n"; } else { die("No such template '$template' in language file.\n"); } } $hash{channel} = $conf->{channel}; foreach my $key (sort keys %hash) { $text =~ s/\[:$key\]/$hash{$key}/; $text =~ s/ü/ü/go; $text =~ s/ö/ö/go; $text =~ s/ä/ä/go; $text =~ s/ß/ß/go; $text =~ s/å/å/go; $text =~ s/æ/æ/go; $text =~ s/ø/ø/go; } if ($text =~ /\[:.*?:.*?:\]/o) { $text =~ s/\[:(.*?):(.*?):\]/get_subst($1,$2,\%hash)/geo; } return $text; } sub mostusedword { # Lao the infamous word usage statistics my ($stats) = @_; my %usages; foreach my $word (keys %{ $stats->{wordcounts} }) { # Skip people's nicks. next if exists $stats->{lines}{$word}; $usages{$word} = $stats->{wordcounts}{$word}; } my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages; if (@popular) { &headline(template_text('mostwordstopic')); html("{tablewidth}\">"); html(""); html(""); html(""); my $count = 0; for(my $i = 0; $count < 10; $i++) { last unless $i < $#popular; # Skip nicks. It's far more efficient to do this here than when # @popular is created. next if is_ignored($popular[$i]); next if exists $stats->{lines}{find_alias($popular[$i])}; my $a = $count + 1; my $popular = htmlentities($popular[$i]); my $wordcount = $stats->{wordcounts}{$popular[$i]}; my $lastused = htmlentities($stats->{wordnicks}{$popular[$i]}); html(""); html(""); html(""); html(""); $count++; } html("
 {tdtop}\">" . template_text('word') . "{tdtop}\">" . template_text('numberuses') . "{tdtop}\">" . template_text('lastused') . "
{rankc}\">$a"); html("{hicell}\">$popular{hicell}\">$wordcount{hicell}\">$lastused
"); } } sub mostwordsperline { # The person who got words the most my ($stats) = @_; my %wpl = (); my ($numlines,$avg,$numwords); foreach my $n (keys %{ $stats->{words} }) { $wpl{$n} = sprintf("%.2f", $stats->{words}{$n}/$stats->{lines}{$n}); $numlines += $stats->{lines}{$n}; $numwords += $stats->{words}{$n}; } $avg = sprintf("%.2f", $numwords/$numlines); my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl; if (@wpl) { my %hash = ( nick => $wpl[0], wpl => $wpl{$wpl[0]} ); my $text = template_text('wpl1', %hash); html("{hicell}\">$text"); %hash = ( avg => $avg ); $text = template_text('wpl2', %hash); html("
$text"); html(""); } } sub mostreferencednicks { my ($stats) = @_; my (%usages); foreach my $word (sort keys %{ $stats->{wordcounts} }) { next unless exists $stats->{lines}{$word}; next if is_ignored($word); $usages{$word} = $stats->{wordcounts}{$word}; } my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages; if (@popular) { &headline(template_text('referencetopic')); html("{tablewidth}\">"); html(""); html(""); html(""); for(my $i = 0; $i < 5; $i++) { last unless $i < $#popular; my $a = $i + 1; my $popular = $popular[$i]; my $wordcount = $stats->{wordcounts}{$popular[$i]}; my $lastused = $stats->{wordnicks}{$popular[$i]}; html(""); html(""); html(""); html(""); } html("
 {tdtop}\">" . template_text('nick') . "{tdtop}\">" . template_text('numberuses') . "{tdtop}\">" . template_text('lastused') . "
{rankc}\">$a"); html("{hicell}\">$popular{hicell}\">$wordcount{hicell}\">$lastused
"); } } sub mosturls { my ($stats) = @_; my @sorturls = sort { $stats->{urlcounts}{$b} <=> $stats->{urlcounts}{$a} } keys %{ $stats->{urlcounts} }; if (@sorturls) { &headline(template_text('urlstopic')); html("{tablewidth}\">"); html(""); html(""); html(""); for(my $i = 0; $i < 5; $i++) { last unless $i < $#sorturls; my $a = $i + 1; my $sorturl = $sorturls[$i]; my $urlcount = $stats->{urlcounts}{$sorturls[$i]}; my $lastused = $stats->{urlnicks}{$sorturls[$i]}; if (length($sorturl) > 60) { $sorturl = substr($sorturl, 0, 60); } html(""); html(""); html(""); html(""); } html("
 {tdtop}\">" . template_text('url') . "{tdtop}\">" . template_text('numberuses') . "{tdtop}\">" . template_text('lastused') . "
{rankc}\">$a"); html("{hicell}\">$sorturl{hicell}\">$urlcount{hicell}\">$lastused
"); } } sub legend { html(""); html(""); html(""); html(""); html(""); html("
{pic_h_0}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 0-5{pic_h_6}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 6-11{pic_h_12}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 12-17{pic_h_18}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 18-23
\n"); } sub replace_links { # Sub to replace urls and e-mail addys to links my $str = shift; my $nick = shift; my ($url, $email); if ($nick) { if ($url = match_url($str)) { $str =~ s/(\Q$url\E)/$nick<\/a>/g; } if ($email = match_email($str)) { $str =~ s/(\Q$email\E)/$nick<\/a>/g; } } else { if ($url = match_url($str)) { $str =~ s/(\Q$url\E)/$1<\/a>/g; } if ($email = match_email($str)) { $str =~ s/(\Q$email\E)/$1<\/a>/g; } } return $str; } sub user_linetimes { my $stats = shift; my $nick = shift; my $top = shift; my $bar = ""; my $len = ($stats->{lines}{$nick} / $stats->{lines}{$top}) * 100; my $debuglen = 0; for (my $i = 0; $i <= 3; $i++) { next if not defined $stats->{line_times}{$nick}[$i]; my $w = int(($stats->{line_times}{$nick}[$i] / $stats->{lines}{$nick}) * $len); $debuglen += $w; if ($w) { my $pic = 'pic_h_'.(6*$i); $bar .= "{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\">"; } } $debug->("Length='$len', Sum='$debuglen'"); return "$bar $stats->{lines}{$nick}"; } sub user_times { my ($stats, $nick) = @_; my $bar = ""; for (my $i = 0; $i <= 3; $i++) { next if not defined $stats->{line_times}{$nick}[$i]; my $w = int(($stats->{line_times}{$nick}[$i] / $stats->{lines}{$nick}) * 40); if ($w) { my $pic = 'pic_h_'.(6*$i); $bar .= "{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\">"; } } return $bar; } 1;