HTMLGenerator.pm 52 KB

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