HTMLGenerator.pm 49 KB

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