HTMLGenerator.pm 48 KB

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