package Pisg::HTMLGenerator;
# $Id$
#
# Copyright and license, as well as documentation(POD) for this module is
# found at the end of the file.
use strict;
$^W = 1;
# test for Text::Iconv
my $has_iconv = 1;
eval 'use Text::Iconv';
$has_iconv = 0 if $@;
sub new
{
my $type = shift;
my %args = @_;
my $self = {
cfg => $args{cfg},
stats => $args{stats},
users => $args{users},
tmps => $args{tmps},
topactive => {},
};
# Import common functions in Pisg::Common
require Pisg::Common;
Pisg::Common->import();
bless($self, $type);
return $self;
}
sub create_output
{
# 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;
$self->{cfg}->{lang} = shift;
# save table width as multiplie files would just increase tablewidth
my $tablewidth_original = $self->{cfg}->{tablewidth};
# remove old iconv if it exist as it could mess up recode.
delete $self->{iconv} if $self->{iconv};
my $lang_charset = $self->{tmps}->{$self->{cfg}->{lang}}{lang_charset};
if($lang_charset and $lang_charset ne $self->{cfg}->{charset}) {
if($has_iconv) {
# convert from template charset to our
$self->{iconv} = Text::Iconv->new($lang_charset, $self->{cfg}->{charset});
} else {
print "Text::Iconv is not installed, skipping charset conversion of language templates\n"
unless ($self->{cfg}->{silent});
}
}
$self->_topactive();
if($self->{cfg}->{bignumbersthreshold} =~ /^sqrt/) {
$self->{cfg}->{bignumbersthreshold} = int(sqrt($self->{stats}->{topactive_lines}));
}
my $fname = $self->{cfg}->{outputfile};
$fname =~ s/\%t/$self->{cfg}->{outputtag}/g;
$fname =~ s/\%l/$self->{cfg}->{lang}/g;
print "Now generating HTML ($self->{cfg}->{lang}) in $fname...\n"
unless ($self->{cfg}->{silent});
open (OUTPUT, "> $fname") or
die("$0: Unable to open outputfile($fname): $!\n");
if ($self->{cfg}->{showlines}) {
$self->{cfg}->{tablewidth} += 40;
}
if ($self->{cfg}->{showtime}) {
$self->{cfg}->{tablewidth} += 40;
}
if ($self->{cfg}->{showlinetime}) {
$self->{cfg}->{tablewidth} += 100;
}
if ($self->{cfg}->{showwordtime}) {
$self->{cfg}->{tablewidth} += 100;
}
if ($self->{cfg}->{showwords}) {
$self->{cfg}->{tablewidth} += 40;
}
if ($self->{cfg}->{showwpl}) {
$self->{cfg}->{tablewidth} += 40;
}
if ($self->{cfg}->{showcpl}) {
$self->{cfg}->{tablewidth} += 40;
}
if ($self->{cfg}->{userpics}) {
$self->{cfg}->{tablewidth} += $self->{cfg}->{userpics} * ($self->{cfg}->{picwidth} || 60);
}
$self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
$self->_htmlheader();
$self->_pageheader()
if ($self->{cfg}->{pagehead} ne 'none');
if ($self->{cfg}->{dailyactivity}) {
$self->_activedays();
}
if ($self->{cfg}->{showactivetimes}) {
$self->_activetimes();
}
if ($self->{cfg}->{showactivenicks}) {
$self->_activenicks();
}
if ($self->{cfg}->{showmostactivebyhour}) {
$self->_mostactivebyhour();
}
if ($self->{cfg}->{showbignumbers}) {
$self->_headline($self->_template_text('bignumtopic'));
_html("
');
}
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';
$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 $stats_text = $self->_template_text('stats_gen_in', %hash);
_html( <
$stats_gen
$stats_text
HTML
_html( sprintf( qq(),
$self->{cfg}->{nfiles},
$self->{cfg}->{format},
$self->{cfg}->{lang},
$self->{cfg}->{langfile},
$self->{cfg}->{charset},
$self->{cfg}->{logcharset},
$self->{cfg}->{logcharsetfallback},
$self->{cfg}->{logprefix},
$self->{cfg}->{logsuffix},
$self->{cfg}->{nicktracking},
$self->{cfg}->{timeoffset}
));
if($self->{cfg}->{colorscheme} ne "none") {
_html( <
HTML
}
}
sub _headline
{
my $self = shift;
my ($title) = (@_);
_html( <