HTMLGenerator.pm 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  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. my @active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} } keys %{ $self->{stats}->{lines} };
  304. my $nicks = scalar keys %{ $self->{stats}->{lines} };
  305. if ($self->{cfg}->{activenicks} > $nicks) {
  306. $self->{cfg}->{activenicks} = $nicks;
  307. }
  308. my $have_userpics;
  309. for (my $c = 0; $c < $self->{cfg}->{activenicks}; $c++) {
  310. my $nick = $active[$c];
  311. if ($self->{users}->{userpics}{$nick}) {
  312. $have_userpics = 1;
  313. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('userpic') ."</b></td>");
  314. last;
  315. }
  316. }
  317. _html("</tr>");
  318. my ($nick, $visiblenick, $randomline, %hash);
  319. my $i = 1;
  320. for (my $c = 0; $c < $self->{cfg}->{activenicks}; $c++) {
  321. $nick = $active[$c];
  322. $visiblenick = $active[$c];
  323. if (not defined $self->{stats}->{sayings}{$nick}) {
  324. $randomline = "";
  325. } else {
  326. $randomline = htmlentities($self->{stats}->{sayings}{$nick});
  327. }
  328. # Convert URLs and e-mail addys to links
  329. $randomline = _replace_links($randomline);
  330. # Add a link to the nick if there is any
  331. if ($self->{users}->{userlinks}{$nick}) {
  332. $visiblenick = _replace_links($self->{users}->{userlinks}{$nick}, $nick);
  333. }
  334. my $h = $self->{cfg}->{hicell};
  335. $h =~ s/^#//;
  336. $h = hex $h;
  337. my $h2 = $self->{cfg}->{hicell2};
  338. $h2 =~ s/^#//;
  339. $h2 = hex $h2;
  340. my $f_b = $h & 0xff;
  341. my $f_g = ($h & 0xff00) >> 8;
  342. my $f_r = ($h & 0xff0000) >> 16;
  343. my $t_b = $h2 & 0xff;
  344. my $t_g = ($h2 & 0xff00) >> 8;
  345. my $t_r = ($h2 & 0xff0000) >> 16;
  346. my $col_b = sprintf "%0.2x", abs int(((($t_b - $f_b) / $self->{cfg}->{activenicks}) * +$c) + $f_b);
  347. my $col_g = sprintf "%0.2x", abs int(((($t_g - $f_g) / $self->{cfg}->{activenicks}) * +$c) + $f_g);
  348. my $col_r = sprintf "%0.2x", abs int(((($t_r - $f_r) / $self->{cfg}->{activenicks}) * +$c) + $f_r);
  349. my $bgcolor;
  350. if ($i == 1) {
  351. $bgcolor = $self->{cfg}->{hi_rankc};
  352. } else {
  353. $bgcolor = $self->{cfg}->{rankc};
  354. }
  355. _html("<tr><td bgcolor=\"$bgcolor\" align=\"left\">");
  356. my $line = $self->{stats}->{lines}{$nick};
  357. my $w = $self->{stats}->{words}{$nick};
  358. my $ch = $self->{stats}->{lengths}{$nick};
  359. _html("$i</td><td bgcolor=\"#$col_r$col_g$col_b\">$visiblenick</td>"
  360. . ($self->{cfg}->{show_linetime} ?
  361. "<td bgcolor=\"$col_r$col_g$col_b\">".$self->_user_linetimes($nick,$active[0])."</td>"
  362. : "<td bgcolor=\"#$col_r$col_g$col_b\">$line</td>")
  363. . ($self->{cfg}->{show_time} ?
  364. "<td bgcolor=\"$col_r$col_g$col_b\">".$self->_user_times($nick)."</td>"
  365. : "")
  366. . ($self->{cfg}->{show_words} ?
  367. "<td bgcolor=\"#$col_r$col_g$col_b\">$w</td>"
  368. : "")
  369. . ($self->{cfg}->{show_wpl} ?
  370. "<td bgcolor=\"#$col_r$col_g$col_b\">".sprintf("%.1f",$w/$line)."</td>"
  371. : "")
  372. . ($self->{cfg}->{show_cpl} ?
  373. "<td bgcolor=\"#$col_r$col_g$col_b\">".sprintf("%.1f",$ch/$line)."</td>"
  374. : "")
  375. . ($self->{cfg}->{show_randquote} ?
  376. "<td bgcolor=\"#$col_r$col_g$col_b\">\"$randomline\"</td>"
  377. : "")
  378. );
  379. my $height = $self->{cfg}->{pic_height};
  380. my $width = $self->{cfg}->{pic_width};
  381. if ($self->{users}->{userpics}{$nick}) {
  382. if ($width ne '') {
  383. _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>");
  384. } else {
  385. _html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$self->{cfg}->{imagepath}$self->{users}->{userpics}{$nick}\"></td>");
  386. }
  387. } elsif ($self->{cfg}->{default_pic} ne '') {
  388. _html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$self->{cfg}->{imagepath}$self->{cfg}->{default_pic}\"></td>");
  389. }
  390. _html("</tr>");
  391. $i++;
  392. }
  393. _html("</table><br>");
  394. # Almost as active nicks ('These didn't make it to the top..')
  395. my $toshow = $self->{cfg}->{activenicks2} - $self->{cfg}->{activenicks};
  396. my $remain = $self->{cfg}->{activenicks} + $toshow;
  397. unless ($toshow > $nicks) {
  398. $remain = $self->{cfg}->{activenicks} + $self->{cfg}->{activenicks2};
  399. if ($remain > $nicks) {
  400. $remain = $nicks;
  401. }
  402. _html("<br><b><i>" . $self->_template_text('nottop') . "</i></b><table><tr>");
  403. for (my $c = $self->{cfg}->{activenicks}; $c < $remain; $c++) {
  404. unless ($c % 5) { unless ($c == $self->{cfg}->{activenicks}) { _html("</tr><tr>"); } }
  405. _html("<td bgcolor=\"$self->{cfg}->{rankc}\" class=\"small\">");
  406. my $nick = $active[$c];
  407. my $lines = $self->{stats}->{lines}{$nick};
  408. _html("$nick ($lines)</td>");
  409. }
  410. _html("</table>");
  411. }
  412. $hash{totalnicks} = $nicks - $remain;
  413. if ($hash{totalnicks} > 0) {
  414. _html("<br><b>" . $self->_template_text('totalnicks', %hash) . "</b><br>");
  415. }
  416. }
  417. sub _html
  418. {
  419. my $html = shift;
  420. print OUTPUT "$html\n";
  421. }
  422. sub _questions
  423. {
  424. # Persons who asked the most questions
  425. my $self = shift;
  426. my %qpercent;
  427. foreach my $nick (sort keys %{ $self->{stats}->{questions} }) {
  428. if ($self->{stats}->{lines}{$nick} > 100) {
  429. $qpercent{$nick} = ($self->{stats}->{questions}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  430. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  431. }
  432. }
  433. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  434. if (@question) {
  435. my %hash = (
  436. nick => $question[0],
  437. per => $qpercent{$question[0]}
  438. );
  439. my $text = $self->_template_text('question1', %hash);
  440. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  441. if (@question >= 2) {
  442. my %hash = (
  443. nick => $question[1],
  444. per => $qpercent{$question[1]}
  445. );
  446. my $text = $self->_template_text('question2', %hash);
  447. _html("<br><span class=\"small\">$text</span>");
  448. }
  449. _html("</td></tr>");
  450. } else {
  451. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">" . $self->_template_text('question3') . "</td></tr>");
  452. }
  453. }
  454. sub _shoutpeople
  455. {
  456. # The ones who speak with exclamation marks!
  457. my $self = shift;
  458. my %spercent;
  459. foreach my $nick (sort keys %{ $self->{stats}->{shouts} }) {
  460. if ($self->{stats}->{lines}{$nick} > 100) {
  461. $spercent{$nick} = ($self->{stats}->{shouts}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  462. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  463. }
  464. }
  465. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  466. if (@shout) {
  467. my %hash = (
  468. nick => $shout[0],
  469. per => $spercent{$shout[0]}
  470. );
  471. my $text = $self->_template_text('shout1', %hash);
  472. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  473. if (@shout >= 2) {
  474. my %hash = (
  475. nick => $shout[1],
  476. per => $spercent{$shout[1]}
  477. );
  478. my $text = $self->_template_text('shout2', %hash);
  479. _html("<br><span class=\"small\">$text</span>");
  480. }
  481. _html("</td></tr>");
  482. } else {
  483. my $text = $self->_template_text('shout3');
  484. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  485. }
  486. }
  487. sub _capspeople
  488. {
  489. # The ones who speak ALL CAPS.
  490. my $self = shift;
  491. my %cpercent;
  492. foreach my $nick (sort keys %{ $self->{stats}->{allcaps} }) {
  493. if ($self->{stats}->{lines}{$nick} > 100) {
  494. $cpercent{$nick} = $self->{stats}->{allcaps}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  495. $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
  496. }
  497. }
  498. my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent;
  499. if (@caps) {
  500. my %hash = (
  501. nick => $caps[0],
  502. per => $cpercent{$caps[0]},
  503. line => htmlentities($self->{stats}->{allcaplines}{$caps[0]})
  504. );
  505. my $text = $self->_template_text('allcaps1', %hash);
  506. if($self->{cfg}->{show_shoutline}) {
  507. my $exttext = $self->_template_text('allcapstext', %hash);
  508. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  509. } else {
  510. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  511. }
  512. if (@caps >= 2) {
  513. my %hash = (
  514. nick => $caps[1],
  515. per => $cpercent{$caps[1]}
  516. );
  517. my $text = $self->_template_text('allcaps2', %hash);
  518. _html("<br><span class=\"small\">$text</span>");
  519. }
  520. _html("</td></tr>");
  521. } else {
  522. my $text = $self->_template_text('allcaps3');
  523. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  524. }
  525. }
  526. sub _violent
  527. {
  528. # They attacked others (words defined by $self->{cfg}->{violent})
  529. my $self = shift;
  530. my @aggressors;
  531. @aggressors = sort { $self->{stats}->{violence}{$b} <=> $self->{stats}->{violence}{$a} }
  532. keys %{ $self->{stats}->{violence} };
  533. if(@aggressors) {
  534. my %hash = (
  535. nick => $aggressors[0],
  536. attacks => $self->{stats}->{violence}{$aggressors[0]},
  537. line => htmlentities($self->{stats}->{violencelines}{$aggressors[0]})
  538. );
  539. my $text = $self->_template_text('violent1', %hash);
  540. if($self->{cfg}->{show_violentlines}) {
  541. my $exttext = $self->_template_text('violenttext', %hash);
  542. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  543. } else {
  544. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  545. }
  546. if (@aggressors >= 2) {
  547. my %hash = (
  548. nick => $aggressors[1],
  549. attacks => $self->{stats}->{violence}{$aggressors[1]}
  550. );
  551. my $text = $self->_template_text('violent2', %hash);
  552. _html("<br><span class=\"small\">$text</span>");
  553. }
  554. _html("</td></tr>");
  555. } else {
  556. my $text = $self->_template_text('violent3');
  557. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  558. }
  559. # They got attacked
  560. my @victims;
  561. @victims = sort { $self->{stats}->{attacked}{$b} <=> $self->{stats}->{attacked}{$a} }
  562. keys %{ $self->{stats}->{attacked} };
  563. if(@victims) {
  564. my %hash = (
  565. nick => $victims[0],
  566. attacks => $self->{stats}->{attacked}{$victims[0]},
  567. line => htmlentities($self->{stats}->{attackedlines}{$victims[0]})
  568. );
  569. my $text = $self->_template_text('attacked1', %hash);
  570. if($self->{cfg}->{show_violentlines}) {
  571. my $exttext = $self->_template_text('attackedtext', %hash);
  572. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  573. } else {
  574. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  575. }
  576. if (@victims >= 2) {
  577. my %hash = (
  578. nick => $victims[1],
  579. attacks => $self->{stats}->{attacked}{$victims[1]}
  580. );
  581. my $text = $self->_template_text('attacked2', %hash);
  582. _html("<br><span class=\"small\">$text</span>");
  583. }
  584. _html("</td></tr>");
  585. }
  586. }
  587. sub _gotkicks
  588. {
  589. # The persons who got kicked the most
  590. my $self = shift;
  591. my @gotkick = sort { $self->{stats}->{gotkicked}{$b} <=> $self->{stats}->{gotkicked}{$a} }
  592. keys %{ $self->{stats}->{gotkicked} };
  593. if (@gotkick) {
  594. my %hash = (
  595. nick => $gotkick[0],
  596. kicks => $self->{stats}->{gotkicked}{$gotkick[0]},
  597. line => $self->{stats}->{kicklines}{$gotkick[0]}
  598. );
  599. my $text = $self->_template_text('gotkick1', %hash);
  600. if ($self->{cfg}->{show_kickline}) {
  601. my $exttext = $self->_template_text('kicktext', %hash);
  602. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  603. } else {
  604. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  605. }
  606. if (@gotkick >= 2) {
  607. my %hash = (
  608. nick => $gotkick[1],
  609. kicks => $self->{stats}->{gotkicked}{$gotkick[1]}
  610. );
  611. my $text = $self->_template_text('gotkick2', %hash);
  612. _html("<br><span class=\"small\">$text</span>");
  613. }
  614. _html("</td></tr>");
  615. }
  616. }
  617. sub _mostjoins
  618. {
  619. my $self = shift;
  620. my @joins = sort { $self->{stats}->{joins}{$b} <=> $self->{stats}->{joins}{$a} }
  621. keys %{ $self->{stats}->{joins} };
  622. if (@joins) {
  623. my %hash = (
  624. nick => $joins[0],
  625. joins => $self->{stats}->{joins}{$joins[0]}
  626. );
  627. my $text = $self->_template_text('joins', %hash);
  628. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  629. }
  630. }
  631. sub _mostwords
  632. {
  633. # The person who got words the most
  634. my $self = shift;
  635. my @words = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  636. keys %{ $self->{stats}->{words} };
  637. if (@words) {
  638. my %hash = (
  639. nick => $words[0],
  640. words => $self->{stats}->{words}{$words[0]}
  641. );
  642. my $text = $self->_template_text('words1', %hash);
  643. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  644. if (@words >= 2) {
  645. my %hash = (
  646. oldnick => $words[0],
  647. nick => $words[1],
  648. words => $self->{stats}->{words}{$words[1]}
  649. );
  650. my $text = $self->_template_text('words2', %hash);
  651. _html("<br><span class=\"small\">$text</span>");
  652. }
  653. _html("</td></tr>");
  654. } else {
  655. my $text = $self->_template_text('kick3');
  656. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  657. }
  658. }
  659. sub _mostkicks
  660. {
  661. # The person who kicked the most
  662. my $self = shift;
  663. my @kicked = sort { $self->{stats}->{kicked}{$b} <=> $self->{stats}->{kicked}{$a} }
  664. keys %{ $self->{stats}->{kicked} };
  665. if (@kicked) {
  666. my %hash = (
  667. nick => $kicked[0],
  668. kicked => $self->{stats}->{kicked}{$kicked[0]}
  669. );
  670. my $text = $self->_template_text('kick1', %hash);
  671. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  672. if (@kicked >= 2) {
  673. my %hash = (
  674. oldnick => $kicked[0],
  675. nick => $kicked[1],
  676. kicked => $self->{stats}->{kicked}{$kicked[1]}
  677. );
  678. my $text = $self->_template_text('kick2', %hash);
  679. _html("<br><span class=\"small\">$text</span>");
  680. }
  681. _html("</td></tr>");
  682. } else {
  683. my $text = $self->_template_text('kick3');
  684. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  685. }
  686. }
  687. sub _mostmonologues
  688. {
  689. # The person who had the most monologues (speaking to himself)
  690. my $self = shift;
  691. my @monologue = sort { $self->{stats}->{monologues}{$b} <=> $self->{stats}->{monologues}{$a} } keys %{ $self->{stats}->{monologues} };
  692. if (@monologue) {
  693. my %hash = (
  694. nick => $monologue[0],
  695. monos => $self->{stats}->{monologues}{$monologue[0]}
  696. );
  697. my $text = $self->_template_text('mono1', %hash);
  698. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  699. if (@monologue >= 2) {
  700. my %hash = (
  701. nick => $monologue[1],
  702. monos => $self->{stats}->{monologues}{$monologue[1]}
  703. );
  704. my $text = $self->_template_text('mono2', %hash);
  705. _html("<br><span class=\"small\">$text</span>");
  706. }
  707. _html("</td></tr>");
  708. }
  709. }
  710. sub _linelengths
  711. {
  712. # The person(s) who wrote the longest lines
  713. my $self = shift;
  714. my %len;
  715. foreach my $nick (sort keys %{ $self->{stats}->{lengths} }) {
  716. if ($self->{stats}->{lines}{$nick} > 100) {
  717. $len{$nick} = $self->{stats}->{lengths}{$nick} / $self->{stats}->{lines}{$nick};
  718. $len{$nick} =~ s/(\.\d)\d+/$1/;
  719. }
  720. }
  721. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  722. my $all_lines = 0;
  723. my $totallength;
  724. foreach my $nick (keys %{ $self->{stats}->{lines} }) {
  725. $all_lines += $self->{stats}->{lines}{$nick};
  726. $totallength += $self->{stats}->{lengths}{$nick};
  727. }
  728. my $totalaverage;
  729. if ($all_lines > 0) {
  730. $totalaverage = $totallength / $all_lines;
  731. $totalaverage =~ s/(\.\d)\d+/$1/;
  732. }
  733. if (@len) {
  734. my %hash = (
  735. nick => $len[0],
  736. letters => $len{$len[0]}
  737. );
  738. my $text = $self->_template_text('long1', %hash);
  739. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br>");
  740. if (@len >= 2) {
  741. %hash = (
  742. avg => $totalaverage
  743. );
  744. $text = $self->_template_text('long2', %hash);
  745. _html("<span class=\"small\">$text</span></td></tr>");
  746. }
  747. }
  748. # The person(s) who wrote the shortest lines
  749. if (@len) {
  750. my %hash = (
  751. nick => $len[$#len],
  752. letters => $len{$len[$#len]}
  753. );
  754. my $text = $self->_template_text('short1', %hash);
  755. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br>");
  756. if (@len >= 2) {
  757. %hash = (
  758. nick => $len[$#len - 1],
  759. letters => $len{$len[$#len - 1]}
  760. );
  761. $text = $self->_template_text('short2', %hash);
  762. _html("<span class=\"small\">$text</span></td></tr>");
  763. }
  764. }
  765. }
  766. sub _mostfoul
  767. {
  768. my $self = shift;
  769. my %spercent;
  770. foreach my $nick (sort keys %{ $self->{stats}->{foul} }) {
  771. if ($self->{stats}->{lines}{$nick} > 15) {
  772. $spercent{$nick} = $self->{stats}->{foul}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  773. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  774. }
  775. }
  776. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  777. if (@foul) {
  778. my %hash = (
  779. nick => $foul[0],
  780. per => $spercent{$foul[0]}
  781. );
  782. my $text = $self->_template_text('foul1', %hash);
  783. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  784. if (@foul >= 2) {
  785. my %hash = (
  786. nick => $foul[1],
  787. per => $spercent{$foul[1]}
  788. );
  789. my $text = $self->_template_text('foul2', %hash);
  790. _html("<br><span class=\"small\">$text</span>");
  791. }
  792. _html("</td></tr>");
  793. } else {
  794. my $text = $self->_template_text('foul3');
  795. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  796. }
  797. }
  798. sub _mostsad
  799. {
  800. my $self = shift;
  801. my %spercent;
  802. foreach my $nick (sort keys %{ $self->{stats}->{frowns} }) {
  803. if ($self->{stats}->{lines}{$nick} > 100) {
  804. $spercent{$nick} = $self->{stats}->{frowns}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  805. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  806. }
  807. }
  808. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  809. if (@sadface) {
  810. my %hash = (
  811. nick => $sadface[0],
  812. per => $spercent{$sadface[0]}
  813. );
  814. my $text = $self->_template_text('sad1', %hash);
  815. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  816. if (@sadface >= 2) {
  817. my %hash = (
  818. nick => $sadface[1],
  819. per => $spercent{$sadface[1]}
  820. );
  821. my $text = $self->_template_text('sad2', %hash);
  822. _html("<br><span class=\"small\">$text</span>");
  823. }
  824. _html("</td></tr>");
  825. } else {
  826. my $text = $self->_template_text('sad3');
  827. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  828. }
  829. }
  830. sub _mostop
  831. {
  832. my $self = shift;
  833. my @ops = sort { $self->{stats}->{gaveops}{$b} <=> $self->{stats}->{gaveops}{$a} }
  834. keys %{ $self->{stats}->{gaveops} };
  835. my @deops = sort { $self->{stats}->{tookops}{$b} <=> $self->{stats}->{tookops}{$a} }
  836. keys %{ $self->{stats}->{tookops} };
  837. if (@ops) {
  838. my %hash = (
  839. nick => $ops[0],
  840. ops => $self->{stats}->{gaveops}{$ops[0]}
  841. );
  842. my $text = $self->_template_text('mostop1', %hash);
  843. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  844. if (@ops >= 2) {
  845. my %hash = (
  846. nick => $ops[1],
  847. ops => $self->{stats}->{gaveops}{$ops[1]}
  848. );
  849. my $text = $self->_template_text('mostop2', %hash);
  850. _html("<br><span class=\"small\">$text</span>");
  851. }
  852. _html("</td></tr>");
  853. } else {
  854. my $text = $self->_template_text('mostop3');
  855. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  856. }
  857. if (@deops) {
  858. my %hash = (
  859. nick => $deops[0],
  860. deops => $self->{stats}->{tookops}{$deops[0]}
  861. );
  862. my $text = $self->_template_text('mostdeop1', %hash);
  863. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  864. if (@deops >= 2) {
  865. my %hash = (
  866. nick => $deops[1],
  867. deops => $self->{stats}->{tookops}{$deops[1]}
  868. );
  869. my $text = $self->_template_text('mostdeop2', %hash);
  870. _html("<br><span class=\"small\">$text</span>");
  871. }
  872. _html("</td></tr>");
  873. } else {
  874. my $text = $self->_template_text('mostdeop3');
  875. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  876. }
  877. }
  878. sub _mostactions
  879. {
  880. # The person who did the most /me's
  881. my $self = shift;
  882. my @actions = sort { $self->{stats}->{actions}{$b} <=> $self->{stats}->{actions}{$a} }
  883. keys %{ $self->{stats}->{actions} };
  884. if (@actions) {
  885. my %hash = (
  886. nick => $actions[0],
  887. actions => $self->{stats}->{actions}{$actions[0]},
  888. line => htmlentities($self->{stats}->{actionlines}{$actions[0]})
  889. );
  890. my $text = $self->_template_text('action1', %hash);
  891. if($self->{cfg}->{show_actionline}) {
  892. my $exttext = $self->_template_text('actiontext', %hash);
  893. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  894. } else {
  895. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  896. }
  897. if (@actions >= 2) {
  898. my %hash = (
  899. nick => $actions[1],
  900. actions => $self->{stats}->{actions}{$actions[1]}
  901. );
  902. my $text = $self->_template_text('action2', %hash);
  903. _html("<br><span class=\"small\">$text</span>");
  904. }
  905. _html("</td></tr>");
  906. } else {
  907. my $text = $self->_template_text('action3');
  908. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  909. }
  910. }
  911. sub _mostsmiles
  912. {
  913. # The person(s) who smiled the most :-)
  914. my $self = shift;
  915. my %spercent;
  916. foreach my $nick (sort keys %{ $self->{stats}->{smiles} }) {
  917. if ($self->{stats}->{lines}{$nick} > 100) {
  918. $spercent{$nick} = $self->{stats}->{smiles}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  919. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  920. }
  921. }
  922. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  923. if (@smiles) {
  924. my %hash = (
  925. nick => $smiles[0],
  926. per => $spercent{$smiles[0]}
  927. );
  928. my $text = $self->_template_text('smiles1', %hash);
  929. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  930. if (@smiles >= 2) {
  931. my %hash = (
  932. nick => $smiles[1],
  933. per => $spercent{$smiles[1]}
  934. );
  935. my $text = $self->_template_text('smiles2', %hash);
  936. _html("<br><span class=\"small\">$text</span>");
  937. }
  938. _html("</td></tr>");
  939. } else {
  940. my $text = $self->_template_text('smiles3');
  941. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  942. }
  943. }
  944. sub _lasttopics
  945. {
  946. my $self = shift;
  947. if ($self->{stats}->{topics}) {
  948. $self->{debug}->("Total number of topics: " . scalar @{ $self->{stats}->{topics} });
  949. my %hash = (
  950. total => scalar @{ $self->{stats}->{topics} }
  951. );
  952. my $ltopic = $#{ $self->{stats}->{topics} };
  953. my $tlimit = 0;
  954. $self->{cfg}->{topichistory} -= 1;
  955. if ($ltopic > $self->{cfg}->{topichistory}) {
  956. $tlimit = $ltopic - $self->{cfg}->{topichistory};
  957. }
  958. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  959. my $topic = htmlentities($self->{stats}->{topics}[$i]{topic});
  960. $topic = _replace_links($topic);
  961. # Strip off the quotes (')
  962. $topic =~ s/^\'(.*)\'$/$1/;
  963. my $nick = $self->{stats}->{topics}[$i]{nick};
  964. my $hour = $self->{stats}->{topics}[$i]{hour};
  965. my $min = $self->{stats}->{topics}[$i]{min};
  966. $hash{nick} = $nick;
  967. $hash{time} = "$hour:$min";
  968. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\"><i>$topic</i></td>");
  969. _html("<td bgcolor=\"$self->{cfg}->{hicell}\"><b>" . $self->_template_text('bylinetopic', %hash) ."</b></td></tr>");
  970. }
  971. _html("<tr><td align=\"center\" colspan=\"2\" class=\"asmall\">" . $self->_template_text('totaltopic', %hash) . "</td></tr>");
  972. } else {
  973. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">" . $self->_template_text('notopic') ."</td></tr>");
  974. }
  975. }
  976. sub _template_text
  977. {
  978. # This function is for the homemade template system. It receives a name
  979. # of a template and a hash with the fields in the template to update to
  980. # its corresponding value
  981. my $self = shift;
  982. my $template = shift;
  983. my %hash = @_;
  984. my $text;
  985. unless ($text = $self->{tmps}->{$self->{cfg}->{lang}}{$template}) {
  986. # Fall back to English if the language template doesn't exist
  987. if ($text = $self->{tmps}->{EN}{$template}) {
  988. print "Note: No translation in '$self->{cfg}->{lang}' for '$template' - falling back to English..\n"
  989. unless ($self->{cfg}->{silent});
  990. } else {
  991. die("No such template '$template' in language file.\n");
  992. }
  993. }
  994. $hash{channel} = $self->{cfg}->{channel};
  995. foreach my $key (sort keys %hash) {
  996. $text =~ s/\[:$key\]/$hash{$key}/;
  997. $text =~ s/ü/&uuml;/go;
  998. $text =~ s/ö/&ouml;/go;
  999. $text =~ s/ä/&auml;/go;
  1000. $text =~ s/ß/&szlig;/go;
  1001. $text =~ s/å/&aring;/go;
  1002. $text =~ s/æ/&aelig;/go;
  1003. $text =~ s/ø/&oslash;/go;
  1004. $text =~ s/Å/&Aring;/go;
  1005. $text =~ s/Æ/&AElig;/go;
  1006. $text =~ s/Ø/&Oslash;/go;
  1007. }
  1008. if ($text =~ /\[:.*?:.*?:\]/o) {
  1009. $text =~ s/\[:(.*?):(.*?):\]/$self->_get_subst($1,$2,\%hash)/geo;
  1010. }
  1011. return $text;
  1012. }
  1013. sub _get_subst
  1014. {
  1015. # This function looks at the user definition and see if there is sex
  1016. # defined. If yes, return the appropriate value. If no, just return the
  1017. # default he/she value.
  1018. my $self = shift;
  1019. my ($m,$f,$hash) = @_;
  1020. if ($hash->{nick} && $self->{users}->{sex}{$hash->{nick}}) {
  1021. if ($self->{users}->{sex}{$hash->{nick}} eq 'm') {
  1022. return $m;
  1023. } elsif ($self->{users}->{sex}{$hash->{nick}} eq 'f') {
  1024. return $f;
  1025. }
  1026. }
  1027. return "$m/$f";
  1028. }
  1029. sub _mostusedword
  1030. {
  1031. # Word usage statistics
  1032. my $self = shift;
  1033. my %usages;
  1034. foreach my $word (keys %{ $self->{stats}->{wordcounts} }) {
  1035. # Skip people's nicks.
  1036. next if exists $self->{stats}->{lines}{$word};
  1037. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1038. }
  1039. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1040. if (@popular) {
  1041. $self->_headline($self->_template_text('mostwordstopic'));
  1042. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1043. _html("<td>&nbsp;</td><td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('word') . "</b></td>");
  1044. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1045. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('lastused') . "</b></td>");
  1046. my $count = 0;
  1047. for(my $i = 0; $count < 10; $i++) {
  1048. last unless $i < $#popular;
  1049. # Skip nicks. It's far more efficient to do this here than when
  1050. # @popular is created.
  1051. next if is_ignored($popular[$i]);
  1052. next if exists $self->{stats}->{lines}{find_alias($popular[$i])};
  1053. my $a = $count + 1;
  1054. my $popular = htmlentities($popular[$i]);
  1055. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1056. my $lastused = htmlentities($self->{stats}->{wordnicks}{$popular[$i]});
  1057. my $bgcolor;
  1058. if ($a == 1) {
  1059. $bgcolor = $self->{cfg}->{hi_rankc};
  1060. } else {
  1061. $bgcolor = $self->{cfg}->{rankc};
  1062. }
  1063. _html("<tr><td bgcolor=\"$bgcolor\"><b>$a</b>");
  1064. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$popular</td>");
  1065. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$wordcount</td>");
  1066. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$lastused</td>");
  1067. _html("</tr>");
  1068. $count++;
  1069. }
  1070. _html("</table>");
  1071. }
  1072. }
  1073. sub _mostwordsperline
  1074. {
  1075. # The person who got the most words per line
  1076. my $self = shift;
  1077. my %wpl = ();
  1078. my $numlines = 0;
  1079. my ($avg, $numwords);
  1080. foreach my $n (keys %{ $self->{stats}->{words} }) {
  1081. $wpl{$n} = sprintf("%.2f", $self->{stats}->{words}{$n}/$self->{stats}->{lines}{$n});
  1082. $numlines += $self->{stats}->{lines}{$n};
  1083. $numwords += $self->{stats}->{words}{$n};
  1084. }
  1085. if ($numlines > 0) {
  1086. $avg = sprintf("%.2f", $numwords/$numlines);
  1087. }
  1088. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  1089. if (@wpl) {
  1090. my %hash = (
  1091. nick => $wpl[0],
  1092. wpl => $wpl{$wpl[0]}
  1093. );
  1094. my $text = $self->_template_text('wpl1', %hash);
  1095. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  1096. %hash = (
  1097. avg => $avg
  1098. );
  1099. $text = $self->_template_text('wpl2', %hash);
  1100. _html("<br><span class=\"small\">$text</span>");
  1101. _html("</td></tr>");
  1102. }
  1103. }
  1104. sub _mostreferencednicks
  1105. {
  1106. # List showing the most referenced nicks
  1107. my $self = shift;
  1108. my %usages;
  1109. foreach my $word (sort keys %{ $self->{stats}->{wordcounts} }) {
  1110. next unless exists $self->{stats}->{lines}{$word};
  1111. next if is_ignored($word);
  1112. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1113. }
  1114. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1115. if (@popular) {
  1116. $self->_headline($self->_template_text('referencetopic'));
  1117. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1118. _html("<td>&nbsp;</td><td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('nick') . "</b></td>");
  1119. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1120. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('lastused') . "</b></td>");
  1121. for(my $i = 0; $i < 5; $i++) {
  1122. last unless $i < $#popular;
  1123. my $a = $i + 1;
  1124. my $popular = $popular[$i];
  1125. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1126. my $lastused = $self->{stats}->{wordnicks}{$popular[$i]};
  1127. my $bgcolor;
  1128. if ($a == 1) {
  1129. $bgcolor = $self->{cfg}->{hi_rankc};
  1130. } else {
  1131. $bgcolor = $self->{cfg}->{rankc};
  1132. }
  1133. _html("<tr><td bgcolor=\"$bgcolor\"><b>$a</b>");
  1134. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$popular</td>");
  1135. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$wordcount</td>");
  1136. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$lastused</td>");
  1137. _html("</tr>");
  1138. }
  1139. _html("</table>");
  1140. }
  1141. }
  1142. sub _mosturls
  1143. {
  1144. # List showing the most referenced URLs
  1145. my $self = shift;
  1146. my @sorturls = sort { $self->{stats}->{urlcounts}{$b} <=> $self->{stats}->{urlcounts}{$a} }
  1147. keys %{ $self->{stats}->{urlcounts} };
  1148. if (@sorturls) {
  1149. $self->_headline($self->_template_text('urlstopic'));
  1150. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1151. _html("<td>&nbsp;</td><td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('url') . "</b></td>");
  1152. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1153. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('lastused') . "</b></td>");
  1154. for(my $i = 0; $i < 5; $i++) {
  1155. last unless $i < $#sorturls;
  1156. my $a = $i + 1;
  1157. my $sorturl = $sorturls[$i];
  1158. my $urlcount = $self->{stats}->{urlcounts}{$sorturls[$i]};
  1159. my $lastused = $self->{stats}->{urlnicks}{$sorturls[$i]};
  1160. if (length($sorturl) > 60) {
  1161. $sorturl = substr($sorturl, 0, 60);
  1162. }
  1163. my $bgcolor;
  1164. if ($a == 1) {
  1165. $bgcolor = $self->{cfg}->{hi_rankc};
  1166. } else {
  1167. $bgcolor = $self->{cfg}->{rankc};
  1168. }
  1169. _html("<tr><td bgcolor=\"$bgcolor\"><b>$a</b>");
  1170. _html("<td bgcolor=\"$self->{cfg}->{hicell}\"><a href=\"$sorturls[$i]\">$sorturl</a></td>");
  1171. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$urlcount</td>");
  1172. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$lastused</td>");
  1173. _html("</tr>");
  1174. }
  1175. _html("</table>");
  1176. }
  1177. }
  1178. sub _legend
  1179. {
  1180. # A legend showing the timebars and their associated time.
  1181. my $self = shift;
  1182. _html("<table align=\"center\" border=\"0\" width=\"520\"><tr>");
  1183. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{pic_h_0}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 0-5</td>");
  1184. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{pic_h_6}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 6-11</td>");
  1185. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{pic_h_12}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 12-17</td>");
  1186. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{pic_h_18}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 18-23</td>");
  1187. _html("</tr></table>\n");
  1188. }
  1189. sub _replace_links
  1190. {
  1191. # Sub to replace urls and e-mail addys to links
  1192. my $str = shift;
  1193. my $nick = shift;
  1194. my ($url, $email);
  1195. if ($nick) {
  1196. if ($url = match_url($str)) {
  1197. $str =~ s/(\Q$url\E)/<a href="$1" target="_blank" title="Open in new window: $1">$nick<\/a>/g;
  1198. }
  1199. if ($email = match_email($str)) {
  1200. $str =~ s/(\Q$email\E)/<a href="mailto:$1" title="Mail to $nick">$nick<\/a>/g;
  1201. }
  1202. } else {
  1203. if ($url = match_url($str)) {
  1204. $str =~ s/(\Q$url\E)/<a href="$1" target="_blank" title="Open in new window: $1">$1<\/a>/g;
  1205. }
  1206. if ($email = match_email($str)) {
  1207. $str =~ s/(\Q$email\E)/<a href="mailto:$1" title="Mail to $1">$1<\/a>/g;
  1208. }
  1209. }
  1210. return $str;
  1211. }
  1212. sub _user_linetimes
  1213. {
  1214. my $self = shift;
  1215. my $nick = shift;
  1216. my $top = shift;
  1217. my $bar = "";
  1218. my $len = ($self->{stats}->{lines}{$nick} / $self->{stats}->{lines}{$top}) * 100;
  1219. my $debuglen = 0;
  1220. for (my $i = 0; $i <= 3; $i++) {
  1221. next if not defined $self->{stats}->{line_times}{$nick}[$i];
  1222. my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * $len);
  1223. $debuglen += $w;
  1224. if ($w) {
  1225. my $pic = 'pic_h_'.(6*$i);
  1226. $bar .= "<img src=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\">";
  1227. }
  1228. }
  1229. $self->{debug}->("Length='$len', Sum='$debuglen'");
  1230. return "$bar&nbsp;$self->{stats}->{lines}{$nick}";
  1231. }
  1232. sub _user_times
  1233. {
  1234. my $self = shift;
  1235. my ($nick) = @_;
  1236. my $bar = "";
  1237. for (my $i = 0; $i <= 3; $i++) {
  1238. next if not defined $self->{stats}->{line_times}{$nick}[$i];
  1239. my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * 40);
  1240. if ($w) {
  1241. my $pic = 'pic_h_'.(6*$i);
  1242. $bar .= "<img src=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\">";
  1243. }
  1244. }
  1245. return $bar;
  1246. }
  1247. 1;
  1248. __END__
  1249. =head1 NAME
  1250. Pisg::HTMLGenerator - class to create a static HTML page out of data parsed
  1251. =head1 DESCRIPTION
  1252. C<Pisg::HTMLGenerator> uses the hash returned by Pisg::Parser::Logfile and turns it into a static HTML page.
  1253. =head1 SYNOPSIS
  1254. use Pisg::HTMLGenerator;
  1255. $generator = new Pisg::HTMLGenerator(
  1256. cfg => $cfg,
  1257. debug => $debug,
  1258. stats => $stats,
  1259. users => $users,
  1260. tmps => $tmps
  1261. );
  1262. =head1 CONSTRUCTOR
  1263. =over 4
  1264. =item new ( [ OPTIONS ] )
  1265. This is the constructor for a new Pisg::HTMLGenerator object. C<OPTIONS> are passed in a hash like fashion using key and value pairs.
  1266. Possible options are:
  1267. B<cfg> - hashref containing configuration variables, created by the Pisg module.
  1268. B<debug> - reference to a sub routine to send the debug information.
  1269. B<stats> - reference to the hash returned by Pisg::Parser::Logfile containing all stats.
  1270. B<users> - reference to a hash containg user information
  1271. B<tmps> - reference to a hash containing the language templates.
  1272. =back
  1273. =head1 AUTHOR
  1274. Morten Brix Pedersen <morten@wtf.dk>
  1275. =head1 COPYRIGHT
  1276. Copyright (C) 2001 Morten Brix Pedersen. All rights resereved.
  1277. This program is free software; you can redistribute it and/or modify it
  1278. under the terms of the GPL, license is included with the distribution of
  1279. this file.
  1280. =cut