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},
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}->{pagehead} ne 'none');
if ($self->{cfg}->{show_activetimes}) {
$self->_activetimes();
}
$self->_activenicks();
if ($self->{cfg}->{show_bignumbers}) {
$self->_headline($self->_template_text('bignumtopic'));
_html("
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;
my %hash;
my $pisg_hp = $self->_template_text('pisghomepage');
$hash{pisg_url} = "
pisg";
my $author_hp = $self->_template_text('authorhomepage');
$hash{author_url} = "
Morten Brix Pedersen";
$hash{version} = $self->{cfg}->{version};
my $hours = $self->_template_text('hours');
my $mins = $self->_template_text('minutes');
my $secs = $self->_template_text('seconds');
my $and = $self->_template_text('and');
my $h = $self->{stats}->{processtime}{hours};
my $m = $self->{stats}->{processtime}{mins};
my $s = $self->{stats}->{processtime}{secs};
$hash{time} = "$h $hours $m $mins $and $s $secs";
my $stats_gen = $self->_template_text('stats_gen_by', %hash);
my $author_text = $self->_template_text('author', %hash);
my $stats_text = $self->_template_text('stats_gen_in', %hash);
print OUTPUT <
$stats_gen
$author_text
$stats_text
HTML
}
sub _headline
{
my $self = shift;
my ($title) = (@_);
print OUTPUT <