HTMLGenerator.pm 47 KB

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