HTMLGenerator.pm 47 KB

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