4
0

HTMLGenerator.pm 51 KB

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