HTMLGenerator.pm 81 KB

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