HTMLGenerator.pm 50 KB

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