package Pisg::HTMLGenerator;
# Copyright and license, as well as documentation(POD) for this module is
# found at the end of the file.
use strict;
$^W = 1;
sub new
{
my $type = shift;
my %args = @_;
my $self = {
cfg => $args{cfg},
debug => $args{debug},
stats => $args{stats},
users => $args{users},
tmps => $args{tmps}
};
# Import common functions in Pisg::Common
require Pisg::Common;
Pisg::Common->import();
bless($self, $type);
return $self;
}
sub create_html
{
# This subroutine calls all the subroutines which create their
# individual stats. The name of the functions is somewhat saying - if
# you don't understand it, most subs have a better explanation in the
# sub itself.
my $self = shift;
print "Now generating HTML($self->{cfg}->{outputfile})...\n"
unless ($self->{cfg}->{silent});
open (OUTPUT, "> $self->{cfg}->{outputfile}") or
die("$0: Unable to open outputfile($self->{cfg}->{outputfile}): $!\n");
if ($self->{cfg}->{show_time}) {
$self->{cfg}->{tablewidth} += 40;
}
if ($self->{cfg}->{show_words}) {
$self->{cfg}->{tablewidth} += 40;
}
if ($self->{cfg}->{show_wpl}) {
$self->{cfg}->{tablewidth} += 40;
}
if ($self->{cfg}->{show_cpl}) {
$self->{cfg}->{tablewidth} += 40;
}
$self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
$self->_htmlheader();
$self->_pageheader();
if ($self->{cfg}->{show_activetimes}) {
$self->_activetimes();
}
$self->_activenicks();
if ($self->{cfg}->{show_bignumbers}) {
$self->_headline($self->_template_text('bignumtopic'));
_html("
{cfg}->{tablewidth}\">\n"); # Needed for sections
$self->_questions();
$self->_shoutpeople();
$self->_capspeople();
$self->_violent();
$self->_mostsmiles();
$self->_mostsad();
$self->_linelengths();
$self->_mostwords();
$self->_mostwordsperline();
_html("
"); # Needed for sections
}
if ($self->{cfg}->{show_muw}) {
$self->_mostusedword();
}
if ($self->{cfg}->{show_mrn}) {
$self->_mostreferencednicks();
}
if ($self->{cfg}->{show_mru}) {
$self->_mosturls();
}
if ($self->{cfg}->{show_bignumbers}) {
$self->_headline($self->_template_text('othernumtopic'));
_html("{cfg}->{tablewidth}\">\n"); # Needed for sections
$self->_gotkicks();
$self->_mostkicks();
$self->_mostop();
$self->_mostvoice() if $self->{cfg}->{show_voice};
$self->_mostactions();
$self->_mostmonologues();
$self->_mostjoins();
$self->_mostfoul();
_html("
"); # Needed for sections
}
$self->_headline($self->_template_text('latesttopic'));
_html("{cfg}->{tablewidth}\">\n"); # Needed for sections
$self->_lasttopics();
_html("
"); # Needed for sections
my %hash = ( lines => $self->{stats}->{totallines} );
_html($self->_template_text('totallines', %hash) . "
");
$self->_htmlfooter();
close(OUTPUT);
}
sub _htmlheader
{
my $self = shift;
my $bgpic = "";
my %hash = (
network => $self->{cfg}->{network},
maintainer => $self->{cfg}->{maintainer},
days => $self->{stats}->{days},
nicks => scalar keys %{ $self->{stats}->{lines} }
);
my $title = $self->_template_text('pagetitle1', %hash);
if ($self->{cfg}->{bgpic}) {
$bgpic = " background=\"$self->{cfg}->{bgpic}\"";
}
print OUTPUT <
$title
HTML
_html("
$title");
_html("
");
_html($self->_template_text('pagetitle2', %hash) . " " . $self->get_time());
_html("
" . $self->_template_text('pagetitle3', %hash) . "
");
}
sub get_time
{
my $self = shift;
my ($tday, %hash);
my $month = $self->_template_text('month', %hash);
my $day = $self->_template_text('day', %hash);
my @month = split(" ", $month);
my @day = split(" ", $day);
# Get the Date from the users computer
my $timezone = $self->{cfg}->{timeoffset} * 3600;
my ($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
} 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;
}
return "$day[$wday] $mday $month[$mon] $year - $hour:$min:$sec";
}
sub _htmlfooter
{
my $self = shift;
print OUTPUT <
Stats generated by
pisg $self->{cfg}->{version}
pisg by
Morten Brix Pedersen and others
Stats generated in $self->{stats}->{processtime}
HTML
}
sub _headline
{
my $self = shift;
my ($title) = (@_);
print OUTPUT <