HTMLGenerator.pm 52 KB

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