HTMLGenerator.pm 52 KB

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