HTMLGenerator.pm 70 KB

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