HTMLGenerator.pm 60 KB

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