HTMLGenerator.pm 49 KB

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