HTMLGenerator.pm 54 KB

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