HTMLGenerator.pm 52 KB

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