HTMLGenerator.pm 53 KB

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