HTMLGenerator.pm 55 KB

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