HTMLGenerator.pm 52 KB

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