HTMLGenerator.pm 47 KB

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