HTMLGenerator.pm 68 KB

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