HTMLGenerator.pm 45 KB

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