HTMLGenerator.pm 49 KB

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