HTMLGenerator.pm 53 KB

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