HTMLGenerator.pm 81 KB

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