HTMLGenerator.pm 78 KB

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