HTMLGenerator.pm 54 KB

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