HTMLGenerator.pm 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707
  1. package Pisg::HTMLGenerator;
  2. # $Id$
  3. #
  4. # Copyright and license, as well as documentation(POD) for this module is
  5. # found at the end of the file.
  6. use strict;
  7. use Encode ();
  8. use Pisg::Insights;
  9. $^W = 1;
  10. # test for Text::Iconv
  11. my $has_iconv = 1;
  12. eval 'use Text::Iconv';
  13. $has_iconv = 0 if $@;
  14. sub new
  15. {
  16. my $type = shift;
  17. my %args = @_;
  18. my $self = {
  19. cfg => $args{cfg},
  20. stats => $args{stats},
  21. users => $args{users},
  22. tmps => $args{tmps},
  23. topactive => {},
  24. };
  25. # Import common functions in Pisg::Common
  26. require Pisg::Common;
  27. Pisg::Common->import();
  28. bless($self, $type);
  29. return $self;
  30. }
  31. # The page is written to a temporary file and moved into place only when it is complete,
  32. # so an error part-way through can never leave a half-written page where the good one was.
  33. sub create_output
  34. {
  35. my ($self, $lang) = @_;
  36. my $ok = eval { $self->_create_output_inner($lang); 1 };
  37. my $err = $@;
  38. my ($tmp, $final) = @{$self}{qw(outfile_tmp outfile_final)};
  39. close(OUTPUT);
  40. if (defined $tmp and -e $tmp) {
  41. if ($ok) {
  42. rename($tmp, $final) or do { unlink($tmp); die("$0: Unable to write $final: $!\n"); };
  43. } else {
  44. unlink($tmp);
  45. }
  46. }
  47. delete @{$self}{qw(outfile_tmp outfile_final)};
  48. die $err unless $ok;
  49. }
  50. sub _create_output_inner
  51. {
  52. # This subroutine calls all the subroutines which create their
  53. # individual stats. The name of the functions is somewhat saying - if
  54. # you don't understand it, most subs have a better explanation in the
  55. # sub itself.
  56. my $self = shift;
  57. $self->{cfg}->{lang} = shift;
  58. # save table width as multiplie files would just increase tablewidth
  59. my $tablewidth_original = $self->{cfg}->{tablewidth};
  60. # remove old iconv if it exist as it could mess up recode.
  61. delete $self->{iconv} if $self->{iconv};
  62. my $lang_charset = $self->{tmps}->{$self->{cfg}->{lang}}{lang_charset};
  63. if($lang_charset and $lang_charset ne $self->{cfg}->{charset}) {
  64. if($has_iconv) {
  65. # convert from template charset to our
  66. $self->{iconv} = Text::Iconv->new($lang_charset, $self->{cfg}->{charset});
  67. } else {
  68. print "Text::Iconv is not installed, skipping charset conversion of language templates\n"
  69. unless ($self->{cfg}->{silent});
  70. }
  71. }
  72. $self->_topactive();
  73. if($self->{cfg}->{bignumbersthreshold} =~ /^sqrt/) {
  74. $self->{cfg}->{bignumbersthreshold} = int(sqrt($self->{stats}->{topactive_lines}));
  75. }
  76. my $fname = $self->{cfg}->{outputfile};
  77. $fname =~ s/\%t/$self->{cfg}->{outputtag}/g;
  78. $fname =~ s/\%l/$self->{cfg}->{lang}/g;
  79. print "Now generating HTML ($self->{cfg}->{lang}) in $fname...\n"
  80. unless ($self->{cfg}->{silent});
  81. $self->{outfile_final} = $fname;
  82. $self->{outfile_tmp} = "$fname.tmp$$";
  83. open (OUTPUT, "> $self->{outfile_tmp}") or
  84. die("$0: Unable to open outputfile($fname): $!\n");
  85. if ($self->{cfg}->{showlines}) {
  86. $self->{cfg}->{tablewidth} += 40;
  87. }
  88. if ($self->{cfg}->{showtime}) {
  89. $self->{cfg}->{tablewidth} += 40;
  90. }
  91. if ($self->{cfg}->{showlinetime}) {
  92. $self->{cfg}->{tablewidth} += 100;
  93. }
  94. if ($self->{cfg}->{showwordtime}) {
  95. $self->{cfg}->{tablewidth} += 100;
  96. }
  97. if ($self->{cfg}->{showwords}) {
  98. $self->{cfg}->{tablewidth} += 40;
  99. }
  100. if ($self->{cfg}->{showwpl}) {
  101. $self->{cfg}->{tablewidth} += 40;
  102. }
  103. if ($self->{cfg}->{showcpl}) {
  104. $self->{cfg}->{tablewidth} += 40;
  105. }
  106. if ($self->{cfg}->{userpics}) {
  107. $self->{cfg}->{tablewidth} += $self->{cfg}->{userpics} * ($self->{cfg}->{picwidth} || 60);
  108. }
  109. $self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
  110. $self->{card_open} = 0;
  111. $self->{nav} = [];
  112. $self->{ins_script_relmap} = 0;
  113. $self->_htmlheader();
  114. $self->_pageheader()
  115. if ($self->{cfg}->{pagehead} ne 'none');
  116. $self->_ins_safe('_insights_overview') if $self->{cfg}->{showoverview};
  117. if ($self->{cfg}->{dailyactivity}) {
  118. $self->_activedays();
  119. }
  120. if ($self->{cfg}->{showactivetimes}) {
  121. $self->_activetimes();
  122. }
  123. if ($self->{cfg}->{showactivenicks}) {
  124. $self->_activenicks();
  125. }
  126. $self->_ins_safe('_insights_relations') if $self->{cfg}->{showrelations};
  127. if ($self->{cfg}->{showmostactivebyhour}) {
  128. $self->_mostactivebyhour();
  129. }
  130. $self->_ins_safe('_insights_personalities') if $self->{cfg}->{showtimepersonalities};
  131. $self->_ins_safe('_insights_concentration') if $self->{cfg}->{showconcentration};
  132. $self->_ins_safe('_insights_signature') if $self->{cfg}->{showsignaturewords};
  133. if ($self->{cfg}->{showbignumbers}) {
  134. $self->_headline($self->_template_text('bignumtopic'), undef, undef, 'bignumtopic');
  135. _html("<table width=\"$self->{cfg}->{tablewidth}\">"); # Needed for sections
  136. $self->_questions();
  137. $self->_shoutpeople();
  138. $self->_capspeople();
  139. $self->_violent();
  140. $self->_mostsmiles();
  141. $self->_mostsad();
  142. $self->_linelengths();
  143. $self->_mostwords();
  144. $self->_mostwordsperline();
  145. _html("</table>"); # Needed for sections
  146. }
  147. if ($self->{cfg}->{showmostnicks}) {
  148. $self->_mostnicks();
  149. }
  150. if ($self->{cfg}->{showactivegenders}) {
  151. $self->_activegenders();
  152. }
  153. if ($self->{cfg}->{showmuw}) {
  154. $self->_mostusedword();
  155. }
  156. if ($self->{cfg}->{showmrn}) {
  157. $self->_mostreferencednicks();
  158. }
  159. if ($self->{cfg}->{showsmileys}) {
  160. $self->_smileys();
  161. }
  162. if ($self->{cfg}->{showkarma}) {
  163. $self->_karma();
  164. }
  165. if ($self->{cfg}->{showmru}) {
  166. $self->_mosturls();
  167. }
  168. if ($self->{cfg}->{showcharts}) {
  169. $self->_charts();
  170. }
  171. if ($self->{cfg}->{showbignumbers}) {
  172. $self->_headline($self->_template_text('othernumtopic'), undef, undef, 'othernumtopic');
  173. _html("<table width=\"$self->{cfg}->{tablewidth}\">"); # Needed for sections
  174. $self->_gotkicks();
  175. $self->_mostkicks();
  176. $self->_mostop() if $self->{cfg}->{showops};
  177. $self->_mosthalfop() if $self->{cfg}->{showhalfops};
  178. $self->_mostvoice() if $self->{cfg}->{showvoices};
  179. $self->_mostactions();
  180. $self->_mostmonologues();
  181. $self->_mostjoins();
  182. $self->_mostfoul();
  183. _html("</table>"); # Needed for sections
  184. }
  185. if ($self->{cfg}->{showtopics}) {
  186. $self->_headline($self->_template_text('latesttopic'), undef, undef, 'latesttopic');
  187. _html("<table width=\"$self->{cfg}->{tablewidth}\">"); # Needed for sections
  188. $self->_lasttopics();
  189. _html("</table>"); # Needed for sections
  190. }
  191. _html('</div>') if $self->{card_open};
  192. $self->{card_open} = 0;
  193. $self->_insights_scripts();
  194. my %hash = ( lines => $self->{stats}->{parsedlines} );
  195. _html('<div id="totallines">' . $self->_template_text('totallines', %hash) . '</div>');
  196. $self->_pagefooter()
  197. if ($self->{cfg}->{pagefoot} ne 'none');
  198. $self->_htmlfooter();
  199. close(OUTPUT);
  200. $self->_insert_navbar();
  201. $self->_update_channel_index();
  202. # restore tablewidth
  203. $self->{cfg}->{tablewidth} = $tablewidth_original;
  204. }
  205. # Keep a small JSON list of the channels found in the output directory, so a
  206. # landing page can offer a channel dropdown straight from pisg's own knowledge
  207. # (no scanning or scraping of the generated HTML). Each run updates only this
  208. # channel's entry, so running channels one at a time works too. Disable with
  209. # ChannelIndex="none".
  210. sub _update_channel_index
  211. {
  212. my $self = shift;
  213. my $name = $self->{cfg}->{channelindex};
  214. return if !defined $name or $name eq '' or lc($name) eq 'none';
  215. return unless eval { require JSON::PP; 1 };
  216. my $out = $self->{outfile_final} || $self->{cfg}->{outputfile};
  217. my ($dir, $file) = $out =~ m{^(.*)/([^/]+)$} ? ($1, $2) : ('.', $out);
  218. $dir = '/' if $dir eq '';
  219. my $path = "$dir/$name";
  220. # No utf8 layer: names come from the config as bytes and go back out as bytes.
  221. my $json = JSON::PP->new->canonical->pretty;
  222. my @channels;
  223. if (open(my $in, '<', $path)) {
  224. local $/;
  225. my $data = <$in>;
  226. close($in);
  227. my $old = eval { $json->decode($data) };
  228. @channels = @{ $old->{channels} }
  229. if ref $old eq 'HASH' and ref $old->{channels} eq 'ARRAY';
  230. }
  231. # Replace this channel's entry; forget pages that no longer exist.
  232. @channels = grep { ref $_ eq 'HASH' and defined $_->{file}
  233. and $_->{file} ne $file and -e "$dir/$_->{file}" } @channels;
  234. my @t = gmtime();
  235. push @channels, {
  236. name => $self->{cfg}->{channel},
  237. file => $file,
  238. network => $self->{cfg}->{network},
  239. updated => sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $t[5] + 1900, $t[4] + 1, @t[3, 2, 1, 0]),
  240. days => 0 + ($self->{stats}->{days} || 0),
  241. nicks => 0 + scalar(keys %{ $self->{stats}->{lines} || {} }),
  242. lines => 0 + ($self->{stats}->{parsedlines} || 0),
  243. %{ $self->_channel_index_extras },
  244. };
  245. @channels = sort { lc($a->{name}) cmp lc($b->{name}) } @channels;
  246. my $tmp = "$path.tmp$$";
  247. if (open(my $fh, '>', $tmp)) {
  248. print $fh $json->encode({ version => 1, channels => \@channels });
  249. close($fh);
  250. rename($tmp, $path) or unlink($tmp);
  251. } else {
  252. print STDERR "Warning: cannot write channel index $path: $!\n" unless $self->{cfg}->{silent};
  253. }
  254. }
  255. # A few numbers per channel for the landing page, which shows the statistics of the statistics:
  256. # what the channel is busy with hour by hour, how the last weeks went, who talks most.
  257. sub _channel_index_extras
  258. {
  259. my $self = shift;
  260. my $st = $self->{stats};
  261. my %x;
  262. my $sum = sub { my $t = 0; $t += $_ for values %{ $_[0] || {} }; return $t; };
  263. $x{words} = 0 + $sum->($st->{words});
  264. $x{questions} = 0 + $sum->($st->{questions});
  265. $x{joins} = 0 + $sum->($st->{joins});
  266. $x{links} = 0 + $sum->($st->{urlcounts});
  267. $x{hours} = [ map { 0 + ($st->{times}{ sprintf('%02d', $_) } || 0) } 0 .. 23 ];
  268. # Lines on each of the last 30 days of the log (days are counted as pisg counts them everywhere).
  269. my $dl = $st->{day_lines} || [];
  270. my $last = $#$dl;
  271. my $first = $last - 29; $first = 1 if $first < 1;
  272. $x{recent} = [ map { 0 + ($dl->[$_] || 0) } $first .. $last ] if $last >= 1;
  273. # Top talkers, bots left out. Names go out as valid UTF-8 whatever the log's charset was.
  274. my @top;
  275. my $humans = eval { $self->_ins_humans } || [];
  276. for my $n (@$humans[0 .. ($#$humans > 4 ? 4 : $#$humans)]) {
  277. next unless defined $n;
  278. my $clean = Encode::encode('UTF-8', Encode::decode('UTF-8', $n, Encode::FB_DEFAULT | Encode::LEAVE_SRC));
  279. push @top, { nick => $clean, lines => 0 + ($st->{lines}{$n} || 0) };
  280. }
  281. $x{top} = \@top;
  282. return \%x;
  283. }
  284. sub _htmlheader
  285. {
  286. my $self = shift;
  287. my %hash = (
  288. network => $self->{cfg}->{network},
  289. maintainer => $self->{cfg}->{maintainer},
  290. days => $self->{stats}->{days},
  291. nicks => scalar keys %{ $self->{stats}->{lines} }
  292. );
  293. my $CSS;
  294. if($self->{cfg}->{colorscheme} =~ /([^\/.]+)\.[^\/]+$/) { # use external CSS file
  295. $CSS = "<link rel=\"stylesheet\" type=\"text/css\" title=\"$1\" href=\"$self->{cfg}->{colorscheme}\" />";
  296. } elsif($self->{cfg}->{colorscheme} ne "none") { # read the chosen CSS file
  297. my $css_file = $self->{cfg}->{cssdir} . $self->{cfg}->{colorscheme} . ".css";
  298. open(FILE, $css_file) or open (FILE, $self->{cfg}->{search_path} . "/$css_file") or die("$0: Unable to open stylesheet $css_file: $!\n");
  299. {
  300. local $/; # enable "slurp" mode
  301. $CSS = "<style type=\"text/css\" title=\"$self->{cfg}->{colorscheme}\">\n". <FILE>. "</style>";
  302. $CSS =~ s/\/\*/\/\* <!--/g;
  303. $CSS =~ s/\*\//--> \*\//g;
  304. }
  305. close FILE;
  306. }
  307. # use alternate CSS file
  308. if($self->{cfg}->{altcolorscheme} ne "none" and $self->{cfg}->{altcolorscheme} =~ /[^\w]/) {
  309. foreach (split /\s+/, $self->{cfg}->{altcolorscheme}) {
  310. /([^\/.]+)\.[^\/]+$/;
  311. $CSS .= "\n<link rel=\"alternate stylesheet\" type=\"text/css\" title=\"$1\" href=\"$_\" />";
  312. }
  313. }
  314. # Styles for the newer sections, so any theme (even a 2003 one) shows them decently;
  315. # a theme that styles them comes later and wins.
  316. if ($self->{cfg}->{colorscheme} ne "none") {
  317. my $base = $self->_ins_basecss;
  318. $CSS = "<style type=\"text/css\" id=\"pisg-base\">\n$base</style>\n" . $CSS if length $base;
  319. }
  320. my $title = $self->_template_text('pagetitle1', %hash);
  321. if($self->{cfg}->{colorscheme} ne "none") {
  322. _html( <<HTML );
  323. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  324. <html xmlns="http://www.w3.org/1999/xhtml">
  325. <head>
  326. <meta http-equiv="Content-Type" content="text/html; charset=$self->{cfg}->{charset}" />
  327. <meta name="viewport" content="width=device-width, initial-scale=1" />
  328. <title>$title</title>
  329. $CSS
  330. </head>
  331. <body>
  332. <div align="center">
  333. HTML
  334. }
  335. # Optional way back to the landing page (option HomeLink): a relative page or an http(s) address.
  336. my $home = $self->{cfg}->{homelink};
  337. if (defined $home and $home =~ m{^(?:[\w.\-/]+|https?://[^\s"'<>]+)$} and lc($home) ne 'none' and $self->{cfg}->{colorscheme} ne 'none') {
  338. _html('<p class="homebar"><a class="homebtn" id="homebtn" href="' . $home . '"><span aria-hidden="true">&larr;</span> '
  339. . $self->_template_text('home_label') . '</a></p>');
  340. }
  341. _html('<h1 class="title" id="pagetitle1">' . $title . '</h1>');
  342. _html('<p class="subtitle"><span id="pagetitle2">' . $self->_template_text('pagetitle2', %hash) . ' ' . $self->get_time() . '</span><br />');
  343. _html('<span id="pagetitle3">' . $self->_template_text('pagetitle3', %hash) . '</span></p>');
  344. $self->_nav_marker;
  345. }
  346. sub get_time
  347. {
  348. my $self = shift;
  349. my ($tday, %hash);
  350. my $month = $self->_template_text('month', %hash);
  351. my $day = $self->_template_text('day', %hash);
  352. my @month = split(" ", $month);
  353. my @day = split(" ", $day);
  354. # Get the Date from the users computer
  355. my $timezone = $self->{cfg}->{timeoffset} * 3600;
  356. my ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+$timezone);
  357. $year += 1900; # Y2K Patch
  358. $min =~ s/^(.)$/0$1/; # Fixes the display of mins/secs below
  359. $sec =~ s/^(.)$/0$1/; # it displays 03 instead of 3
  360. if ($hour > '23') { # Checks to see if it Midnight
  361. $hour = 12; # Makes it display the hour 12
  362. $tday = "AM"; # Display AM
  363. } elsif($hour > '12') { # Get rid of the Military time and
  364. $hour -= 12; # put it into normal time
  365. $tday = "PM"; # If past Noon and before Midnight set
  366. } else {
  367. $tday = "AM"; # If it's past Midnight and before Noon
  368. } # set the time as AM
  369. # Use 24 hours pr. day
  370. if ($tday eq "PM" && $hour < '12') {
  371. $hour += 12;
  372. }
  373. return "$day[$wday] $mday $month[$mon] $year - $hour:$min:$sec";
  374. }
  375. sub _htmlfooter
  376. {
  377. my $self = shift;
  378. my %hash;
  379. my $pisg_hp = $self->_template_text('pisghomepage');
  380. $hash{pisg_url} = '<a href="https://pisg.github.io/" title="' . $pisg_hp . '" class="background">pisg</a>';
  381. $hash{version} = $self->{cfg}->{version};
  382. my $hours = $self->_template_text('hours');
  383. my $mins = $self->_template_text('minutes');
  384. my $secs = $self->_template_text('seconds');
  385. my $and = $self->_template_text('and');
  386. my $h = $self->{stats}->{processtime}{hours};
  387. my $m = $self->{stats}->{processtime}{mins};
  388. my $s = $self->{stats}->{processtime}{secs};
  389. $hash{time} = "$h $hours $m $mins $and $s $secs";
  390. my $stats_gen = $self->_template_text('stats_gen_by', %hash);
  391. my $stats_text = $self->_template_text('stats_gen_in', %hash);
  392. _html( <<HTML );
  393. <div id="footer" class="small">
  394. <div id="stats_gen">$stats_gen</div>
  395. <div id="stats_text">$stats_text</div>
  396. </div>
  397. HTML
  398. _html( sprintf( qq(<!-- NFiles = "%s"; Format = "%s"; Lang = "%s"; LangFile = "%s"; Charset = "%s"; LogCharset = "%s"; LogCharsetFallback = "%s"; LogPrefix = "%s"; LogSuffix = "%s"; NickTracking = "%s"; TimeOffset = "%s" -->),
  399. $self->{cfg}->{nfiles},
  400. $self->{cfg}->{format},
  401. $self->{cfg}->{lang},
  402. $self->{cfg}->{langfile},
  403. $self->{cfg}->{charset},
  404. $self->{cfg}->{logcharset},
  405. $self->{cfg}->{logcharsetfallback},
  406. $self->{cfg}->{logprefix},
  407. $self->{cfg}->{logsuffix},
  408. $self->{cfg}->{nicktracking},
  409. $self->{cfg}->{timeoffset}
  410. ));
  411. if($self->{cfg}->{colorscheme} ne "none") {
  412. _html( <<HTML );
  413. </div>
  414. </body>
  415. </html>
  416. HTML
  417. }
  418. }
  419. sub _headline
  420. {
  421. my $self = shift;
  422. my ($title, $id, $label, $key) = (@_);
  423. # Wrap each section in a <div class="card"> so themes can box sections up.
  424. # Themes that don't style .card render exactly as before. The id is what the
  425. # navbar links to.
  426. $id = $self->_nav_register($title, $id, $label);
  427. _html('</div>') if $self->{card_open};
  428. _html('<div class="card' . ($self->_card_is_half($key) ? ' half' : '') . '" id="' . $id . '">');
  429. $self->{card_open} = 1;
  430. _html( <<HTML );
  431. <br />
  432. <table width="$self->{cfg}->{headwidth}" cellpadding="1" cellspacing="0" border="0">
  433. <tr>
  434. <td class="headlinebg">
  435. <table width="100%" cellpadding="2" cellspacing="0" border="0">
  436. <tr>
  437. <td class="headtext">$title</td>
  438. </tr>
  439. </table>
  440. </td>
  441. </tr>
  442. </table>
  443. HTML
  444. }
  445. sub _pageheader
  446. {
  447. my $self = shift;
  448. unless(open(PAGEHEAD, $self->{cfg}->{pagehead})) {
  449. warn("$0: Unable to open $self->{cfg}->{pagehead} for reading: $!\n");
  450. return;
  451. }
  452. while (<PAGEHEAD>) {
  453. chomp;
  454. _html($_);
  455. }
  456. close(PAGEHEAD);
  457. }
  458. sub _pagefooter
  459. {
  460. my $self = shift;
  461. unless(open(PAGEFOOT, $self->{cfg}->{pagefoot})) {
  462. warn("$0: Unable to open $self->{cfg}->{pagefoot} for reading: $!\n");
  463. return;
  464. }
  465. while (<PAGEFOOT>) {
  466. chomp;
  467. _html($_);
  468. }
  469. close(PAGEFOOT);
  470. }
  471. sub _activedays
  472. {
  473. # The most actives days on the channel
  474. my $self = shift;
  475. my $days = $self->{stats}->{days};
  476. my $ndays = $self->{cfg}->{dailyactivity};
  477. my $highest_value = 1;
  478. for (my $day = $days; $day > $days - $ndays ; $day--) {
  479. if (defined($self->{stats}->{day_lines}->[$day])) {
  480. if ($self->{stats}->{day_lines}->[$day] > $highest_value) {
  481. $highest_value = $self->{stats}->{day_lines}->[$day];
  482. }
  483. } else {
  484. #there are only $days - $day days :)
  485. $ndays = $days - $day;
  486. last;
  487. }
  488. }
  489. my %hash = (
  490. n => $ndays
  491. );
  492. $self->_headline($self->_template_text('dailyactivitytopic', %hash), undef, undef, 'dailyactivitytopic');
  493. _html("<table border=\"0\"><tr>");
  494. my $peak_done = 0;
  495. for (my $day = $days - $ndays + 1; $day <= $days ; $day++) {
  496. my $lines = $self->{stats}->{day_lines}[$day];
  497. my $pk = ($lines == $highest_value && !$peak_done++) ? ' pk' : ''; # only the busiest day keeps its number
  498. _html("<td align=\"center\" valign=\"bottom\" class=\"asmall\"><span class=\"v$pk\">$lines</span><br />");
  499. for (my $time = 4; $time >= 0; $time--) {
  500. if (defined($self->{stats}->{day_times}[$day][$time])) {
  501. my $size = int(($self->{stats}->{day_times}[$day][$time] / $highest_value) * 130);
  502. my $image = "pic_v_".$time*6;
  503. $image = $self->{cfg}->{$image};
  504. _html("<img id=\"$image\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  505. \" width=\"15\" height=\"$size\" alt=\"$self->{stats}->{day_times}[$day][$time]\" title=\"$self->{stats}->{day_times}[$day][$time]\" /><br />") if $size;
  506. }
  507. }
  508. _html("</td>");
  509. }
  510. _html("</tr><tr>");
  511. for (my $day = $ndays - 1; $day >= 0 ; $day--) {
  512. my $skip = ($day % 5 == 0) ? '' : ' skip'; # label every 5th day only
  513. _html("<td class=\"rankc10center$skip\" align=\"center\">$day</td>");
  514. }
  515. _html("</tr></table>");
  516. if($self->{cfg}->{showlegend} == 1) {
  517. $self->_legend();
  518. }
  519. }
  520. sub _activetimes
  521. {
  522. # The most actives times on the channel
  523. my $self = shift;
  524. my (%output);
  525. $self->_headline($self->_template_text('activetimestopic'), undef, undef, 'activetimestopic');
  526. my @toptime = sort { $self->{stats}->{times}{$b} <=> $self->{stats}->{times}{$a} } keys %{ $self->{stats}->{times} };
  527. my $highest_value = $self->{stats}->{times}{$toptime[0]};
  528. my $peak_done = 0;
  529. for my $hour (sort keys %{ $self->{stats}->{times} }) {
  530. my $size = int(($self->{stats}->{times}{$hour} / $highest_value) * 110);
  531. my $percent = sprintf("%.1f", ($self->{stats}->{times}{$hour} / $self->{stats}->{parsedlines}) * 100);
  532. my $lines_per_hour = $self->{stats}->{times}{$hour};
  533. my $pk = ($lines_per_hour == $highest_value && !$peak_done++) ? ' pk' : ''; # only the peak hour keeps its label
  534. my $image = "pic_v_".(int($hour/6)*6);
  535. $image = $self->{cfg}->{$image};
  536. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\"><span class=\"v$pk\">$percent%</span><br /><img id=\"$image\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  537. \" width=\"15\" height=\"$size\" alt=\"$lines_per_hour\" title=\"$lines_per_hour\"/></td>" if $size;
  538. }
  539. _html("<table border=\"0\"><tr>");
  540. for ($b = 0; $b < 24; $b++) {
  541. $a = sprintf("%02d", $b);
  542. if (!defined($output{$a})) {
  543. _html("<td align=\"center\" valign=\"bottom\" class=\"asmall\"><span class=\"v\">0%</span></td>");
  544. } else {
  545. _html($output{$a});
  546. }
  547. }
  548. _html("</tr><tr>");
  549. # Remove leading zero
  550. $toptime[0] =~ s/^0//;
  551. for ($b = 0; $b < 24; $b++) {
  552. # Highlight the top time
  553. my $class = $toptime[0] == $b ? 'hirankc10center' : 'rankc10center';
  554. _html("<td class=\"$class hr\" align=\"center\">$b</td>");
  555. }
  556. _html("</tr></table>");
  557. if($self->{cfg}->{showlegend} == 1) {
  558. $self->_legend();
  559. }
  560. }
  561. sub _activenicks
  562. {
  563. # The most active nicks (those who wrote most lines)
  564. my $self = shift;
  565. $self->_headline($self->_template_text('activenickstopic'), undef, undef, 'activenickstopic');
  566. my $output = "";
  567. $output .= "<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>";
  568. $output .= "<td>&nbsp;</td>";
  569. $output .= "<td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>";
  570. $output .= "<td class=\"tdtop\"><b>" . $self->_template_text('numberlines') . "</b></td>" if ($self->{cfg}->{showlines});
  571. $output .= "<td class=\"tdtop\"><b>" . $self->_template_text('show_time') . "</b></td>" if ($self->{cfg}->{showtime});
  572. $output .= "<td class=\"tdtop\"><b>" . $self->_template_text('show_words') . "</b></td>" if ($self->{cfg}->{showwords});
  573. $output .= "<td class=\"tdtop\"><b>" . $self->_template_text('show_wpl') . "</b></td>" if ($self->{cfg}->{showwpl});
  574. $output .= "<td class=\"tdtop\"><b>" . $self->_template_text('show_cpl') . "</b></td>" if ($self->{cfg}->{showcpl});
  575. $output .= "<td class=\"tdtop\"><b>" . $self->_template_text('show_lastseen') . "</b></td>" if ($self->{cfg}->{showlastseen});
  576. $output .= "<td class=\"tdtop\"><b>" . $self->_template_text('randquote') . "</b></td>" if ($self->{cfg}->{showrandquote});
  577. $output .= "\n";
  578. my @active;
  579. my $nicks;
  580. if ($self->{cfg}->{sortbywords}) {
  581. @active = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} } keys %{ $self->{stats}->{words} };
  582. $nicks = scalar keys %{ $self->{stats}->{words} };
  583. } else {
  584. @active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} } keys %{ $self->{stats}->{lines} };
  585. $nicks = scalar keys %{ $self->{stats}->{lines} };
  586. }
  587. if ($self->{cfg}->{activenicks} > $nicks) { $self->{cfg}->{activenicks} = $nicks; }
  588. for (my $c = 0; $c < $self->{cfg}->{activenicks}; $c++) {
  589. last unless $self->{cfg}->{userpics};
  590. my $nick = $active[$c];
  591. if ($self->{users}->{userpics}{$nick} or $self->{cfg}->{defaultpic}) {
  592. $output .= "<td class=\"tdtop\"";
  593. $output .= " colspan=\"$self->{cfg}->{userpics}\"" if ($self->{cfg}->{userpics} > 1);
  594. $output .= "><b>" . $self->_template_text('userpic') ."</b></td>";
  595. last;
  596. }
  597. }
  598. $output .= "\n</tr>";
  599. _html($output);
  600. undef $output;
  601. for (my $i = 0; $i < $self->{cfg}->{activenicks}; $i++) {
  602. my $c = $i + 1;
  603. my $nick = $active[$i];
  604. my $visiblenick;
  605. my $randomline;
  606. if (not defined $self->{stats}->{sayings}{$nick}) {
  607. if ($self->{stats}->{actions}{$nick}) {
  608. $randomline = $self->{stats}->{actionlines}{$nick};
  609. } else {
  610. $randomline = "";
  611. }
  612. } else {
  613. $randomline = $self->{stats}->{sayings}{$nick};
  614. }
  615. if ($randomline) {
  616. $randomline = $self->_format_line($randomline);
  617. }
  618. # Add a link to the nick if there is any and quote nick
  619. if ($self->{users}->{userlinks}{$nick}) {
  620. $visiblenick = $self->_format_word($self->{users}->{userlinks}{$nick}, $nick);
  621. } else {
  622. $visiblenick = $self->_format_word($nick);
  623. }
  624. my $style = $self->generate_colors($c);
  625. my $class = 'rankc';
  626. if ($c == 1) {
  627. $class = 'hirankc';
  628. }
  629. my $lastseen;
  630. if ($self->{cfg}->{showlastseen}) {
  631. $lastseen = $self->{stats}->{days} - $self->{stats}->{lastvisited}{$nick};
  632. my %hash = ( days => $lastseen );
  633. if ($lastseen == 0) {
  634. $lastseen = $self->_template_text('today');
  635. } elsif ($lastseen == 1) {
  636. $lastseen = $self->_template_text('lastseen1', %hash);
  637. } else {
  638. $lastseen = $self->_template_text('lastseen2', %hash);
  639. }
  640. }
  641. _html("<tr><td class=\"$class\" align=\"left\">$c</td>");
  642. my $line = $self->{stats}->{lines}{$nick};
  643. my $w = $self->{stats}->{words}{$nick} ? $self->{stats}->{words}{$nick} : 0;
  644. my $ch = $self->{stats}->{lengths}{$nick};
  645. my $sex = $self->{users}->{sex}{$nick};
  646. my $output = '';
  647. $output .= "<td $style>";
  648. # Hilight nick with gendercolors
  649. if ($sex and $sex eq 'm') {
  650. $output .= '<span class="male">';
  651. } elsif ($sex and $sex eq 'f') {
  652. $output .= '<span class="female">';
  653. } elsif ($sex and $sex eq 'b') {
  654. $output .= '<span class="bot">';
  655. } else {
  656. $output .= '<span>';
  657. }
  658. $output .= $visiblenick;
  659. $output .= '</span></td>';
  660. if ($self->{cfg}->{showlines}) {
  661. if ($self->{cfg}->{showlinetime}) {
  662. $output .= "<td $style nowrap=\"nowrap\">" . $self->_user_linetimes($nick,$active[0]) . "</td>";
  663. } else {
  664. $output .= "<td $style>$line</td>";
  665. }
  666. }
  667. $output .= "<td $style>" . $self->_user_times($nick) . "</td>" if ($self->{cfg}->{showtime});
  668. if ($self->{cfg}->{showwords}) {
  669. if ($self->{cfg}->{showwordtime}) {
  670. $output .= "<td $style nowrap=\"nowrap\">" . $self->_user_wordtimes($nick,$active[0]) . "</td>";
  671. } else {
  672. $output .= "<td $style>$w</td>";
  673. }
  674. }
  675. $output .= "<td $style>" . sprintf("%.1f", $w/$line) . "</td>" if ($self->{cfg}->{showwpl});
  676. $output .= "<td $style>" . sprintf("%.1f", $ch/$line) . "</td>" if ($self->{cfg}->{showcpl});
  677. $output .= "<td $style class=\"lastseen\">$lastseen</td>" if ($self->{cfg}->{showlastseen});
  678. $output .= "<td $style class=\"quote\">\"$randomline\"</td>" if ($self->{cfg}->{showrandquote});
  679. _html($output);
  680. undef $output;
  681. if ($self->{cfg}->{userpics} && $i % $self->{cfg}->{userpics} == 0) {
  682. for my $ii (0 .. $self->{cfg}->{userpics} - 1) {
  683. last if $i + $ii >= $self->{cfg}->{activenicks};
  684. $self->_user_pic($active[$i + $ii], $style);
  685. }
  686. }
  687. _html("</tr>");
  688. }
  689. _html("</table><br />");
  690. # Almost as active nicks ('These didn't make it to the top..')
  691. my $toshow = $self->{cfg}->{activenicks2} - $self->{cfg}->{activenicks};
  692. my $remain = $self->{cfg}->{activenicks} + $toshow;
  693. unless ($toshow > $nicks) {
  694. $remain = $self->{cfg}->{activenicks} + $self->{cfg}->{activenicks2};
  695. if ($remain > $nicks) {
  696. $remain = $nicks;
  697. }
  698. if ($self->{cfg}->{activenicks} < $remain) {
  699. _html("<br /><b><i>" . $self->_template_text('nottop') . "</i></b><table><tr>");
  700. for (my $i = $self->{cfg}->{activenicks}; $i < $remain; $i++) {
  701. my $visiblenick;
  702. my $nick = $active[$i];
  703. if ($i != $self->{cfg}->{activenicks} and ($i - $self->{cfg}->{activenicks}) % 5 == 0) {
  704. _html("</tr><tr>");
  705. }
  706. my $items;
  707. if ($self->{users}->{userlinks}{$nick}) {
  708. $visiblenick = $self->_format_word($self->{users}->{userlinks}{$nick}, $nick);
  709. } else {
  710. $visiblenick = $self->_format_word($nick);
  711. }
  712. if ($self->{cfg}->{sortbywords}) {
  713. $items = $self->{stats}->{words}{$active[$i]};
  714. } else {
  715. $items = $self->{stats}->{lines}{$active[$i]};
  716. }
  717. my $sex = $self->{users}->{sex}{$active[$i]};
  718. my $output = "";
  719. $output .= "<td class=\"rankc10\">";
  720. if ($sex and $sex eq 'm') {
  721. $output .= "<span class=\"male\">";
  722. } elsif ($sex and $sex eq 'f') {
  723. $output .= "<span class=\"female\">";
  724. } elsif ($sex and $sex eq 'b') {
  725. $output .= "<span class=\"bot\">";
  726. } else {
  727. $output .= "<span>";
  728. }
  729. $output .= "$visiblenick ($items)";
  730. $output .= "</span></td>";
  731. _html($output);
  732. undef $output;
  733. }
  734. _html("</tr></table>");
  735. }
  736. }
  737. my %hash;
  738. $hash{totalnicks} = $nicks - $remain;
  739. if ($hash{totalnicks} > 0) {
  740. _html("<br /><b>" . $self->_template_text('totalnicks', %hash) . "</b><br />");
  741. }
  742. }
  743. sub generate_colors
  744. {
  745. my $self = shift;
  746. my $c = shift;
  747. # if hicell or hicell2 is "", do not print the class as it could mess up the gendercode
  748. return "" if not (length $self->{cfg}->{hicell} and length $self->{cfg}->{hicell2});
  749. my $h = $self->{cfg}->{hicell} or return "class=\"hicell\"";
  750. $h =~ s/^#//;
  751. $h = hex $h;
  752. my $h2 = $self->{cfg}->{hicell2} or return "class=\"hicell\"";
  753. $h2 =~ s/^#//;
  754. $h2 = hex $h2;
  755. my $f_b = $h & 0xff;
  756. my $f_g = ($h & 0xff00) >> 8;
  757. my $f_r = ($h & 0xff0000) >> 16;
  758. my $t_b = $h2 & 0xff;
  759. my $t_g = ($h2 & 0xff00) >> 8;
  760. my $t_r = ($h2 & 0xff0000) >> 16;
  761. my $blue = sprintf "%0.2x", abs int(((($t_b - $f_b) / $self->{cfg}->{activenicks}) * +$c) + $f_b);
  762. my $green = sprintf "%0.2x", abs int(((($t_g - $f_g) / $self->{cfg}->{activenicks}) * +$c) + $f_g);
  763. my $red = sprintf "%0.2x", abs int(((($t_r - $f_r) / $self->{cfg}->{activenicks}) * +$c) + $f_r);
  764. return "style=\"background-color: #$red$green$blue\"";
  765. }
  766. sub _html
  767. {
  768. my $html = shift;
  769. print OUTPUT "$html\n" or die "Could not write to disk: $!\n";
  770. }
  771. sub _questions
  772. {
  773. # Persons who asked the most questions
  774. my $self = shift;
  775. my %qpercent;
  776. foreach my $nick (sort keys %{ $self->{stats}->{questions} }) {
  777. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  778. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  779. $qpercent{$nick} = sprintf("%.1f", ($self->{stats}->{questions}{$nick} / $self->{stats}->{lines}{$nick}) * 100);
  780. }
  781. }
  782. }
  783. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  784. if (@question) {
  785. my %hash = (
  786. nick => $question[0],
  787. per => $qpercent{$question[0]}
  788. );
  789. my $text = $self->_template_text('question1', %hash);
  790. _html("<tr><td class=\"hicell\">$text");
  791. if (@question >= 2) {
  792. my %hash = (
  793. nick => $question[1],
  794. per => $qpercent{$question[1]}
  795. );
  796. my $text = $self->_template_text('question2', %hash);
  797. _html("<br /><span class=\"small\">$text</span>");
  798. }
  799. _html("</td></tr>");
  800. } else {
  801. _html("<tr><td class=\"hicell\">" . $self->_template_text('question3') . "</td></tr>");
  802. }
  803. }
  804. sub _shoutpeople
  805. {
  806. # The ones who speak with exclamation marks!
  807. my $self = shift;
  808. my %spercent;
  809. foreach my $nick (sort keys %{ $self->{stats}->{shouts} }) {
  810. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  811. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  812. $spercent{$nick} = sprintf("%.1f", ($self->{stats}->{shouts}{$nick} / $self->{stats}->{lines}{$nick}) * 100);
  813. }
  814. }
  815. }
  816. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  817. if (@shout) {
  818. my %hash = (
  819. nick => $shout[0],
  820. per => $spercent{$shout[0]}
  821. );
  822. my $text = $self->_template_text('shout1', %hash);
  823. _html("<tr><td class=\"hicell\">$text");
  824. if (@shout >= 2) {
  825. my %hash = (
  826. nick => $shout[1],
  827. per => $spercent{$shout[1]}
  828. );
  829. my $text = $self->_template_text('shout2', %hash);
  830. _html("<br /><span class=\"small\">$text</span>");
  831. }
  832. _html("</td></tr>");
  833. } else {
  834. my $text = $self->_template_text('shout3');
  835. _html("<tr><td class=\"hicell\">$text</td></tr>");
  836. }
  837. }
  838. sub _capspeople
  839. {
  840. # The ones who speak ALL CAPS.
  841. my $self = shift;
  842. my %cpercent;
  843. foreach my $nick (sort keys %{ $self->{stats}->{allcaps} }) {
  844. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  845. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  846. $cpercent{$nick} = sprintf("%.1f", $self->{stats}->{allcaps}{$nick} / $self->{stats}->{lines}{$nick} * 100);
  847. }
  848. }
  849. }
  850. my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent;
  851. if (@caps) {
  852. my %hash = (
  853. nick => $caps[0],
  854. per => $cpercent{$caps[0]},
  855. line => $self->_format_line($self->{stats}->{allcaplines}{$caps[0]})
  856. );
  857. my $text = $self->_template_text('allcaps1', %hash);
  858. if($self->{cfg}->{showshoutline}) {
  859. my $exttext = $self->_template_text('allcapstext', %hash);
  860. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  861. } else {
  862. _html("<tr><td class=\"hicell\">$text");
  863. }
  864. if (@caps >= 2) {
  865. my %hash = (
  866. nick => $caps[1],
  867. per => $cpercent{$caps[1]}
  868. );
  869. my $text = $self->_template_text('allcaps2', %hash);
  870. _html("<br /><span class=\"small\">$text</span>");
  871. }
  872. _html("</td></tr>");
  873. } else {
  874. my $text = $self->_template_text('allcaps3');
  875. _html("<tr><td class=\"hicell\">$text</td></tr>");
  876. }
  877. }
  878. sub _violent
  879. {
  880. # They attacked others (words defined by $self->{cfg}->{violent})
  881. my $self = shift;
  882. my @aggressors = sort { $self->{stats}->{violence}{$b} <=> $self->{stats}->{violence}{$a} }
  883. keys %{ $self->{stats}->{violence} };
  884. @aggressors = $self->_istoponly(@aggressors);
  885. if(@aggressors) {
  886. my %hash = (
  887. nick => $aggressors[0],
  888. attacks => $self->{stats}->{violence}{$aggressors[0]},
  889. line => $self->_format_line($self->{stats}->{violencelines}{$aggressors[0]})
  890. );
  891. my $text = $self->_template_text('violent1', %hash);
  892. if($self->{cfg}->{showviolentlines}) {
  893. my $exttext = $self->_template_text('violenttext', %hash);
  894. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  895. } else {
  896. _html("<tr><td class=\"hicell\">$text");
  897. }
  898. if (@aggressors >= 2) {
  899. my %hash = (
  900. nick => $aggressors[1],
  901. attacks => $self->{stats}->{violence}{$aggressors[1]}
  902. );
  903. my $text = $self->_template_text('violent2', %hash);
  904. _html("<br /><span class=\"small\">$text</span>");
  905. }
  906. _html("</td></tr>");
  907. } else {
  908. my $text = $self->_template_text('violent3');
  909. _html("<tr><td class=\"hicell\">$text</td></tr>");
  910. }
  911. # They got attacked
  912. my @victims = sort { $self->{stats}->{attacked}{$b} <=> $self->{stats}->{attacked}{$a} }
  913. keys %{ $self->{stats}->{attacked} };
  914. @victims = $self->_istoponly(@victims);
  915. if(@victims) {
  916. my %hash = (
  917. nick => $victims[0],
  918. attacks => $self->{stats}->{attacked}{$victims[0]},
  919. line => $self->_format_line($self->{stats}->{attackedlines}{$victims[0]})
  920. );
  921. my $text = $self->_template_text('attacked1', %hash);
  922. if($self->{cfg}->{showviolentlines}) {
  923. my $exttext = $self->_template_text('attackedtext', %hash);
  924. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  925. } else {
  926. _html("<tr><td class=\"hicell\">$text");
  927. }
  928. if (@victims >= 2) {
  929. my %hash = (
  930. nick => $victims[1],
  931. attacks => $self->{stats}->{attacked}{$victims[1]}
  932. );
  933. my $text = $self->_template_text('attacked2', %hash);
  934. _html("<br /><span class=\"small\">$text</span>");
  935. }
  936. _html("</td></tr>");
  937. }
  938. }
  939. sub _gotkicks
  940. {
  941. # The persons who got kicked the most
  942. my $self = shift;
  943. my @gotkick = sort { $self->{stats}->{gotkicked}{$b} <=> $self->{stats}->{gotkicked}{$a} }
  944. keys %{ $self->{stats}->{gotkicked} };
  945. @gotkick = $self->_istoponly(@gotkick);
  946. if (@gotkick) {
  947. my %hash = (
  948. nick => $gotkick[0],
  949. kicks => $self->{stats}->{gotkicked}{$gotkick[0]},
  950. line => $self->_format_line($self->{stats}->{kicklines}{$gotkick[0]})
  951. );
  952. my $text = $self->_template_text('gotkick1', %hash);
  953. if ($self->{cfg}->{showkickline}) {
  954. my $exttext = $self->_template_text('kicktext', %hash);
  955. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  956. } else {
  957. _html("<tr><td class=\"hicell\">$text");
  958. }
  959. if (@gotkick >= 2) {
  960. my %hash = (
  961. nick => $gotkick[1],
  962. kicks => $self->{stats}->{gotkicked}{$gotkick[1]}
  963. );
  964. my $text = $self->_template_text('gotkick2', %hash);
  965. _html("<br /><span class=\"small\">$text</span>");
  966. }
  967. _html("</td></tr>");
  968. }
  969. }
  970. sub _mostjoins
  971. {
  972. my $self = shift;
  973. my @joins = sort { $self->{stats}->{joins}{$b} <=> $self->{stats}->{joins}{$a} }
  974. keys %{ $self->{stats}->{joins} };
  975. @joins = $self->_istoponly(@joins);
  976. if (@joins) {
  977. my %hash = (
  978. nick => $joins[0],
  979. joins => $self->{stats}->{joins}{$joins[0]}
  980. );
  981. my $text = $self->_template_text('joins', %hash);
  982. _html("<tr><td class=\"hicell\">$text</td></tr>");
  983. }
  984. }
  985. sub _mostwords
  986. {
  987. # The person who got words the most
  988. my $self = shift;
  989. my @words = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  990. keys %{ $self->{stats}->{words} };
  991. @words = $self->_istoponly(@words);
  992. if (@words) {
  993. my %hash = (
  994. nick => $words[0],
  995. words => $self->{stats}->{words}{$words[0]}
  996. );
  997. my $text = $self->_template_text('words1', %hash);
  998. _html("<tr><td class=\"hicell\">$text");
  999. if (@words >= 2) {
  1000. my %hash = (
  1001. oldnick => $words[0],
  1002. nick => $words[1],
  1003. words => $self->{stats}->{words}{$words[1]}
  1004. );
  1005. my $text = $self->_template_text('words2', %hash);
  1006. _html("<br /><span class=\"small\">$text</span>");
  1007. }
  1008. _html("</td></tr>");
  1009. } else {
  1010. my $text = $self->_template_text('words3');
  1011. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1012. }
  1013. }
  1014. sub _mostkicks
  1015. {
  1016. # The person who kicked the most
  1017. my $self = shift;
  1018. my @kicked = sort { $self->{stats}->{kicked}{$b} <=> $self->{stats}->{kicked}{$a} }
  1019. keys %{ $self->{stats}->{kicked} };
  1020. @kicked = $self->_istoponly(@kicked);
  1021. if (@kicked) {
  1022. my %hash = (
  1023. nick => $kicked[0],
  1024. kicked => $self->{stats}->{kicked}{$kicked[0]}
  1025. );
  1026. my $text = $self->_template_text('kick1', %hash);
  1027. _html("<tr><td class=\"hicell\">$text");
  1028. if (@kicked >= 2) {
  1029. my %hash = (
  1030. oldnick => $kicked[0],
  1031. nick => $kicked[1],
  1032. kicked => $self->{stats}->{kicked}{$kicked[1]}
  1033. );
  1034. my $text = $self->_template_text('kick2', %hash);
  1035. _html("<br /><span class=\"small\">$text</span>");
  1036. }
  1037. _html("</td></tr>");
  1038. } else {
  1039. my $text = $self->_template_text('kick3');
  1040. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1041. }
  1042. }
  1043. sub _mostmonologues
  1044. {
  1045. # The person who had the most monologues (speaking to himself)
  1046. my $self = shift;
  1047. my @monologue = sort { $self->{stats}->{monologues}{$b} <=> $self->{stats}->{monologues}{$a} }
  1048. keys %{ $self->{stats}->{monologues} };
  1049. @monologue = $self->_istoponly(@monologue);
  1050. if (@monologue) {
  1051. my %hash = (
  1052. nick => $monologue[0],
  1053. monos => $self->{stats}->{monologues}{$monologue[0]}
  1054. );
  1055. my $text = $self->_template_text('mono1', %hash);
  1056. _html("<tr><td class=\"hicell\">$text");
  1057. if (@monologue >= 2) {
  1058. my %hash = (
  1059. nick => $monologue[1],
  1060. monos => $self->{stats}->{monologues}{$monologue[1]}
  1061. );
  1062. my $text = $self->_template_text('mono2', %hash);
  1063. _html("<br /><span class=\"small\">$text</span>");
  1064. }
  1065. _html("</td></tr>");
  1066. }
  1067. }
  1068. sub _linelengths
  1069. {
  1070. # The person(s) who wrote the longest lines
  1071. my $self = shift;
  1072. my %len;
  1073. foreach my $nick (sort keys %{ $self->{stats}->{lengths} }) {
  1074. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1075. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  1076. $len{$nick} = sprintf("%.1f", $self->{stats}->{lengths}{$nick} / $self->{stats}->{lines}{$nick});
  1077. }
  1078. }
  1079. }
  1080. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  1081. my $all_lines = 0;
  1082. my $totallength;
  1083. foreach my $nick (keys %{ $self->{stats}->{lines} }) {
  1084. $all_lines += $self->{stats}->{lines}{$nick};
  1085. $totallength += $self->{stats}->{lengths}{$nick};
  1086. }
  1087. my $totalaverage;
  1088. if ($all_lines > 0) {
  1089. $totalaverage = sprintf("%.1f", $totallength / $all_lines);
  1090. }
  1091. if (@len) {
  1092. my %hash = (
  1093. nick => $len[0],
  1094. letters => $len{$len[0]}
  1095. );
  1096. my $text = $self->_template_text('long1', %hash);
  1097. _html("<tr><td class=\"hicell\">$text<br />");
  1098. if (@len >= 2) {
  1099. %hash = (
  1100. avg => $totalaverage
  1101. );
  1102. $text = $self->_template_text('long2', %hash);
  1103. _html("<span class=\"small\">$text</span></td></tr>");
  1104. } else {
  1105. _html("</td></tr>");
  1106. }
  1107. }
  1108. # The person(s) who wrote the shortest lines
  1109. if (@len) {
  1110. my %hash = (
  1111. nick => $len[$#len],
  1112. letters => $len{$len[$#len]}
  1113. );
  1114. my $text = $self->_template_text('short1', %hash);
  1115. _html("<tr><td class=\"hicell\">$text<br />");
  1116. if (@len >= 2) {
  1117. %hash = (
  1118. nick => $len[$#len - 1],
  1119. letters => $len{$len[$#len - 1]}
  1120. );
  1121. $text = $self->_template_text('short2', %hash);
  1122. _html("<span class=\"small\">$text</span></td></tr>");
  1123. } else {
  1124. _html("</td></tr>");
  1125. }
  1126. }
  1127. }
  1128. sub _mostfoul
  1129. {
  1130. my $self = shift;
  1131. my %spercent;
  1132. foreach my $nick (sort keys %{ $self->{stats}->{foul} }) {
  1133. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1134. if ($self->{stats}->{lines}{$nick} > 15) {
  1135. my $dec = $self->{cfg}->{showfouldecimals};
  1136. $dec = 1 if($dec < 0); # default to 1
  1137. $spercent{$nick} = sprintf("%.${dec}f", $self->{stats}->{foul}{$nick} / $self->{stats}->{words}{$nick} * 100);
  1138. }
  1139. }
  1140. }
  1141. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1142. if (@foul) {
  1143. my %hash = (
  1144. nick => $foul[0],
  1145. per => $spercent{$foul[0]},
  1146. line => $self->_format_line($self->{stats}{foullines}{$foul[0]}),
  1147. );
  1148. my $text = $self->_template_text('foul1', %hash);
  1149. if($self->{cfg}->{showfoulline}) {
  1150. my $exttext = $self->_template_text('foultext', %hash);
  1151. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  1152. } else {
  1153. _html("<tr><td class=\"hicell\">$text");
  1154. }
  1155. if (@foul >= 2) {
  1156. my %hash = (
  1157. nick => $foul[1],
  1158. per => $spercent{$foul[1]}
  1159. );
  1160. my $text = $self->_template_text('foul2', %hash);
  1161. _html("<br /><span class=\"small\">$text</span>");
  1162. }
  1163. _html("</td></tr>");
  1164. } else {
  1165. my $text = $self->_template_text('foul3');
  1166. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1167. }
  1168. }
  1169. sub _mostsad
  1170. {
  1171. my $self = shift;
  1172. my %spercent;
  1173. foreach my $nick (sort keys %{ $self->{stats}->{frowns} }) {
  1174. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1175. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  1176. $spercent{$nick} = sprintf("%.1f", $self->{stats}->{frowns}{$nick} / $self->{stats}->{lines}{$nick} * 100);
  1177. }
  1178. }
  1179. }
  1180. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1181. if (@sadface) {
  1182. my %hash = (
  1183. nick => $sadface[0],
  1184. per => $spercent{$sadface[0]}
  1185. );
  1186. my $text = $self->_template_text('sad1', %hash);
  1187. _html("<tr><td class=\"hicell\">$text");
  1188. if (@sadface >= 2) {
  1189. my %hash = (
  1190. nick => $sadface[1],
  1191. per => $spercent{$sadface[1]}
  1192. );
  1193. my $text = $self->_template_text('sad2', %hash);
  1194. _html("<br /><span class=\"small\">$text</span>");
  1195. }
  1196. _html("</td></tr>");
  1197. } else {
  1198. my $text = $self->_template_text('sad3');
  1199. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1200. }
  1201. }
  1202. sub _mostop
  1203. {
  1204. my $self = shift;
  1205. my @ops = sort { $self->{stats}->{gaveops}{$b} <=> $self->{stats}->{gaveops}{$a} }
  1206. keys %{ $self->{stats}->{gaveops} };
  1207. @ops = $self->_istoponly(@ops);
  1208. my @deops = sort { $self->{stats}->{tookops}{$b} <=> $self->{stats}->{tookops}{$a} }
  1209. keys %{ $self->{stats}->{tookops} };
  1210. @deops = $self->_istoponly(@deops);
  1211. if (@ops) {
  1212. my %hash = (
  1213. nick => $ops[0],
  1214. ops => $self->{stats}->{gaveops}{$ops[0]}
  1215. );
  1216. my $text = $self->_template_text('mostop1', %hash);
  1217. _html("<tr><td class=\"hicell\">$text");
  1218. if (@ops >= 2) {
  1219. my %hash = (
  1220. nick => $ops[1],
  1221. ops => $self->{stats}->{gaveops}{$ops[1]}
  1222. );
  1223. my $text = $self->_template_text('mostop2', %hash);
  1224. _html("<br /><span class=\"small\">$text</span>");
  1225. }
  1226. _html("</td></tr>");
  1227. } else {
  1228. my $text = $self->_template_text('mostop3');
  1229. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1230. }
  1231. if (@deops) {
  1232. my %hash = (
  1233. nick => $deops[0],
  1234. deops => $self->{stats}->{tookops}{$deops[0]}
  1235. );
  1236. my $text = $self->_template_text('mostdeop1', %hash);
  1237. _html("<tr><td class=\"hicell\">$text");
  1238. if (@deops >= 2) {
  1239. my %hash = (
  1240. nick => $deops[1],
  1241. deops => $self->{stats}->{tookops}{$deops[1]}
  1242. );
  1243. my $text = $self->_template_text('mostdeop2', %hash);
  1244. _html("<br /><span class=\"small\">$text</span>");
  1245. }
  1246. _html("</td></tr>");
  1247. } else {
  1248. my $text = $self->_template_text('mostdeop3');
  1249. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1250. }
  1251. }
  1252. sub _mostvoice
  1253. {
  1254. my $self = shift;
  1255. my @voice = sort { $self->{stats}->{gavevoice}{$b} <=> $self->{stats}->{gavevoice}{$a} }
  1256. keys %{ $self->{stats}->{gavevoice} };
  1257. @voice = $self->_istoponly(@voice);
  1258. my @devoice = sort { $self->{stats}->{tookvoice}{$b} <=> $self->{stats}->{tookvoice}{$a} }
  1259. keys %{ $self->{stats}->{tookvoice} };
  1260. @devoice = $self->_istoponly(@devoice);
  1261. if (@voice) {
  1262. my %hash = (
  1263. nick => $voice[0],
  1264. voices => $self->{stats}->{gavevoice}{$voice[0]}
  1265. );
  1266. my $text = $self->_template_text('mostvoice1', %hash);
  1267. _html("<tr><td class=\"hicell\">$text");
  1268. if (@voice >= 2) {
  1269. my %hash = (
  1270. nick => $voice[1],
  1271. voices => $self->{stats}->{gavevoice}{$voice[1]}
  1272. );
  1273. my $text = $self->_template_text('mostvoice2', %hash);
  1274. _html("<br /><span class=\"small\">$text</span>");
  1275. }
  1276. _html("</td></tr>");
  1277. } else {
  1278. my $text = $self->_template_text('mostvoice3');
  1279. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1280. }
  1281. if (@devoice) {
  1282. my %hash = (
  1283. nick => $devoice[0],
  1284. devoices => $self->{stats}->{tookvoice}{$devoice[0]}
  1285. );
  1286. my $text = $self->_template_text('mostdevoice1', %hash);
  1287. _html("<tr><td class=\"hicell\">$text");
  1288. if (@devoice >= 2) {
  1289. my %hash = (
  1290. nick => $devoice[1],
  1291. devoices => $self->{stats}->{tookvoice}{$devoice[1]}
  1292. );
  1293. my $text = $self->_template_text('mostdevoice2', %hash);
  1294. _html("<br /><span class=\"small\">$text</span>");
  1295. }
  1296. _html("</td></tr>");
  1297. } else {
  1298. my $text = $self->_template_text('mostdevoice3');
  1299. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1300. }
  1301. }
  1302. sub _mosthalfop
  1303. {
  1304. my $self = shift;
  1305. my @halfops = sort { $self->{stats}->{gavehalfops}{$b} <=> $self->{stats}->{gavehalfops}{$a} }
  1306. keys %{ $self->{stats}->{gavehalfops} };
  1307. @halfops = $self->_istoponly(@halfops);
  1308. my @dehalfops = sort { $self->{stats}->{tookhalfops}{$b} <=> $self->{stats}->{tookhalfops}{$a} }
  1309. keys %{ $self->{stats}->{tookhalfops} };
  1310. @dehalfops = $self->_istoponly(@dehalfops);
  1311. if (@halfops) {
  1312. my %hash = (
  1313. nick => $halfops[0],
  1314. halfops => $self->{stats}->{gavehalfops}{$halfops[0]}
  1315. );
  1316. my $text = $self->_template_text('mosthalfop1', %hash);
  1317. _html("<tr><td class=\"hicell\">$text");
  1318. if (@halfops >= 2) {
  1319. my %hash = (
  1320. nick => $halfops[1],
  1321. halfops => $self->{stats}->{gavehalfops}{$halfops[1]}
  1322. );
  1323. my $text = $self->_template_text('mosthalfop2', %hash);
  1324. _html("<br /><span class=\"small\">$text</span>");
  1325. }
  1326. _html("</td></tr>");
  1327. } else {
  1328. my $text = $self->_template_text('mosthalfop3');
  1329. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1330. }
  1331. if (@dehalfops) {
  1332. my %hash = (
  1333. nick => $dehalfops[0],
  1334. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[0]}
  1335. );
  1336. my $text = $self->_template_text('mostdehalfop1', %hash);
  1337. _html("<tr><td class=\"hicell\">$text");
  1338. if (@dehalfops >= 2) {
  1339. my %hash = (
  1340. nick => $dehalfops[1],
  1341. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[1]}
  1342. );
  1343. my $text = $self->_template_text('mostdehalfop2', %hash);
  1344. _html("<br /><span class=\"small\">$text</span>");
  1345. }
  1346. _html("</td></tr>");
  1347. } else {
  1348. my $text = $self->_template_text('mostdehalfop3');
  1349. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1350. }
  1351. }
  1352. sub _mostactions
  1353. {
  1354. # The person who did the most /me's
  1355. my $self = shift;
  1356. my @actions = sort { $self->{stats}->{actions}{$b} <=> $self->{stats}->{actions}{$a} }
  1357. keys %{ $self->{stats}->{actions} };
  1358. @actions = $self->_istoponly(@actions);
  1359. if (@actions) {
  1360. my %linehash =
  1361. my %hash = (
  1362. nick => $actions[0],
  1363. actions => $self->{stats}->{actions}{$actions[0]},
  1364. line => $self->_format_line($self->{stats}->{actionlines}{$actions[0]})
  1365. );
  1366. my $text = $self->_template_text('action1', %hash);
  1367. if($self->{cfg}->{showactionline}) {
  1368. my $exttext = $self->_template_text('actiontext', %hash);
  1369. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span>");
  1370. } else {
  1371. _html("<tr><td class=\"hicell\">$text");
  1372. }
  1373. if (@actions >= 2) {
  1374. my %hash = (
  1375. nick => $actions[1],
  1376. actions => $self->{stats}->{actions}{$actions[1]}
  1377. );
  1378. my $text = $self->_template_text('action2', %hash);
  1379. _html("<br /><span class=\"small\">$text</span>");
  1380. }
  1381. _html("</td></tr>");
  1382. } else {
  1383. my $text = $self->_template_text('action3');
  1384. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1385. }
  1386. }
  1387. sub _mostsmiles
  1388. {
  1389. # The person(s) who smiled the most :-)
  1390. my $self = shift;
  1391. my %spercent;
  1392. foreach my $nick (sort keys %{ $self->{stats}->{smiles} }) {
  1393. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1394. if ($self->{stats}->{lines}{$nick} > $self->{cfg}->{bignumbersthreshold}) {
  1395. $spercent{$nick} = sprintf("%.1f", $self->{stats}->{smiles}{$nick} / $self->{stats}->{lines}{$nick} * 100);
  1396. }
  1397. }
  1398. }
  1399. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1400. if (@smiles) {
  1401. my %hash = (
  1402. nick => $smiles[0],
  1403. per => $spercent{$smiles[0]}
  1404. );
  1405. my $text = $self->_template_text('smiles1', %hash);
  1406. _html("<tr><td class=\"hicell\">$text");
  1407. if (@smiles >= 2) {
  1408. my %hash = (
  1409. nick => $smiles[1],
  1410. per => $spercent{$smiles[1]}
  1411. );
  1412. my $text = $self->_template_text('smiles2', %hash);
  1413. _html("<br /><span class=\"small\">$text</span>");
  1414. }
  1415. _html("</td></tr>");
  1416. } else {
  1417. my $text = $self->_template_text('smiles3');
  1418. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1419. }
  1420. }
  1421. sub _lasttopics
  1422. {
  1423. my $self = shift;
  1424. if ($self->{stats}->{topics}) {
  1425. my %topic_seen;
  1426. my %hash = (
  1427. total => scalar @{ $self->{stats}->{topics} }
  1428. );
  1429. my $ltopic = $#{ $self->{stats}->{topics} };
  1430. my $tlimit = 0;
  1431. $self->{cfg}->{topichistory} -= 1;
  1432. if ($ltopic > $self->{cfg}->{topichistory}) {
  1433. $tlimit = $ltopic - $self->{cfg}->{topichistory};
  1434. }
  1435. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1436. my $topic = $self->{stats}->{topics}[$i]{topic};
  1437. # This code makes sure that we don't see the same topic twice
  1438. next if ($topic_seen{$topic});
  1439. $topic_seen{$topic} = 1;
  1440. # Strip off the quotes (')
  1441. $topic =~ s/^\'(.*)\'$/$1/;
  1442. my $nick = $self->{stats}->{topics}[$i]{nick};
  1443. my $hour = $self->{stats}->{topics}[$i]{hour};
  1444. my $min = $self->{stats}->{topics}[$i]{min};
  1445. $hash{nick} = $nick;
  1446. $hash{time} = "$hour:$min";
  1447. $hash{days} = $self->{stats}->{days} - $self->{stats}->{topics}[$i]{days};
  1448. if ($hash{days} == 0) {
  1449. $hash{date} = $self->_template_text('today');
  1450. } elsif ($hash{days} == 1) {
  1451. $hash{date} = $self->_template_text('lastseen1', %hash);
  1452. } else {
  1453. $hash{date} = $self->_template_text('lastseen2', %hash);
  1454. }
  1455. _html('<tr><td class="hicell"><i>' . $self->_format_line($topic) . '</i></td>');
  1456. _html('<td class="hicell"><b>' . $self->_template_text('bylinetopic', %hash) . '</b></td></tr>');
  1457. }
  1458. _html("<tr><td align=\"center\" colspan=\"2\" class=\"asmall\">" . $self->_template_text('totaltopic', %hash) . "</td></tr>");
  1459. } else {
  1460. _html("<tr><td class=\"hicell\">" . $self->_template_text('notopic') ."</td></tr>");
  1461. }
  1462. }
  1463. sub _template_text
  1464. {
  1465. # This function is for the homemade template system. It receives a name
  1466. # of a template and a hash with the fields in the template to update to
  1467. # its corresponding value
  1468. my $self = shift;
  1469. my $template = shift;
  1470. my %hash = @_;
  1471. my $text;
  1472. unless ($text = $self->{tmps}->{$self->{cfg}->{lang}}{$template}) {
  1473. # Fall back to English if the language template doesn't exist
  1474. if ($text = $self->{tmps}->{EN}{$template}) {
  1475. print "Note: No translation in '$self->{cfg}->{lang}' for '$template' - falling back to English.\n"
  1476. unless ($self->{cfg}->{silent});
  1477. } else {
  1478. die("No template for '$template' in language file.\n");
  1479. }
  1480. }
  1481. if($self->{iconv}) {
  1482. $text = $self->{iconv}->convert($text);
  1483. die("Could not convert charset for template '$template'.\n") unless $text;
  1484. }
  1485. $hash{channel} = $self->{cfg}->{channel};
  1486. # the nick is sanitized here, everything else outside of _template_text
  1487. $hash{nick} = $self->_format_word($hash{nick}) if $hash{nick};
  1488. foreach my $key (sort keys %hash) {
  1489. $text =~ s/\[:$key\]/$hash{$key}/;
  1490. }
  1491. if ($text =~ /\[:[^:]*?:[^:]*?:[^:]*?:\]/o) {
  1492. $text =~ s/\[:([^:]*?):([^:]*?):([^:]*?):\]/$self->_get_subst($1,$2,$3,\%hash)/geo;
  1493. }
  1494. if ($text =~ /\[:[^:]*?:[^:]*?:]/o) {
  1495. $text =~ s/\[:([^:]*?):([^:]*?):]/$self->_get_subst($1,$2,undef,\%hash)/geo;
  1496. }
  1497. return $text;
  1498. }
  1499. sub _format_word
  1500. {
  1501. # This function formats a word -- should ONLY be called on words used alone (EG: not whole line printed)
  1502. my ($self, $word, $nick) = @_; # nick is only defined for user links in top table
  1503. $word = htmlentities($word, $self->{cfg}->{charset});
  1504. $word = $self->_replace_links($word, $nick);
  1505. return $word;
  1506. }
  1507. sub _format_line
  1508. {
  1509. # This function formats a action/normal line to be more readable, and calls any other function
  1510. # that should be executed on every line.
  1511. my ($self, $line) = @_;
  1512. my $hashref;
  1513. if ($hashref = $self->{cfg}->{analyzer}->{parser}->normalline($line)) {
  1514. $line = '<' . $hashref->{nick} . '> ' . $hashref->{saying};
  1515. } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->actionline($line)) {
  1516. $line = '* ' . $hashref->{nick} . ' ' . $hashref->{saying};
  1517. } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->thirdline($line)) {
  1518. if (defined($hashref->{kicker})) {
  1519. $line = '*** ' . $hashref->{nick} . ' was kicked by ' . $hashref->{kicker};
  1520. $line .= ' (' . $hashref->{kicktext} . ')'
  1521. if (defined($hashref->{kicktext}));
  1522. } elsif (defined($hashref->{newtopic})) {
  1523. $line = '*** ' . $hashref->{nick} . ' changes topic to \'' . $hashref->{newtopic} . '\'';
  1524. } elsif (defined($hashref->{newmode})) {
  1525. $line = '*** ' . $hashref->{nick} . ' sets mode ' . $hashref->{newmode};
  1526. $line .= ' ' . $hashref->{modechanges}
  1527. if (defined($hashref->{kicktext}));
  1528. } elsif (defined($hashref->{newjoin})) {
  1529. $line = '*** Joins: ' . $hashref->{nick};
  1530. } elsif (defined($hashref->{newnick})) {
  1531. $line = '*** ' . $hashref->{nick} . ' is now known as ' . $hashref->{newnick};
  1532. } elsif (defined($hashref->{newtopic})) {
  1533. $line = '*** ' . $hashref->{nick} . ' changes topic to: ' . $hashref->{newtopic};
  1534. }
  1535. }
  1536. $line = htmlentities($line, $self->{cfg}->{charset});
  1537. $line = $self->_replace_links($line);
  1538. return $line;
  1539. }
  1540. sub _get_subst
  1541. {
  1542. # This function looks at the user definition and see if there is sex
  1543. # defined. If yes, return the appropriate value. If no, just return the
  1544. # default he/she value.
  1545. my $self = shift;
  1546. my ($m,$f,$d,$hash) = @_;
  1547. if ($hash->{nick} && $self->{users}->{sex}{$hash->{nick}}) {
  1548. if ($self->{users}->{sex}{$hash->{nick}} eq 'm') {
  1549. return $m;
  1550. } elsif ($self->{users}->{sex}{$hash->{nick}} eq 'f') {
  1551. return $f;
  1552. }
  1553. }
  1554. return defined($d) ? $d : "$m/$f";
  1555. }
  1556. sub _mostusedword
  1557. {
  1558. # Word usage statistics
  1559. my $self = shift;
  1560. my %usages;
  1561. foreach my $word (keys %{ $self->{stats}->{wordcounts} }) {
  1562. # Skip people's nicks.
  1563. next if is_nick($word, $self->{cfg}->{cachedir});
  1564. next if (length($word) < $self->{cfg}->{wordlength});
  1565. next unless $self->_has_letters($word); # ASCII art and punctuation are not words
  1566. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1567. }
  1568. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1569. if (@popular) {
  1570. $self->_headline($self->_template_text('mostwordstopic'), undef, undef, 'mostwordstopic');
  1571. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1572. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('word') . "</b></td>");
  1573. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1574. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1575. my $count = 0;
  1576. for(my $i = 0; $count < $self->{cfg}->{wordhistory}; $i++) {
  1577. last unless $i < $#popular+1;
  1578. # Skip nicks. It's far more efficient to do this here than when
  1579. # @popular is created.
  1580. next if is_ignored($popular[$i]);
  1581. my $a = $count + 1;
  1582. my $popular = $self->_format_word($self->{stats}->{word_upcase}{$popular[$i]});
  1583. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1584. my $lastused = $self->_format_word($self->{stats}->{wordnicks}{$popular[$i]});
  1585. my $class;
  1586. if ($a == 1) {
  1587. $class = 'hirankc';
  1588. } else {
  1589. $class = 'rankc';
  1590. }
  1591. _html("<tr><td class=\"$class\">$a</td>");
  1592. _html("<td class=\"hicell\">$popular</td>");
  1593. _html("<td class=\"hicell\">$wordcount</td>");
  1594. _html("<td class=\"hicell\">$lastused</td>");
  1595. _html("</tr>");
  1596. $count++;
  1597. }
  1598. _html("</table>");
  1599. }
  1600. }
  1601. sub _mostwordsperline
  1602. {
  1603. # The person who got the most words per line
  1604. my $self = shift;
  1605. my %wpl = ();
  1606. my $numlines = 0;
  1607. my ($avg, $numwords);
  1608. foreach my $nick (keys %{ $self->{stats}->{words} }) {
  1609. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1610. $wpl{$nick} = sprintf("%.2f", $self->{stats}->{words}{$nick}/$self->{stats}->{lines}{$nick});
  1611. $numlines += $self->{stats}->{lines}{$nick};
  1612. $numwords += $self->{stats}->{words}{$nick};
  1613. }
  1614. }
  1615. if ($numlines > 0) {
  1616. $avg = sprintf("%.2f", $numwords/$numlines);
  1617. }
  1618. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  1619. if (@wpl) {
  1620. my %hash = (
  1621. nick => $wpl[0],
  1622. wpl => $wpl{$wpl[0]}
  1623. );
  1624. my $text = $self->_template_text('wpl1', %hash);
  1625. _html("<tr><td class=\"hicell\">$text");
  1626. $hash{avg} = $avg;
  1627. $text = $self->_template_text('wpl2', %hash);
  1628. _html("<br /><span class=\"small\">$text</span>");
  1629. _html("</td></tr>");
  1630. }
  1631. }
  1632. sub _mostreferencednicks
  1633. {
  1634. # List showing the most referenced nicks
  1635. my $self = shift;
  1636. my %usages;
  1637. foreach my $word (sort keys %{ $self->{stats}->{wordcounts} }) {
  1638. next if is_ignored($word);
  1639. my $nick = is_nick($word) or next;
  1640. next if !exists $self->{stats}->{lines}{$nick};
  1641. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1642. }
  1643. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1644. if (@popular) {
  1645. $self->_headline($self->_template_text('referencetopic'), undef, undef, 'referencetopic');
  1646. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1647. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>");
  1648. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1649. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1650. for(my $i = 0; $i < $self->{cfg}->{nickhistory}; $i++) {
  1651. last if $i >= @popular;
  1652. my $a = $i + 1;
  1653. my $popular = $self->_format_word(is_nick($popular[$i]));
  1654. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1655. my $lastused = $self->_format_word($self->{stats}->{wordnicks}{$popular[$i]} || "");
  1656. # this is undefined when a nick is referenced before being used
  1657. # first (this is a minor bug we ignore here, see test/01.cfg)
  1658. my $class;
  1659. if ($a == 1) {
  1660. $class = 'hirankc';
  1661. } else {
  1662. $class = 'rankc';
  1663. }
  1664. _html("<tr><td class=\"$class\">$a</td>");
  1665. _html("<td class=\"hicell\">$popular</td>");
  1666. _html("<td class=\"hicell\">$wordcount</td>");
  1667. _html("<td class=\"hicell\">$lastused</td>");
  1668. _html("</tr>");
  1669. }
  1670. _html("</table>");
  1671. }
  1672. }
  1673. sub _smileys
  1674. {
  1675. my $self = shift;
  1676. my %usages;
  1677. foreach my $smiley (sort keys %{ $self->{stats}->{smileys} }) {
  1678. $usages{$smiley} = $self->{stats}->{smileys}{$smiley};
  1679. }
  1680. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1681. return unless @popular;
  1682. $self->_headline($self->_template_text('smileytopic'), undef, undef, 'smileytopic');
  1683. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1684. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('smiley') . "</b></td>");
  1685. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1686. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1687. for(my $i = 0; $i < $self->{cfg}->{smileyhistory}; $i++) {
  1688. last if $i >= @popular;
  1689. my $a = $i + 1;
  1690. my $popular = $self->_format_word($popular[$i]);
  1691. my $count = $self->{stats}->{smileys}{$popular[$i]};
  1692. my $lastused = $self->_format_word($self->{stats}->{smileynicks}{$popular[$i]} || "");
  1693. my $class = ($a == 1) ? 'hirankc' : 'rankc';
  1694. _html("<tr><td class=\"$class\">$a</td>");
  1695. _html("<td class=\"hicell\">$popular</td>");
  1696. _html("<td class=\"hicell\">$count</td>");
  1697. _html("<td class=\"hicell\">$lastused</td>");
  1698. _html("</tr>");
  1699. }
  1700. _html("</table>");
  1701. }
  1702. sub _karma
  1703. {
  1704. # List showing the most referenced nicks
  1705. my $self = shift;
  1706. my %karma;
  1707. foreach my $thing (sort keys %{ $self->{stats}->{karma} }) {
  1708. my $Thing = lc(is_nick($thing) || $thing); # FIXME: this is ugly
  1709. foreach my $nick (keys %{ $self->{stats}->{karma}{$thing} }) {
  1710. $karma{$Thing} += $self->{stats}->{karma}{$thing}{$nick};
  1711. }
  1712. }
  1713. my @popular = sort { $karma{$b} <=> $karma{$a} } keys %karma;
  1714. return unless @popular;
  1715. $self->_headline($self->_template_text('karmatopic'), undef, undef, 'karmatopic');
  1716. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1717. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>");
  1718. _html("<td class=\"tdtop\"><b>" . $self->_template_text('karma') . "</b></td>");
  1719. _html("<td class=\"tdtop\"><b>" . $self->_template_text('goodkarma') . "</b></td>");
  1720. _html("<td class=\"tdtop\"><b>" . $self->_template_text('badkarma') . "</b></td></tr>");
  1721. my @goodpos = grep { $karma{$_} > 0 } @popular;
  1722. splice @goodpos, $self->{cfg}->{karmahistory}, @goodpos
  1723. if @goodpos > $self->{cfg}->{karmahistory};
  1724. my @badpos = grep { $karma{$_} < 0 } @popular;
  1725. splice @badpos, 0, @badpos - $self->{cfg}->{karmahistory}
  1726. if @badpos > $self->{cfg}->{karmahistory};
  1727. my $pos = 0;
  1728. foreach my $thing (@goodpos) {
  1729. my $class = ($pos++ == 0) ? 'hirankc' : 'rankc';
  1730. my $Thing = $self->_format_word(is_nick($thing) || $thing); # ugliness #2
  1731. _html("<tr><td class=\"$class\">$pos</td>");
  1732. _html("<td class=\"hicell\">$Thing</td>");
  1733. _html("<td class=\"hicell\">$karma{$thing}</td>");
  1734. my @k = grep { $self->{stats}->{karma}{$thing}{$_} > 0 }
  1735. (keys %{ $self->{stats}->{karma}{$thing} });
  1736. @k = $self->_trimlist(@k);
  1737. my $n = join ', ', map { $self->_format_word($_) } @k;
  1738. _html("<td class=\"hicell\">$n</td>");
  1739. @k = grep { $self->{stats}->{karma}{$thing}{$_} < 0 }
  1740. (keys %{ $self->{stats}->{karma}{$thing} });
  1741. @k = $self->_trimlist(@k);
  1742. $n = join ', ', map { $self->_format_word($_) } @k;
  1743. _html("<td class=\"hicell\">$n</td>");
  1744. _html("</tr>");
  1745. }
  1746. if (@goodpos and @badpos) {
  1747. _html("<tr><td class=\"rankc\"></td>");
  1748. _html("<td class=\"hicell\" colspan=\"4\"></td>");
  1749. _html("</tr>");
  1750. }
  1751. $pos = @badpos;
  1752. foreach my $thing (@badpos) {
  1753. my $class = ($pos == 1) ? 'hirankc' : 'rankc';
  1754. my $Thing = $self->_format_word(is_nick($thing) || $thing);
  1755. _html("<tr><td class=\"$class\">". ($pos--) ."</td>");
  1756. _html("<td class=\"hicell\">$Thing</td>");
  1757. _html("<td class=\"hicell\">$karma{$thing}</td>");
  1758. my @k = grep { $self->{stats}->{karma}{$thing}{$_} > 0 }
  1759. (keys %{ $self->{stats}->{karma}{$thing} });
  1760. @k = $self->_trimlist(@k);
  1761. my $n = join ', ', map { $self->_format_word($_) } @k;
  1762. _html("<td class=\"hicell\">$n</td>");
  1763. @k = grep { $self->{stats}->{karma}{$thing}{$_} < 0 }
  1764. (keys %{ $self->{stats}->{karma}{$thing} });
  1765. @k = $self->_trimlist(@k);
  1766. $n = join ', ', map { $self->_format_word($_) } @k;
  1767. _html("<td class=\"hicell\">$n</td>");
  1768. _html("</tr>");
  1769. }
  1770. _html("</table>");
  1771. }
  1772. sub _mosturls
  1773. {
  1774. # List showing the most referenced URLs
  1775. my $self = shift;
  1776. my @sorturls = sort { $self->{stats}->{urlcounts}{$b} <=> $self->{stats}->{urlcounts}{$a} }
  1777. keys %{ $self->{stats}->{urlcounts} };
  1778. if (@sorturls) {
  1779. $self->_headline($self->_template_text('urlstopic'), undef, undef, 'urlstopic');
  1780. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1781. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('url') . "</b></td>");
  1782. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1783. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1784. for(my $i = 0; $i < $self->{cfg}->{urlhistory}; $i++) {
  1785. last unless $i < @sorturls;
  1786. my $a = $i + 1;
  1787. my $urlcount = $self->{stats}->{urlcounts}{$sorturls[$i]};
  1788. my $lastused = $self->{stats}->{urlnicks}{$sorturls[$i]};
  1789. my $printurl = $sorturls[$i];
  1790. if ($printurl and length($printurl) > 60) {
  1791. $printurl = substr($printurl, 0, 60);
  1792. }
  1793. $printurl = htmlentities($printurl, $self->{cfg}->{charset});
  1794. my $linkurl = urlencode($sorturls[$i]);
  1795. my $class = ($a == 1) ? 'hirankc' : 'rankc';
  1796. _html("<tr><td class=\"$class\">$a</td>");
  1797. _html("<td class=\"hicell\"><a href=\"$linkurl\">$printurl</a></td>");
  1798. _html("<td class=\"hicell\">$urlcount</td>");
  1799. _html("<td class=\"hicell\">$lastused</td>");
  1800. _html("</tr>");
  1801. }
  1802. _html("</table>");
  1803. }
  1804. }
  1805. sub _charts
  1806. {
  1807. # List showing the most played songs
  1808. my $self = shift;
  1809. my @sortcharts = sort { $self->{stats}->{chartcounts}{$b} <=> $self->{stats}->{chartcounts}{$a} }
  1810. keys %{ $self->{stats}->{chartcounts} };
  1811. if (@sortcharts) {
  1812. $self->_headline($self->_template_text('chartstopic'), undef, undef, 'chartstopic');
  1813. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1814. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('song') . "</b></td>");
  1815. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberplayed') . "</b></td>");
  1816. _html("<td class=\"tdtop\"><b>" . $self->_template_text('playedby') . "</b></td></tr>");
  1817. for(my $i = 0; $i < $self->{cfg}->{chartshistory}; $i++) {
  1818. last unless $i < @sortcharts;
  1819. my $a = $i + 1;
  1820. my $song = $sortcharts[$i];
  1821. my $chartcount = $self->{stats}->{chartcounts}{$song};
  1822. my $lastused = $self->{stats}->{chartnicks}{$song};
  1823. $song = $self->{stats}->{word_upcase}{$song};
  1824. $song = substr($song, 0, 60) if (length($song) > 60);
  1825. $song = $self->_format_word($song);
  1826. my $class = ($a == 1) ? 'hirankc' : 'rankc';
  1827. _html("<tr><td class=\"$class\">$a</td>");
  1828. _html("<td class=\"hicell\">$song</td>");
  1829. _html("<td class=\"hicell\">$chartcount</td>");
  1830. _html("<td class=\"hicell\">$lastused</td>");
  1831. _html("</tr>");
  1832. }
  1833. _html("</table>");
  1834. }
  1835. }
  1836. sub _legend
  1837. {
  1838. # A legend showing the timebars and their associated time.
  1839. my $self = shift;
  1840. _html("<table align=\"center\" border=\"0\" width=\"520\"><tr>");
  1841. _html("<td align=\"center\" class=\"asmall\"><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  1842. \" id=\"$self->{cfg}->{pic_h_0}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"0-5\" /> = 0-5</td>");
  1843. _html("<td align=\"center\" class=\"asmall\"><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  1844. \" id=\"$self->{cfg}->{pic_h_6}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"6-11\" /> = 6-11</td>");
  1845. _html("<td align=\"center\" class=\"asmall\"><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  1846. \" id=\"$self->{cfg}->{pic_h_12}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"12-17\" /> = 12-17</td>");
  1847. _html("<td align=\"center\" class=\"asmall\"><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  1848. \" id=\"$self->{cfg}->{pic_h_18}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"18-23\" /> = 18-23</td>");
  1849. _html("</tr></table>");
  1850. }
  1851. sub _replace_url # used internally by _replace_links
  1852. {
  1853. my ($self, $url, $www, $ftp, $text) = @_;
  1854. $url = "http://$url" if $www;
  1855. $url = "ftp://$url" if $ftp;
  1856. my $texturl = $self->_template_text("newwindow");
  1857. return "<a href=\"$url\" target=\"_blank\" title=\"$texturl $url\">" . $self->_split_long_text($text) . '</a>';
  1858. }
  1859. sub _replace_email # used internally by _replace_links
  1860. {
  1861. my ($self, $mailto, $user, $domain, $nick) = @_;
  1862. $mailto = '' if $nick or not $mailto;
  1863. $nick ||= "$user&#64;$domain"; # obfuscate mail address
  1864. my $textmail = $self->_template_text("mailto");
  1865. return "<a href=\"mailto:$user&#64;$domain\" title=\"$textmail $nick\">" . $self->_split_long_text($mailto . $nick) . "<\/a>";
  1866. }
  1867. sub _replace_links
  1868. {
  1869. # replace URLs and email addresses by links
  1870. my ($self, $str, $nick) = @_; # nick is only defined for user links in top table
  1871. # Regular expressions are taken from match_urls() and match_email() in
  1872. # Common.pm
  1873. my (@str) = split(/ /,$str);
  1874. foreach (@str) {
  1875. s/((?:(?:https?|ftp|telnet|news):\/\/|(?:(?:(www)|(ftp))[\w-]*\.))[-\w\/~\@:]+\.\S+[^\s]+)/$self->_replace_url($1, $2, $3, $nick || $1)/egio
  1876. or s/(mailto:)?([-\w.]+)@([-\w]+\.[-\w.]+)/$self->_replace_email($1, $2, $3, $nick)/egio
  1877. or $_ = $self->_split_long_text($_);
  1878. }
  1879. return join(' ', @str);
  1880. }
  1881. sub _split_long_text
  1882. {
  1883. my ($self, $str) = @_;
  1884. $str =~ s/(\S{$self->{cfg}->{quotewidth}})(?!\s)/$1-<br \/>/og;
  1885. return($str);
  1886. }
  1887. sub _user_linetimes
  1888. {
  1889. my $self = shift;
  1890. my $nick = shift;
  1891. my $top = shift;
  1892. my $bar = "";
  1893. my $len = ($self->{stats}->{lines}{$nick} / $self->{stats}->{lines}{$top}) * 100;
  1894. for (my $i = 0; $i <= 3; $i++) {
  1895. my $l = $self->{stats}->{line_times}{$nick}[$i];
  1896. next if not defined $l;
  1897. my $w = int(($l / $self->{stats}->{lines}{$nick}) * $len);
  1898. if ($w) {
  1899. my $pic = 'pic_h_'.(6*$i);
  1900. $bar .= "<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  1901. \" id=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"$l\" title=\"$l\" />";
  1902. }
  1903. }
  1904. return "$bar&nbsp;$self->{stats}->{lines}{$nick}";
  1905. }
  1906. sub _user_wordtimes
  1907. {
  1908. my $self = shift;
  1909. my $nick = shift;
  1910. my $top = shift;
  1911. $self->{stats}->{words}{$nick} ||= 0;
  1912. my $len = ($self->{stats}->{words}{$nick} / $self->{stats}->{words}{$top}) * 100;
  1913. my $bar = "";
  1914. for (my $i = 0; $i <= 3; $i++) {
  1915. next if not defined $self->{stats}->{word_times}{$nick}[$i];
  1916. my $w = int(($self->{stats}->{word_times}{$nick}[$i] / $self->{stats}->{words}{$nick}) * $len);
  1917. if ($w) {
  1918. my $pic = 'pic_h_'.(6*$i);
  1919. $bar .= "<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  1920. \" id=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />";
  1921. }
  1922. }
  1923. return "$bar&nbsp;$self->{stats}->{words}{$nick}";
  1924. }
  1925. sub _user_times
  1926. {
  1927. my $self = shift;
  1928. my ($nick) = @_;
  1929. my $bar = "";
  1930. my $itemstat = ($self->{cfg}->{sortbywords} ? 'words' : 'lines');
  1931. my $timestat = ($self->{cfg}->{sortbywords} ? 'word_times' : 'line_times');
  1932. for (my $i = 0; $i <= 3; $i++) {
  1933. my $l = $self->{stats}->{$timestat}{$nick}[$i];
  1934. next if not defined $l;
  1935. my $w = int(($l / $self->{stats}->{$itemstat}{$nick}) * 40);
  1936. if ($w) {
  1937. my $pic = 'pic_h_'.(6*$i);
  1938. $bar .= "<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  1939. \" id=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"$l\" title=\"$l\" />";
  1940. }
  1941. }
  1942. return $bar;
  1943. }
  1944. sub _user_pic
  1945. {
  1946. my $self = shift;
  1947. my $nick = shift;
  1948. my $style = shift;
  1949. return unless $self->{users}->{userpics}{$nick} or $self->{cfg}->{defaultpic};
  1950. my $rowspan = $self->{cfg}->{userpics} ? " rowspan=\"$self->{cfg}->{userpics}\"" : "";
  1951. my $output = "<td $style align=\"center\" valign=\"middle\"$rowspan>";
  1952. my $biguserpic = $self->{users}->{biguserpics}{$nick};
  1953. if ($biguserpic) {
  1954. $biguserpic = $self->{cfg}->{imagepath} .
  1955. randomglob($biguserpic, $self->{cfg}->{imageglobpath}, $nick)
  1956. if $biguserpic !~ /^http:\/\//i;
  1957. $output .= "<a href=\"$biguserpic\">";
  1958. }
  1959. my $pic = $self->{users}->{userpics}{$nick} || $self->{cfg}->{defaultpic};
  1960. $pic = $self->{cfg}->{imagepath} .
  1961. randomglob($pic, $self->{cfg}->{imageglobpath}, $nick)
  1962. unless $pic =~ /^http:\/\//i;
  1963. my $height = $self->{cfg}->{picheight} ? " height=\"$self->{cfg}->{picheight}\"" : "";
  1964. my $width = $self->{cfg}->{picwidth} ? " width=\"$self->{cfg}->{picwidth}\"" : "";
  1965. my $alt = $self->{users}->{userpics}{$nick} ? " alt=\"$nick\" title=\"$nick\"" : ' alt=""';
  1966. my $border = $biguserpic ? ' border="0"' : '';
  1967. my $cls = $self->{users}->{userpics}{$nick} ? '' : ' class="defpic"'; # the shared default picture, so themes can tone it down
  1968. $output .= "<img src=\"$pic\"$cls$width$height$alt$border />";
  1969. $output .= "</a>" if $biguserpic;
  1970. _html("$output</td>");
  1971. }
  1972. sub _mostnicks
  1973. {
  1974. # List showing the user with most used nicks
  1975. my $self = shift;
  1976. my @sortnicks = sort { keys %{ $self->{stats}->{nicks}->{$b} } <=> keys %{ $self->{stats}->{nicks}->{$a} } }
  1977. keys %{ $self->{stats}->{nicks} };
  1978. if (keys %{ $self->{stats}->{nicks}->{$sortnicks[0]} } > 1) {
  1979. $self->_headline($self->_template_text('mostnickstopic'), undef, undef, 'mostnickstopic');
  1980. my $names1 = $self->_template_text('names1');
  1981. my $names2 = $self->_template_text('names2');
  1982. my $nick_txt = $self->_template_text('nick');
  1983. my $names_txt = $self->_template_text('names');
  1984. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1985. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>$nick_txt</b></td>");
  1986. _html("<td class=\"tdtop\"><b>$names_txt</b></td></tr>");
  1987. my $a = 0;
  1988. foreach my $nick (@sortnicks) {
  1989. next if is_ignored($nick);
  1990. my $nickcount = keys %{ $self->{stats}->{nicks}->{$nick} };
  1991. my @nicks = values %{ $self->{stats}->{nicks}->{$nick} };
  1992. my $nickused = join(", ", $self->_trimlist(@nicks));
  1993. last unless ($nickcount > 1);
  1994. $a++;
  1995. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1996. my $n = $nickcount > 1 ? $names1 : $names2;
  1997. _html("<tr><td class=\"$class\">$a</td>");
  1998. if ($self->{cfg}->{mostnicksverbose}) {
  1999. _html("<td class=\"hicell\">$nick ($nickcount $n)</td>");
  2000. _html("<td class=\"hicell\" valign='top'>$nickused</td>");
  2001. } else {
  2002. _html("<td class=\"hicell\">$nick</td>");
  2003. _html("<td class=\"hicell\" valign='top'>$nickcount $n</td>");
  2004. }
  2005. _html("</tr>");
  2006. last if $a >= $self->{cfg}->{mostnickshistory};
  2007. }
  2008. _html("</table>");
  2009. }
  2010. }
  2011. sub _mostactivebyhour
  2012. {
  2013. # Charts for most active nicks by hour (0-5, 6-11, 12-17, 18-23)
  2014. my $self = shift;
  2015. my $sortnicks;
  2016. my $lastline=-1;
  2017. my $maxlines=0;
  2018. foreach my $period (0,1,2,3) {
  2019. my @sortnicks =
  2020. sort
  2021. {
  2022. (defined $self->{stats}->{line_times}{$b}[$period]?$self->{stats}->{line_times}{$b}[$period]:0)
  2023. <=>
  2024. (defined $self->{stats}->{line_times}{$a}[$period]?$self->{stats}->{line_times}{$a}[$period]:0)
  2025. }
  2026. keys %{ $self->{stats}->{line_times} } ;
  2027. for(my $i = 0; $i < $self->{cfg}->{activenicksbyhour}; $i++) {
  2028. next if ! $sortnicks[$i];
  2029. next if is_ignored($sortnicks[$i]);
  2030. last unless $i < @sortnicks;
  2031. my $nick=$sortnicks[$i];
  2032. my $count=$self->{stats}->{line_times}{$nick}[$period] || 0;
  2033. last unless $nick;
  2034. last unless $count;
  2035. $sortnicks->[$period][$i]=$nick;
  2036. if ($lastline<$i) {
  2037. $lastline=$i;
  2038. }
  2039. if ($maxlines<$count) {
  2040. $maxlines=$count;
  2041. }
  2042. }
  2043. }
  2044. if ($lastline>=0) {
  2045. $self->_headline($self->_template_text('activenickbyhourtopic'), undef, undef, 'activenickbyhourtopic');
  2046. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  2047. _html("<td>&nbsp;</td>");
  2048. _html("<td class=\"tdtop\"><b>0-5</b></td>");
  2049. _html("<td class=\"tdtop\"><b>6-11</b></td>");
  2050. _html("<td class=\"tdtop\"><b>12-17</b></td>");
  2051. _html("<td class=\"tdtop\"><b>18-23</b></td>");
  2052. _html("</tr>");
  2053. for(my $i = 0; $i <= $lastline; $i++) {
  2054. my $a = $i + 1;
  2055. my $class = $a == 1 ? 'hirankc' : 'rankc';
  2056. _html("<tr><td class=\"$class\">$a</td>");
  2057. foreach my $period (0,1,2,3) {
  2058. my $nick=$sortnicks->[$period][$i];
  2059. if ($nick) {
  2060. my $count=$self->{stats}->{line_times}{$nick}[$period];
  2061. if ($count) {
  2062. _html("<td class=\"hicell\">");
  2063. if ($self->{cfg}->{showmostactivebyhourgraph}) {
  2064. my $pic = 'pic_h_'.(6*$period);
  2065. my $w = int(($count / $maxlines) * 100) || 1;
  2066. _html("<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  2067. \" id=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />");
  2068. }
  2069. _html($self->_format_word($nick)." - ".$count);
  2070. _html("</td>");
  2071. } else {
  2072. _html("<td class=\"hicell\">&nbsp;</td>");
  2073. }
  2074. } else {
  2075. _html("<td class=\"hicell\">&nbsp;</td>");
  2076. }
  2077. }
  2078. _html("</tr>");
  2079. }
  2080. _html("</table>");
  2081. }
  2082. }
  2083. sub _topactive {
  2084. my $self = shift;
  2085. my @top_active;
  2086. my $top_nicks;
  2087. if ($self->{cfg}->{sortbywords}) {
  2088. @top_active = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  2089. keys %{ $self->{stats}->{words} };
  2090. $top_nicks = scalar keys %{ $self->{stats}->{words} };
  2091. } else {
  2092. @top_active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} }
  2093. keys %{ $self->{stats}->{lines} };
  2094. $top_nicks = scalar keys %{ $self->{stats}->{lines} };
  2095. }
  2096. if ($self->{cfg}->{activenicks} > $top_nicks) {
  2097. $self->{cfg}->{activenicks} = $top_nicks;
  2098. }
  2099. if (($self->{cfg}->{activenicks}+$self->{cfg}->{activenicks2}) > $top_nicks) {
  2100. $self->{cfg}->{activenicks2} = $top_nicks-$self->{cfg}->{activenicks};
  2101. }
  2102. (@top_active) = @top_active[0..($self->{cfg}->{activenicks}-1)];
  2103. $self->{stats}->{topactive_lines} = @top_active ? $self->{stats}->{lines}{$top_active[0]} : 1;
  2104. foreach (@top_active) {
  2105. $self->{topactive}{$_} = 1;
  2106. }
  2107. }
  2108. sub _istoponly {
  2109. my $self = shift;
  2110. my (@nicks_tmp) = @_;
  2111. my @nicks;
  2112. my $cnt=0;
  2113. if ($self->{cfg}->{showonlytop}) {
  2114. foreach my $nick (@nicks_tmp) {
  2115. if ($self->{topactive}{$nick}) {
  2116. push(@nicks, $nick);
  2117. }
  2118. }
  2119. return(@nicks);
  2120. } else {
  2121. return(@nicks_tmp);
  2122. }
  2123. }
  2124. sub _trimlist {
  2125. my $self = shift;
  2126. return @_ unless $self->{cfg}->{nicklimit};
  2127. splice @_, $self->{cfg}->{nicklimit}, @_, qw/.../ if @_ > $self->{cfg}->{nicklimit};
  2128. return @_;
  2129. }
  2130. sub _activegenders {
  2131. # The most active gender in the channel
  2132. my $self = shift;
  2133. my @topgender = sort {$self->{stats}->{sex_lines}{$b} <=> $self->{stats}->{sex_lines}{$a}} keys %{$self->{stats}->{sex_lines}};
  2134. return unless @topgender;
  2135. $self->_headline($self->_template_text('activegenderstopic'), undef, undef, 'activegenderstopic');
  2136. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  2137. _html(" <td>&nbsp;</td>"
  2138. . "<td class=\"tdtop\"><b>" . $self->_template_text('gender') . "</b></td>"
  2139. . "<td class=\"tdtop\"><b>" . $self->_template_text('numberlines') . "</b></td>"
  2140. . "<td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>"
  2141. );
  2142. my $i = 1;
  2143. for my $gender (@topgender) {
  2144. my $bar = "";
  2145. my $len = ($self->{stats}->{sex_lines}{$gender} / $self->{stats}->{sex_lines}{$topgender[0]}) * 100;
  2146. for (0 .. 3) {
  2147. next if not defined $self->{stats}->{sex_line_times}{$gender}[$_];
  2148. my $w = int(($self->{stats}->{sex_line_times}{$gender}[$_] / $self->{stats}->{sex_lines}{$gender}) * $len);
  2149. if ($w) {
  2150. my $pic = 'pic_h_'.(6*$_);
  2151. $bar .= "<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
  2152. \" id=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"$self->{stats}->{sex_line_times}{$gender}[$_]\" />";
  2153. }
  2154. }
  2155. my @top_active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} }
  2156. grep { $self->{users}->{sex}{$_} and $self->{users}->{sex}{$_} eq $gender }
  2157. keys %{ $self->{stats}->{lines} };
  2158. my $nicklist = join ", ",
  2159. map { $_ . ($self->{stats}->{lines}{$_} ? " ($self->{stats}->{lines}{$_})" : "") }
  2160. $self->_trimlist(@top_active);
  2161. my $class = ($i == 1 ? "hirankc" : "rankc");
  2162. my $span_class = $gender eq 'm' ? "male" : ($gender eq 'f' ? "female" : "bot");
  2163. _html("</tr><tr>");
  2164. _html(" <td class=\"$class\" align=\"left\">$i</td>");
  2165. _html(" <td class=\"hicell\"><span class=\"$span_class\">" . $self->_template_text("gender_$gender") . "</span></td>");
  2166. _html(" <td class=\"hicell\"><span style=\"white-space:nowrap;\">$bar</span> $self->{stats}->{sex_lines}{$gender}</td>");
  2167. _html(" <td class=\"hicell\">$nicklist</td>");
  2168. $i++;
  2169. }
  2170. _html("</tr></table>");
  2171. }
  2172. 1;
  2173. __END__
  2174. =head1 NAME
  2175. Pisg::HTMLGenerator - class to create a static HTML page out of data parsed
  2176. =head1 DESCRIPTION
  2177. C<Pisg::HTMLGenerator> uses the hash returned by Pisg::Parser::Logfile and turns it into a static HTML page.
  2178. =head1 SYNOPSIS
  2179. use Pisg::HTMLGenerator;
  2180. $generator = new Pisg::HTMLGenerator(
  2181. cfg => $cfg,
  2182. stats => $stats,
  2183. users => $users,
  2184. tmps => $tmps
  2185. );
  2186. =head1 CONSTRUCTOR
  2187. =over 4
  2188. =item new ( [ OPTIONS ] )
  2189. This is the constructor for a new Pisg::HTMLGenerator object. C<OPTIONS> are passed in a hash like fashion using key and value pairs.
  2190. Possible options are:
  2191. B<cfg> - hashref containing configuration variables, created by the Pisg module.
  2192. B<stats> - reference to the hash returned by Pisg::Parser::Logfile containing all stats.
  2193. B<users> - reference to a hash containg user information
  2194. B<tmps> - reference to a hash containing the language templates.
  2195. =back
  2196. =head1 AUTHOR
  2197. Morten Brix Pedersen <morten@wtf.dk>
  2198. Christoph Berg <cb@df7cb.de>
  2199. James "HM2K" <james@hm2k.org>
  2200. =head1 COPYRIGHT
  2201. Copyright (C) 2001-2012 The pisg project. All rights reserved.
  2202. This program is free software; you can redistribute it and/or modify it
  2203. under the terms of the GPL, license is included with the distribution of
  2204. this file.
  2205. =cut