HTMLGenerator.pm 47 KB

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