HTMLGenerator.pm 71 KB

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