HTMLGenerator.pm 49 KB

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