4
0

HTMLGenerator.pm 48 KB

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