HTMLGenerator.pm 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  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. debug => $args{debug},
  13. stats => $args{stats},
  14. users => $args{users},
  15. tmps => $args{tmps}
  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_html
  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. print "Now generating HTML($self->{cfg}->{outputfile})...\n"
  31. unless ($self->{cfg}->{silent});
  32. open (OUTPUT, "> $self->{cfg}->{outputfile}") or
  33. die("$0: Unable to open outputfile($self->{cfg}->{outputfile}): $!\n");
  34. if ($self->{cfg}->{show_time}) {
  35. $self->{cfg}->{tablewidth} += 40;
  36. }
  37. if ($self->{cfg}->{show_words}) {
  38. $self->{cfg}->{tablewidth} += 40;
  39. }
  40. if ($self->{cfg}->{show_wpl}) {
  41. $self->{cfg}->{tablewidth} += 40;
  42. }
  43. if ($self->{cfg}->{show_cpl}) {
  44. $self->{cfg}->{tablewidth} += 40;
  45. }
  46. $self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
  47. $self->_htmlheader();
  48. $self->_pageheader();
  49. $self->_activetimes();
  50. $self->_activenicks();
  51. $self->_headline($self->_template_text('bignumtopic'));
  52. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  53. $self->_questions();
  54. $self->_shoutpeople();
  55. $self->_capspeople();
  56. $self->_violent();
  57. $self->_mostsmiles();
  58. $self->_mostsad();
  59. $self->_linelengths();
  60. $self->_mostwords();
  61. $self->_mostwordsperline();
  62. _html("</table>"); # Needed for sections
  63. if ($self->{cfg}->{show_muw}) {
  64. $self->_mostusedword();
  65. }
  66. if ($self->{cfg}->{show_mrn}) {
  67. $self->_mostreferencednicks();
  68. }
  69. if ($self->{cfg}->{show_mru}) {
  70. $self->_mosturls();
  71. }
  72. $self->_headline($self->_template_text('othernumtopic'));
  73. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  74. $self->_gotkicks();
  75. $self->_mostkicks();
  76. $self->_mostop();
  77. $self->_mostactions();
  78. $self->_mostmonologues();
  79. $self->_mostjoins();
  80. $self->_mostfoul();
  81. _html("</table>"); # Needed for sections
  82. $self->_headline($self->_template_text('latesttopic'));
  83. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  84. $self->_lasttopics();
  85. _html("</table>"); # Needed for sections
  86. my %hash = ( lines => $self->{stats}->{totallines} );
  87. _html($self->_template_text('totallines', %hash) . "<br><br>");
  88. $self->_htmlfooter();
  89. close(OUTPUT);
  90. }
  91. sub _htmlheader
  92. {
  93. my $self = shift;
  94. my $bgpic = "";
  95. if ($self->{cfg}->{bgpic}) {
  96. $bgpic = " background=\"$self->{cfg}->{bgpic}\"";
  97. }
  98. print OUTPUT <<HTML;
  99. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  100. <html>
  101. <head>
  102. <title>$self->{cfg}->{channel} @ $self->{cfg}->{network} channel statistics</title>
  103. <style type="text/css">
  104. a { text-decoration: none }
  105. a:link { color: $self->{cfg}->{link}; }
  106. a:visited { color: $self->{cfg}->{vlink}; }
  107. a:hover { text-decoration: underline; color: $self->{cfg}->{hlink} }
  108. body {
  109. background-color: $self->{cfg}->{bgcolor};
  110. font-family: verdana, arial, sans-serif;
  111. font-size: 13px;
  112. color: $self->{cfg}->{text};
  113. }
  114. td {
  115. font-family: verdana, arial, sans-serif;
  116. font-size: 13px;
  117. color: $self->{cfg}->{tdcolor};
  118. }
  119. .title {
  120. font-family: tahoma, arial, sans-serif;
  121. font-size: 16px;
  122. font-weight: bold;
  123. }
  124. .headline { color: $self->{cfg}->{hcolor}; }
  125. .small { font-family: verdana, arial, sans-serif; font-size: 10px; }
  126. .asmall {
  127. font-family: arial narrow, sans-serif;
  128. font-size: 10px;
  129. color: $self->{cfg}->{text};
  130. }
  131. </style></head>
  132. <body$bgpic>
  133. <div align="center">
  134. HTML
  135. my %hash = (
  136. network => $self->{cfg}->{network},
  137. maintainer => $self->{cfg}->{maintainer},
  138. days => $self->{stats}->{days},
  139. nicks => scalar keys %{ $self->{stats}->{lines} }
  140. );
  141. print OUTPUT "<span class=\"title\">" . $self->_template_text('pagetitle1', %hash) . "</span><br>";
  142. print OUTPUT "<br>";
  143. print OUTPUT $self->_template_text('pagetitle2', %hash);
  144. sub timefix
  145. {
  146. my $self = shift;
  147. my ($timezone, $sec, $min, $hour, $mday, $mon, $year, $wday, $month, $day, $tday, $wdisplay, @month, @day, $timefixx, %hash);
  148. $month = $self->_template_text('month', %hash);
  149. $day = $self->_template_text('day', %hash);
  150. @month = split(" ", $month);
  151. @day = split(" ", $day);
  152. # Get the Date from the users computer
  153. $timezone = $self->{cfg}->{timeoffset} * 3600;
  154. ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+$timezone);
  155. $year += 1900; # Y2K Patch
  156. $min =~ s/^(.)$/0$1/; # Fixes the display of mins/secs below
  157. $sec =~ s/^(.)$/0$1/; # it displays 03 instead of 3
  158. if ($hour > '23') { # Checks to see if it Midnight
  159. $hour = 12; # Makes it display the hour 12
  160. $tday = "AM"; # Display AM
  161. } elsif($hour > '12') { # Get rid of the Military time and
  162. $hour -= 12; # put it into normal time
  163. $tday = "PM"; # If past Noon and before Midnight set
  164. } else {
  165. $tday = "AM"; # If it's past Midnight and before Noon
  166. } # set the time as AM
  167. # Use 24 hours pr. day
  168. if ($tday eq "PM" && $hour < '12') {
  169. $hour += 12;
  170. }
  171. print OUTPUT "$day[$wday] $mday $month[$mon] $year - $hour:$min:$sec\n";
  172. }
  173. $self->timefix();
  174. print OUTPUT "<br>" . $self->_template_text('pagetitle3', %hash) . "<br><br>";
  175. }
  176. sub _htmlfooter
  177. {
  178. my $self = shift;
  179. print OUTPUT <<HTML;
  180. <span class="small">
  181. Stats generated by <a href="http://pisg.sourceforge.net/" title="Go to the pisg homepage">pisg</a> $self->{cfg}->{version}<br>
  182. pisg by <a href="http://www.wtf.dk/hp/" title="Go to the authors homepage">Morten Brix Pedersen</a> and others<br>
  183. Stats generated in $self->{stats}->{processtime}
  184. </span>
  185. </div>
  186. </body>
  187. </html>
  188. HTML
  189. }
  190. sub _headline
  191. {
  192. my $self = shift;
  193. my ($title) = (@_);
  194. print OUTPUT <<HTML;
  195. <br>
  196. <table width="$self->{cfg}->{headwidth}" cellpadding="1" cellspacing="0" border="0">
  197. <tr>
  198. <td bgcolor="$self->{cfg}->{headline}">
  199. <table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">
  200. <tr>
  201. <td bgcolor="$self->{cfg}->{hbgcolor}" class="text10">
  202. <div align="center" class="headline"><b>$title</b></div>
  203. </td>
  204. </tr>
  205. </table>
  206. </td>
  207. </tr>
  208. </table>
  209. HTML
  210. }
  211. sub _pageheader
  212. {
  213. my $self = shift;
  214. if ($self->{cfg}->{pagehead} ne 'none') {
  215. open(PAGEHEAD, $self->{cfg}->{pagehead}) or die("$0: Unable to open $self->{cfg}->{pagehead} for reading: $!\n");
  216. while (<PAGEHEAD>) {
  217. _html($_);
  218. }
  219. }
  220. }
  221. sub _activetimes
  222. {
  223. # The most actives times on the channel
  224. my $self = shift;
  225. my (%output, $tbgcolor);
  226. $self->_headline($self->_template_text('activetimestopic'));
  227. my @toptime = sort { $self->{stats}->{times}{$b} <=> $self->{stats}->{times}{$a} } keys %{ $self->{stats}->{times} };
  228. my $highest_value = $self->{stats}->{times}{$toptime[0]};
  229. my @now = localtime($self->{cfg}->{timestamp});
  230. my $image;
  231. for my $hour (sort keys %{ $self->{stats}->{times} }) {
  232. $self->{debug}->("Time: $hour => ". $self->{stats}->{times}{$hour});
  233. my $size = ($self->{stats}->{times}{$hour} / $highest_value) * 100;
  234. my $percent = ($self->{stats}->{times}{$hour} / $self->{stats}->{totallines}) * 100;
  235. $percent =~ s/(\.\d)\d+/$1/;
  236. if ($size < 1 && $size != 0) {
  237. # Opera doesn't understand '0.xxxx' in the height="xx" attr,
  238. # so we simply round up to 1.0 here.
  239. $size = 1.0;
  240. }
  241. if ($self->{cfg}->{timeoffset} =~ /\+(\d+)/) {
  242. # We must plus some hours to the time
  243. $hour += $1;
  244. $hour = $hour % 24;
  245. if ($hour < 10) { $hour = "0" . $hour; }
  246. } elsif ($self->{cfg}->{timeoffset} =~ /-(\d+)/) {
  247. # We must remove some hours from the time
  248. $hour -= $1;
  249. $hour = $hour % 24;
  250. if ($hour < 10) { $hour = "0" . $hour; }
  251. }
  252. $image = "pic_v_".(int($hour/6)*6);
  253. $image = $self->{cfg}->{$image};
  254. $self->{debug}->("Image: $image");
  255. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br><img src=\"$image\" width=\"15\" height=\"$size\" alt=\"$percent\"></td>\n";
  256. }
  257. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>\n");
  258. for ($b = 0; $b < 24; $b++) {
  259. if ($b < 10) { $a = "0" . $b; } else { $a = $b; }
  260. if (!defined($output{$a}) || $output{$a} eq "") {
  261. _html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  262. } else {
  263. _html($output{$a});
  264. }
  265. }
  266. _html("</tr><tr>");
  267. for ($b = 0; $b < 24; $b++) {
  268. if ($now[2] == $b) { $tbgcolor = "\#AAAAAA"; } else { $tbgcolor = "\#CCCCCC"; }
  269. _html("<td bgcolor=\"$tbgcolor\" align=\"center\" class=\"small\">$b</td>");
  270. }
  271. _html("</tr></table>");
  272. if($self->{cfg}->{show_legend} == 1) {
  273. $self->_legend();
  274. }
  275. }
  276. sub _activenicks
  277. {
  278. # The most active nicks (those who wrote most lines)
  279. my $self = shift;
  280. $self->_headline($self->_template_text('activenickstopic'));
  281. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  282. _html("<td>&nbsp;</td>"
  283. . "<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('nick') . "</b></td>"
  284. . "<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('numberlines') . "</b></td>"
  285. . ($self->{cfg}->{show_time} ? "<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>".$self->_template_text('show_time')."</b></td>" : "")
  286. . ($self->{cfg}->{show_words} ? "<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>".$self->_template_text('show_words')."</b></td>" : "")
  287. . ($self->{cfg}->{show_wpl} ? "<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>".$self->_template_text('show_wpl')."</b></td>" : "")
  288. . ($self->{cfg}->{show_cpl} ? "<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>".$self->_template_text('show_cpl')."</b></td>" : "")
  289. . ($self->{cfg}->{show_randquote} ? "<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>".$self->_template_text('randquote')."</b></td>" : "")
  290. );
  291. if (scalar keys %{$self->{users}->{userpics}} > 0) {
  292. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('userpic') ."</b></td>");
  293. }
  294. _html("</tr>");
  295. my @active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} } keys %{ $self->{stats}->{lines} };
  296. my $nicks = scalar keys %{ $self->{stats}->{lines} };
  297. if ($self->{cfg}->{activenicks} > $nicks) {
  298. $self->{cfg}->{activenicks} = $nicks;
  299. }
  300. my ($nick, $visiblenick, $randomline, %hash);
  301. my $i = 1;
  302. for (my $c = 0; $c < $self->{cfg}->{activenicks}; $c++) {
  303. $nick = $active[$c];
  304. $visiblenick = $active[$c];
  305. if (not defined $self->{stats}->{sayings}{$nick}) {
  306. $randomline = "";
  307. } else {
  308. $randomline = htmlentities($self->{stats}->{sayings}{$nick});
  309. }
  310. # Convert URLs and e-mail addys to links
  311. $randomline = _replace_links($randomline);
  312. # Add a link to the nick if there is any
  313. if ($self->{users}->{userlinks}{$nick}) {
  314. $visiblenick = _replace_links($self->{users}->{userlinks}{$nick}, $nick);
  315. }
  316. my $h = $self->{cfg}->{hicell};
  317. $h =~ s/^#//;
  318. $h = hex $h;
  319. my $h2 = $self->{cfg}->{hicell2};
  320. $h2 =~ s/^#//;
  321. $h2 = hex $h2;
  322. my $f_b = $h & 0xff;
  323. my $f_g = ($h & 0xff00) >> 8;
  324. my $f_r = ($h & 0xff0000) >> 16;
  325. my $t_b = $h2 & 0xff;
  326. my $t_g = ($h2 & 0xff00) >> 8;
  327. my $t_r = ($h2 & 0xff0000) >> 16;
  328. my $col_b = sprintf "%0.2x", abs int(((($t_b - $f_b) / $self->{cfg}->{activenicks}) * +$c) + $f_b);
  329. my $col_g = sprintf "%0.2x", abs int(((($t_g - $f_g) / $self->{cfg}->{activenicks}) * +$c) + $f_g);
  330. my $col_r = sprintf "%0.2x", abs int(((($t_r - $f_r) / $self->{cfg}->{activenicks}) * +$c) + $f_r);
  331. _html("<tr><td bgcolor=\"$self->{cfg}->{rankc}\" align=\"left\">");
  332. my $line = $self->{stats}->{lines}{$nick};
  333. my $w = $self->{stats}->{words}{$nick};
  334. my $ch = $self->{stats}->{lengths}{$nick};
  335. _html("$i</td><td bgcolor=\"#$col_r$col_g$col_b\">$visiblenick</td>"
  336. . ($self->{cfg}->{show_linetime} ?
  337. "<td bgcolor=\"$col_r$col_g$col_b\">".$self->_user_linetimes($nick,$active[0])."</td>"
  338. : "<td bgcolor=\"#$col_r$col_g$col_b\">$line</td>")
  339. . ($self->{cfg}->{show_time} ?
  340. "<td bgcolor=\"$col_r$col_g$col_b\">".$self->_user_times($nick)."</td>"
  341. : "")
  342. . ($self->{cfg}->{show_words} ?
  343. "<td bgcolor=\"#$col_r$col_g$col_b\">$w</td>"
  344. : "")
  345. . ($self->{cfg}->{show_wpl} ?
  346. "<td bgcolor=\"#$col_r$col_g$col_b\">".sprintf("%.1f",$w/$line)."</td>"
  347. : "")
  348. . ($self->{cfg}->{show_cpl} ?
  349. "<td bgcolor=\"#$col_r$col_g$col_b\">".sprintf("%.1f",$ch/$line)."</td>"
  350. : "")
  351. . ($self->{cfg}->{show_randquote} ?
  352. "<td bgcolor=\"#$col_r$col_g$col_b\">\"$randomline\"</td>"
  353. : "")
  354. );
  355. my $height = $self->{cfg}->{pic_height};
  356. my $width = $self->{cfg}->{pic_width};
  357. if ($self->{users}->{userpics}{$nick}) {
  358. if ($width ne '') {
  359. _html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$self->{cfg}->{imagepath}$self->{users}->{userpics}{$nick}\" width=\"$width\" height=\"$height\"></td>");
  360. } else {
  361. _html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$self->{cfg}->{imagepath}$self->{users}->{userpics}{$nick}\"></td>");
  362. }
  363. }
  364. _html("</tr>");
  365. $i++;
  366. }
  367. _html("</table><br>");
  368. # Almost as active nicks ('These didn't make it to the top..')
  369. my $nickstoshow = $self->{cfg}->{activenicks} + $self->{cfg}->{activenicks2};
  370. $hash{totalnicks} = $nicks - $nickstoshow;
  371. unless ($nickstoshow > $nicks) {
  372. _html("<br><b><i>" . $self->_template_text('nottop') . "</i></b><table><tr>");
  373. for (my $c = $self->{cfg}->{activenicks}; $c < $nickstoshow; $c++) {
  374. unless ($c % 5) { unless ($c == $self->{cfg}->{activenicks}) { _html("</tr><tr>"); } }
  375. _html("<td bgcolor=\"$self->{cfg}->{rankc}\" class=\"small\">");
  376. my $nick = $active[$c];
  377. my $lines = $self->{stats}->{lines}{$nick};
  378. _html("$nick ($lines)</td>");
  379. }
  380. _html("</table>");
  381. }
  382. if($hash{totalnicks} > 0) {
  383. _html("<br><b>" . $self->_template_text('totalnicks', %hash) . "</b><br>");
  384. }
  385. }
  386. sub _html
  387. {
  388. my $html = shift;
  389. print OUTPUT "$html\n";
  390. }
  391. sub _questions
  392. {
  393. # Persons who asked the most questions
  394. my $self = shift;
  395. my %qpercent;
  396. foreach my $nick (sort keys %{ $self->{stats}->{questions} }) {
  397. if ($self->{stats}->{lines}{$nick} > 100) {
  398. $qpercent{$nick} = ($self->{stats}->{questions}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  399. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  400. }
  401. }
  402. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  403. if (@question) {
  404. my %hash = (
  405. nick => $question[0],
  406. per => $qpercent{$question[0]}
  407. );
  408. my $text = $self->_template_text('question1', %hash);
  409. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  410. if (@question >= 2) {
  411. my %hash = (
  412. nick => $question[1],
  413. per => $qpercent{$question[1]}
  414. );
  415. my $text = $self->_template_text('question2', %hash);
  416. _html("<br><span class=\"small\">$text</span>");
  417. }
  418. _html("</td></tr>");
  419. } else {
  420. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">" . $self->_template_text('question3') . "</td></tr>");
  421. }
  422. }
  423. sub _shoutpeople
  424. {
  425. # The ones who speak with exclamation marks!
  426. my $self = shift;
  427. my %spercent;
  428. foreach my $nick (sort keys %{ $self->{stats}->{shouts} }) {
  429. if ($self->{stats}->{lines}{$nick} > 100) {
  430. $spercent{$nick} = ($self->{stats}->{shouts}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  431. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  432. }
  433. }
  434. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  435. if (@shout) {
  436. my %hash = (
  437. nick => $shout[0],
  438. per => $spercent{$shout[0]}
  439. );
  440. my $text = $self->_template_text('shout1', %hash);
  441. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  442. if (@shout >= 2) {
  443. my %hash = (
  444. nick => $shout[1],
  445. per => $spercent{$shout[1]}
  446. );
  447. my $text = $self->_template_text('shout2', %hash);
  448. _html("<br><span class=\"small\">$text</span>");
  449. }
  450. _html("</td></tr>");
  451. } else {
  452. my $text = $self->_template_text('shout3');
  453. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  454. }
  455. }
  456. sub _capspeople
  457. {
  458. # The ones who speak ALL CAPS.
  459. my $self = shift;
  460. my %cpercent;
  461. foreach my $nick (sort keys %{ $self->{stats}->{allcaps} }) {
  462. if ($self->{stats}->{lines}{$nick} > 100) {
  463. $cpercent{$nick} = $self->{stats}->{allcaps}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  464. $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
  465. }
  466. }
  467. my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent;
  468. if (@caps) {
  469. my %hash = (
  470. nick => $caps[0],
  471. per => $cpercent{$caps[0]},
  472. line => htmlentities($self->{stats}->{allcaplines}{$caps[0]})
  473. );
  474. my $text = $self->_template_text('allcaps1', %hash);
  475. if($self->{cfg}->{show_shoutline}) {
  476. my $exttext = $self->_template_text('allcapstext', %hash);
  477. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  478. } else {
  479. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  480. }
  481. if (@caps >= 2) {
  482. my %hash = (
  483. nick => $caps[1],
  484. per => $cpercent{$caps[1]}
  485. );
  486. my $text = $self->_template_text('allcaps2', %hash);
  487. _html("<br><span class=\"small\">$text</span>");
  488. }
  489. _html("</td></tr>");
  490. } else {
  491. my $text = $self->_template_text('allcaps3');
  492. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  493. }
  494. }
  495. sub _violent
  496. {
  497. # They attacked others (words defined by $self->{cfg}->{violent})
  498. my $self = shift;
  499. my @aggressors;
  500. @aggressors = sort { $self->{stats}->{violence}{$b} <=> $self->{stats}->{violence}{$a} }
  501. keys %{ $self->{stats}->{violence} };
  502. if(@aggressors) {
  503. my %hash = (
  504. nick => $aggressors[0],
  505. attacks => $self->{stats}->{violence}{$aggressors[0]},
  506. line => htmlentities($self->{stats}->{violencelines}{$aggressors[0]})
  507. );
  508. my $text = $self->_template_text('violent1', %hash);
  509. if($self->{cfg}->{show_violentlines}) {
  510. my $exttext = $self->_template_text('violenttext', %hash);
  511. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  512. } else {
  513. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  514. }
  515. if (@aggressors >= 2) {
  516. my %hash = (
  517. nick => $aggressors[1],
  518. attacks => $self->{stats}->{violence}{$aggressors[1]}
  519. );
  520. my $text = $self->_template_text('violent2', %hash);
  521. _html("<br><span class=\"small\">$text</span>");
  522. }
  523. _html("</td></tr>");
  524. } else {
  525. my $text = $self->_template_text('violent3');
  526. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  527. }
  528. # They got attacked
  529. my @victims;
  530. @victims = sort { $self->{stats}->{attacked}{$b} <=> $self->{stats}->{attacked}{$a} }
  531. keys %{ $self->{stats}->{attacked} };
  532. if(@victims) {
  533. my %hash = (
  534. nick => $victims[0],
  535. attacks => $self->{stats}->{attacked}{$victims[0]},
  536. line => htmlentities($self->{stats}->{attackedlines}{$victims[0]})
  537. );
  538. my $text = $self->_template_text('attacked1', %hash);
  539. if($self->{cfg}->{show_violentlines}) {
  540. my $exttext = $self->_template_text('attackedtext', %hash);
  541. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  542. } else {
  543. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  544. }
  545. if (@victims >= 2) {
  546. my %hash = (
  547. nick => $victims[1],
  548. attacks => $self->{stats}->{attacked}{$victims[1]}
  549. );
  550. my $text = $self->_template_text('attacked2', %hash);
  551. _html("<br><span class=\"small\">$text</span>");
  552. }
  553. _html("</td></tr>");
  554. }
  555. }
  556. sub _gotkicks
  557. {
  558. # The persons who got kicked the most
  559. my $self = shift;
  560. my @gotkick = sort { $self->{stats}->{gotkicked}{$b} <=> $self->{stats}->{gotkicked}{$a} }
  561. keys %{ $self->{stats}->{gotkicked} };
  562. if (@gotkick) {
  563. my %hash = (
  564. nick => $gotkick[0],
  565. kicks => $self->{stats}->{gotkicked}{$gotkick[0]},
  566. line => $self->{stats}->{kicklines}{$gotkick[0]}
  567. );
  568. my $text = $self->_template_text('gotkick1', %hash);
  569. if ($self->{cfg}->{show_kickline}) {
  570. my $exttext = $self->_template_text('kicktext', %hash);
  571. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  572. } else {
  573. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  574. }
  575. if (@gotkick >= 2) {
  576. my %hash = (
  577. nick => $gotkick[1],
  578. kicks => $self->{stats}->{gotkicked}{$gotkick[1]}
  579. );
  580. my $text = $self->_template_text('gotkick2', %hash);
  581. _html("<br><span class=\"small\">$text</span>");
  582. }
  583. _html("</td></tr>");
  584. }
  585. }
  586. sub _mostjoins
  587. {
  588. my $self = shift;
  589. my @joins = sort { $self->{stats}->{joins}{$b} <=> $self->{stats}->{joins}{$a} }
  590. keys %{ $self->{stats}->{joins} };
  591. if (@joins) {
  592. my %hash = (
  593. nick => $joins[0],
  594. joins => $self->{stats}->{joins}{$joins[0]}
  595. );
  596. my $text = $self->_template_text('joins', %hash);
  597. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  598. }
  599. }
  600. sub _mostwords
  601. {
  602. # The person who got words the most
  603. my $self = shift;
  604. my @words = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  605. keys %{ $self->{stats}->{words} };
  606. if (@words) {
  607. my %hash = (
  608. nick => $words[0],
  609. words => $self->{stats}->{words}{$words[0]}
  610. );
  611. my $text = $self->_template_text('words1', %hash);
  612. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  613. if (@words >= 2) {
  614. my %hash = (
  615. oldnick => $words[0],
  616. nick => $words[1],
  617. words => $self->{stats}->{words}{$words[1]}
  618. );
  619. my $text = $self->_template_text('words2', %hash);
  620. _html("<br><span class=\"small\">$text</span>");
  621. }
  622. _html("</td></tr>");
  623. } else {
  624. my $text = $self->_template_text('kick3');
  625. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  626. }
  627. }
  628. sub _mostkicks
  629. {
  630. # The person who kicked the most
  631. my $self = shift;
  632. my @kicked = sort { $self->{stats}->{kicked}{$b} <=> $self->{stats}->{kicked}{$a} }
  633. keys %{ $self->{stats}->{kicked} };
  634. if (@kicked) {
  635. my %hash = (
  636. nick => $kicked[0],
  637. kicked => $self->{stats}->{kicked}{$kicked[0]}
  638. );
  639. my $text = $self->_template_text('kick1', %hash);
  640. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  641. if (@kicked >= 2) {
  642. my %hash = (
  643. oldnick => $kicked[0],
  644. nick => $kicked[1],
  645. kicked => $self->{stats}->{kicked}{$kicked[1]}
  646. );
  647. my $text = $self->_template_text('kick2', %hash);
  648. _html("<br><span class=\"small\">$text</span>");
  649. }
  650. _html("</td></tr>");
  651. } else {
  652. my $text = $self->_template_text('kick3');
  653. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  654. }
  655. }
  656. sub _mostmonologues
  657. {
  658. # The person who had the most monologues (speaking to himself)
  659. my $self = shift;
  660. my @monologue = sort { $self->{stats}->{monologues}{$b} <=> $self->{stats}->{monologues}{$a} } keys %{ $self->{stats}->{monologues} };
  661. if (@monologue) {
  662. my %hash = (
  663. nick => $monologue[0],
  664. monos => $self->{stats}->{monologues}{$monologue[0]}
  665. );
  666. my $text = $self->_template_text('mono1', %hash);
  667. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  668. if (@monologue >= 2) {
  669. my %hash = (
  670. nick => $monologue[1],
  671. monos => $self->{stats}->{monologues}{$monologue[1]}
  672. );
  673. my $text = $self->_template_text('mono2', %hash);
  674. _html("<br><span class=\"small\">$text</span>");
  675. }
  676. _html("</td></tr>");
  677. }
  678. }
  679. sub _linelengths
  680. {
  681. # The person(s) who wrote the longest lines
  682. my $self = shift;
  683. my %len;
  684. foreach my $nick (sort keys %{ $self->{stats}->{lengths} }) {
  685. if ($self->{stats}->{lines}{$nick} > 100) {
  686. $len{$nick} = $self->{stats}->{lengths}{$nick} / $self->{stats}->{lines}{$nick};
  687. $len{$nick} =~ s/(\.\d)\d+/$1/;
  688. }
  689. }
  690. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  691. my $all_lines = 0;
  692. my $totallength;
  693. foreach my $nick (keys %{ $self->{stats}->{lines} }) {
  694. $all_lines += $self->{stats}->{lines}{$nick};
  695. $totallength += $self->{stats}->{lengths}{$nick};
  696. }
  697. my $totalaverage;
  698. if ($all_lines > 0) {
  699. $totalaverage = $totallength / $all_lines;
  700. $totalaverage =~ s/(\.\d)\d+/$1/;
  701. }
  702. if (@len) {
  703. my %hash = (
  704. nick => $len[0],
  705. letters => $len{$len[0]}
  706. );
  707. my $text = $self->_template_text('long1', %hash);
  708. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br>");
  709. if (@len >= 2) {
  710. %hash = (
  711. avg => $totalaverage
  712. );
  713. $text = $self->_template_text('long2', %hash);
  714. _html("<span class=\"small\">$text</span></td></tr>");
  715. }
  716. }
  717. # The person(s) who wrote the shortest lines
  718. if (@len) {
  719. my %hash = (
  720. nick => $len[$#len],
  721. letters => $len{$len[$#len]}
  722. );
  723. my $text = $self->_template_text('short1', %hash);
  724. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br>");
  725. if (@len >= 2) {
  726. %hash = (
  727. nick => $len[$#len - 1],
  728. letters => $len{$len[$#len - 1]}
  729. );
  730. $text = $self->_template_text('short2', %hash);
  731. _html("<span class=\"small\">$text</span></td></tr>");
  732. }
  733. }
  734. }
  735. sub _mostfoul
  736. {
  737. my $self = shift;
  738. my %spercent;
  739. foreach my $nick (sort keys %{ $self->{stats}->{foul} }) {
  740. if ($self->{stats}->{lines}{$nick} > 15) {
  741. $spercent{$nick} = $self->{stats}->{foul}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  742. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  743. }
  744. }
  745. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  746. if (@foul) {
  747. my %hash = (
  748. nick => $foul[0],
  749. per => $spercent{$foul[0]}
  750. );
  751. my $text = $self->_template_text('foul1', %hash);
  752. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  753. if (@foul >= 2) {
  754. my %hash = (
  755. nick => $foul[1],
  756. per => $spercent{$foul[1]}
  757. );
  758. my $text = $self->_template_text('foul2', %hash);
  759. _html("<br><span class=\"small\">$text</span>");
  760. }
  761. _html("</td></tr>");
  762. } else {
  763. my $text = $self->_template_text('foul3');
  764. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  765. }
  766. }
  767. sub _mostsad
  768. {
  769. my $self = shift;
  770. my %spercent;
  771. foreach my $nick (sort keys %{ $self->{stats}->{frowns} }) {
  772. if ($self->{stats}->{lines}{$nick} > 100) {
  773. $spercent{$nick} = $self->{stats}->{frowns}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  774. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  775. }
  776. }
  777. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  778. if (@sadface) {
  779. my %hash = (
  780. nick => $sadface[0],
  781. per => $spercent{$sadface[0]}
  782. );
  783. my $text = $self->_template_text('sad1', %hash);
  784. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  785. if (@sadface >= 2) {
  786. my %hash = (
  787. nick => $sadface[1],
  788. per => $spercent{$sadface[1]}
  789. );
  790. my $text = $self->_template_text('sad2', %hash);
  791. _html("<br><span class=\"small\">$text</span>");
  792. }
  793. _html("</td></tr>");
  794. } else {
  795. my $text = $self->_template_text('sad3');
  796. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  797. }
  798. }
  799. sub _mostop
  800. {
  801. my $self = shift;
  802. my @ops = sort { $self->{stats}->{gaveops}{$b} <=> $self->{stats}->{gaveops}{$a} }
  803. keys %{ $self->{stats}->{gaveops} };
  804. my @deops = sort { $self->{stats}->{tookops}{$b} <=> $self->{stats}->{tookops}{$a} }
  805. keys %{ $self->{stats}->{tookops} };
  806. if (@ops) {
  807. my %hash = (
  808. nick => $ops[0],
  809. ops => $self->{stats}->{gaveops}{$ops[0]}
  810. );
  811. my $text = $self->_template_text('mostop1', %hash);
  812. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  813. if (@ops >= 2) {
  814. my %hash = (
  815. nick => $ops[1],
  816. ops => $self->{stats}->{gaveops}{$ops[1]}
  817. );
  818. my $text = $self->_template_text('mostop2', %hash);
  819. _html("<br><span class=\"small\">$text</span>");
  820. }
  821. _html("</td></tr>");
  822. } else {
  823. my $text = $self->_template_text('mostop3');
  824. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  825. }
  826. if (@deops) {
  827. my %hash = (
  828. nick => $deops[0],
  829. deops => $self->{stats}->{tookops}{$deops[0]}
  830. );
  831. my $text = $self->_template_text('mostdeop1', %hash);
  832. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  833. if (@deops >= 2) {
  834. my %hash = (
  835. nick => $deops[1],
  836. deops => $self->{stats}->{tookops}{$deops[1]}
  837. );
  838. my $text = $self->_template_text('mostdeop2', %hash);
  839. _html("<br><span class=\"small\">$text</span>");
  840. }
  841. _html("</td></tr>");
  842. } else {
  843. my $text = $self->_template_text('mostdeop3');
  844. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  845. }
  846. }
  847. sub _mostactions
  848. {
  849. # The person who did the most /me's
  850. my $self = shift;
  851. my @actions = sort { $self->{stats}->{actions}{$b} <=> $self->{stats}->{actions}{$a} }
  852. keys %{ $self->{stats}->{actions} };
  853. if (@actions) {
  854. my %hash = (
  855. nick => $actions[0],
  856. actions => $self->{stats}->{actions}{$actions[0]},
  857. line => htmlentities($self->{stats}->{actionlines}{$actions[0]})
  858. );
  859. my $text = $self->_template_text('action1', %hash);
  860. if($self->{cfg}->{show_actionline}) {
  861. my $exttext = $self->_template_text('actiontext', %hash);
  862. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  863. } else {
  864. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  865. }
  866. if (@actions >= 2) {
  867. my %hash = (
  868. nick => $actions[1],
  869. actions => $self->{stats}->{actions}{$actions[1]}
  870. );
  871. my $text = $self->_template_text('action2', %hash);
  872. _html("<br><span class=\"small\">$text</span>");
  873. }
  874. _html("</td></tr>");
  875. } else {
  876. my $text = $self->_template_text('action3');
  877. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  878. }
  879. }
  880. sub _mostsmiles
  881. {
  882. # The person(s) who smiled the most :-)
  883. my $self = shift;
  884. my %spercent;
  885. foreach my $nick (sort keys %{ $self->{stats}->{smiles} }) {
  886. if ($self->{stats}->{lines}{$nick} > 100) {
  887. $spercent{$nick} = $self->{stats}->{smiles}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  888. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  889. }
  890. }
  891. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  892. if (@smiles) {
  893. my %hash = (
  894. nick => $smiles[0],
  895. per => $spercent{$smiles[0]}
  896. );
  897. my $text = $self->_template_text('smiles1', %hash);
  898. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  899. if (@smiles >= 2) {
  900. my %hash = (
  901. nick => $smiles[1],
  902. per => $spercent{$smiles[1]}
  903. );
  904. my $text = $self->_template_text('smiles2', %hash);
  905. _html("<br><span class=\"small\">$text</span>");
  906. }
  907. _html("</td></tr>");
  908. } else {
  909. my $text = $self->_template_text('smiles3');
  910. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text</td></tr>");
  911. }
  912. }
  913. sub _lasttopics
  914. {
  915. my $self = shift;
  916. if ($self->{stats}->{topics}) {
  917. $self->{debug}->("Total number of topics: " . scalar @{ $self->{stats}->{topics} });
  918. my %hash = (
  919. total => scalar @{ $self->{stats}->{topics} }
  920. );
  921. my $ltopic = $#{ $self->{stats}->{topics} };
  922. my $tlimit = 0;
  923. $self->{cfg}->{topichistory} -= 1;
  924. if ($ltopic > $self->{cfg}->{topichistory}) {
  925. $tlimit = $ltopic - $self->{cfg}->{topichistory};
  926. }
  927. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  928. my $topic = htmlentities($self->{stats}->{topics}[$i]{topic});
  929. $topic = _replace_links($self->{stats}->{topics}[$i]{topic});
  930. # Strip off the quotes (')
  931. $topic =~ s/^\'(.*)\'$/$1/;
  932. my $nick = $self->{stats}->{topics}[$i]{nick};
  933. my $hour = $self->{stats}->{topics}[$i]{hour};
  934. my $min = $self->{stats}->{topics}[$i]{min};
  935. $hash{nick} = $nick;
  936. $hash{time} = "$hour:$min";
  937. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\"><i>$topic</i></td>");
  938. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">" . $self->_template_text('bylinetopic', %hash) ."</b></td></tr>");
  939. }
  940. _html("<tr><td align=\"center\" colspan=\"2\" class=\"asmall\">" . $self->_template_text('totaltopic', %hash) . "</td></tr>");
  941. } else {
  942. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">" . $self->_template_text('notopic') ."</td></tr>");
  943. }
  944. }
  945. sub _template_text
  946. {
  947. # This function is for the homemade template system. It receives a name
  948. # of a template and a hash with the fields in the template to update to
  949. # its corresponding value
  950. my $self = shift;
  951. my $template = shift;
  952. my %hash = @_;
  953. my $text;
  954. unless ($text = $self->{tmps}->{$self->{cfg}->{lang}}{$template}) {
  955. # Fall back to English if the language template doesn't exist
  956. if ($text = $self->{tmps}->{EN}{$template}) {
  957. print "Note: No translation in '$self->{cfg}->{lang}' for '$template' - falling back to English..\n"
  958. unless ($self->{cfg}->{silent});
  959. } else {
  960. die("No such template '$template' in language file.\n");
  961. }
  962. }
  963. $hash{channel} = $self->{cfg}->{channel};
  964. foreach my $key (sort keys %hash) {
  965. $text =~ s/\[:$key\]/$hash{$key}/;
  966. $text =~ s/ü/&uuml;/go;
  967. $text =~ s/ö/&ouml;/go;
  968. $text =~ s/ä/&auml;/go;
  969. $text =~ s/ß/&szlig;/go;
  970. $text =~ s/å/&aring;/go;
  971. $text =~ s/æ/&aelig;/go;
  972. $text =~ s/ø/&oslash;/go;
  973. }
  974. if ($text =~ /\[:.*?:.*?:\]/o) {
  975. $text =~ s/\[:(.*?):(.*?):\]/$self->_get_subst($1,$2,\%hash)/geo;
  976. }
  977. return $text;
  978. }
  979. sub _get_subst
  980. {
  981. # This function looks at the user definition and see if there is sex
  982. # defined. If yes, return the appropriate value. If no, just return the
  983. # default he/she value.
  984. my $self = shift;
  985. my ($m,$f,$hash) = @_;
  986. if ($hash->{nick} && $self->{users}->{sex}{$hash->{nick}}) {
  987. if ($self->{users}->{sex}{$hash->{nick}} eq 'm') {
  988. return $m;
  989. } elsif ($self->{users}->{sex}{$hash->{nick}} eq 'f') {
  990. return $f;
  991. }
  992. }
  993. return "$m/$f";
  994. }
  995. sub _mostusedword
  996. {
  997. # Word usage statistics
  998. my $self = shift;
  999. my %usages;
  1000. foreach my $word (keys %{ $self->{stats}->{wordcounts} }) {
  1001. # Skip people's nicks.
  1002. next if exists $self->{stats}->{lines}{$word};
  1003. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1004. }
  1005. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1006. if (@popular) {
  1007. $self->_headline($self->_template_text('mostwordstopic'));
  1008. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1009. _html("<td>&nbsp;</td><td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('word') . "</b></td>");
  1010. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1011. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('lastused') . "</b></td>");
  1012. my $count = 0;
  1013. for(my $i = 0; $count < 10; $i++) {
  1014. last unless $i < $#popular;
  1015. # Skip nicks. It's far more efficient to do this here than when
  1016. # @popular is created.
  1017. next if is_ignored($popular[$i]);
  1018. next if exists $self->{stats}->{lines}{find_alias($popular[$i])};
  1019. my $a = $count + 1;
  1020. my $popular = htmlentities($popular[$i]);
  1021. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1022. my $lastused = htmlentities($self->{stats}->{wordnicks}{$popular[$i]});
  1023. _html("<tr><td bgcolor=\"$self->{cfg}->{rankc}\"><b>$a</b>");
  1024. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$popular</td>");
  1025. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$wordcount</td>");
  1026. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$lastused</td>");
  1027. _html("</tr>");
  1028. $count++;
  1029. }
  1030. _html("</table>");
  1031. }
  1032. }
  1033. sub _mostwordsperline
  1034. {
  1035. # The person who got the most words per line
  1036. my $self = shift;
  1037. my %wpl = ();
  1038. my $numlines = 0;
  1039. my ($avg, $numwords);
  1040. foreach my $n (keys %{ $self->{stats}->{words} }) {
  1041. $wpl{$n} = sprintf("%.2f", $self->{stats}->{words}{$n}/$self->{stats}->{lines}{$n});
  1042. $numlines += $self->{stats}->{lines}{$n};
  1043. $numwords += $self->{stats}->{words}{$n};
  1044. }
  1045. if ($numlines > 0) {
  1046. $avg = sprintf("%.2f", $numwords/$numlines);
  1047. }
  1048. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  1049. if (@wpl) {
  1050. my %hash = (
  1051. nick => $wpl[0],
  1052. wpl => $wpl{$wpl[0]}
  1053. );
  1054. my $text = $self->_template_text('wpl1', %hash);
  1055. _html("<tr><td bgcolor=\"$self->{cfg}->{hicell}\">$text");
  1056. %hash = (
  1057. avg => $avg
  1058. );
  1059. $text = $self->_template_text('wpl2', %hash);
  1060. _html("<br><span class=\"small\">$text</span>");
  1061. _html("</td></tr>");
  1062. }
  1063. }
  1064. sub _mostreferencednicks
  1065. {
  1066. # List showing the most referenced nicks
  1067. my $self = shift;
  1068. my (%usages);
  1069. foreach my $word (sort keys %{ $self->{stats}->{wordcounts} }) {
  1070. next unless exists $self->{stats}->{lines}{$word};
  1071. next if is_ignored($word);
  1072. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1073. }
  1074. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1075. if (@popular) {
  1076. $self->_headline($self->_template_text('referencetopic'));
  1077. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1078. _html("<td>&nbsp;</td><td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('nick') . "</b></td>");
  1079. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1080. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('lastused') . "</b></td>");
  1081. for(my $i = 0; $i < 5; $i++) {
  1082. last unless $i < $#popular;
  1083. my $a = $i + 1;
  1084. my $popular = $popular[$i];
  1085. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1086. my $lastused = $self->{stats}->{wordnicks}{$popular[$i]};
  1087. _html("<tr><td bgcolor=\"$self->{cfg}->{rankc}\"><b>$a</b>");
  1088. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$popular</td>");
  1089. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$wordcount</td>");
  1090. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$lastused</td>");
  1091. _html("</tr>");
  1092. }
  1093. _html("</table>");
  1094. }
  1095. }
  1096. sub _mosturls
  1097. {
  1098. # List showing the most referenced URLs
  1099. my $self = shift;
  1100. my @sorturls = sort { $self->{stats}->{urlcounts}{$b} <=> $self->{stats}->{urlcounts}{$a} }
  1101. keys %{ $self->{stats}->{urlcounts} };
  1102. if (@sorturls) {
  1103. $self->_headline($self->_template_text('urlstopic'));
  1104. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1105. _html("<td>&nbsp;</td><td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('url') . "</b></td>");
  1106. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1107. _html("<td bgcolor=\"$self->{cfg}->{tdtop}\"><b>" . $self->_template_text('lastused') . "</b></td>");
  1108. for(my $i = 0; $i < 5; $i++) {
  1109. last unless $i < $#sorturls;
  1110. my $a = $i + 1;
  1111. my $sorturl = $sorturls[$i];
  1112. my $urlcount = $self->{stats}->{urlcounts}{$sorturls[$i]};
  1113. my $lastused = $self->{stats}->{urlnicks}{$sorturls[$i]};
  1114. if (length($sorturl) > 60) {
  1115. $sorturl = substr($sorturl, 0, 60);
  1116. }
  1117. _html("<tr><td bgcolor=\"$self->{cfg}->{rankc}\"><b>$a</b>");
  1118. _html("<td bgcolor=\"$self->{cfg}->{hicell}\"><a href=\"$sorturls[$i]\">$sorturl</a></td>");
  1119. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$urlcount</td>");
  1120. _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$lastused</td>");
  1121. _html("</tr>");
  1122. }
  1123. _html("</table>");
  1124. }
  1125. }
  1126. sub _legend
  1127. {
  1128. # A legend showing the timebars and their associated time.
  1129. my $self = shift;
  1130. _html("<table align=\"center\" border=\"0\" width=\"520\"><tr>");
  1131. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{pic_h_0}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 0-5</td>");
  1132. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{pic_h_6}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 6-11</td>");
  1133. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{pic_h_12}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 12-17</td>");
  1134. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{pic_h_18}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 18-23</td>");
  1135. _html("</tr></table>\n");
  1136. }
  1137. sub _replace_links
  1138. {
  1139. # Sub to replace urls and e-mail addys to links
  1140. my $str = shift;
  1141. my $nick = shift;
  1142. my ($url, $email);
  1143. if ($nick) {
  1144. if ($url = match_url($str)) {
  1145. $str =~ s/(\Q$url\E)/<a href="$1" target="_blank" title="Open in new window: $1">$nick<\/a>/g;
  1146. }
  1147. if ($email = match_email($str)) {
  1148. $str =~ s/(\Q$email\E)/<a href="mailto:$1" title="Mail to $nick">$nick<\/a>/g;
  1149. }
  1150. } else {
  1151. if ($url = match_url($str)) {
  1152. $str =~ s/(\Q$url\E)/<a href="$1" target="_blank" title="Open in new window: $1">$1<\/a>/g;
  1153. }
  1154. if ($email = match_email($str)) {
  1155. $str =~ s/(\Q$email\E)/<a href="mailto:$1" title="Mail to $1">$1<\/a>/g;
  1156. }
  1157. }
  1158. return $str;
  1159. }
  1160. sub _user_linetimes
  1161. {
  1162. my $self = shift;
  1163. my $nick = shift;
  1164. my $top = shift;
  1165. my $bar = "";
  1166. my $len = ($self->{stats}->{lines}{$nick} / $self->{stats}->{lines}{$top}) * 100;
  1167. my $debuglen = 0;
  1168. for (my $i = 0; $i <= 3; $i++) {
  1169. next if not defined $self->{stats}->{line_times}{$nick}[$i];
  1170. my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * $len);
  1171. $debuglen += $w;
  1172. if ($w) {
  1173. my $pic = 'pic_h_'.(6*$i);
  1174. $bar .= "<img src=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\">";
  1175. }
  1176. }
  1177. $self->{debug}->("Length='$len', Sum='$debuglen'");
  1178. return "$bar&nbsp;$self->{stats}->{lines}{$nick}";
  1179. }
  1180. sub _user_times
  1181. {
  1182. my $self = shift;
  1183. my ($nick) = @_;
  1184. my $bar = "";
  1185. for (my $i = 0; $i <= 3; $i++) {
  1186. next if not defined $self->{stats}->{line_times}{$nick}[$i];
  1187. my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * 40);
  1188. if ($w) {
  1189. my $pic = 'pic_h_'.(6*$i);
  1190. $bar .= "<img src=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\">";
  1191. }
  1192. }
  1193. return $bar;
  1194. }
  1195. 1;
  1196. __END__
  1197. =head1 NAME
  1198. Pisg::HTMLGenerator - class to create a static HTML page out of data parsed
  1199. =head1 DESCRIPTION
  1200. C<Pisg::HTMLGenerator> uses the hash returned by Pisg::Parser::Logfile and turns it into a static HTML page.
  1201. =head1 SYNOPSIS
  1202. use Pisg::HTMLGenerator;
  1203. $generator = new Pisg::HTMLGenerator(
  1204. cfg => $cfg,
  1205. debug => $debug,
  1206. stats => $stats,
  1207. users => $users,
  1208. tmps => $tmps
  1209. );
  1210. =head1 CONSTRUCTOR
  1211. =over 4
  1212. =item new ( [ OPTIONS ] )
  1213. This is the constructor for a new Pisg::HTMLGenerator object. C<OPTIONS> are passed in a hash like fashion using key and value pairs.
  1214. Possible options are:
  1215. B<cfg> - hashref containing configuration variables, created by the Pisg module.
  1216. B<debug> - reference to a sub routine to send the debug information.
  1217. B<stats> - reference to the hash returned by Pisg::Parser::Logfile containing all stats.
  1218. B<users> - reference to a hash containg user information
  1219. B<tmps> - reference to a hash containing the language templates.
  1220. =back
  1221. =head1 AUTHOR
  1222. Morten Brix Pedersen <morten@wtf.dk>
  1223. =head1 COPYRIGHT
  1224. Copyright (C) 2001 Morten Brix Pedersen. All rights resereved.
  1225. This program is free software; you can redistribute it and/or modify it
  1226. under the terms of the GPL, license is included with the distribution of
  1227. this file.
  1228. =cut