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