HTMLGenerator.pm 53 KB

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