HTMLGenerator.pm 84 KB

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