HTMLGenerator.pm 70 KB

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