HTMLGenerator.pm 47 KB

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