HTMLGenerator.pm 65 KB

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