HTMLGenerator.pm 52 KB

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