HTMLGenerator.pm 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914
  1. package Pisg::HTMLGenerator;
  2. # Copyright and license, as well as documentation(POD) for this module is
  3. # found at the end of the file.
  4. use strict;
  5. $^W = 1;
  6. sub new
  7. {
  8. my $type = shift;
  9. my %args = @_;
  10. my $self = {
  11. cfg => $args{cfg},
  12. stats => $args{stats},
  13. users => $args{users},
  14. tmps => $args{tmps},
  15. };
  16. # Import common functions in Pisg::Common
  17. require Pisg::Common;
  18. Pisg::Common->import();
  19. bless($self, $type);
  20. return $self;
  21. }
  22. sub create_html
  23. {
  24. # This subroutine calls all the subroutines which create their
  25. # individual stats. The name of the functions is somewhat saying - if
  26. # you don't understand it, most subs have a better explanation in the
  27. # sub itself.
  28. my $self = shift;
  29. print "Now generating HTML($self->{cfg}->{outputfile})...\n"
  30. unless ($self->{cfg}->{silent});
  31. open (OUTPUT, "> $self->{cfg}->{outputfile}") or
  32. die("$0: Unable to open outputfile($self->{cfg}->{outputfile}): $!\n");
  33. if ($self->{cfg}->{showtime}) {
  34. $self->{cfg}->{tablewidth} += 40;
  35. }
  36. if ($self->{cfg}->{showlinetime}) {
  37. $self->{cfg}->{tablewidth} += 100;
  38. }
  39. if ($self->{cfg}->{showwordtime}) {
  40. $self->{cfg}->{tablewidth} += 100;
  41. }
  42. if ($self->{cfg}->{showwords}) {
  43. $self->{cfg}->{tablewidth} += 40;
  44. }
  45. if ($self->{cfg}->{showwpl}) {
  46. $self->{cfg}->{tablewidth} += 40;
  47. }
  48. if ($self->{cfg}->{showcpl}) {
  49. $self->{cfg}->{tablewidth} += 40;
  50. }
  51. $self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
  52. $self->_htmlheader();
  53. $self->_pageheader()
  54. if ($self->{cfg}->{pagehead} ne 'none');
  55. if ($self->{cfg}->{showactivetimes}) {
  56. $self->_activetimes();
  57. }
  58. $self->_activenicks();
  59. if ($self->{cfg}->{showmostactivebyhour}) {
  60. $self->_mostactivebyhour();
  61. }
  62. if ($self->{cfg}->{showbignumbers}) {
  63. $self->_headline($self->_template_text('bignumtopic'));
  64. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  65. $self->_questions();
  66. $self->_shoutpeople();
  67. $self->_capspeople();
  68. $self->_violent();
  69. $self->_mostsmiles();
  70. $self->_mostsad();
  71. $self->_linelengths();
  72. $self->_mostwords();
  73. $self->_mostwordsperline();
  74. _html("</table>"); # Needed for sections
  75. }
  76. if ($self->{cfg}->{showmostnicks}) {
  77. $self->_mostnicks();
  78. }
  79. if ($self->{cfg}->{showmuw}) {
  80. $self->_mostusedword();
  81. }
  82. if ($self->{cfg}->{showmrn}) {
  83. $self->_mostreferencednicks();
  84. }
  85. if ($self->{cfg}->{showmru}) {
  86. $self->_mosturls();
  87. }
  88. if ($self->{cfg}->{showbignumbers}) {
  89. $self->_headline($self->_template_text('othernumtopic'));
  90. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  91. $self->_gotkicks();
  92. $self->_mostkicks();
  93. $self->_mostop();
  94. $self->_mosthalfop() if $self->{cfg}->{showhalfops};
  95. $self->_mostvoice() if $self->{cfg}->{showvoices};
  96. $self->_mostactions();
  97. $self->_mostmonologues();
  98. $self->_mostjoins();
  99. $self->_mostfoul();
  100. _html("</table>"); # Needed for sections
  101. }
  102. $self->_headline($self->_template_text('latesttopic'));
  103. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  104. $self->_lasttopics()
  105. if ($self->{cfg}->{showtopics});
  106. _html("</table>"); # Needed for sections
  107. my %hash = ( lines => $self->{stats}->{totallines} );
  108. _html($self->_template_text('totallines', %hash) . "<br /><br />");
  109. $self->_pagefooter()
  110. if ($self->{cfg}->{pagefoot} ne 'none');
  111. $self->_htmlfooter();
  112. close(OUTPUT);
  113. }
  114. sub _htmlheader
  115. {
  116. my $self = shift;
  117. my %hash = (
  118. network => $self->{cfg}->{network},
  119. maintainer => $self->{cfg}->{maintainer},
  120. days => $self->{stats}->{days},
  121. nicks => scalar keys %{ $self->{stats}->{lines} }
  122. );
  123. my $css_file = $self->{cfg}->{cssdir} . $self->{cfg}->{colorscheme} . ".css";
  124. # Get the chosen CSS file
  125. open(FILE, $css_file) or open (FILE, $self->{cfg}->{search_path} . "/$css_file") or die("$0: Unable to open stylesheet($css_file): $!\n");
  126. my @CSS = <FILE>;
  127. my $title = $self->_template_text('pagetitle1', %hash);
  128. print OUTPUT <<HTML;
  129. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  130. <html>
  131. <head>
  132. <meta http-equiv="Content-Type" content="text/html; charset=$self->{cfg}->{charset}" />
  133. <title>$title</title>
  134. <style type="text/css">
  135. @CSS
  136. </style></head>
  137. <body>
  138. <div align="center">
  139. HTML
  140. _html("<span class=\"title\">$title</span><br />");
  141. _html("<br />");
  142. _html($self->_template_text('pagetitle2', %hash) . " " . $self->get_time());
  143. _html("<br />" . $self->_template_text('pagetitle3', %hash) . "<br /><br />");
  144. }
  145. sub get_time
  146. {
  147. my $self = shift;
  148. my ($tday, %hash);
  149. my $month = $self->_template_text('month', %hash);
  150. my $day = $self->_template_text('day', %hash);
  151. my @month = split(" ", $month);
  152. my @day = split(" ", $day);
  153. # Get the Date from the users computer
  154. my $timezone = $self->{cfg}->{timeoffset} * 3600;
  155. my ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+$timezone);
  156. $year += 1900; # Y2K Patch
  157. $min =~ s/^(.)$/0$1/; # Fixes the display of mins/secs below
  158. $sec =~ s/^(.)$/0$1/; # it displays 03 instead of 3
  159. if ($hour > '23') { # Checks to see if it Midnight
  160. $hour = 12; # Makes it display the hour 12
  161. $tday = "AM"; # Display AM
  162. } elsif($hour > '12') { # Get rid of the Military time and
  163. $hour -= 12; # put it into normal time
  164. $tday = "PM"; # If past Noon and before Midnight set
  165. } else {
  166. $tday = "AM"; # If it's past Midnight and before Noon
  167. } # set the time as AM
  168. # Use 24 hours pr. day
  169. if ($tday eq "PM" && $hour < '12') {
  170. $hour += 12;
  171. }
  172. return "$day[$wday] $mday $month[$mon] $year - $hour:$min:$sec";
  173. }
  174. sub _htmlfooter
  175. {
  176. my $self = shift;
  177. my %hash;
  178. my $pisg_hp = $self->_template_text('pisghomepage');
  179. $hash{pisg_url} = "<a href=\"http://pisg.sourceforge.net/\" title=\"$pisg_hp\" class=\"background\">pisg</a>";
  180. my $author_hp = $self->_template_text('authorhomepage');
  181. $hash{author_url} = "<a href=\"http://wtf.dk/hp/\" title=\"$author_hp\" class=\"background\">Morten Brix Pedersen</a>";
  182. $hash{version} = $self->{cfg}->{version};
  183. my $hours = $self->_template_text('hours');
  184. my $mins = $self->_template_text('minutes');
  185. my $secs = $self->_template_text('seconds');
  186. my $and = $self->_template_text('and');
  187. my $h = $self->{stats}->{processtime}{hours};
  188. my $m = $self->{stats}->{processtime}{mins};
  189. my $s = $self->{stats}->{processtime}{secs};
  190. $hash{time} = "$h $hours $m $mins $and $s $secs";
  191. my $stats_gen = $self->_template_text('stats_gen_by', %hash);
  192. my $author_text = $self->_template_text('author', %hash);
  193. my $stats_text = $self->_template_text('stats_gen_in', %hash);
  194. print OUTPUT <<HTML;
  195. <span class="small">
  196. $stats_gen<br />
  197. $author_text<br />
  198. $stats_text
  199. </span>
  200. </div>
  201. </body>
  202. </html>
  203. HTML
  204. }
  205. sub _headline
  206. {
  207. my $self = shift;
  208. my ($title) = (@_);
  209. print OUTPUT <<HTML;
  210. <br />
  211. <table width="$self->{cfg}->{headwidth}" cellpadding="1" cellspacing="0" border="0">
  212. <tr>
  213. <td class="headlinebg">
  214. <table width="100%" cellpadding="2" cellspacing="0" border="0">
  215. <tr>
  216. <td class="headtext">$title</td>
  217. </tr>
  218. </table>
  219. </td>
  220. </tr>
  221. </table>
  222. HTML
  223. }
  224. sub _pageheader
  225. {
  226. my $self = shift;
  227. open(PAGEHEAD, $self->{cfg}->{pagehead}) or die("$0: Unable to open $self->{cfg}->{pagehead} for reading: $!\n");
  228. while (<PAGEHEAD>) {
  229. _html($_);
  230. }
  231. close(PAGEHEAD);
  232. }
  233. sub _pagefooter
  234. {
  235. my $self = shift;
  236. open(PAGEFOOT, $self->{cfg}->{pagefoot}) or die("$0: Unable to open $self->{cfg}->{pagefoot} for reading: $!\n");
  237. while (<PAGEFOOT>) {
  238. _html($_);
  239. }
  240. close(PAGEFOOT);
  241. }
  242. sub _activetimes
  243. {
  244. # The most actives times on the channel
  245. my $self = shift;
  246. my (%output, $class);
  247. $self->_headline($self->_template_text('activetimestopic'));
  248. my @toptime = sort { $self->{stats}->{times}{$b} <=> $self->{stats}->{times}{$a} } keys %{ $self->{stats}->{times} };
  249. my $highest_value = $self->{stats}->{times}{$toptime[0]};
  250. my @now = localtime($self->{cfg}->{timestamp});
  251. my $image;
  252. for my $hour (sort keys %{ $self->{stats}->{times} }) {
  253. my $size = ($self->{stats}->{times}{$hour} / $highest_value) * 100;
  254. my $percent = ($self->{stats}->{times}{$hour} / $self->{stats}->{totallines}) * 100;
  255. $percent =~ s/(\.\d)\d+/$1/;
  256. if ($size < 1 && $size != 0) {
  257. # Opera doesn't understand '0.xxxx' in the height="xx" attr,
  258. # so we simply round up to 1.0 here.
  259. $size = 1.0;
  260. }
  261. $image = "pic_v_".(int($hour/6)*6);
  262. $image = $self->{cfg}->{$image};
  263. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br /><img src=\"$self->{cfg}->{piclocation}/$image\" width=\"15\" height=\"$size\" alt=\"$percent\" /></td>\n";
  264. }
  265. _html("<table border=\"0\"><tr>\n");
  266. for ($b = 0; $b < 24; $b++) {
  267. $a = sprintf("%02d", $b);
  268. if (!defined($output{$a}) || $output{$a} eq "") {
  269. _html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  270. } else {
  271. _html($output{$a});
  272. }
  273. }
  274. _html("</tr><tr>");
  275. # Remove leading zero
  276. $toptime[0] =~ s/0(\d)/$1/;
  277. for ($b = 0; $b < 24; $b++) {
  278. if ($toptime[0] == $b) {
  279. # Highlight the top time
  280. $class = 'hirankc10center';
  281. } else {
  282. $class = 'rankc10center';
  283. }
  284. _html("<td class=\"$class\" align=\"center\">$b</td>");
  285. }
  286. _html("</tr></table>");
  287. if($self->{cfg}->{showlegend} == 1) {
  288. $self->_legend();
  289. }
  290. }
  291. sub _activenicks
  292. {
  293. # The most active nicks (those who wrote most lines)
  294. my $self = shift;
  295. $self->_headline($self->_template_text('activenickstopic'));
  296. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  297. _html("<td>&nbsp;</td>"
  298. . "<td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>"
  299. . "<td class=\"tdtop\"><b>" . $self->_template_text('numberlines') . "</b></td>"
  300. . ($self->{cfg}->{showtime} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_time')."</b></td>" : "")
  301. . ($self->{cfg}->{showwords} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_words')."</b></td>" : "")
  302. . ($self->{cfg}->{showwpl} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_wpl')."</b></td>" : "")
  303. . ($self->{cfg}->{showcpl} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_cpl')."</b></td>" : "")
  304. . ($self->{cfg}->{showlastseen} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_lastseen')."</b></td>" : "")
  305. . ($self->{cfg}->{showrandquote} ? "<td class=\"tdtop\"><b>".$self->_template_text('randquote')."</b></td>" : "")
  306. );
  307. my @active;
  308. my $nicks;
  309. if ($self->{cfg}->{sortbywords}) {
  310. @active = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} } keys %{ $self->{stats}->{words} };
  311. $nicks = scalar keys %{ $self->{stats}->{words} };
  312. } else {
  313. @active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} } keys %{ $self->{stats}->{lines} };
  314. $nicks = scalar keys %{ $self->{stats}->{lines} };
  315. }
  316. if ($self->{cfg}->{activenicks} > $nicks) { $self->{cfg}->{activenicks} = $nicks; }
  317. my $have_userpics;
  318. for (my $c = 0; $c < $self->{cfg}->{activenicks}; $c++) {
  319. my $nick = $active[$c];
  320. if ($self->{users}->{userpics}{$nick} && $self->{cfg}->{userpics} !~ /n/i) {
  321. $have_userpics = 1;
  322. _html("<td class=\"tdtop\"><b>" . $self->_template_text('userpic') ."</b></td>");
  323. last;
  324. }
  325. }
  326. _html("</tr>");
  327. for (my $i = 0; $i < $self->{cfg}->{activenicks}; $i++) {
  328. my $c = $i + 1;
  329. my $nick = $active[$i];
  330. my $visiblenick = $active[$i];
  331. my $randomline;
  332. if (not defined $self->{stats}->{sayings}{$nick}) {
  333. $randomline = "";
  334. } else {
  335. $randomline = htmlentities($self->{stats}->{sayings}{$nick});
  336. }
  337. # Convert URLs and e-mail addys to links
  338. $randomline = $self->_replace_links($randomline);
  339. # Add a link to the nick if there is any
  340. if ($self->{users}->{userlinks}{$nick}) {
  341. $visiblenick = $self->_replace_links($self->{users}->{userlinks}{$nick}, $nick);
  342. }
  343. my $color = $self->generate_colors($c);
  344. my $class = 'rankc';
  345. if ($c == 1) {
  346. $class = 'hirankc';
  347. }
  348. my $lastseen;
  349. if ($self->{cfg}->{showlastseen}) {
  350. $lastseen = $self->{stats}->{days} - $self->{stats}->{lastvisited}{$nick};
  351. if ($lastseen == 0) {
  352. $lastseen = $self->_template_text('today');
  353. } elsif ($lastseen == 1) {
  354. $lastseen = "$lastseen " .$self->_template_text('lastseen1');
  355. } else {
  356. $lastseen = "$lastseen " .$self->_template_text('lastseen2');
  357. }
  358. }
  359. _html("<tr><td class=\"$class\" align=\"left\">$c</td>");
  360. my $line = $self->{stats}->{lines}{$nick};
  361. my $w = $self->{stats}->{words}{$nick} ? $self->{stats}->{words}{$nick} : 0;
  362. my $ch = $self->{stats}->{lengths}{$nick};
  363. _html("<td style=\"background-color: $color\">$visiblenick</td>"
  364. . ($self->{cfg}->{showlinetime} ?
  365. "<td style=\"background-color: $color\" nowrap=\"nowrap\">".$self->_user_linetimes($nick,$active[0])."</td>"
  366. : "<td style=\"background-color: $color\">$line</td>")
  367. . ($self->{cfg}->{showtime} ?
  368. "<td style=\"background-color: $color\">".$self->_user_times($nick)."</td>"
  369. : "")
  370. . ($self->{cfg}->{showwords} ?
  371. ($self->{cfg}->{showwordtime} ?
  372. "<td style=\"background-color: $color\" nowrap=\"nowrap\">".$self->_user_wordtimes($nick,$active[0])."</td>"
  373. : "<td style=\"background-color: $color\">$w</td>")
  374. : "")
  375. . ($self->{cfg}->{showwpl} ?
  376. "<td style=\"background-color: $color\">".sprintf("%.1f",$w/$line)."</td>"
  377. : "")
  378. . ($self->{cfg}->{showcpl} ?
  379. "<td style=\"background-color: $color\">".sprintf("%.1f",$ch/$line)."</td>"
  380. : "")
  381. . ($self->{cfg}->{showlastseen} ?
  382. "<td style=\"background-color: $color\">$lastseen</td>"
  383. : "")
  384. . ($self->{cfg}->{showrandquote} ?
  385. "<td style=\"background-color: $color\">\"$randomline\"</td>"
  386. : "")
  387. );
  388. my $height = $self->{cfg}->{picheight};
  389. my $width = $self->{cfg}->{picwidth};
  390. if ($self->{users}->{userpics}{$nick} && $self->{cfg}->{userpics} !~ /n/i) {
  391. _html("<td style=\"background-color: $color\" align=\"center\">");
  392. if (defined $self->{users}->{biguserpics}{$nick}) {
  393. _html("<a href=\"$self->{cfg}->{imagepath}$self->{users}->{biguserpics}{$nick}\">");
  394. }
  395. if ($width ne '') {
  396. _html("<img valign=\"middle\" src=\"$self->{cfg}->{imagepath}$self->{users}->{userpics}{$nick}\" width=\"$width\" height=\"$height\" alt=\"$nick\" />");
  397. } else {
  398. _html("<img valign=\"middle\" src=\"$self->{cfg}->{imagepath}$self->{users}->{userpics}{$nick}\" alt=\"$nick\" />");
  399. }
  400. if (defined $self->{users}->{biguserpics}{$nick}) {
  401. _html("</a>");
  402. }
  403. _html("</td>");
  404. } elsif ($self->{cfg}->{defaultpic} ne '' && $self->{cfg}->{userpics} !~ /n/i) {
  405. _html("<td style=\"background-color: $color\" align=\"center\"><img valign=\"middle\" src=\"$self->{cfg}->{imagepath}$self->{cfg}->{defaultpic}\" alt=\"\" /></td>");
  406. }
  407. _html("</tr>");
  408. }
  409. _html("</table><br />");
  410. # Almost as active nicks ('These didn't make it to the top..')
  411. my $toshow = $self->{cfg}->{activenicks2} - $self->{cfg}->{activenicks};
  412. my $remain = $self->{cfg}->{activenicks} + $toshow;
  413. unless ($toshow > $nicks) {
  414. $remain = $self->{cfg}->{activenicks} + $self->{cfg}->{activenicks2};
  415. if ($remain > $nicks) {
  416. $remain = $nicks;
  417. }
  418. if ($self->{cfg}->{activenicks} < $remain) {
  419. _html("<br /><b><i>" . $self->_template_text('nottop') . "</i></b><table><tr>");
  420. for (my $i = $self->{cfg}->{activenicks}; $i < $remain; $i++) {
  421. unless ($i % 5) { if ($i != $self->{cfg}->{activenicks}) { _html("</tr><tr>"); } }
  422. my $items;
  423. if ($self->{cfg}->{sortbywords}) {
  424. $items = $self->{stats}->{words}{$active[$i]};
  425. } else {
  426. $items = $self->{stats}->{lines}{$active[$i]};
  427. }
  428. _html("<td class=\"rankc10\">$active[$i] ($items)</td>");
  429. }
  430. _html("</tr></table>");
  431. }
  432. }
  433. my %hash;
  434. $hash{totalnicks} = $nicks - $remain;
  435. if ($hash{totalnicks} > 0) {
  436. _html("<br /><b>" . $self->_template_text('totalnicks', %hash) . "</b><br />");
  437. }
  438. }
  439. sub generate_colors
  440. {
  441. my $self = shift;
  442. my $c = shift;
  443. my $h = $self->{cfg}->{hicell};
  444. $h =~ s/^#//;
  445. $h = hex $h;
  446. my $h2 = $self->{cfg}->{hicell2};
  447. $h2 =~ s/^#//;
  448. $h2 = hex $h2;
  449. my $f_b = $h & 0xff;
  450. my $f_g = ($h & 0xff00) >> 8;
  451. my $f_r = ($h & 0xff0000) >> 16;
  452. my $t_b = $h2 & 0xff;
  453. my $t_g = ($h2 & 0xff00) >> 8;
  454. my $t_r = ($h2 & 0xff0000) >> 16;
  455. my $blue = sprintf "%0.2x", abs int(((($t_b - $f_b) / $self->{cfg}->{activenicks}) * +$c) + $f_b);
  456. my $green = sprintf "%0.2x", abs int(((($t_g - $f_g) / $self->{cfg}->{activenicks}) * +$c) + $f_g);
  457. my $red = sprintf "%0.2x", abs int(((($t_r - $f_r) / $self->{cfg}->{activenicks}) * +$c) + $f_r);
  458. return "#$red$green$blue";
  459. }
  460. sub _html
  461. {
  462. my $html = shift;
  463. print OUTPUT "$html\n";
  464. }
  465. sub _questions
  466. {
  467. # Persons who asked the most questions
  468. my $self = shift;
  469. my %qpercent;
  470. foreach my $nick (sort keys %{ $self->{stats}->{questions} }) {
  471. if ($self->{stats}->{lines}{$nick} > 100) {
  472. $qpercent{$nick} = ($self->{stats}->{questions}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  473. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  474. }
  475. }
  476. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  477. if (@question) {
  478. my %hash = (
  479. nick => $question[0],
  480. per => $qpercent{$question[0]}
  481. );
  482. my $text = $self->_template_text('question1', %hash);
  483. _html("<tr><td class=\"hicell\">$text");
  484. if (@question >= 2) {
  485. my %hash = (
  486. nick => $question[1],
  487. per => $qpercent{$question[1]}
  488. );
  489. my $text = $self->_template_text('question2', %hash);
  490. _html("<br /><span class=\"small\">$text</span>");
  491. }
  492. _html("</td></tr>");
  493. } else {
  494. _html("<tr><td class=\"hicell\">" . $self->_template_text('question3') . "</td></tr>");
  495. }
  496. }
  497. sub _shoutpeople
  498. {
  499. # The ones who speak with exclamation marks!
  500. my $self = shift;
  501. my %spercent;
  502. foreach my $nick (sort keys %{ $self->{stats}->{shouts} }) {
  503. if ($self->{stats}->{lines}{$nick} > 100) {
  504. $spercent{$nick} = ($self->{stats}->{shouts}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  505. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  506. }
  507. }
  508. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  509. if (@shout) {
  510. my %hash = (
  511. nick => $shout[0],
  512. per => $spercent{$shout[0]}
  513. );
  514. my $text = $self->_template_text('shout1', %hash);
  515. _html("<tr><td class=\"hicell\">$text");
  516. if (@shout >= 2) {
  517. my %hash = (
  518. nick => $shout[1],
  519. per => $spercent{$shout[1]}
  520. );
  521. my $text = $self->_template_text('shout2', %hash);
  522. _html("<br /><span class=\"small\">$text</span>");
  523. }
  524. _html("</td></tr>");
  525. } else {
  526. my $text = $self->_template_text('shout3');
  527. _html("<tr><td class=\"hicell\">$text</td></tr>");
  528. }
  529. }
  530. sub _capspeople
  531. {
  532. # The ones who speak ALL CAPS.
  533. my $self = shift;
  534. my %cpercent;
  535. foreach my $nick (sort keys %{ $self->{stats}->{allcaps} }) {
  536. if ($self->{stats}->{lines}{$nick} > 100) {
  537. $cpercent{$nick} = $self->{stats}->{allcaps}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  538. $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
  539. }
  540. }
  541. my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent;
  542. if (@caps) {
  543. my %hash = (
  544. nick => $caps[0],
  545. per => $cpercent{$caps[0]},
  546. line => htmlentities($self->{stats}->{allcaplines}{$caps[0]})
  547. );
  548. my $text = $self->_template_text('allcaps1', %hash);
  549. if($self->{cfg}->{showshoutline}) {
  550. my $exttext = $self->_template_text('allcapstext', %hash);
  551. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  552. } else {
  553. _html("<tr><td class=\"hicell\">$text");
  554. }
  555. if (@caps >= 2) {
  556. my %hash = (
  557. nick => $caps[1],
  558. per => $cpercent{$caps[1]}
  559. );
  560. my $text = $self->_template_text('allcaps2', %hash);
  561. _html("<br /><span class=\"small\">$text</span>");
  562. }
  563. _html("</td></tr>");
  564. } else {
  565. my $text = $self->_template_text('allcaps3');
  566. _html("<tr><td class=\"hicell\">$text</td></tr>");
  567. }
  568. }
  569. sub _violent
  570. {
  571. # They attacked others (words defined by $self->{cfg}->{violent})
  572. my $self = shift;
  573. my @aggressors;
  574. @aggressors = sort { $self->{stats}->{violence}{$b} <=> $self->{stats}->{violence}{$a} }
  575. keys %{ $self->{stats}->{violence} };
  576. if(@aggressors) {
  577. my %hash = (
  578. nick => $aggressors[0],
  579. attacks => $self->{stats}->{violence}{$aggressors[0]},
  580. line => htmlentities($self->{stats}->{violencelines}{$aggressors[0]})
  581. );
  582. my $text = $self->_template_text('violent1', %hash);
  583. if($self->{cfg}->{showviolentlines}) {
  584. my $exttext = $self->_template_text('violenttext', %hash);
  585. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  586. } else {
  587. _html("<tr><td class=\"hicell\">$text");
  588. }
  589. if (@aggressors >= 2) {
  590. my %hash = (
  591. nick => $aggressors[1],
  592. attacks => $self->{stats}->{violence}{$aggressors[1]}
  593. );
  594. my $text = $self->_template_text('violent2', %hash);
  595. _html("<br /><span class=\"small\">$text</span>");
  596. }
  597. _html("</td></tr>");
  598. } else {
  599. my $text = $self->_template_text('violent3');
  600. _html("<tr><td class=\"hicell\">$text</td></tr>");
  601. }
  602. # They got attacked
  603. my @victims;
  604. @victims = sort { $self->{stats}->{attacked}{$b} <=> $self->{stats}->{attacked}{$a} }
  605. keys %{ $self->{stats}->{attacked} };
  606. if(@victims) {
  607. my %hash = (
  608. nick => $victims[0],
  609. attacks => $self->{stats}->{attacked}{$victims[0]},
  610. line => htmlentities($self->{stats}->{attackedlines}{$victims[0]})
  611. );
  612. my $text = $self->_template_text('attacked1', %hash);
  613. if($self->{cfg}->{showviolentlines}) {
  614. my $exttext = $self->_template_text('attackedtext', %hash);
  615. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  616. } else {
  617. _html("<tr><td class=\"hicell\">$text");
  618. }
  619. if (@victims >= 2) {
  620. my %hash = (
  621. nick => $victims[1],
  622. attacks => $self->{stats}->{attacked}{$victims[1]}
  623. );
  624. my $text = $self->_template_text('attacked2', %hash);
  625. _html("<br /><span class=\"small\">$text</span>");
  626. }
  627. _html("</td></tr>");
  628. }
  629. }
  630. sub _gotkicks
  631. {
  632. # The persons who got kicked the most
  633. my $self = shift;
  634. my @gotkick = sort { $self->{stats}->{gotkicked}{$b} <=> $self->{stats}->{gotkicked}{$a} }
  635. keys %{ $self->{stats}->{gotkicked} };
  636. if (@gotkick) {
  637. my %hash = (
  638. nick => $gotkick[0],
  639. kicks => $self->{stats}->{gotkicked}{$gotkick[0]},
  640. line => $self->{stats}->{kicklines}{$gotkick[0]}
  641. );
  642. my $text = $self->_template_text('gotkick1', %hash);
  643. if ($self->{cfg}->{showkickline}) {
  644. my $exttext = $self->_template_text('kicktext', %hash);
  645. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  646. } else {
  647. _html("<tr><td class=\"hicell\">$text");
  648. }
  649. if (@gotkick >= 2) {
  650. my %hash = (
  651. nick => $gotkick[1],
  652. kicks => $self->{stats}->{gotkicked}{$gotkick[1]}
  653. );
  654. my $text = $self->_template_text('gotkick2', %hash);
  655. _html("<br /><span class=\"small\">$text</span>");
  656. }
  657. _html("</td></tr>");
  658. }
  659. }
  660. sub _mostjoins
  661. {
  662. my $self = shift;
  663. my @joins = sort { $self->{stats}->{joins}{$b} <=> $self->{stats}->{joins}{$a} }
  664. keys %{ $self->{stats}->{joins} };
  665. if (@joins) {
  666. my %hash = (
  667. nick => $joins[0],
  668. joins => $self->{stats}->{joins}{$joins[0]}
  669. );
  670. my $text = $self->_template_text('joins', %hash);
  671. _html("<tr><td class=\"hicell\">$text</td></tr>");
  672. }
  673. }
  674. sub _mostwords
  675. {
  676. # The person who got words the most
  677. my $self = shift;
  678. my @words = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  679. keys %{ $self->{stats}->{words} };
  680. if (@words) {
  681. my %hash = (
  682. nick => $words[0],
  683. words => $self->{stats}->{words}{$words[0]}
  684. );
  685. my $text = $self->_template_text('words1', %hash);
  686. _html("<tr><td class=\"hicell\">$text");
  687. if (@words >= 2) {
  688. my %hash = (
  689. oldnick => $words[0],
  690. nick => $words[1],
  691. words => $self->{stats}->{words}{$words[1]}
  692. );
  693. my $text = $self->_template_text('words2', %hash);
  694. _html("<br /><span class=\"small\">$text</span>");
  695. }
  696. _html("</td></tr>");
  697. } else {
  698. my $text = $self->_template_text('kick3');
  699. _html("<tr><td class=\"hicell\">$text</td></tr>");
  700. }
  701. }
  702. sub _mostkicks
  703. {
  704. # The person who kicked the most
  705. my $self = shift;
  706. my @kicked = sort { $self->{stats}->{kicked}{$b} <=> $self->{stats}->{kicked}{$a} }
  707. keys %{ $self->{stats}->{kicked} };
  708. if (@kicked) {
  709. my %hash = (
  710. nick => $kicked[0],
  711. kicked => $self->{stats}->{kicked}{$kicked[0]}
  712. );
  713. my $text = $self->_template_text('kick1', %hash);
  714. _html("<tr><td class=\"hicell\">$text");
  715. if (@kicked >= 2) {
  716. my %hash = (
  717. oldnick => $kicked[0],
  718. nick => $kicked[1],
  719. kicked => $self->{stats}->{kicked}{$kicked[1]}
  720. );
  721. my $text = $self->_template_text('kick2', %hash);
  722. _html("<br /><span class=\"small\">$text</span>");
  723. }
  724. _html("</td></tr>");
  725. } else {
  726. my $text = $self->_template_text('kick3');
  727. _html("<tr><td class=\"hicell\">$text</td></tr>");
  728. }
  729. }
  730. sub _mostmonologues
  731. {
  732. # The person who had the most monologues (speaking to himself)
  733. my $self = shift;
  734. my @monologue = sort { $self->{stats}->{monologues}{$b} <=> $self->{stats}->{monologues}{$a} } keys %{ $self->{stats}->{monologues} };
  735. if (@monologue) {
  736. my %hash = (
  737. nick => $monologue[0],
  738. monos => $self->{stats}->{monologues}{$monologue[0]}
  739. );
  740. my $text = $self->_template_text('mono1', %hash);
  741. _html("<tr><td class=\"hicell\">$text");
  742. if (@monologue >= 2) {
  743. my %hash = (
  744. nick => $monologue[1],
  745. monos => $self->{stats}->{monologues}{$monologue[1]}
  746. );
  747. my $text = $self->_template_text('mono2', %hash);
  748. _html("<br /><span class=\"small\">$text</span>");
  749. }
  750. _html("</td></tr>");
  751. }
  752. }
  753. sub _linelengths
  754. {
  755. # The person(s) who wrote the longest lines
  756. my $self = shift;
  757. my %len;
  758. foreach my $nick (sort keys %{ $self->{stats}->{lengths} }) {
  759. if ($self->{stats}->{lines}{$nick} > 100) {
  760. $len{$nick} = $self->{stats}->{lengths}{$nick} / $self->{stats}->{lines}{$nick};
  761. $len{$nick} =~ s/(\.\d)\d+/$1/;
  762. }
  763. }
  764. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  765. my $all_lines = 0;
  766. my $totallength;
  767. foreach my $nick (keys %{ $self->{stats}->{lines} }) {
  768. $all_lines += $self->{stats}->{lines}{$nick};
  769. $totallength += $self->{stats}->{lengths}{$nick};
  770. }
  771. my $totalaverage;
  772. if ($all_lines > 0) {
  773. $totalaverage = $totallength / $all_lines;
  774. $totalaverage =~ s/(\.\d)\d+/$1/;
  775. }
  776. if (@len) {
  777. my %hash = (
  778. nick => $len[0],
  779. letters => $len{$len[0]}
  780. );
  781. my $text = $self->_template_text('long1', %hash);
  782. _html("<tr><td class=\"hicell\">$text<br />");
  783. if (@len >= 2) {
  784. %hash = (
  785. avg => $totalaverage
  786. );
  787. $text = $self->_template_text('long2', %hash);
  788. _html("<span class=\"small\">$text</span></td></tr>");
  789. }
  790. }
  791. # The person(s) who wrote the shortest lines
  792. if (@len) {
  793. my %hash = (
  794. nick => $len[$#len],
  795. letters => $len{$len[$#len]}
  796. );
  797. my $text = $self->_template_text('short1', %hash);
  798. _html("<tr><td class=\"hicell\">$text<br />");
  799. if (@len >= 2) {
  800. %hash = (
  801. nick => $len[$#len - 1],
  802. letters => $len{$len[$#len - 1]}
  803. );
  804. $text = $self->_template_text('short2', %hash);
  805. _html("<span class=\"small\">$text</span></td></tr>");
  806. }
  807. }
  808. }
  809. sub _mostfoul
  810. {
  811. my $self = shift;
  812. my %spercent;
  813. foreach my $nick (sort keys %{ $self->{stats}->{foul} }) {
  814. if ($self->{stats}->{lines}{$nick} > 15) {
  815. $spercent{$nick} = $self->{stats}->{foul}{$nick} / $self->{stats}->{words}{$nick} * 100;
  816. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  817. }
  818. }
  819. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  820. if (@foul) {
  821. my %hash = (
  822. nick => $foul[0],
  823. per => $spercent{$foul[0]},
  824. line => htmlentities($self->{stats}{foullines}{$foul[0]}),
  825. );
  826. my $text = $self->_template_text('foul1', %hash);
  827. if($self->{cfg}->{showfoulline}) {
  828. my $exttext = $self->_template_text('foultext', %hash);
  829. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  830. } else {
  831. _html("<tr><td class=\"hicell\">$text");
  832. }
  833. if (@foul >= 2) {
  834. my %hash = (
  835. nick => $foul[1],
  836. per => $spercent{$foul[1]}
  837. );
  838. my $text = $self->_template_text('foul2', %hash);
  839. _html("<br /><span class=\"small\">$text</span>");
  840. }
  841. _html("</td></tr>");
  842. } else {
  843. my $text = $self->_template_text('foul3');
  844. _html("<tr><td class=\"hicell\">$text</td></tr>");
  845. }
  846. }
  847. sub _mostsad
  848. {
  849. my $self = shift;
  850. my %spercent;
  851. foreach my $nick (sort keys %{ $self->{stats}->{frowns} }) {
  852. if ($self->{stats}->{lines}{$nick} > 100) {
  853. $spercent{$nick} = $self->{stats}->{frowns}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  854. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  855. }
  856. }
  857. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  858. if (@sadface) {
  859. my %hash = (
  860. nick => $sadface[0],
  861. per => $spercent{$sadface[0]}
  862. );
  863. my $text = $self->_template_text('sad1', %hash);
  864. _html("<tr><td class=\"hicell\">$text");
  865. if (@sadface >= 2) {
  866. my %hash = (
  867. nick => $sadface[1],
  868. per => $spercent{$sadface[1]}
  869. );
  870. my $text = $self->_template_text('sad2', %hash);
  871. _html("<br /><span class=\"small\">$text</span>");
  872. }
  873. _html("</td></tr>");
  874. } else {
  875. my $text = $self->_template_text('sad3');
  876. _html("<tr><td class=\"hicell\">$text</td></tr>");
  877. }
  878. }
  879. sub _mostop
  880. {
  881. my $self = shift;
  882. my @ops = sort { $self->{stats}->{gaveops}{$b} <=> $self->{stats}->{gaveops}{$a} }
  883. keys %{ $self->{stats}->{gaveops} };
  884. my @deops = sort { $self->{stats}->{tookops}{$b} <=> $self->{stats}->{tookops}{$a} }
  885. keys %{ $self->{stats}->{tookops} };
  886. if (@ops) {
  887. my %hash = (
  888. nick => $ops[0],
  889. ops => $self->{stats}->{gaveops}{$ops[0]}
  890. );
  891. my $text = $self->_template_text('mostop1', %hash);
  892. _html("<tr><td class=\"hicell\">$text");
  893. if (@ops >= 2) {
  894. my %hash = (
  895. nick => $ops[1],
  896. ops => $self->{stats}->{gaveops}{$ops[1]}
  897. );
  898. my $text = $self->_template_text('mostop2', %hash);
  899. _html("<br /><span class=\"small\">$text</span>");
  900. }
  901. _html("</td></tr>");
  902. } else {
  903. my $text = $self->_template_text('mostop3');
  904. _html("<tr><td class=\"hicell\">$text</td></tr>");
  905. }
  906. if (@deops) {
  907. my %hash = (
  908. nick => $deops[0],
  909. deops => $self->{stats}->{tookops}{$deops[0]}
  910. );
  911. my $text = $self->_template_text('mostdeop1', %hash);
  912. _html("<tr><td class=\"hicell\">$text");
  913. if (@deops >= 2) {
  914. my %hash = (
  915. nick => $deops[1],
  916. deops => $self->{stats}->{tookops}{$deops[1]}
  917. );
  918. my $text = $self->_template_text('mostdeop2', %hash);
  919. _html("<br /><span class=\"small\">$text</span>");
  920. }
  921. _html("</td></tr>");
  922. } else {
  923. my $text = $self->_template_text('mostdeop3');
  924. _html("<tr><td class=\"hicell\">$text</td></tr>");
  925. }
  926. }
  927. sub _mostvoice
  928. {
  929. my $self = shift;
  930. my @voice = sort { $self->{stats}->{gavevoice}{$b} <=> $self->{stats}->{gavevoice}{$a} }
  931. keys %{ $self->{stats}->{gavevoice} };
  932. my @devoice = sort { $self->{stats}->{tookvoice}{$b} <=> $self->{stats}->{tookvoice}{$a} }
  933. keys %{ $self->{stats}->{tookvoice} };
  934. if (@voice) {
  935. my %hash = (
  936. nick => $voice[0],
  937. voices => $self->{stats}->{gavevoice}{$voice[0]}
  938. );
  939. my $text = $self->_template_text('mostvoice1', %hash);
  940. _html("<tr><td class=\"hicell\">$text");
  941. if (@voice >= 2) {
  942. my %hash = (
  943. nick => $voice[1],
  944. voices => $self->{stats}->{gavevoice}{$voice[1]}
  945. );
  946. my $text = $self->_template_text('mostvoice2', %hash);
  947. _html("<br /><span class=\"small\">$text</span>");
  948. }
  949. _html("</td></tr>");
  950. } else {
  951. my $text = $self->_template_text('mostvoice3');
  952. _html("<tr><td class=\"hicell\">$text</td></tr>");
  953. }
  954. if (@devoice) {
  955. my %hash = (
  956. nick => $devoice[0],
  957. devoices => $self->{stats}->{tookvoice}{$devoice[0]}
  958. );
  959. my $text = $self->_template_text('mostdevoice1', %hash);
  960. _html("<tr><td class=\"hicell\">$text");
  961. if (@devoice >= 2) {
  962. my %hash = (
  963. nick => $devoice[1],
  964. devoices => $self->{stats}->{tookvoice}{$devoice[1]}
  965. );
  966. my $text = $self->_template_text('mostdevoice2', %hash);
  967. _html("<br /><span class=\"small\">$text</span>");
  968. }
  969. _html("</td></tr>");
  970. } else {
  971. my $text = $self->_template_text('mostdevoice3');
  972. _html("<tr><td class=\"hicell\">$text</td></tr>");
  973. }
  974. }
  975. sub _mosthalfop
  976. {
  977. my $self = shift;
  978. my @halfops = sort { $self->{stats}->{gavehalfops}{$b} <=> $self->{stats}->{gavehalfops}{$a} }
  979. keys %{ $self->{stats}->{gavehalfops} };
  980. my @dehalfops = sort { $self->{stats}->{tookhalfops}{$b} <=> $self->{stats}->{tookhalfops}{$a} }
  981. keys %{ $self->{stats}->{tookhalfops} };
  982. if (@halfops) {
  983. my %hash = (
  984. nick => $halfops[0],
  985. halfops => $self->{stats}->{gavehalfops}{$halfops[0]}
  986. );
  987. my $text = $self->_template_text('mosthalfop1', %hash);
  988. _html("<tr><td class=\"hicell\">$text");
  989. if (@halfops >= 2) {
  990. my %hash = (
  991. nick => $halfops[1],
  992. halfops => $self->{stats}->{gavehalfops}{$halfops[1]}
  993. );
  994. my $text = $self->_template_text('mosthalfop2', %hash);
  995. _html("<br /><span class=\"small\">$text</span>");
  996. }
  997. _html("</td></tr>");
  998. } else {
  999. my $text = $self->_template_text('mosthalfop3');
  1000. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1001. }
  1002. if (@dehalfops) {
  1003. my %hash = (
  1004. nick => $dehalfops[0],
  1005. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[0]}
  1006. );
  1007. my $text = $self->_template_text('mostdehalfop1', %hash);
  1008. _html("<tr><td class=\"hicell\">$text");
  1009. if (@dehalfops >= 2) {
  1010. my %hash = (
  1011. nick => $dehalfops[1],
  1012. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[1]}
  1013. );
  1014. my $text = $self->_template_text('mostdehalfop2', %hash);
  1015. _html("<br /><span class=\"small\">$text</span>");
  1016. }
  1017. _html("</td></tr>");
  1018. } else {
  1019. my $text = $self->_template_text('mostdehalfop3');
  1020. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1021. }
  1022. }
  1023. sub _mostactions
  1024. {
  1025. # The person who did the most /me's
  1026. my $self = shift;
  1027. my @actions = sort { $self->{stats}->{actions}{$b} <=> $self->{stats}->{actions}{$a} }
  1028. keys %{ $self->{stats}->{actions} };
  1029. if (@actions) {
  1030. my %hash = (
  1031. nick => $actions[0],
  1032. actions => $self->{stats}->{actions}{$actions[0]},
  1033. line => htmlentities($self->{stats}->{actionlines}{$actions[0]})
  1034. );
  1035. my $text = $self->_template_text('action1', %hash);
  1036. if($self->{cfg}->{showactionline}) {
  1037. my $exttext = $self->_template_text('actiontext', %hash);
  1038. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  1039. } else {
  1040. _html("<tr><td class=\"hicell\">$text");
  1041. }
  1042. if (@actions >= 2) {
  1043. my %hash = (
  1044. nick => $actions[1],
  1045. actions => $self->{stats}->{actions}{$actions[1]}
  1046. );
  1047. my $text = $self->_template_text('action2', %hash);
  1048. _html("<br /><span class=\"small\">$text</span>");
  1049. }
  1050. _html("</td></tr>");
  1051. } else {
  1052. my $text = $self->_template_text('action3');
  1053. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1054. }
  1055. }
  1056. sub _mostsmiles
  1057. {
  1058. # The person(s) who smiled the most :-)
  1059. my $self = shift;
  1060. my %spercent;
  1061. foreach my $nick (sort keys %{ $self->{stats}->{smiles} }) {
  1062. if ($self->{stats}->{lines}{$nick} > 100) {
  1063. $spercent{$nick} = $self->{stats}->{smiles}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  1064. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1065. }
  1066. }
  1067. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1068. if (@smiles) {
  1069. my %hash = (
  1070. nick => $smiles[0],
  1071. per => $spercent{$smiles[0]}
  1072. );
  1073. my $text = $self->_template_text('smiles1', %hash);
  1074. _html("<tr><td class=\"hicell\">$text");
  1075. if (@smiles >= 2) {
  1076. my %hash = (
  1077. nick => $smiles[1],
  1078. per => $spercent{$smiles[1]}
  1079. );
  1080. my $text = $self->_template_text('smiles2', %hash);
  1081. _html("<br /><span class=\"small\">$text</span>");
  1082. }
  1083. _html("</td></tr>");
  1084. } else {
  1085. my $text = $self->_template_text('smiles3');
  1086. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1087. }
  1088. }
  1089. sub _lasttopics
  1090. {
  1091. my $self = shift;
  1092. if ($self->{stats}->{topics}) {
  1093. my %topic_seen;
  1094. my %hash = (
  1095. total => scalar @{ $self->{stats}->{topics} }
  1096. );
  1097. my $ltopic = $#{ $self->{stats}->{topics} };
  1098. my $tlimit = 0;
  1099. $self->{cfg}->{topichistory} -= 1;
  1100. if ($ltopic > $self->{cfg}->{topichistory}) {
  1101. $tlimit = $ltopic - $self->{cfg}->{topichistory};
  1102. }
  1103. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1104. my $topic = htmlentities($self->{stats}->{topics}[$i]{topic});
  1105. # This code makes sure that we don't see the same topic twice
  1106. next if ($topic_seen{$topic});
  1107. $topic_seen{$topic} = 1;
  1108. $topic = $self->_replace_links($topic);
  1109. # Strip off the quotes (')
  1110. $topic =~ s/^\'(.*)\'$/$1/;
  1111. my $nick = $self->{stats}->{topics}[$i]{nick};
  1112. my $hour = $self->{stats}->{topics}[$i]{hour};
  1113. my $min = $self->{stats}->{topics}[$i]{min};
  1114. $hash{nick} = $nick;
  1115. $hash{time} = "$hour:$min";
  1116. _html("<tr><td class=\"hicell\"><i>$topic</i></td>");
  1117. _html("<td class=\"hicell\"><b>" . $self->_template_text('bylinetopic', %hash) ."</b></td></tr>");
  1118. }
  1119. _html("<tr><td align=\"center\" colspan=\"2\" class=\"asmall\">" . $self->_template_text('totaltopic', %hash) . "</td></tr>");
  1120. } else {
  1121. _html("<tr><td class=\"hicell\">" . $self->_template_text('notopic') ."</td></tr>");
  1122. }
  1123. }
  1124. sub _template_text
  1125. {
  1126. # This function is for the homemade template system. It receives a name
  1127. # of a template and a hash with the fields in the template to update to
  1128. # its corresponding value
  1129. my $self = shift;
  1130. my $template = shift;
  1131. my %hash = @_;
  1132. my $text;
  1133. unless ($text = $self->{tmps}->{lc($self->{cfg}->{lang})}{$template}) {
  1134. # Fall back to English if the language template doesn't exist
  1135. if ($text = $self->{tmps}->{en}{$template}) {
  1136. print "Note: No translation in '$self->{cfg}->{lang}' for '$template' - falling back to English..\n"
  1137. unless ($self->{cfg}->{silent});
  1138. } else {
  1139. die("No such template '$template' in language file.\n");
  1140. }
  1141. }
  1142. $hash{channel} = $self->{cfg}->{channel};
  1143. foreach my $key (sort keys %hash) {
  1144. $text =~ s/\[:$key\]/$hash{$key}/;
  1145. $text =~ s/ü/&uuml;/go;
  1146. $text =~ s/ö/&ouml;/go;
  1147. $text =~ s/ä/&auml;/go;
  1148. $text =~ s/ß/&szlig;/go;
  1149. $text =~ s/å/&aring;/go;
  1150. $text =~ s/æ/&aelig;/go;
  1151. $text =~ s/ø/&oslash;/go;
  1152. $text =~ s/Å/&Aring;/go;
  1153. $text =~ s/Æ/&AElig;/go;
  1154. $text =~ s/Ø/&Oslash;/go;
  1155. }
  1156. if ($text =~ /\[:.*?:.*?:\]/o) {
  1157. $text =~ s/\[:(.*?):(.*?):\]/$self->_get_subst($1,$2,\%hash)/geo;
  1158. }
  1159. return $text;
  1160. }
  1161. sub _get_subst
  1162. {
  1163. # This function looks at the user definition and see if there is sex
  1164. # defined. If yes, return the appropriate value. If no, just return the
  1165. # default he/she value.
  1166. my $self = shift;
  1167. my ($m,$f,$hash) = @_;
  1168. if ($hash->{nick} && $self->{users}->{sex}{$hash->{nick}}) {
  1169. if ($self->{users}->{sex}{$hash->{nick}} eq 'm') {
  1170. return $m;
  1171. } elsif ($self->{users}->{sex}{$hash->{nick}} eq 'f') {
  1172. return $f;
  1173. }
  1174. }
  1175. return "$m/$f";
  1176. }
  1177. sub _mostusedword
  1178. {
  1179. # Word usage statistics
  1180. my $self = shift;
  1181. my %usages;
  1182. foreach my $word (keys %{ $self->{stats}->{wordcounts} }) {
  1183. # Skip people's nicks.
  1184. next if exists $self->{stats}->{lines}{$word};
  1185. next if (length($word) < $self->{cfg}->{wordlength});
  1186. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1187. }
  1188. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1189. if (@popular) {
  1190. $self->_headline($self->_template_text('mostwordstopic'));
  1191. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1192. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('word') . "</b></td>");
  1193. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1194. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1195. my $count = 0;
  1196. for(my $i = 0; $count < $self->{cfg}->{wordhistory}; $i++) {
  1197. last unless $i < $#popular;
  1198. # Skip nicks. It's far more efficient to do this here than when
  1199. # @popular is created.
  1200. next if is_ignored($popular[$i]);
  1201. next if exists $self->{stats}->{lines}{find_alias($popular[$i])};
  1202. my $a = $count + 1;
  1203. my $popular = htmlentities($popular[$i]);
  1204. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1205. my $lastused = htmlentities($self->{stats}->{wordnicks}{$popular[$i]});
  1206. my $class;
  1207. if ($a == 1) {
  1208. $class = 'hirankc';
  1209. } else {
  1210. $class = 'rankc';
  1211. }
  1212. _html("<tr><td class=\"$class\">$a</td>");
  1213. _html("<td class=\"hicell\">$popular</td>");
  1214. _html("<td class=\"hicell\">$wordcount</td>");
  1215. _html("<td class=\"hicell\">$lastused</td>");
  1216. _html("</tr>");
  1217. $count++;
  1218. }
  1219. _html("</table>");
  1220. }
  1221. }
  1222. sub _mostwordsperline
  1223. {
  1224. # The person who got the most words per line
  1225. my $self = shift;
  1226. my %wpl = ();
  1227. my $numlines = 0;
  1228. my ($avg, $numwords);
  1229. foreach my $n (keys %{ $self->{stats}->{words} }) {
  1230. $wpl{$n} = sprintf("%.2f", $self->{stats}->{words}{$n}/$self->{stats}->{lines}{$n});
  1231. $numlines += $self->{stats}->{lines}{$n};
  1232. $numwords += $self->{stats}->{words}{$n};
  1233. }
  1234. if ($numlines > 0) {
  1235. $avg = sprintf("%.2f", $numwords/$numlines);
  1236. }
  1237. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  1238. if (@wpl) {
  1239. my %hash = (
  1240. nick => $wpl[0],
  1241. wpl => $wpl{$wpl[0]}
  1242. );
  1243. my $text = $self->_template_text('wpl1', %hash);
  1244. _html("<tr><td class=\"hicell\">$text");
  1245. $hash{avg} = $avg;
  1246. $text = $self->_template_text('wpl2', %hash);
  1247. _html("<br /><span class=\"small\">$text</span>");
  1248. _html("</td></tr>");
  1249. }
  1250. }
  1251. sub _mostreferencednicks
  1252. {
  1253. # List showing the most referenced nicks
  1254. my $self = shift;
  1255. my %usages;
  1256. foreach my $word (sort keys %{ $self->{stats}->{wordcounts} }) {
  1257. next if !exists $self->{stats}->{lines}{$word};
  1258. next if is_ignored($word);
  1259. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1260. }
  1261. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1262. if (@popular) {
  1263. $self->_headline($self->_template_text('referencetopic'));
  1264. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1265. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>");
  1266. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1267. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1268. for(my $i = 0; $i < $self->{cfg}->{nickhistory}; $i++) {
  1269. last unless $i < $#popular;
  1270. my $a = $i + 1;
  1271. my $popular = $popular[$i];
  1272. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1273. my $lastused = $self->{stats}->{wordnicks}{$popular[$i]};
  1274. my $class;
  1275. if ($a == 1) {
  1276. $class = 'hirankc';
  1277. } else {
  1278. $class = 'rankc';
  1279. }
  1280. _html("<tr><td class=\"$class\">$a</td>");
  1281. _html("<td class=\"hicell\">$popular</td>");
  1282. _html("<td class=\"hicell\">$wordcount</td>");
  1283. _html("<td class=\"hicell\">$lastused</td>");
  1284. _html("</tr>");
  1285. }
  1286. _html("</table>");
  1287. }
  1288. }
  1289. sub _mosturls
  1290. {
  1291. # List showing the most referenced URLs
  1292. my $self = shift;
  1293. my @sorturls = sort { $self->{stats}->{urlcounts}{$b} <=> $self->{stats}->{urlcounts}{$a} }
  1294. keys %{ $self->{stats}->{urlcounts} };
  1295. if (@sorturls) {
  1296. $self->_headline($self->_template_text('urlstopic'));
  1297. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1298. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('url') . "</b></td>");
  1299. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1300. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1301. for(my $i = 0; $i < $self->{cfg}->{urlhistory}; $i++) {
  1302. last unless $i < @sorturls;
  1303. my $a = $i + 1;
  1304. my $sorturl = $sorturls[$i];
  1305. my $urlcount = $self->{stats}->{urlcounts}{$sorturls[$i]};
  1306. my $lastused = $self->{stats}->{urlnicks}{$sorturls[$i]};
  1307. if (length($sorturl) > 60) {
  1308. $sorturl = substr($sorturl, 0, 60);
  1309. }
  1310. my $class;
  1311. if ($a == 1) {
  1312. $class = 'hirankc';
  1313. } else {
  1314. $class = 'rankc';
  1315. }
  1316. _html("<tr><td class=\"$class\">$a</td>");
  1317. _html("<td class=\"hicell\"><a href=\"$sorturls[$i]\">$sorturl</a></td>");
  1318. _html("<td class=\"hicell\">$urlcount</td>");
  1319. _html("<td class=\"hicell\">$lastused</td>");
  1320. _html("</tr>");
  1321. }
  1322. _html("</table>");
  1323. }
  1324. }
  1325. sub _legend
  1326. {
  1327. # A legend showing the timebars and their associated time.
  1328. my $self = shift;
  1329. _html("<table align=\"center\" border=\"0\" width=\"520\"><tr>");
  1330. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_0}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"0-5\" /> = 0-5</td>");
  1331. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_6}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"6-11\" /> = 6-11</td>");
  1332. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_12}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"12-17\" /> = 12-17</td>");
  1333. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_18}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"18-23\" /> = 18-23</td>");
  1334. _html("</tr></table>\n");
  1335. }
  1336. sub _replace_links
  1337. {
  1338. # Sub to replace urls and e-mail addys to links
  1339. my $self = shift;
  1340. my $str = shift;
  1341. my $nick = shift;
  1342. # Regular expressions are taken from match_urls() and match_email() in
  1343. # Common.pm
  1344. my $texturl = $self->_template_text("newwindow");
  1345. my $textmail = $self->_template_text("mailto");
  1346. if ($nick) {
  1347. $str =~ s/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_\/~]+\.[-a-zA-Z0-9.,_~=:&amp;@%?#\/+]+)/<a href="$1$2" target="_blank" title="$texturl $1$2">$nick<\/a>/g;
  1348. $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="$textmail $nick">$nick<\/a>/g;
  1349. } else {
  1350. $str =~ s/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_\/~]+\.[-a-zA-Z0-9.,_~=:&amp;@%?#\/+]+)/<a href="$1$2" target="_blank" title="$texturl $1$2">$1$2<\/a>/g;
  1351. $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="$textmail $1">$1<\/a>/g;
  1352. }
  1353. return $str;
  1354. }
  1355. sub _user_linetimes
  1356. {
  1357. my $self = shift;
  1358. my $nick = shift;
  1359. my $top = shift;
  1360. my $bar = "";
  1361. my $len = ($self->{stats}->{lines}{$nick} / $self->{stats}->{lines}{$top}) * 100;
  1362. for (my $i = 0; $i <= 3; $i++) {
  1363. next if not defined $self->{stats}->{line_times}{$nick}[$i];
  1364. my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * $len);
  1365. if ($w) {
  1366. my $pic = 'pic_h_'.(6*$i);
  1367. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />";
  1368. }
  1369. }
  1370. return "$bar&nbsp;$self->{stats}->{lines}{$nick}";
  1371. }
  1372. sub _user_wordtimes
  1373. {
  1374. my $self = shift;
  1375. my $nick = shift;
  1376. my $top = shift;
  1377. my $bar = "";
  1378. my $len = ($self->{stats}->{words}{$nick} / $self->{stats}->{words}{$top}) * 100;
  1379. for (my $i = 0; $i <= 3; $i++) {
  1380. next if not defined $self->{stats}->{word_times}{$nick}[$i];
  1381. my $w = int(($self->{stats}->{word_times}{$nick}[$i] / $self->{stats}->{words}{$nick}) * $len);
  1382. if ($w) {
  1383. my $pic = 'pic_h_'.(6*$i);
  1384. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />";
  1385. }
  1386. }
  1387. return "$bar&nbsp;$self->{stats}->{words}{$nick}";
  1388. }
  1389. sub _user_times
  1390. {
  1391. my $self = shift;
  1392. my ($nick) = @_;
  1393. my $bar = "";
  1394. my $itemstat = ($self->{cfg}->{sortbywords} ? 'words' : 'lines');
  1395. my $timestat = ($self->{cfg}->{sortbywords} ? 'word_times' : 'line_times');
  1396. for (my $i = 0; $i <= 3; $i++) {
  1397. next if not defined $self->{stats}->{$timestat}{$nick}[$i];
  1398. my $w = int(($self->{stats}->{$timestat}{$nick}[$i] / $self->{stats}->{$itemstat}{$nick}) * 40);
  1399. if ($w) {
  1400. my $pic = 'pic_h_'.(6*$i);
  1401. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\" />";
  1402. }
  1403. }
  1404. return $bar;
  1405. }
  1406. sub _mostnicks
  1407. {
  1408. # List showing the user with most used nicks
  1409. my $self = shift;
  1410. my @sortnicks = sort { @{ $self->{stats}->{nicks}->{$b} } <=> @{ $self->{stats}->{nicks}->{$a} } }
  1411. keys %{ $self->{stats}->{nicks} };
  1412. if (@{ $self->{stats}->{nicks}->{$sortnicks[0]} } > 1) {
  1413. $self->_headline($self->_template_text('mostnickstopic'));
  1414. my $names1 = $self->_template_text('names1');
  1415. my $names2 = $self->_template_text('names2');
  1416. my $nick_txt = $self->_template_text('nick');
  1417. my $names_txt = $self->_template_text('names');
  1418. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1419. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>$nick_txt</b></td>");
  1420. _html("<td class=\"tdtop\"><b>$names_txt</b></td></tr>");
  1421. for(my $i = 0; $i < $self->{cfg}->{mostnickshistory}; $i++) {
  1422. next if is_ignored($sortnicks[$i]);
  1423. last unless $i < @sortnicks;
  1424. my $nickcount = scalar(@{ $self->{stats}->{nicks}->{$sortnicks[$i]} });
  1425. my $nickused = join(", ", @{ $self->{stats}->{nicks}->{$sortnicks[$i]} });
  1426. next unless ($nickcount > 1);
  1427. my $a = $i + 1;
  1428. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1429. my $n = $nickcount > 1 ? $names1 : $names2;
  1430. _html("<tr><td class=\"$class\">$a</td>");
  1431. _html("<td class=\"hicell10\">$sortnicks[$i]<br />($nickcount $n)</td>");
  1432. _html("<td class=\"hicell10\" valign='top'>$nickused</td>");
  1433. _html("</tr>");
  1434. }
  1435. _html("</table>");
  1436. }
  1437. }
  1438. sub _mostactivebyhour
  1439. {
  1440. # Charts for most active nicks by hour (0-5, 6-11, 12-17, 18-23)
  1441. my $self = shift;
  1442. my $sortnicks;
  1443. my $lastline=-1;
  1444. my $maxlines=0;
  1445. foreach my $period (0,1,2,3) {
  1446. my @sortnicks =
  1447. sort
  1448. {
  1449. (defined $self->{stats}->{line_times}{$b}[$period]?$self->{stats}->{line_times}{$b}[$period]:0)
  1450. <=>
  1451. (defined $self->{stats}->{line_times}{$a}[$period]?$self->{stats}->{line_times}{$a}[$period]:0)
  1452. }
  1453. keys %{ $self->{stats}->{line_times} } ;
  1454. for(my $i = 0; $i < $self->{cfg}->{activenicksbyhour}; $i++) {
  1455. next if ! $sortnicks[$i];
  1456. next if is_ignored($sortnicks[$i]);
  1457. last unless $i < @sortnicks;
  1458. my $nick=$sortnicks[$i];
  1459. my $count=$self->{stats}->{line_times}{$nick}[$period] || 0;
  1460. last unless $nick;
  1461. last unless $count;
  1462. $sortnicks->[$period][$i]=$nick;
  1463. if ($lastline<$i) {
  1464. $lastline=$i;
  1465. }
  1466. if ($maxlines<$count) {
  1467. $maxlines=$count;
  1468. }
  1469. }
  1470. }
  1471. if ($lastline>=0) {
  1472. $self->_headline($self->_template_text('activenickbyhourtopic'));
  1473. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1474. _html("<td>&nbsp;</td>");
  1475. _html("<td class=\"tdtop\"><b>0-5</b></td>");
  1476. _html("<td class=\"tdtop\"><b>6-11</b></td>");
  1477. _html("<td class=\"tdtop\"><b>12-17</b></td>");
  1478. _html("<td class=\"tdtop\"><b>18-23</b></td>");
  1479. _html("</tr>");
  1480. for(my $i = 0; $i <= $lastline; $i++) {
  1481. my $a = $i + 1;
  1482. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1483. _html("<tr><td class=\"$class\">$a</td>");
  1484. foreach my $period (0,1,2,3) {
  1485. my $nick=$sortnicks->[$period][$i];
  1486. if ($nick) {
  1487. my $count=$self->{stats}->{line_times}{$nick}[$period];
  1488. if ($count) {
  1489. _html("<td class=\"hicell\">".$nick." - ".$count);
  1490. if ($self->{cfg}->{showmostactivebyhourgraph}) {
  1491. my $pic = 'pic_h_'.(6*$period);
  1492. my $w = int(($count / $maxlines) * 100);
  1493. _html("<br /><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />");
  1494. }
  1495. _html("</td>");
  1496. } else {
  1497. _html("<td class=\"hicell\">&nbsp;</td>");
  1498. }
  1499. } else {
  1500. _html("<td class=\"hicell\">&nbsp;</td>");
  1501. }
  1502. }
  1503. _html("</tr>");
  1504. }
  1505. _html("</table>");
  1506. }
  1507. }
  1508. 1;
  1509. __END__
  1510. =head1 NAME
  1511. Pisg::HTMLGenerator - class to create a static HTML page out of data parsed
  1512. =head1 DESCRIPTION
  1513. C<Pisg::HTMLGenerator> uses the hash returned by Pisg::Parser::Logfile and turns it into a static HTML page.
  1514. =head1 SYNOPSIS
  1515. use Pisg::HTMLGenerator;
  1516. $generator = new Pisg::HTMLGenerator(
  1517. cfg => $cfg,
  1518. stats => $stats,
  1519. users => $users,
  1520. tmps => $tmps
  1521. );
  1522. =head1 CONSTRUCTOR
  1523. =over 4
  1524. =item new ( [ OPTIONS ] )
  1525. This is the constructor for a new Pisg::HTMLGenerator object. C<OPTIONS> are passed in a hash like fashion using key and value pairs.
  1526. Possible options are:
  1527. B<cfg> - hashref containing configuration variables, created by the Pisg module.
  1528. B<stats> - reference to the hash returned by Pisg::Parser::Logfile containing all stats.
  1529. B<users> - reference to a hash containg user information
  1530. B<tmps> - reference to a hash containing the language templates.
  1531. =back
  1532. =head1 AUTHOR
  1533. Morten Brix Pedersen <morten@wtf.dk>
  1534. =head1 COPYRIGHT
  1535. Copyright (C) 2001-2002 Morten Brix Pedersen. All rights reserved.
  1536. This program is free software; you can redistribute it and/or modify it
  1537. under the terms of the GPL, license is included with the distribution of
  1538. this file.
  1539. =cut