HTMLGenerator.pm 54 KB

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