HTMLGenerator.pm 70 KB

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