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