HTMLGenerator.pm 55 KB

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