HTMLGenerator.pm 47 KB

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