HTMLGenerator.pm 53 KB

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