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