HTMLGenerator.pm 52 KB

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