HTMLGenerator.pm 81 KB

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