HTMLGenerator.pm 68 KB

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