HTMLGenerator.pm 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951
  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. if ($self->{stats}->{actions}{$nick}) {
  335. $randomline = htmlentities($self->_format_line($self->{stats}->{actionlines}{$nick}));
  336. } else {
  337. $randomline = "";
  338. }
  339. } else {
  340. $randomline = htmlentities($self->{stats}->{sayings}{$nick});
  341. }
  342. # Convert URLs and e-mail addys to links
  343. $randomline = $self->_replace_links($randomline);
  344. # Add a link to the nick if there is any
  345. if ($self->{users}->{userlinks}{$nick}) {
  346. $visiblenick = $self->_replace_links($self->{users}->{userlinks}{$nick}, $nick);
  347. }
  348. my $color = $self->generate_colors($c);
  349. my $class = 'rankc';
  350. if ($c == 1) {
  351. $class = 'hirankc';
  352. }
  353. my $lastseen;
  354. if ($self->{cfg}->{showlastseen}) {
  355. $lastseen = $self->{stats}->{days} - $self->{stats}->{lastvisited}{$nick};
  356. if ($lastseen == 0) {
  357. $lastseen = $self->_template_text('today');
  358. } elsif ($lastseen == 1) {
  359. $lastseen = "$lastseen " .$self->_template_text('lastseen1');
  360. } else {
  361. $lastseen = "$lastseen " .$self->_template_text('lastseen2');
  362. }
  363. }
  364. _html("<tr><td class=\"$class\" align=\"left\">$c</td>");
  365. my $line = $self->{stats}->{lines}{$nick};
  366. my $w = $self->{stats}->{words}{$nick} ? $self->{stats}->{words}{$nick} : 0;
  367. my $ch = $self->{stats}->{lengths}{$nick};
  368. _html("<td style=\"background-color: $color\">$visiblenick</td>"
  369. . ($self->{cfg}->{showlinetime} ?
  370. "<td style=\"background-color: $color\" nowrap=\"nowrap\">".$self->_user_linetimes($nick,$active[0])."</td>"
  371. : "<td style=\"background-color: $color\">$line</td>")
  372. . ($self->{cfg}->{showtime} ?
  373. "<td style=\"background-color: $color\">".$self->_user_times($nick)."</td>"
  374. : "")
  375. . ($self->{cfg}->{showwords} ?
  376. ($self->{cfg}->{showwordtime} ?
  377. "<td style=\"background-color: $color\" nowrap=\"nowrap\">".$self->_user_wordtimes($nick,$active[0])."</td>"
  378. : "<td style=\"background-color: $color\">$w</td>")
  379. : "")
  380. . ($self->{cfg}->{showwpl} ?
  381. "<td style=\"background-color: $color\">".sprintf("%.1f",$w/$line)."</td>"
  382. : "")
  383. . ($self->{cfg}->{showcpl} ?
  384. "<td style=\"background-color: $color\">".sprintf("%.1f",$ch/$line)."</td>"
  385. : "")
  386. . ($self->{cfg}->{showlastseen} ?
  387. "<td style=\"background-color: $color\">$lastseen</td>"
  388. : "")
  389. . ($self->{cfg}->{showrandquote} ?
  390. "<td style=\"background-color: $color\">\"$randomline\"</td>"
  391. : "")
  392. );
  393. my $height = $self->{cfg}->{picheight};
  394. my $width = $self->{cfg}->{picwidth};
  395. if ($self->{users}->{userpics}{$nick} && $self->{cfg}->{userpics} !~ /n/i) {
  396. _html("<td style=\"background-color: $color\" align=\"center\">");
  397. if (defined $self->{users}->{biguserpics}{$nick}) {
  398. _html("<a href=\"$self->{cfg}->{imagepath}$self->{users}->{biguserpics}{$nick}\">");
  399. }
  400. if ($width ne '') {
  401. _html("<img valign=\"middle\" src=\"$self->{cfg}->{imagepath}$self->{users}->{userpics}{$nick}\" width=\"$width\" height=\"$height\" alt=\"$nick\" />");
  402. } else {
  403. _html("<img valign=\"middle\" src=\"$self->{cfg}->{imagepath}$self->{users}->{userpics}{$nick}\" alt=\"$nick\" />");
  404. }
  405. if (defined $self->{users}->{biguserpics}{$nick}) {
  406. _html("</a>");
  407. }
  408. _html("</td>");
  409. } elsif ($self->{cfg}->{defaultpic} ne '' && $self->{cfg}->{userpics} !~ /n/i) {
  410. _html("<td style=\"background-color: $color\" align=\"center\"><img valign=\"middle\" src=\"$self->{cfg}->{imagepath}$self->{cfg}->{defaultpic}\" alt=\"\" /></td>");
  411. }
  412. _html("</tr>");
  413. }
  414. _html("</table><br />");
  415. # Almost as active nicks ('These didn't make it to the top..')
  416. my $toshow = $self->{cfg}->{activenicks2} - $self->{cfg}->{activenicks};
  417. my $remain = $self->{cfg}->{activenicks} + $toshow;
  418. unless ($toshow > $nicks) {
  419. $remain = $self->{cfg}->{activenicks} + $self->{cfg}->{activenicks2};
  420. if ($remain > $nicks) {
  421. $remain = $nicks;
  422. }
  423. if ($self->{cfg}->{activenicks} < $remain) {
  424. _html("<br /><b><i>" . $self->_template_text('nottop') . "</i></b><table><tr>");
  425. for (my $i = $self->{cfg}->{activenicks}; $i < $remain; $i++) {
  426. unless ($i % 5) { if ($i != $self->{cfg}->{activenicks}) { _html("</tr><tr>"); } }
  427. my $items;
  428. if ($self->{cfg}->{sortbywords}) {
  429. $items = $self->{stats}->{words}{$active[$i]};
  430. } else {
  431. $items = $self->{stats}->{lines}{$active[$i]};
  432. }
  433. _html("<td class=\"rankc10\">$active[$i] ($items)</td>");
  434. }
  435. _html("</tr></table>");
  436. }
  437. }
  438. my %hash;
  439. $hash{totalnicks} = $nicks - $remain;
  440. if ($hash{totalnicks} > 0) {
  441. _html("<br /><b>" . $self->_template_text('totalnicks', %hash) . "</b><br />");
  442. }
  443. }
  444. sub generate_colors
  445. {
  446. my $self = shift;
  447. my $c = shift;
  448. my $h = $self->{cfg}->{hicell};
  449. $h =~ s/^#//;
  450. $h = hex $h;
  451. my $h2 = $self->{cfg}->{hicell2};
  452. $h2 =~ s/^#//;
  453. $h2 = hex $h2;
  454. my $f_b = $h & 0xff;
  455. my $f_g = ($h & 0xff00) >> 8;
  456. my $f_r = ($h & 0xff0000) >> 16;
  457. my $t_b = $h2 & 0xff;
  458. my $t_g = ($h2 & 0xff00) >> 8;
  459. my $t_r = ($h2 & 0xff0000) >> 16;
  460. my $blue = sprintf "%0.2x", abs int(((($t_b - $f_b) / $self->{cfg}->{activenicks}) * +$c) + $f_b);
  461. my $green = sprintf "%0.2x", abs int(((($t_g - $f_g) / $self->{cfg}->{activenicks}) * +$c) + $f_g);
  462. my $red = sprintf "%0.2x", abs int(((($t_r - $f_r) / $self->{cfg}->{activenicks}) * +$c) + $f_r);
  463. return "#$red$green$blue";
  464. }
  465. sub _html
  466. {
  467. my $html = shift;
  468. print OUTPUT "$html\n";
  469. }
  470. sub _questions
  471. {
  472. # Persons who asked the most questions
  473. my $self = shift;
  474. my %qpercent;
  475. foreach my $nick (sort keys %{ $self->{stats}->{questions} }) {
  476. if ($self->{stats}->{lines}{$nick} > 100) {
  477. $qpercent{$nick} = ($self->{stats}->{questions}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  478. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  479. }
  480. }
  481. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  482. if (@question) {
  483. my %hash = (
  484. nick => $question[0],
  485. per => $qpercent{$question[0]}
  486. );
  487. my $text = $self->_template_text('question1', %hash);
  488. _html("<tr><td class=\"hicell\">$text");
  489. if (@question >= 2) {
  490. my %hash = (
  491. nick => $question[1],
  492. per => $qpercent{$question[1]}
  493. );
  494. my $text = $self->_template_text('question2', %hash);
  495. _html("<br /><span class=\"small\">$text</span>");
  496. }
  497. _html("</td></tr>");
  498. } else {
  499. _html("<tr><td class=\"hicell\">" . $self->_template_text('question3') . "</td></tr>");
  500. }
  501. }
  502. sub _shoutpeople
  503. {
  504. # The ones who speak with exclamation marks!
  505. my $self = shift;
  506. my %spercent;
  507. foreach my $nick (sort keys %{ $self->{stats}->{shouts} }) {
  508. if ($self->{stats}->{lines}{$nick} > 100) {
  509. $spercent{$nick} = ($self->{stats}->{shouts}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  510. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  511. }
  512. }
  513. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  514. if (@shout) {
  515. my %hash = (
  516. nick => $shout[0],
  517. per => $spercent{$shout[0]}
  518. );
  519. my $text = $self->_template_text('shout1', %hash);
  520. _html("<tr><td class=\"hicell\">$text");
  521. if (@shout >= 2) {
  522. my %hash = (
  523. nick => $shout[1],
  524. per => $spercent{$shout[1]}
  525. );
  526. my $text = $self->_template_text('shout2', %hash);
  527. _html("<br /><span class=\"small\">$text</span>");
  528. }
  529. _html("</td></tr>");
  530. } else {
  531. my $text = $self->_template_text('shout3');
  532. _html("<tr><td class=\"hicell\">$text</td></tr>");
  533. }
  534. }
  535. sub _capspeople
  536. {
  537. # The ones who speak ALL CAPS.
  538. my $self = shift;
  539. my %cpercent;
  540. foreach my $nick (sort keys %{ $self->{stats}->{allcaps} }) {
  541. if ($self->{stats}->{lines}{$nick} > 100) {
  542. $cpercent{$nick} = $self->{stats}->{allcaps}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  543. $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
  544. }
  545. }
  546. my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent;
  547. if (@caps) {
  548. my %hash = (
  549. nick => $caps[0],
  550. per => $cpercent{$caps[0]},
  551. line => htmlentities($self->_format_line($self->{stats}->{allcaplines}{$caps[0]}))
  552. );
  553. my $text = $self->_template_text('allcaps1', %hash);
  554. if($self->{cfg}->{showshoutline}) {
  555. my $exttext = $self->_template_text('allcapstext', %hash);
  556. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  557. } else {
  558. _html("<tr><td class=\"hicell\">$text");
  559. }
  560. if (@caps >= 2) {
  561. my %hash = (
  562. nick => $caps[1],
  563. per => $cpercent{$caps[1]}
  564. );
  565. my $text = $self->_template_text('allcaps2', %hash);
  566. _html("<br /><span class=\"small\">$text</span>");
  567. }
  568. _html("</td></tr>");
  569. } else {
  570. my $text = $self->_template_text('allcaps3');
  571. _html("<tr><td class=\"hicell\">$text</td></tr>");
  572. }
  573. }
  574. sub _violent
  575. {
  576. # They attacked others (words defined by $self->{cfg}->{violent})
  577. my $self = shift;
  578. my @aggressors;
  579. @aggressors = sort { $self->{stats}->{violence}{$b} <=> $self->{stats}->{violence}{$a} }
  580. keys %{ $self->{stats}->{violence} };
  581. if(@aggressors) {
  582. my %hash = (
  583. nick => $aggressors[0],
  584. attacks => $self->{stats}->{violence}{$aggressors[0]},
  585. line => htmlentities($self->_format_line($self->{stats}->{violencelines}{$aggressors[0]}))
  586. );
  587. my $text = $self->_template_text('violent1', %hash);
  588. if($self->{cfg}->{showviolentlines}) {
  589. my $exttext = $self->_template_text('violenttext', %hash);
  590. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  591. } else {
  592. _html("<tr><td class=\"hicell\">$text");
  593. }
  594. if (@aggressors >= 2) {
  595. my %hash = (
  596. nick => $aggressors[1],
  597. attacks => $self->{stats}->{violence}{$aggressors[1]}
  598. );
  599. my $text = $self->_template_text('violent2', %hash);
  600. _html("<br /><span class=\"small\">$text</span>");
  601. }
  602. _html("</td></tr>");
  603. } else {
  604. my $text = $self->_template_text('violent3');
  605. _html("<tr><td class=\"hicell\">$text</td></tr>");
  606. }
  607. # They got attacked
  608. my @victims;
  609. @victims = sort { $self->{stats}->{attacked}{$b} <=> $self->{stats}->{attacked}{$a} }
  610. keys %{ $self->{stats}->{attacked} };
  611. if(@victims) {
  612. my %hash = (
  613. nick => $victims[0],
  614. attacks => $self->{stats}->{attacked}{$victims[0]},
  615. line => htmlentities($self->_format_line($self->{stats}->{attackedlines}{$victims[0]}))
  616. );
  617. my $text = $self->_template_text('attacked1', %hash);
  618. if($self->{cfg}->{showviolentlines}) {
  619. my $exttext = $self->_template_text('attackedtext', %hash);
  620. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  621. } else {
  622. _html("<tr><td class=\"hicell\">$text");
  623. }
  624. if (@victims >= 2) {
  625. my %hash = (
  626. nick => $victims[1],
  627. attacks => $self->{stats}->{attacked}{$victims[1]}
  628. );
  629. my $text = $self->_template_text('attacked2', %hash);
  630. _html("<br /><span class=\"small\">$text</span>");
  631. }
  632. _html("</td></tr>");
  633. }
  634. }
  635. sub _gotkicks
  636. {
  637. # The persons who got kicked the most
  638. my $self = shift;
  639. my @gotkick = sort { $self->{stats}->{gotkicked}{$b} <=> $self->{stats}->{gotkicked}{$a} }
  640. keys %{ $self->{stats}->{gotkicked} };
  641. if (@gotkick) {
  642. my %hash = (
  643. nick => $gotkick[0],
  644. kicks => $self->{stats}->{gotkicked}{$gotkick[0]},
  645. line => $self->_format_line($self->{stats}->{kicklines}{$gotkick[0]})
  646. );
  647. my $text = $self->_template_text('gotkick1', %hash);
  648. if ($self->{cfg}->{showkickline}) {
  649. my $exttext = $self->_template_text('kicktext', %hash);
  650. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  651. } else {
  652. _html("<tr><td class=\"hicell\">$text");
  653. }
  654. if (@gotkick >= 2) {
  655. my %hash = (
  656. nick => $gotkick[1],
  657. kicks => $self->{stats}->{gotkicked}{$gotkick[1]}
  658. );
  659. my $text = $self->_template_text('gotkick2', %hash);
  660. _html("<br /><span class=\"small\">$text</span>");
  661. }
  662. _html("</td></tr>");
  663. }
  664. }
  665. sub _mostjoins
  666. {
  667. my $self = shift;
  668. my @joins = sort { $self->{stats}->{joins}{$b} <=> $self->{stats}->{joins}{$a} }
  669. keys %{ $self->{stats}->{joins} };
  670. if (@joins) {
  671. my %hash = (
  672. nick => $joins[0],
  673. joins => $self->{stats}->{joins}{$joins[0]}
  674. );
  675. my $text = $self->_template_text('joins', %hash);
  676. _html("<tr><td class=\"hicell\">$text</td></tr>");
  677. }
  678. }
  679. sub _mostwords
  680. {
  681. # The person who got words the most
  682. my $self = shift;
  683. my @words = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  684. keys %{ $self->{stats}->{words} };
  685. if (@words) {
  686. my %hash = (
  687. nick => $words[0],
  688. words => $self->{stats}->{words}{$words[0]}
  689. );
  690. my $text = $self->_template_text('words1', %hash);
  691. _html("<tr><td class=\"hicell\">$text");
  692. if (@words >= 2) {
  693. my %hash = (
  694. oldnick => $words[0],
  695. nick => $words[1],
  696. words => $self->{stats}->{words}{$words[1]}
  697. );
  698. my $text = $self->_template_text('words2', %hash);
  699. _html("<br /><span class=\"small\">$text</span>");
  700. }
  701. _html("</td></tr>");
  702. } else {
  703. my $text = $self->_template_text('kick3');
  704. _html("<tr><td class=\"hicell\">$text</td></tr>");
  705. }
  706. }
  707. sub _mostkicks
  708. {
  709. # The person who kicked the most
  710. my $self = shift;
  711. my @kicked = sort { $self->{stats}->{kicked}{$b} <=> $self->{stats}->{kicked}{$a} }
  712. keys %{ $self->{stats}->{kicked} };
  713. if (@kicked) {
  714. my %hash = (
  715. nick => $kicked[0],
  716. kicked => $self->{stats}->{kicked}{$kicked[0]}
  717. );
  718. my $text = $self->_template_text('kick1', %hash);
  719. _html("<tr><td class=\"hicell\">$text");
  720. if (@kicked >= 2) {
  721. my %hash = (
  722. oldnick => $kicked[0],
  723. nick => $kicked[1],
  724. kicked => $self->{stats}->{kicked}{$kicked[1]}
  725. );
  726. my $text = $self->_template_text('kick2', %hash);
  727. _html("<br /><span class=\"small\">$text</span>");
  728. }
  729. _html("</td></tr>");
  730. } else {
  731. my $text = $self->_template_text('kick3');
  732. _html("<tr><td class=\"hicell\">$text</td></tr>");
  733. }
  734. }
  735. sub _mostmonologues
  736. {
  737. # The person who had the most monologues (speaking to himself)
  738. my $self = shift;
  739. my @monologue = sort { $self->{stats}->{monologues}{$b} <=> $self->{stats}->{monologues}{$a} } keys %{ $self->{stats}->{monologues} };
  740. if (@monologue) {
  741. my %hash = (
  742. nick => $monologue[0],
  743. monos => $self->{stats}->{monologues}{$monologue[0]}
  744. );
  745. my $text = $self->_template_text('mono1', %hash);
  746. _html("<tr><td class=\"hicell\">$text");
  747. if (@monologue >= 2) {
  748. my %hash = (
  749. nick => $monologue[1],
  750. monos => $self->{stats}->{monologues}{$monologue[1]}
  751. );
  752. my $text = $self->_template_text('mono2', %hash);
  753. _html("<br /><span class=\"small\">$text</span>");
  754. }
  755. _html("</td></tr>");
  756. }
  757. }
  758. sub _linelengths
  759. {
  760. # The person(s) who wrote the longest lines
  761. my $self = shift;
  762. my %len;
  763. foreach my $nick (sort keys %{ $self->{stats}->{lengths} }) {
  764. if ($self->{stats}->{lines}{$nick} > 100) {
  765. $len{$nick} = $self->{stats}->{lengths}{$nick} / $self->{stats}->{lines}{$nick};
  766. $len{$nick} =~ s/(\.\d)\d+/$1/;
  767. }
  768. }
  769. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  770. my $all_lines = 0;
  771. my $totallength;
  772. foreach my $nick (keys %{ $self->{stats}->{lines} }) {
  773. $all_lines += $self->{stats}->{lines}{$nick};
  774. $totallength += $self->{stats}->{lengths}{$nick};
  775. }
  776. my $totalaverage;
  777. if ($all_lines > 0) {
  778. $totalaverage = $totallength / $all_lines;
  779. $totalaverage =~ s/(\.\d)\d+/$1/;
  780. }
  781. if (@len) {
  782. my %hash = (
  783. nick => $len[0],
  784. letters => $len{$len[0]}
  785. );
  786. my $text = $self->_template_text('long1', %hash);
  787. _html("<tr><td class=\"hicell\">$text<br />");
  788. if (@len >= 2) {
  789. %hash = (
  790. avg => $totalaverage
  791. );
  792. $text = $self->_template_text('long2', %hash);
  793. _html("<span class=\"small\">$text</span></td></tr>");
  794. }
  795. }
  796. # The person(s) who wrote the shortest lines
  797. if (@len) {
  798. my %hash = (
  799. nick => $len[$#len],
  800. letters => $len{$len[$#len]}
  801. );
  802. my $text = $self->_template_text('short1', %hash);
  803. _html("<tr><td class=\"hicell\">$text<br />");
  804. if (@len >= 2) {
  805. %hash = (
  806. nick => $len[$#len - 1],
  807. letters => $len{$len[$#len - 1]}
  808. );
  809. $text = $self->_template_text('short2', %hash);
  810. _html("<span class=\"small\">$text</span></td></tr>");
  811. }
  812. }
  813. }
  814. sub _mostfoul
  815. {
  816. my $self = shift;
  817. my %spercent;
  818. foreach my $nick (sort keys %{ $self->{stats}->{foul} }) {
  819. if ($self->{stats}->{lines}{$nick} > 15) {
  820. $spercent{$nick} = $self->{stats}->{foul}{$nick} / $self->{stats}->{words}{$nick} * 100;
  821. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  822. }
  823. }
  824. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  825. if (@foul) {
  826. my %hash = (
  827. nick => $foul[0],
  828. per => $spercent{$foul[0]},
  829. line => htmlentities($self->_format_line($self->{stats}{foullines}{$foul[0]})),
  830. );
  831. my $text = $self->_template_text('foul1', %hash);
  832. if($self->{cfg}->{showfoulline}) {
  833. my $exttext = $self->_template_text('foultext', %hash);
  834. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  835. } else {
  836. _html("<tr><td class=\"hicell\">$text");
  837. }
  838. if (@foul >= 2) {
  839. my %hash = (
  840. nick => $foul[1],
  841. per => $spercent{$foul[1]}
  842. );
  843. my $text = $self->_template_text('foul2', %hash);
  844. _html("<br /><span class=\"small\">$text</span>");
  845. }
  846. _html("</td></tr>");
  847. } else {
  848. my $text = $self->_template_text('foul3');
  849. _html("<tr><td class=\"hicell\">$text</td></tr>");
  850. }
  851. }
  852. sub _mostsad
  853. {
  854. my $self = shift;
  855. my %spercent;
  856. foreach my $nick (sort keys %{ $self->{stats}->{frowns} }) {
  857. if ($self->{stats}->{lines}{$nick} > 100) {
  858. $spercent{$nick} = $self->{stats}->{frowns}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  859. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  860. }
  861. }
  862. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  863. if (@sadface) {
  864. my %hash = (
  865. nick => $sadface[0],
  866. per => $spercent{$sadface[0]}
  867. );
  868. my $text = $self->_template_text('sad1', %hash);
  869. _html("<tr><td class=\"hicell\">$text");
  870. if (@sadface >= 2) {
  871. my %hash = (
  872. nick => $sadface[1],
  873. per => $spercent{$sadface[1]}
  874. );
  875. my $text = $self->_template_text('sad2', %hash);
  876. _html("<br /><span class=\"small\">$text</span>");
  877. }
  878. _html("</td></tr>");
  879. } else {
  880. my $text = $self->_template_text('sad3');
  881. _html("<tr><td class=\"hicell\">$text</td></tr>");
  882. }
  883. }
  884. sub _mostop
  885. {
  886. my $self = shift;
  887. my @ops = sort { $self->{stats}->{gaveops}{$b} <=> $self->{stats}->{gaveops}{$a} }
  888. keys %{ $self->{stats}->{gaveops} };
  889. my @deops = sort { $self->{stats}->{tookops}{$b} <=> $self->{stats}->{tookops}{$a} }
  890. keys %{ $self->{stats}->{tookops} };
  891. if (@ops) {
  892. my %hash = (
  893. nick => $ops[0],
  894. ops => $self->{stats}->{gaveops}{$ops[0]}
  895. );
  896. my $text = $self->_template_text('mostop1', %hash);
  897. _html("<tr><td class=\"hicell\">$text");
  898. if (@ops >= 2) {
  899. my %hash = (
  900. nick => $ops[1],
  901. ops => $self->{stats}->{gaveops}{$ops[1]}
  902. );
  903. my $text = $self->_template_text('mostop2', %hash);
  904. _html("<br /><span class=\"small\">$text</span>");
  905. }
  906. _html("</td></tr>");
  907. } else {
  908. my $text = $self->_template_text('mostop3');
  909. _html("<tr><td class=\"hicell\">$text</td></tr>");
  910. }
  911. if (@deops) {
  912. my %hash = (
  913. nick => $deops[0],
  914. deops => $self->{stats}->{tookops}{$deops[0]}
  915. );
  916. my $text = $self->_template_text('mostdeop1', %hash);
  917. _html("<tr><td class=\"hicell\">$text");
  918. if (@deops >= 2) {
  919. my %hash = (
  920. nick => $deops[1],
  921. deops => $self->{stats}->{tookops}{$deops[1]}
  922. );
  923. my $text = $self->_template_text('mostdeop2', %hash);
  924. _html("<br /><span class=\"small\">$text</span>");
  925. }
  926. _html("</td></tr>");
  927. } else {
  928. my $text = $self->_template_text('mostdeop3');
  929. _html("<tr><td class=\"hicell\">$text</td></tr>");
  930. }
  931. }
  932. sub _mostvoice
  933. {
  934. my $self = shift;
  935. my @voice = sort { $self->{stats}->{gavevoice}{$b} <=> $self->{stats}->{gavevoice}{$a} }
  936. keys %{ $self->{stats}->{gavevoice} };
  937. my @devoice = sort { $self->{stats}->{tookvoice}{$b} <=> $self->{stats}->{tookvoice}{$a} }
  938. keys %{ $self->{stats}->{tookvoice} };
  939. if (@voice) {
  940. my %hash = (
  941. nick => $voice[0],
  942. voices => $self->{stats}->{gavevoice}{$voice[0]}
  943. );
  944. my $text = $self->_template_text('mostvoice1', %hash);
  945. _html("<tr><td class=\"hicell\">$text");
  946. if (@voice >= 2) {
  947. my %hash = (
  948. nick => $voice[1],
  949. voices => $self->{stats}->{gavevoice}{$voice[1]}
  950. );
  951. my $text = $self->_template_text('mostvoice2', %hash);
  952. _html("<br /><span class=\"small\">$text</span>");
  953. }
  954. _html("</td></tr>");
  955. } else {
  956. my $text = $self->_template_text('mostvoice3');
  957. _html("<tr><td class=\"hicell\">$text</td></tr>");
  958. }
  959. if (@devoice) {
  960. my %hash = (
  961. nick => $devoice[0],
  962. devoices => $self->{stats}->{tookvoice}{$devoice[0]}
  963. );
  964. my $text = $self->_template_text('mostdevoice1', %hash);
  965. _html("<tr><td class=\"hicell\">$text");
  966. if (@devoice >= 2) {
  967. my %hash = (
  968. nick => $devoice[1],
  969. devoices => $self->{stats}->{tookvoice}{$devoice[1]}
  970. );
  971. my $text = $self->_template_text('mostdevoice2', %hash);
  972. _html("<br /><span class=\"small\">$text</span>");
  973. }
  974. _html("</td></tr>");
  975. } else {
  976. my $text = $self->_template_text('mostdevoice3');
  977. _html("<tr><td class=\"hicell\">$text</td></tr>");
  978. }
  979. }
  980. sub _mosthalfop
  981. {
  982. my $self = shift;
  983. my @halfops = sort { $self->{stats}->{gavehalfops}{$b} <=> $self->{stats}->{gavehalfops}{$a} }
  984. keys %{ $self->{stats}->{gavehalfops} };
  985. my @dehalfops = sort { $self->{stats}->{tookhalfops}{$b} <=> $self->{stats}->{tookhalfops}{$a} }
  986. keys %{ $self->{stats}->{tookhalfops} };
  987. if (@halfops) {
  988. my %hash = (
  989. nick => $halfops[0],
  990. halfops => $self->{stats}->{gavehalfops}{$halfops[0]}
  991. );
  992. my $text = $self->_template_text('mosthalfop1', %hash);
  993. _html("<tr><td class=\"hicell\">$text");
  994. if (@halfops >= 2) {
  995. my %hash = (
  996. nick => $halfops[1],
  997. halfops => $self->{stats}->{gavehalfops}{$halfops[1]}
  998. );
  999. my $text = $self->_template_text('mosthalfop2', %hash);
  1000. _html("<br /><span class=\"small\">$text</span>");
  1001. }
  1002. _html("</td></tr>");
  1003. } else {
  1004. my $text = $self->_template_text('mosthalfop3');
  1005. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1006. }
  1007. if (@dehalfops) {
  1008. my %hash = (
  1009. nick => $dehalfops[0],
  1010. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[0]}
  1011. );
  1012. my $text = $self->_template_text('mostdehalfop1', %hash);
  1013. _html("<tr><td class=\"hicell\">$text");
  1014. if (@dehalfops >= 2) {
  1015. my %hash = (
  1016. nick => $dehalfops[1],
  1017. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[1]}
  1018. );
  1019. my $text = $self->_template_text('mostdehalfop2', %hash);
  1020. _html("<br /><span class=\"small\">$text</span>");
  1021. }
  1022. _html("</td></tr>");
  1023. } else {
  1024. my $text = $self->_template_text('mostdehalfop3');
  1025. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1026. }
  1027. }
  1028. sub _mostactions
  1029. {
  1030. # The person who did the most /me's
  1031. my $self = shift;
  1032. my @actions = sort { $self->{stats}->{actions}{$b} <=> $self->{stats}->{actions}{$a} }
  1033. keys %{ $self->{stats}->{actions} };
  1034. if (@actions) {
  1035. my %linehash =
  1036. my %hash = (
  1037. nick => $actions[0],
  1038. actions => $self->{stats}->{actions}{$actions[0]},
  1039. line => htmlentities($self->_format_line($self->{stats}->{actionlines}{$actions[0]}))
  1040. );
  1041. my $text = $self->_template_text('action1', %hash);
  1042. if($self->{cfg}->{showactionline}) {
  1043. my $exttext = $self->_template_text('actiontext', %hash);
  1044. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  1045. } else {
  1046. _html("<tr><td class=\"hicell\">$text");
  1047. }
  1048. if (@actions >= 2) {
  1049. my %hash = (
  1050. nick => $actions[1],
  1051. actions => $self->{stats}->{actions}{$actions[1]}
  1052. );
  1053. my $text = $self->_template_text('action2', %hash);
  1054. _html("<br /><span class=\"small\">$text</span>");
  1055. }
  1056. _html("</td></tr>");
  1057. } else {
  1058. my $text = $self->_template_text('action3');
  1059. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1060. }
  1061. }
  1062. sub _mostsmiles
  1063. {
  1064. # The person(s) who smiled the most :-)
  1065. my $self = shift;
  1066. my %spercent;
  1067. foreach my $nick (sort keys %{ $self->{stats}->{smiles} }) {
  1068. if ($self->{stats}->{lines}{$nick} > 100) {
  1069. $spercent{$nick} = $self->{stats}->{smiles}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  1070. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1071. }
  1072. }
  1073. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1074. if (@smiles) {
  1075. my %hash = (
  1076. nick => $smiles[0],
  1077. per => $spercent{$smiles[0]}
  1078. );
  1079. my $text = $self->_template_text('smiles1', %hash);
  1080. _html("<tr><td class=\"hicell\">$text");
  1081. if (@smiles >= 2) {
  1082. my %hash = (
  1083. nick => $smiles[1],
  1084. per => $spercent{$smiles[1]}
  1085. );
  1086. my $text = $self->_template_text('smiles2', %hash);
  1087. _html("<br /><span class=\"small\">$text</span>");
  1088. }
  1089. _html("</td></tr>");
  1090. } else {
  1091. my $text = $self->_template_text('smiles3');
  1092. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1093. }
  1094. }
  1095. sub _lasttopics
  1096. {
  1097. my $self = shift;
  1098. if ($self->{stats}->{topics}) {
  1099. my %topic_seen;
  1100. my %hash = (
  1101. total => scalar @{ $self->{stats}->{topics} }
  1102. );
  1103. my $ltopic = $#{ $self->{stats}->{topics} };
  1104. my $tlimit = 0;
  1105. $self->{cfg}->{topichistory} -= 1;
  1106. if ($ltopic > $self->{cfg}->{topichistory}) {
  1107. $tlimit = $ltopic - $self->{cfg}->{topichistory};
  1108. }
  1109. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1110. my $topic = htmlentities($self->{stats}->{topics}[$i]{topic});
  1111. # This code makes sure that we don't see the same topic twice
  1112. next if ($topic_seen{$topic});
  1113. $topic_seen{$topic} = 1;
  1114. $topic = $self->_replace_links($topic);
  1115. # Strip off the quotes (')
  1116. $topic =~ s/^\'(.*)\'$/$1/;
  1117. my $nick = $self->{stats}->{topics}[$i]{nick};
  1118. my $hour = $self->{stats}->{topics}[$i]{hour};
  1119. my $min = $self->{stats}->{topics}[$i]{min};
  1120. $hash{nick} = $nick;
  1121. $hash{time} = "$hour:$min";
  1122. _html("<tr><td class=\"hicell\"><i>$topic</i></td>");
  1123. _html("<td class=\"hicell\"><b>" . $self->_template_text('bylinetopic', %hash) ."</b></td></tr>");
  1124. }
  1125. _html("<tr><td align=\"center\" colspan=\"2\" class=\"asmall\">" . $self->_template_text('totaltopic', %hash) . "</td></tr>");
  1126. } else {
  1127. _html("<tr><td class=\"hicell\">" . $self->_template_text('notopic') ."</td></tr>");
  1128. }
  1129. }
  1130. sub _template_text
  1131. {
  1132. # This function is for the homemade template system. It receives a name
  1133. # of a template and a hash with the fields in the template to update to
  1134. # its corresponding value
  1135. my $self = shift;
  1136. my $template = shift;
  1137. my %hash = @_;
  1138. my $text;
  1139. unless ($text = $self->{tmps}->{lc($self->{cfg}->{lang})}{$template}) {
  1140. # Fall back to English if the language template doesn't exist
  1141. if ($text = $self->{tmps}->{en}{$template}) {
  1142. print "Note: No translation in '$self->{cfg}->{lang}' for '$template' - falling back to English..\n"
  1143. unless ($self->{cfg}->{silent});
  1144. } else {
  1145. die("No such template '$template' in language file.\n");
  1146. }
  1147. }
  1148. $hash{channel} = $self->{cfg}->{channel};
  1149. foreach my $key (sort keys %hash) {
  1150. $text =~ s/\[:$key\]/$hash{$key}/;
  1151. $text =~ s/ü/&uuml;/go;
  1152. $text =~ s/ö/&ouml;/go;
  1153. $text =~ s/ä/&auml;/go;
  1154. $text =~ s/ß/&szlig;/go;
  1155. $text =~ s/å/&aring;/go;
  1156. $text =~ s/æ/&aelig;/go;
  1157. $text =~ s/ø/&oslash;/go;
  1158. $text =~ s/Å/&Aring;/go;
  1159. $text =~ s/Æ/&AElig;/go;
  1160. $text =~ s/Ø/&Oslash;/go;
  1161. }
  1162. if ($text =~ /\[:.*?:.*?:\]/o) {
  1163. $text =~ s/\[:(.*?):(.*?):\]/$self->_get_subst($1,$2,\%hash)/geo;
  1164. }
  1165. return $text;
  1166. }
  1167. sub _format_line
  1168. {
  1169. # This function formats a action/normal line to be more readable
  1170. my ($self,$line) = @_;
  1171. my $hashref;
  1172. if ($hashref = $self->{cfg}->{analyzer}->{parser}->normalline($line)) {
  1173. return '<' . $hashref->{nick} . '> ' . $hashref->{saying};
  1174. } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->actionline($line)) {
  1175. return '* ' . $hashref->{nick} . ' ' . $hashref->{saying};
  1176. } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->thirdline($line)) {
  1177. if (defined($hashref->{kicker})) {
  1178. $line = '*** ' . $hashref->{nick} . ' was kicked by ' . $hashref->{kicker};
  1179. $line .= ' (' . $hashref->{kicktext} . ')'
  1180. if (defined($hashref->{kicktext}));
  1181. } elsif (defined($hashref->{newtopic})) {
  1182. $line = '*** ' . $hashref->{nick} . ' changes topic to \'' . $hashref->{newtopic} . '\'';
  1183. } elsif (defined($hashref->{newmode})) {
  1184. $line = '*** ' . $hashref->{nick} . ' sets mode ' . $hashref->{newmode};
  1185. $line .= ' ' . $hashref->{modechanges}
  1186. if (defined($hashref->{kicktext}));
  1187. } elsif (defined($hashref->{newjoin})) {
  1188. $line = '*** Joins: ' . $hashref->{nick};
  1189. } elsif (defined($hashref->{newnick})) {
  1190. $line = '*** ' . $hashref->{nick} . ' is now known as ' . $hashref->{newnick};
  1191. }
  1192. return $line;
  1193. } else {
  1194. return $line;
  1195. }
  1196. }
  1197. sub _get_subst
  1198. {
  1199. # This function looks at the user definition and see if there is sex
  1200. # defined. If yes, return the appropriate value. If no, just return the
  1201. # default he/she value.
  1202. my $self = shift;
  1203. my ($m,$f,$hash) = @_;
  1204. if ($hash->{nick} && $self->{users}->{sex}{$hash->{nick}}) {
  1205. if ($self->{users}->{sex}{$hash->{nick}} eq 'm') {
  1206. return $m;
  1207. } elsif ($self->{users}->{sex}{$hash->{nick}} eq 'f') {
  1208. return $f;
  1209. }
  1210. }
  1211. return "$m/$f";
  1212. }
  1213. sub _mostusedword
  1214. {
  1215. # Word usage statistics
  1216. my $self = shift;
  1217. my %usages;
  1218. foreach my $word (keys %{ $self->{stats}->{wordcounts} }) {
  1219. # Skip people's nicks.
  1220. next if exists $self->{stats}->{lines}{$word};
  1221. next if (length($word) < $self->{cfg}->{wordlength});
  1222. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1223. }
  1224. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1225. if (@popular) {
  1226. $self->_headline($self->_template_text('mostwordstopic'));
  1227. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1228. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('word') . "</b></td>");
  1229. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1230. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1231. my $count = 0;
  1232. for(my $i = 0; $count < $self->{cfg}->{wordhistory}; $i++) {
  1233. last unless $i < $#popular;
  1234. # Skip nicks. It's far more efficient to do this here than when
  1235. # @popular is created.
  1236. next if is_ignored($popular[$i]);
  1237. next if exists $self->{stats}->{lines}{find_alias($popular[$i])};
  1238. my $a = $count + 1;
  1239. my $popular = htmlentities($popular[$i]);
  1240. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1241. my $lastused = htmlentities($self->{stats}->{wordnicks}{$popular[$i]});
  1242. my $class;
  1243. if ($a == 1) {
  1244. $class = 'hirankc';
  1245. } else {
  1246. $class = 'rankc';
  1247. }
  1248. _html("<tr><td class=\"$class\">$a</td>");
  1249. _html("<td class=\"hicell\">$popular</td>");
  1250. _html("<td class=\"hicell\">$wordcount</td>");
  1251. _html("<td class=\"hicell\">$lastused</td>");
  1252. _html("</tr>");
  1253. $count++;
  1254. }
  1255. _html("</table>");
  1256. }
  1257. }
  1258. sub _mostwordsperline
  1259. {
  1260. # The person who got the most words per line
  1261. my $self = shift;
  1262. my %wpl = ();
  1263. my $numlines = 0;
  1264. my ($avg, $numwords);
  1265. foreach my $n (keys %{ $self->{stats}->{words} }) {
  1266. $wpl{$n} = sprintf("%.2f", $self->{stats}->{words}{$n}/$self->{stats}->{lines}{$n});
  1267. $numlines += $self->{stats}->{lines}{$n};
  1268. $numwords += $self->{stats}->{words}{$n};
  1269. }
  1270. if ($numlines > 0) {
  1271. $avg = sprintf("%.2f", $numwords/$numlines);
  1272. }
  1273. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  1274. if (@wpl) {
  1275. my %hash = (
  1276. nick => $wpl[0],
  1277. wpl => $wpl{$wpl[0]}
  1278. );
  1279. my $text = $self->_template_text('wpl1', %hash);
  1280. _html("<tr><td class=\"hicell\">$text");
  1281. $hash{avg} = $avg;
  1282. $text = $self->_template_text('wpl2', %hash);
  1283. _html("<br /><span class=\"small\">$text</span>");
  1284. _html("</td></tr>");
  1285. }
  1286. }
  1287. sub _mostreferencednicks
  1288. {
  1289. # List showing the most referenced nicks
  1290. my $self = shift;
  1291. my %usages;
  1292. foreach my $word (sort keys %{ $self->{stats}->{wordcounts} }) {
  1293. next if !exists $self->{stats}->{lines}{$word};
  1294. next if is_ignored($word);
  1295. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1296. }
  1297. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1298. if (@popular) {
  1299. $self->_headline($self->_template_text('referencetopic'));
  1300. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1301. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>");
  1302. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1303. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1304. for(my $i = 0; $i < $self->{cfg}->{nickhistory}; $i++) {
  1305. last unless $i < $#popular;
  1306. my $a = $i + 1;
  1307. my $popular = $popular[$i];
  1308. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1309. my $lastused = $self->{stats}->{wordnicks}{$popular[$i]};
  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\">$popular</td>");
  1318. _html("<td class=\"hicell\">$wordcount</td>");
  1319. _html("<td class=\"hicell\">$lastused</td>");
  1320. _html("</tr>");
  1321. }
  1322. _html("</table>");
  1323. }
  1324. }
  1325. sub _mosturls
  1326. {
  1327. # List showing the most referenced URLs
  1328. my $self = shift;
  1329. my @sorturls = sort { $self->{stats}->{urlcounts}{$b} <=> $self->{stats}->{urlcounts}{$a} }
  1330. keys %{ $self->{stats}->{urlcounts} };
  1331. if (@sorturls) {
  1332. $self->_headline($self->_template_text('urlstopic'));
  1333. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1334. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('url') . "</b></td>");
  1335. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1336. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1337. for(my $i = 0; $i < $self->{cfg}->{urlhistory}; $i++) {
  1338. last unless $i < @sorturls;
  1339. my $a = $i + 1;
  1340. my $sorturl = $sorturls[$i];
  1341. my $urlcount = $self->{stats}->{urlcounts}{$sorturls[$i]};
  1342. my $lastused = $self->{stats}->{urlnicks}{$sorturls[$i]};
  1343. if (length($sorturl) > 60) {
  1344. $sorturl = substr($sorturl, 0, 60);
  1345. }
  1346. my $class;
  1347. if ($a == 1) {
  1348. $class = 'hirankc';
  1349. } else {
  1350. $class = 'rankc';
  1351. }
  1352. _html("<tr><td class=\"$class\">$a</td>");
  1353. _html("<td class=\"hicell\"><a href=\"$sorturls[$i]\">$sorturl</a></td>");
  1354. _html("<td class=\"hicell\">$urlcount</td>");
  1355. _html("<td class=\"hicell\">$lastused</td>");
  1356. _html("</tr>");
  1357. }
  1358. _html("</table>");
  1359. }
  1360. }
  1361. sub _legend
  1362. {
  1363. # A legend showing the timebars and their associated time.
  1364. my $self = shift;
  1365. _html("<table align=\"center\" border=\"0\" width=\"520\"><tr>");
  1366. _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>");
  1367. _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>");
  1368. _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>");
  1369. _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>");
  1370. _html("</tr></table>\n");
  1371. }
  1372. sub _replace_links
  1373. {
  1374. # Sub to replace urls and e-mail addys to links
  1375. my $self = shift;
  1376. my $str = shift;
  1377. my $nick = shift;
  1378. # Regular expressions are taken from match_urls() and match_email() in
  1379. # Common.pm
  1380. my $texturl = $self->_template_text("newwindow");
  1381. my $textmail = $self->_template_text("mailto");
  1382. if ($nick) {
  1383. $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;
  1384. $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="$textmail $nick">$nick<\/a>/g;
  1385. } else {
  1386. $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;
  1387. $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="$textmail $1">$1<\/a>/g;
  1388. }
  1389. return $str;
  1390. }
  1391. sub _user_linetimes
  1392. {
  1393. my $self = shift;
  1394. my $nick = shift;
  1395. my $top = shift;
  1396. my $bar = "";
  1397. my $len = ($self->{stats}->{lines}{$nick} / $self->{stats}->{lines}{$top}) * 100;
  1398. for (my $i = 0; $i <= 3; $i++) {
  1399. next if not defined $self->{stats}->{line_times}{$nick}[$i];
  1400. my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * $len);
  1401. if ($w) {
  1402. my $pic = 'pic_h_'.(6*$i);
  1403. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />";
  1404. }
  1405. }
  1406. return "$bar&nbsp;$self->{stats}->{lines}{$nick}";
  1407. }
  1408. sub _user_wordtimes
  1409. {
  1410. my $self = shift;
  1411. my $nick = shift;
  1412. my $top = shift;
  1413. my $bar = "";
  1414. my $len = ($self->{stats}->{words}{$nick} / $self->{stats}->{words}{$top}) * 100;
  1415. for (my $i = 0; $i <= 3; $i++) {
  1416. next if not defined $self->{stats}->{word_times}{$nick}[$i];
  1417. my $w = int(($self->{stats}->{word_times}{$nick}[$i] / $self->{stats}->{words}{$nick}) * $len);
  1418. if ($w) {
  1419. my $pic = 'pic_h_'.(6*$i);
  1420. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />";
  1421. }
  1422. }
  1423. return "$bar&nbsp;$self->{stats}->{words}{$nick}";
  1424. }
  1425. sub _user_times
  1426. {
  1427. my $self = shift;
  1428. my ($nick) = @_;
  1429. my $bar = "";
  1430. my $itemstat = ($self->{cfg}->{sortbywords} ? 'words' : 'lines');
  1431. my $timestat = ($self->{cfg}->{sortbywords} ? 'word_times' : 'line_times');
  1432. for (my $i = 0; $i <= 3; $i++) {
  1433. next if not defined $self->{stats}->{$timestat}{$nick}[$i];
  1434. my $w = int(($self->{stats}->{$timestat}{$nick}[$i] / $self->{stats}->{$itemstat}{$nick}) * 40);
  1435. if ($w) {
  1436. my $pic = 'pic_h_'.(6*$i);
  1437. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\" />";
  1438. }
  1439. }
  1440. return $bar;
  1441. }
  1442. sub _mostnicks
  1443. {
  1444. # List showing the user with most used nicks
  1445. my $self = shift;
  1446. my @sortnicks = sort { @{ $self->{stats}->{nicks}->{$b} } <=> @{ $self->{stats}->{nicks}->{$a} } }
  1447. keys %{ $self->{stats}->{nicks} };
  1448. if (@{ $self->{stats}->{nicks}->{$sortnicks[0]} } > 1) {
  1449. $self->_headline($self->_template_text('mostnickstopic'));
  1450. my $names1 = $self->_template_text('names1');
  1451. my $names2 = $self->_template_text('names2');
  1452. my $nick_txt = $self->_template_text('nick');
  1453. my $names_txt = $self->_template_text('names');
  1454. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1455. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>$nick_txt</b></td>");
  1456. _html("<td class=\"tdtop\"><b>$names_txt</b></td></tr>");
  1457. for(my $i = 0; $i < $self->{cfg}->{mostnickshistory}; $i++) {
  1458. next if is_ignored($sortnicks[$i]);
  1459. last unless $i < @sortnicks;
  1460. my $nickcount = scalar(@{ $self->{stats}->{nicks}->{$sortnicks[$i]} });
  1461. my $nickused = join(", ", @{ $self->{stats}->{nicks}->{$sortnicks[$i]} });
  1462. next unless ($nickcount > 1);
  1463. my $a = $i + 1;
  1464. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1465. my $n = $nickcount > 1 ? $names1 : $names2;
  1466. _html("<tr><td class=\"$class\">$a</td>");
  1467. _html("<td class=\"hicell10\">$sortnicks[$i]<br />($nickcount $n)</td>");
  1468. _html("<td class=\"hicell10\" valign='top'>$nickused</td>");
  1469. _html("</tr>");
  1470. }
  1471. _html("</table>");
  1472. }
  1473. }
  1474. sub _mostactivebyhour
  1475. {
  1476. # Charts for most active nicks by hour (0-5, 6-11, 12-17, 18-23)
  1477. my $self = shift;
  1478. my $sortnicks;
  1479. my $lastline=-1;
  1480. my $maxlines=0;
  1481. foreach my $period (0,1,2,3) {
  1482. my @sortnicks =
  1483. sort
  1484. {
  1485. (defined $self->{stats}->{line_times}{$b}[$period]?$self->{stats}->{line_times}{$b}[$period]:0)
  1486. <=>
  1487. (defined $self->{stats}->{line_times}{$a}[$period]?$self->{stats}->{line_times}{$a}[$period]:0)
  1488. }
  1489. keys %{ $self->{stats}->{line_times} } ;
  1490. for(my $i = 0; $i < $self->{cfg}->{activenicksbyhour}; $i++) {
  1491. next if ! $sortnicks[$i];
  1492. next if is_ignored($sortnicks[$i]);
  1493. last unless $i < @sortnicks;
  1494. my $nick=$sortnicks[$i];
  1495. my $count=$self->{stats}->{line_times}{$nick}[$period] || 0;
  1496. last unless $nick;
  1497. last unless $count;
  1498. $sortnicks->[$period][$i]=$nick;
  1499. if ($lastline<$i) {
  1500. $lastline=$i;
  1501. }
  1502. if ($maxlines<$count) {
  1503. $maxlines=$count;
  1504. }
  1505. }
  1506. }
  1507. if ($lastline>=0) {
  1508. $self->_headline($self->_template_text('activenickbyhourtopic'));
  1509. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1510. _html("<td>&nbsp;</td>");
  1511. _html("<td class=\"tdtop\"><b>0-5</b></td>");
  1512. _html("<td class=\"tdtop\"><b>6-11</b></td>");
  1513. _html("<td class=\"tdtop\"><b>12-17</b></td>");
  1514. _html("<td class=\"tdtop\"><b>18-23</b></td>");
  1515. _html("</tr>");
  1516. for(my $i = 0; $i <= $lastline; $i++) {
  1517. my $a = $i + 1;
  1518. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1519. _html("<tr><td class=\"$class\">$a</td>");
  1520. foreach my $period (0,1,2,3) {
  1521. my $nick=$sortnicks->[$period][$i];
  1522. if ($nick) {
  1523. my $count=$self->{stats}->{line_times}{$nick}[$period];
  1524. if ($count) {
  1525. _html("<td class=\"hicell\">".$nick." - ".$count);
  1526. if ($self->{cfg}->{showmostactivebyhourgraph}) {
  1527. my $pic = 'pic_h_'.(6*$period);
  1528. my $w = int(($count / $maxlines) * 100);
  1529. _html("<br /><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />");
  1530. }
  1531. _html("</td>");
  1532. } else {
  1533. _html("<td class=\"hicell\">&nbsp;</td>");
  1534. }
  1535. } else {
  1536. _html("<td class=\"hicell\">&nbsp;</td>");
  1537. }
  1538. }
  1539. _html("</tr>");
  1540. }
  1541. _html("</table>");
  1542. }
  1543. }
  1544. 1;
  1545. __END__
  1546. =head1 NAME
  1547. Pisg::HTMLGenerator - class to create a static HTML page out of data parsed
  1548. =head1 DESCRIPTION
  1549. C<Pisg::HTMLGenerator> uses the hash returned by Pisg::Parser::Logfile and turns it into a static HTML page.
  1550. =head1 SYNOPSIS
  1551. use Pisg::HTMLGenerator;
  1552. $generator = new Pisg::HTMLGenerator(
  1553. cfg => $cfg,
  1554. stats => $stats,
  1555. users => $users,
  1556. tmps => $tmps
  1557. );
  1558. =head1 CONSTRUCTOR
  1559. =over 4
  1560. =item new ( [ OPTIONS ] )
  1561. This is the constructor for a new Pisg::HTMLGenerator object. C<OPTIONS> are passed in a hash like fashion using key and value pairs.
  1562. Possible options are:
  1563. B<cfg> - hashref containing configuration variables, created by the Pisg module.
  1564. B<stats> - reference to the hash returned by Pisg::Parser::Logfile containing all stats.
  1565. B<users> - reference to a hash containg user information
  1566. B<tmps> - reference to a hash containing the language templates.
  1567. =back
  1568. =head1 AUTHOR
  1569. Morten Brix Pedersen <morten@wtf.dk>
  1570. =head1 COPYRIGHT
  1571. Copyright (C) 2001-2002 Morten Brix Pedersen. All rights reserved.
  1572. This program is free software; you can redistribute it and/or modify it
  1573. under the terms of the GPL, license is included with the distribution of
  1574. this file.
  1575. =cut