HTMLGenerator.pm 53 KB

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