HTMLGenerator.pm 52 KB

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