HTMLGenerator.pm 52 KB

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