HTMLGenerator.pm 79 KB

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