HTMLGenerator.pm 47 KB

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