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; # test for Text::Iconv my $have_iconv = 1; eval 'use Text::Iconv'; $have_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(); my $lang_charset = $self->{tmps}->{lc($self->{cfg}->{lang})}{lang_charset}; if($lang_charset and $lang_charset ne $self->{cfg}->{charset}) { if($have_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}); } } 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->_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; print "Now generating HTML in $fname...\n" unless ($self->{cfg}->{silent}); open (OUTPUT, "> $fname") or die("$0: Unable to open outputfile($fname): $!\n"); 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("