HTMLGenerator.pm 82 KB

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