HTMLGenerator.pm 81 KB

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