HTMLGenerator.pm 78 KB

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