HTMLGenerator.pm 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115
  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. topactive => {},
  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. $self->_topactive();
  31. my $fname = $self->{cfg}->{outputfile};
  32. $fname =~ s/\%t/$self->{cfg}->{outputtag}/g;
  33. print "Now generating HTML($fname)...\n"
  34. unless ($self->{cfg}->{silent});
  35. open (OUTPUT, "> $fname") or
  36. die("$0: Unable to open outputfile($fname): $!\n");
  37. if ($self->{cfg}->{showtime}) {
  38. $self->{cfg}->{tablewidth} += 40;
  39. }
  40. if ($self->{cfg}->{showlinetime}) {
  41. $self->{cfg}->{tablewidth} += 100;
  42. }
  43. if ($self->{cfg}->{showwordtime}) {
  44. $self->{cfg}->{tablewidth} += 100;
  45. }
  46. if ($self->{cfg}->{showwords}) {
  47. $self->{cfg}->{tablewidth} += 40;
  48. }
  49. if ($self->{cfg}->{showwpl}) {
  50. $self->{cfg}->{tablewidth} += 40;
  51. }
  52. if ($self->{cfg}->{showcpl}) {
  53. $self->{cfg}->{tablewidth} += 40;
  54. }
  55. $self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
  56. $self->_htmlheader();
  57. $self->_pageheader()
  58. if ($self->{cfg}->{pagehead} ne 'none');
  59. if ($self->{cfg}->{showactivetimes}) {
  60. $self->_activetimes();
  61. }
  62. $self->_activenicks();
  63. if ($self->{cfg}->{showmostactivebyhour}) {
  64. $self->_mostactivebyhour();
  65. }
  66. if ($self->{cfg}->{showbignumbers}) {
  67. $self->_headline($self->_template_text('bignumtopic'));
  68. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  69. $self->_questions();
  70. $self->_shoutpeople();
  71. $self->_capspeople();
  72. $self->_violent();
  73. $self->_mostsmiles();
  74. $self->_mostsad();
  75. $self->_linelengths();
  76. $self->_mostwords();
  77. $self->_mostwordsperline();
  78. _html("</table>"); # Needed for sections
  79. }
  80. if ($self->{cfg}->{showmostnicks}) {
  81. $self->_mostnicks();
  82. }
  83. if ($self->{cfg}->{showmuw}) {
  84. $self->_mostusedword();
  85. }
  86. if ($self->{cfg}->{showmrn}) {
  87. $self->_mostreferencednicks();
  88. }
  89. if ($self->{cfg}->{showmru}) {
  90. $self->_mosturls();
  91. }
  92. if ($self->{cfg}->{showbignumbers}) {
  93. $self->_headline($self->_template_text('othernumtopic'));
  94. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  95. $self->_gotkicks();
  96. $self->_mostkicks();
  97. $self->_mostop() if $self->{cfg}->{showops};
  98. $self->_mosthalfop() if $self->{cfg}->{showhalfops};
  99. $self->_mostvoice() if $self->{cfg}->{showvoices};
  100. $self->_mostactions();
  101. $self->_mostmonologues();
  102. $self->_mostjoins();
  103. $self->_mostfoul();
  104. _html("</table>"); # Needed for sections
  105. }
  106. if ($self->{cfg}->{showtopics}) {
  107. $self->_headline($self->_template_text('latesttopic'));
  108. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  109. $self->_lasttopics();
  110. _html("</table>"); # Needed for sections
  111. }
  112. my %hash = ( lines => $self->{stats}->{parsedlines} );
  113. _html($self->_template_text('totallines', %hash) . "<br /><br />");
  114. $self->_pagefooter()
  115. if ($self->{cfg}->{pagefoot} ne 'none');
  116. $self->_htmlfooter();
  117. close(OUTPUT);
  118. }
  119. sub _htmlheader
  120. {
  121. my $self = shift;
  122. my %hash = (
  123. network => $self->{cfg}->{network},
  124. maintainer => $self->{cfg}->{maintainer},
  125. days => $self->{stats}->{days},
  126. nicks => scalar keys %{ $self->{stats}->{lines} }
  127. );
  128. my $css_file = $self->{cfg}->{cssdir} . $self->{cfg}->{colorscheme} . ".css";
  129. # Get the chosen CSS file
  130. open(FILE, $css_file) or open (FILE, $self->{cfg}->{search_path} . "/$css_file") or die("$0: Unable to open stylesheet($css_file): $!\n");
  131. my @CSS = <FILE>;
  132. my $title = $self->_template_text('pagetitle1', %hash);
  133. print OUTPUT <<HTML;
  134. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  135. <html>
  136. <head>
  137. <meta http-equiv="Content-Type" content="text/html; charset=$self->{cfg}->{charset}" />
  138. <title>$title</title>
  139. <style type="text/css">
  140. @CSS
  141. </style></head>
  142. <body>
  143. <div align="center">
  144. HTML
  145. _html("<span class=\"title\">$title</span><br />");
  146. _html("<br />");
  147. _html($self->_template_text('pagetitle2', %hash) . " " . $self->get_time());
  148. _html("<br />" . $self->_template_text('pagetitle3', %hash) . "<br /><br />");
  149. }
  150. sub get_time
  151. {
  152. my $self = shift;
  153. my ($tday, %hash);
  154. my $month = $self->_template_text('month', %hash);
  155. my $day = $self->_template_text('day', %hash);
  156. my @month = split(" ", $month);
  157. my @day = split(" ", $day);
  158. # Get the Date from the users computer
  159. my $timezone = $self->{cfg}->{timeoffset} * 3600;
  160. my ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+$timezone);
  161. $year += 1900; # Y2K Patch
  162. $min =~ s/^(.)$/0$1/; # Fixes the display of mins/secs below
  163. $sec =~ s/^(.)$/0$1/; # it displays 03 instead of 3
  164. if ($hour > '23') { # Checks to see if it Midnight
  165. $hour = 12; # Makes it display the hour 12
  166. $tday = "AM"; # Display AM
  167. } elsif($hour > '12') { # Get rid of the Military time and
  168. $hour -= 12; # put it into normal time
  169. $tday = "PM"; # If past Noon and before Midnight set
  170. } else {
  171. $tday = "AM"; # If it's past Midnight and before Noon
  172. } # set the time as AM
  173. # Use 24 hours pr. day
  174. if ($tday eq "PM" && $hour < '12') {
  175. $hour += 12;
  176. }
  177. return "$day[$wday] $mday $month[$mon] $year - $hour:$min:$sec";
  178. }
  179. sub _htmlfooter
  180. {
  181. my $self = shift;
  182. my %hash;
  183. my $pisg_hp = $self->_template_text('pisghomepage');
  184. $hash{pisg_url} = "<a href=\"http://pisg.sourceforge.net/\" title=\"$pisg_hp\" class=\"background\">pisg</a>";
  185. my $author_hp = $self->_template_text('authorhomepage');
  186. $hash{author_url} = "<a href=\"http://mbrix.dk/\" title=\"$author_hp\" class=\"background\">Morten Brix Pedersen</a>";
  187. $hash{version} = $self->{cfg}->{version};
  188. my $hours = $self->_template_text('hours');
  189. my $mins = $self->_template_text('minutes');
  190. my $secs = $self->_template_text('seconds');
  191. my $and = $self->_template_text('and');
  192. my $h = $self->{stats}->{processtime}{hours};
  193. my $m = $self->{stats}->{processtime}{mins};
  194. my $s = $self->{stats}->{processtime}{secs};
  195. $hash{time} = "$h $hours $m $mins $and $s $secs";
  196. my $stats_gen = $self->_template_text('stats_gen_by', %hash);
  197. my $author_text = $self->_template_text('author', %hash);
  198. my $stats_text = $self->_template_text('stats_gen_in', %hash);
  199. print OUTPUT <<HTML;
  200. <span class="small">
  201. $stats_gen<br />
  202. $author_text<br />
  203. $stats_text
  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 class="headlinebg">
  219. <table width="100%" cellpadding="2" cellspacing="0" border="0">
  220. <tr>
  221. <td 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. open(PAGEHEAD, $self->{cfg}->{pagehead}) or die("$0: Unable to open $self->{cfg}->{pagehead} for reading: $!\n");
  233. while (<PAGEHEAD>) {
  234. _html($_);
  235. }
  236. close(PAGEHEAD);
  237. }
  238. sub _pagefooter
  239. {
  240. my $self = shift;
  241. open(PAGEFOOT, $self->{cfg}->{pagefoot}) or die("$0: Unable to open $self->{cfg}->{pagefoot} for reading: $!\n");
  242. while (<PAGEFOOT>) {
  243. _html($_);
  244. }
  245. close(PAGEFOOT);
  246. }
  247. sub _activetimes
  248. {
  249. # The most actives times on the channel
  250. my $self = shift;
  251. my (%output, $class);
  252. $self->_headline($self->_template_text('activetimestopic'));
  253. my @toptime = sort { $self->{stats}->{times}{$b} <=> $self->{stats}->{times}{$a} } keys %{ $self->{stats}->{times} };
  254. my $highest_value = $self->{stats}->{times}{$toptime[0]};
  255. my @now = localtime($self->{cfg}->{timestamp});
  256. my $image;
  257. for my $hour (sort keys %{ $self->{stats}->{times} }) {
  258. my $size = ($self->{stats}->{times}{$hour} / $highest_value) * 100;
  259. my $percent = ($self->{stats}->{times}{$hour} / $self->{stats}->{parsedlines}) * 100;
  260. $percent =~ s/(\.\d)\d+/$1/;
  261. if ($size < 1 && $size != 0) {
  262. # Opera doesn't understand '0.xxxx' in the height="xx" attr,
  263. # so we simply round up to 1.0 here.
  264. $size = 1.0;
  265. }
  266. $image = "pic_v_".(int($hour/6)*6);
  267. $image = $self->{cfg}->{$image};
  268. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br /><img src=\"$self->{cfg}->{piclocation}/$image\" width=\"15\" height=\"$size\" alt=\"$percent\" /></td>\n";
  269. }
  270. _html("<table border=\"0\"><tr>\n");
  271. for ($b = 0; $b < 24; $b++) {
  272. $a = sprintf("%02d", $b);
  273. if (!defined($output{$a}) || $output{$a} eq "") {
  274. _html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  275. } else {
  276. _html($output{$a});
  277. }
  278. }
  279. _html("</tr><tr>");
  280. # Remove leading zero
  281. $toptime[0] =~ s/0(\d)/$1/;
  282. for ($b = 0; $b < 24; $b++) {
  283. if ($toptime[0] == $b) {
  284. # Highlight the top time
  285. $class = 'hirankc10center';
  286. } else {
  287. $class = 'rankc10center';
  288. }
  289. _html("<td class=\"$class\" align=\"center\">$b</td>");
  290. }
  291. _html("</tr></table>");
  292. if($self->{cfg}->{showlegend} == 1) {
  293. $self->_legend();
  294. }
  295. }
  296. sub _activenicks
  297. {
  298. # The most active nicks (those who wrote most lines)
  299. my $self = shift;
  300. $self->_headline($self->_template_text('activenickstopic'));
  301. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  302. _html("<td>&nbsp;</td>"
  303. . "<td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>"
  304. . "<td class=\"tdtop\"><b>" . $self->_template_text('numberlines') . "</b></td>"
  305. . ($self->{cfg}->{showtime} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_time')."</b></td>" : "")
  306. . ($self->{cfg}->{showwords} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_words')."</b></td>" : "")
  307. . ($self->{cfg}->{showwpl} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_wpl')."</b></td>" : "")
  308. . ($self->{cfg}->{showcpl} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_cpl')."</b></td>" : "")
  309. . ($self->{cfg}->{showlastseen} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_lastseen')."</b></td>" : "")
  310. . ($self->{cfg}->{showrandquote} ? "<td class=\"tdtop\"><b>".$self->_template_text('randquote')."</b></td>" : "")
  311. );
  312. my @active;
  313. my $nicks;
  314. if ($self->{cfg}->{sortbywords}) {
  315. @active = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} } keys %{ $self->{stats}->{words} };
  316. $nicks = scalar keys %{ $self->{stats}->{words} };
  317. } else {
  318. @active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} } keys %{ $self->{stats}->{lines} };
  319. $nicks = scalar keys %{ $self->{stats}->{lines} };
  320. }
  321. if ($self->{cfg}->{activenicks} > $nicks) { $self->{cfg}->{activenicks} = $nicks; }
  322. my $have_userpics;
  323. for (my $c = 0; $c < $self->{cfg}->{activenicks}; $c++) {
  324. my $nick = $active[$c];
  325. if ($self->{users}->{userpics}{$nick} && $self->{cfg}->{userpics} !~ /n/i) {
  326. $have_userpics = 1;
  327. _html("<td class=\"tdtop\"><b>" . $self->_template_text('userpic') ."</b></td>");
  328. last;
  329. }
  330. }
  331. _html("</tr>");
  332. for (my $i = 0; $i < $self->{cfg}->{activenicks}; $i++) {
  333. my $c = $i + 1;
  334. my $nick = $active[$i];
  335. my $visiblenick = $active[$i];
  336. my $randomline;
  337. if (not defined $self->{stats}->{sayings}{$nick}) {
  338. if ($self->{stats}->{actions}{$nick}) {
  339. $randomline = $self->{stats}->{actionlines}{$nick};
  340. } else {
  341. $randomline = "";
  342. }
  343. } else {
  344. $randomline = $self->{stats}->{sayings}{$nick};
  345. }
  346. if ($randomline) {
  347. $randomline = $self->_format_line($randomline);
  348. }
  349. # Add a link to the nick if there is any
  350. if ($self->{users}->{userlinks}{$nick}) {
  351. $visiblenick = $self->_replace_links($self->{users}->{userlinks}{$nick}, $nick);
  352. }
  353. my $color = $self->generate_colors($c);
  354. my $class = 'rankc';
  355. if ($c == 1) {
  356. $class = 'hirankc';
  357. }
  358. my $lastseen;
  359. if ($self->{cfg}->{showlastseen}) {
  360. $lastseen = $self->{stats}->{days} - $self->{stats}->{lastvisited}{$nick};
  361. if ($lastseen == 0) {
  362. $lastseen = $self->_template_text('today');
  363. } elsif ($lastseen == 1) {
  364. $lastseen = "$lastseen " .$self->_template_text('lastseen1');
  365. } else {
  366. $lastseen = "$lastseen " .$self->_template_text('lastseen2');
  367. }
  368. }
  369. _html("<tr><td class=\"$class\" align=\"left\">$c</td>");
  370. my $line = $self->{stats}->{lines}{$nick};
  371. my $w = $self->{stats}->{words}{$nick} ? $self->{stats}->{words}{$nick} : 0;
  372. my $ch = $self->{stats}->{lengths}{$nick};
  373. my $sex = $self->{users}->{sex}{$nick};
  374. _html("<td style=\"background-color: $color\""
  375. . ($sex ? ($sex eq 'm' ? " class=\"male\">"
  376. : ($sex eq 'f' ? " class=\"female\">" : " class=\"bot\">")) : ">")
  377. ."$visiblenick</td>"
  378. . ($self->{cfg}->{showlinetime} ?
  379. "<td style=\"background-color: $color\" nowrap=\"nowrap\">".$self->_user_linetimes($nick,$active[0])."</td>"
  380. : "<td style=\"background-color: $color\">$line</td>")
  381. . ($self->{cfg}->{showtime} ?
  382. "<td style=\"background-color: $color\">".$self->_user_times($nick)."</td>"
  383. : "")
  384. . ($self->{cfg}->{showwords} ?
  385. ($self->{cfg}->{showwordtime} ?
  386. "<td style=\"background-color: $color\" nowrap=\"nowrap\">".$self->_user_wordtimes($nick,$active[0])."</td>"
  387. : "<td style=\"background-color: $color\">$w</td>")
  388. : "")
  389. . ($self->{cfg}->{showwpl} ?
  390. "<td style=\"background-color: $color\">".sprintf("%.1f",$w/$line)."</td>"
  391. : "")
  392. . ($self->{cfg}->{showcpl} ?
  393. "<td style=\"background-color: $color\">".sprintf("%.1f",$ch/$line)."</td>"
  394. : "")
  395. . ($self->{cfg}->{showlastseen} ?
  396. "<td style=\"background-color: $color\">$lastseen</td>"
  397. : "")
  398. . ($self->{cfg}->{showrandquote} ?
  399. "<td style=\"background-color: $color\">\"$randomline\"</td>"
  400. : "")
  401. );
  402. my $height = $self->{cfg}->{picheight};
  403. my $width = $self->{cfg}->{picwidth};
  404. if ($width ne '') {
  405. $width = "width=\"$width\"";
  406. }
  407. if ($height ne '') {
  408. $height = "height=\"$height\"";
  409. }
  410. if ($self->{users}->{userpics}{$nick} && $self->{cfg}->{userpics} !~ /n/i) {
  411. _html("<td style=\"background-color: $color\" align=\"center\" valign=\"middle\">");
  412. if (defined $self->{users}->{biguserpics}{$nick}) {
  413. if ($self->{users}->{biguserpics}{$nick} =~ /^http:\/\//i) {
  414. _html("<a href=\"$self->{users}->{biguserpics}{$nick}\">");
  415. } else {
  416. _html("<a href=\"$self->{cfg}->{imagepath}$self->{users}->{biguserpics}{$nick}\">");
  417. }
  418. }
  419. if ($self->{users}->{userpics}{$nick} =~ /^http:\/\//i) {
  420. _html("<img src=\"$self->{users}->{userpics}{$nick}\" $width $height alt=\"$nick\" />");
  421. } else {
  422. _html("<img src=\"$self->{cfg}->{imagepath}$self->{users}->{userpics}{$nick}\" $width $height alt=\"$nick\" />");
  423. }
  424. if (defined $self->{users}->{biguserpics}{$nick}) {
  425. _html("</a>");
  426. }
  427. _html("</td>");
  428. } elsif ($self->{cfg}->{defaultpic} ne '' && $self->{cfg}->{userpics} !~ /n/i) {
  429. if ($self->{cfg}->{defaultpic} =~ /^http:\/\//i) {
  430. _html("<td style=\"background-color: $color\" align=\"center\" valign=\"middle\"><img src=\"$self->{cfg}->{defaultpic}\" $width $height alt=\"\" /></td>");
  431. } else {
  432. _html("<td style=\"background-color: $color\" align=\"center\" valign=\"middle\"><img src=\"$self->{cfg}->{imagepath}$self->{cfg}->{defaultpic}\" $width $height alt=\"\" /></td>");
  433. }
  434. }
  435. _html("</tr>");
  436. }
  437. _html("</table><br />");
  438. # Almost as active nicks ('These didn't make it to the top..')
  439. my $toshow = $self->{cfg}->{activenicks2} - $self->{cfg}->{activenicks};
  440. my $remain = $self->{cfg}->{activenicks} + $toshow;
  441. unless ($toshow > $nicks) {
  442. $remain = $self->{cfg}->{activenicks} + $self->{cfg}->{activenicks2};
  443. if ($remain > $nicks) {
  444. $remain = $nicks;
  445. }
  446. if ($self->{cfg}->{activenicks} < $remain) {
  447. _html("<br /><b><i>" . $self->_template_text('nottop') . "</i></b><table><tr>");
  448. for (my $i = $self->{cfg}->{activenicks}; $i < $remain; $i++) {
  449. unless ($i % 5) { if ($i != $self->{cfg}->{activenicks}) { _html("</tr><tr>"); } }
  450. my $items;
  451. if ($self->{cfg}->{sortbywords}) {
  452. $items = $self->{stats}->{words}{$active[$i]};
  453. } else {
  454. $items = $self->{stats}->{lines}{$active[$i]};
  455. }
  456. my $sex = $self->{users}->{sex}{$active[$i]};
  457. _html("<td class=\"rankc10\">"
  458. . ($sex ? ($sex eq 'm' ? "<span class=\"male\">"
  459. : ($sex eq 'f' ? "<span class=\"female\">" : "<span class=\"bot\">")) : "")
  460. ."$active[$i] ($items)"
  461. . ($sex ? "</span>" : "")
  462. ."</td>");
  463. }
  464. _html("</tr></table>");
  465. }
  466. }
  467. my %hash;
  468. $hash{totalnicks} = $nicks - $remain;
  469. if ($hash{totalnicks} > 0) {
  470. _html("<br /><b>" . $self->_template_text('totalnicks', %hash) . "</b><br />");
  471. }
  472. }
  473. sub generate_colors
  474. {
  475. my $self = shift;
  476. my $c = shift;
  477. my $h = $self->{cfg}->{hicell};
  478. $h =~ s/^#//;
  479. $h = hex $h;
  480. my $h2 = $self->{cfg}->{hicell2};
  481. $h2 =~ s/^#//;
  482. $h2 = hex $h2;
  483. my $f_b = $h & 0xff;
  484. my $f_g = ($h & 0xff00) >> 8;
  485. my $f_r = ($h & 0xff0000) >> 16;
  486. my $t_b = $h2 & 0xff;
  487. my $t_g = ($h2 & 0xff00) >> 8;
  488. my $t_r = ($h2 & 0xff0000) >> 16;
  489. my $blue = sprintf "%0.2x", abs int(((($t_b - $f_b) / $self->{cfg}->{activenicks}) * +$c) + $f_b);
  490. my $green = sprintf "%0.2x", abs int(((($t_g - $f_g) / $self->{cfg}->{activenicks}) * +$c) + $f_g);
  491. my $red = sprintf "%0.2x", abs int(((($t_r - $f_r) / $self->{cfg}->{activenicks}) * +$c) + $f_r);
  492. return "#$red$green$blue";
  493. }
  494. sub _html
  495. {
  496. my $html = shift;
  497. print OUTPUT "$html\n";
  498. }
  499. sub _questions
  500. {
  501. # Persons who asked the most questions
  502. my $self = shift;
  503. my %qpercent;
  504. foreach my $nick (sort keys %{ $self->{stats}->{questions} }) {
  505. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  506. if ($self->{stats}->{lines}{$nick} > 100) {
  507. $qpercent{$nick} = ($self->{stats}->{questions}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  508. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  509. }
  510. }
  511. }
  512. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  513. if (@question) {
  514. my %hash = (
  515. nick => $question[0],
  516. per => $qpercent{$question[0]}
  517. );
  518. my $text = $self->_template_text('question1', %hash);
  519. _html("<tr><td class=\"hicell\">$text");
  520. if (@question >= 2) {
  521. my %hash = (
  522. nick => $question[1],
  523. per => $qpercent{$question[1]}
  524. );
  525. my $text = $self->_template_text('question2', %hash);
  526. _html("<br /><span class=\"small\">$text</span>");
  527. }
  528. _html("</td></tr>");
  529. } else {
  530. _html("<tr><td class=\"hicell\">" . $self->_template_text('question3') . "</td></tr>");
  531. }
  532. }
  533. sub _shoutpeople
  534. {
  535. # The ones who speak with exclamation marks!
  536. my $self = shift;
  537. my %spercent;
  538. foreach my $nick (sort keys %{ $self->{stats}->{shouts} }) {
  539. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  540. if ($self->{stats}->{lines}{$nick} > 100) {
  541. $spercent{$nick} = ($self->{stats}->{shouts}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  542. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  543. }
  544. }
  545. }
  546. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  547. if (@shout) {
  548. my %hash = (
  549. nick => $shout[0],
  550. per => $spercent{$shout[0]}
  551. );
  552. my $text = $self->_template_text('shout1', %hash);
  553. _html("<tr><td class=\"hicell\">$text");
  554. if (@shout >= 2) {
  555. my %hash = (
  556. nick => $shout[1],
  557. per => $spercent{$shout[1]}
  558. );
  559. my $text = $self->_template_text('shout2', %hash);
  560. _html("<br /><span class=\"small\">$text</span>");
  561. }
  562. _html("</td></tr>");
  563. } else {
  564. my $text = $self->_template_text('shout3');
  565. _html("<tr><td class=\"hicell\">$text</td></tr>");
  566. }
  567. }
  568. sub _capspeople
  569. {
  570. # The ones who speak ALL CAPS.
  571. my $self = shift;
  572. my %cpercent;
  573. foreach my $nick (sort keys %{ $self->{stats}->{allcaps} }) {
  574. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  575. if ($self->{stats}->{lines}{$nick} > 100) {
  576. $cpercent{$nick} = $self->{stats}->{allcaps}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  577. $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
  578. }
  579. }
  580. }
  581. my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent;
  582. if (@caps) {
  583. my %hash = (
  584. nick => $caps[0],
  585. per => $cpercent{$caps[0]},
  586. line => $self->_format_line($self->{stats}->{allcaplines}{$caps[0]})
  587. );
  588. my $text = $self->_template_text('allcaps1', %hash);
  589. if($self->{cfg}->{showshoutline}) {
  590. my $exttext = $self->_template_text('allcapstext', %hash);
  591. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  592. } else {
  593. _html("<tr><td class=\"hicell\">$text");
  594. }
  595. if (@caps >= 2) {
  596. my %hash = (
  597. nick => $caps[1],
  598. per => $cpercent{$caps[1]}
  599. );
  600. my $text = $self->_template_text('allcaps2', %hash);
  601. _html("<br /><span class=\"small\">$text</span>");
  602. }
  603. _html("</td></tr>");
  604. } else {
  605. my $text = $self->_template_text('allcaps3');
  606. _html("<tr><td class=\"hicell\">$text</td></tr>");
  607. }
  608. }
  609. sub _violent
  610. {
  611. # They attacked others (words defined by $self->{cfg}->{violent})
  612. my $self = shift;
  613. my @aggressors = sort { $self->{stats}->{violence}{$b} <=> $self->{stats}->{violence}{$a} }
  614. keys %{ $self->{stats}->{violence} };
  615. @aggressors = $self->_istoponly(@aggressors);
  616. if(@aggressors) {
  617. my %hash = (
  618. nick => $aggressors[0],
  619. attacks => $self->{stats}->{violence}{$aggressors[0]},
  620. line => $self->_format_line($self->{stats}->{violencelines}{$aggressors[0]})
  621. );
  622. my $text = $self->_template_text('violent1', %hash);
  623. if($self->{cfg}->{showviolentlines}) {
  624. my $exttext = $self->_template_text('violenttext', %hash);
  625. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  626. } else {
  627. _html("<tr><td class=\"hicell\">$text");
  628. }
  629. if (@aggressors >= 2) {
  630. my %hash = (
  631. nick => $aggressors[1],
  632. attacks => $self->{stats}->{violence}{$aggressors[1]}
  633. );
  634. my $text = $self->_template_text('violent2', %hash);
  635. _html("<br /><span class=\"small\">$text</span>");
  636. }
  637. _html("</td></tr>");
  638. } else {
  639. my $text = $self->_template_text('violent3');
  640. _html("<tr><td class=\"hicell\">$text</td></tr>");
  641. }
  642. # They got attacked
  643. my @victims = sort { $self->{stats}->{attacked}{$b} <=> $self->{stats}->{attacked}{$a} }
  644. keys %{ $self->{stats}->{attacked} };
  645. @victims = $self->_istoponly(@victims);
  646. if(@victims) {
  647. my %hash = (
  648. nick => $victims[0],
  649. attacks => $self->{stats}->{attacked}{$victims[0]},
  650. line => $self->_format_line($self->{stats}->{attackedlines}{$victims[0]})
  651. );
  652. my $text = $self->_template_text('attacked1', %hash);
  653. if($self->{cfg}->{showviolentlines}) {
  654. my $exttext = $self->_template_text('attackedtext', %hash);
  655. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  656. } else {
  657. _html("<tr><td class=\"hicell\">$text");
  658. }
  659. if (@victims >= 2) {
  660. my %hash = (
  661. nick => $victims[1],
  662. attacks => $self->{stats}->{attacked}{$victims[1]}
  663. );
  664. my $text = $self->_template_text('attacked2', %hash);
  665. _html("<br /><span class=\"small\">$text</span>");
  666. }
  667. _html("</td></tr>");
  668. }
  669. }
  670. sub _gotkicks
  671. {
  672. # The persons who got kicked the most
  673. my $self = shift;
  674. my @gotkick = sort { $self->{stats}->{gotkicked}{$b} <=> $self->{stats}->{gotkicked}{$a} }
  675. keys %{ $self->{stats}->{gotkicked} };
  676. @gotkick = $self->_istoponly(@gotkick);
  677. if (@gotkick) {
  678. my %hash = (
  679. nick => $gotkick[0],
  680. kicks => $self->{stats}->{gotkicked}{$gotkick[0]},
  681. line => $self->_format_line($self->{stats}->{kicklines}{$gotkick[0]})
  682. );
  683. my $text = $self->_template_text('gotkick1', %hash);
  684. if ($self->{cfg}->{showkickline}) {
  685. my $exttext = $self->_template_text('kicktext', %hash);
  686. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  687. } else {
  688. _html("<tr><td class=\"hicell\">$text");
  689. }
  690. if (@gotkick >= 2) {
  691. my %hash = (
  692. nick => $gotkick[1],
  693. kicks => $self->{stats}->{gotkicked}{$gotkick[1]}
  694. );
  695. my $text = $self->_template_text('gotkick2', %hash);
  696. _html("<br /><span class=\"small\">$text</span>");
  697. }
  698. _html("</td></tr>");
  699. }
  700. }
  701. sub _mostjoins
  702. {
  703. my $self = shift;
  704. my @joins = sort { $self->{stats}->{joins}{$b} <=> $self->{stats}->{joins}{$a} }
  705. keys %{ $self->{stats}->{joins} };
  706. @joins = $self->_istoponly(@joins);
  707. if (@joins) {
  708. my %hash = (
  709. nick => $joins[0],
  710. joins => $self->{stats}->{joins}{$joins[0]}
  711. );
  712. my $text = $self->_template_text('joins', %hash);
  713. _html("<tr><td class=\"hicell\">$text</td></tr>");
  714. }
  715. }
  716. sub _mostwords
  717. {
  718. # The person who got words the most
  719. my $self = shift;
  720. my @words = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  721. keys %{ $self->{stats}->{words} };
  722. @words = $self->_istoponly(@words);
  723. if (@words) {
  724. my %hash = (
  725. nick => $words[0],
  726. words => $self->{stats}->{words}{$words[0]}
  727. );
  728. my $text = $self->_template_text('words1', %hash);
  729. _html("<tr><td class=\"hicell\">$text");
  730. if (@words >= 2) {
  731. my %hash = (
  732. oldnick => $words[0],
  733. nick => $words[1],
  734. words => $self->{stats}->{words}{$words[1]}
  735. );
  736. my $text = $self->_template_text('words2', %hash);
  737. _html("<br /><span class=\"small\">$text</span>");
  738. }
  739. _html("</td></tr>");
  740. } else {
  741. my $text = $self->_template_text('kick3');
  742. _html("<tr><td class=\"hicell\">$text</td></tr>");
  743. }
  744. }
  745. sub _mostkicks
  746. {
  747. # The person who kicked the most
  748. my $self = shift;
  749. my @kicked = sort { $self->{stats}->{kicked}{$b} <=> $self->{stats}->{kicked}{$a} }
  750. keys %{ $self->{stats}->{kicked} };
  751. @kicked = $self->_istoponly(@kicked);
  752. if (@kicked) {
  753. my %hash = (
  754. nick => $kicked[0],
  755. kicked => $self->{stats}->{kicked}{$kicked[0]}
  756. );
  757. my $text = $self->_template_text('kick1', %hash);
  758. _html("<tr><td class=\"hicell\">$text");
  759. if (@kicked >= 2) {
  760. my %hash = (
  761. oldnick => $kicked[0],
  762. nick => $kicked[1],
  763. kicked => $self->{stats}->{kicked}{$kicked[1]}
  764. );
  765. my $text = $self->_template_text('kick2', %hash);
  766. _html("<br /><span class=\"small\">$text</span>");
  767. }
  768. _html("</td></tr>");
  769. } else {
  770. my $text = $self->_template_text('kick3');
  771. _html("<tr><td class=\"hicell\">$text</td></tr>");
  772. }
  773. }
  774. sub _mostmonologues
  775. {
  776. # The person who had the most monologues (speaking to himself)
  777. my $self = shift;
  778. my @monologue = sort { $self->{stats}->{monologues}{$b} <=> $self->{stats}->{monologues}{$a} }
  779. keys %{ $self->{stats}->{monologues} };
  780. @monologue = $self->_istoponly(@monologue);
  781. if (@monologue) {
  782. my %hash = (
  783. nick => $monologue[0],
  784. monos => $self->{stats}->{monologues}{$monologue[0]}
  785. );
  786. my $text = $self->_template_text('mono1', %hash);
  787. _html("<tr><td class=\"hicell\">$text");
  788. if (@monologue >= 2) {
  789. my %hash = (
  790. nick => $monologue[1],
  791. monos => $self->{stats}->{monologues}{$monologue[1]}
  792. );
  793. my $text = $self->_template_text('mono2', %hash);
  794. _html("<br /><span class=\"small\">$text</span>");
  795. }
  796. _html("</td></tr>");
  797. }
  798. }
  799. sub _linelengths
  800. {
  801. # The person(s) who wrote the longest lines
  802. my $self = shift;
  803. my %len;
  804. foreach my $nick (sort keys %{ $self->{stats}->{lengths} }) {
  805. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  806. if ($self->{stats}->{lines}{$nick} > 100) {
  807. $len{$nick} = $self->{stats}->{lengths}{$nick} / $self->{stats}->{lines}{$nick};
  808. $len{$nick} =~ s/(\.\d)\d+/$1/;
  809. }
  810. }
  811. }
  812. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  813. my $all_lines = 0;
  814. my $totallength;
  815. foreach my $nick (keys %{ $self->{stats}->{lines} }) {
  816. $all_lines += $self->{stats}->{lines}{$nick};
  817. $totallength += $self->{stats}->{lengths}{$nick};
  818. }
  819. my $totalaverage;
  820. if ($all_lines > 0) {
  821. $totalaverage = $totallength / $all_lines;
  822. $totalaverage =~ s/(\.\d)\d+/$1/;
  823. }
  824. if (@len) {
  825. my %hash = (
  826. nick => $len[0],
  827. letters => $len{$len[0]}
  828. );
  829. my $text = $self->_template_text('long1', %hash);
  830. _html("<tr><td class=\"hicell\">$text<br />");
  831. if (@len >= 2) {
  832. %hash = (
  833. avg => $totalaverage
  834. );
  835. $text = $self->_template_text('long2', %hash);
  836. _html("<span class=\"small\">$text</span></td></tr>");
  837. } else {
  838. _html("</td></tr>");
  839. }
  840. }
  841. # The person(s) who wrote the shortest lines
  842. if (@len) {
  843. my %hash = (
  844. nick => $len[$#len],
  845. letters => $len{$len[$#len]}
  846. );
  847. my $text = $self->_template_text('short1', %hash);
  848. _html("<tr><td class=\"hicell\">$text<br />");
  849. if (@len >= 2) {
  850. %hash = (
  851. nick => $len[$#len - 1],
  852. letters => $len{$len[$#len - 1]}
  853. );
  854. $text = $self->_template_text('short2', %hash);
  855. _html("<span class=\"small\">$text</span></td></tr>");
  856. } else {
  857. _html("</td></tr>");
  858. }
  859. }
  860. }
  861. sub _mostfoul
  862. {
  863. my $self = shift;
  864. my %spercent;
  865. foreach my $nick (sort keys %{ $self->{stats}->{foul} }) {
  866. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  867. if ($self->{stats}->{lines}{$nick} > 15) {
  868. $spercent{$nick} = $self->{stats}->{foul}{$nick} / $self->{stats}->{words}{$nick} * 100;
  869. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  870. }
  871. }
  872. }
  873. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  874. if (@foul) {
  875. my %hash = (
  876. nick => $foul[0],
  877. per => $spercent{$foul[0]},
  878. line => $self->_format_line($self->{stats}{foullines}{$foul[0]}),
  879. );
  880. my $text = $self->_template_text('foul1', %hash);
  881. if($self->{cfg}->{showfoulline}) {
  882. my $exttext = $self->_template_text('foultext', %hash);
  883. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  884. } else {
  885. _html("<tr><td class=\"hicell\">$text");
  886. }
  887. if (@foul >= 2) {
  888. my %hash = (
  889. nick => $foul[1],
  890. per => $spercent{$foul[1]}
  891. );
  892. my $text = $self->_template_text('foul2', %hash);
  893. _html("<br /><span class=\"small\">$text</span>");
  894. }
  895. _html("</td></tr>");
  896. } else {
  897. my $text = $self->_template_text('foul3');
  898. _html("<tr><td class=\"hicell\">$text</td></tr>");
  899. }
  900. }
  901. sub _mostsad
  902. {
  903. my $self = shift;
  904. my %spercent;
  905. foreach my $nick (sort keys %{ $self->{stats}->{frowns} }) {
  906. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  907. if ($self->{stats}->{lines}{$nick} > 100) {
  908. $spercent{$nick} = $self->{stats}->{frowns}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  909. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  910. }
  911. }
  912. }
  913. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  914. if (@sadface) {
  915. my %hash = (
  916. nick => $sadface[0],
  917. per => $spercent{$sadface[0]}
  918. );
  919. my $text = $self->_template_text('sad1', %hash);
  920. _html("<tr><td class=\"hicell\">$text");
  921. if (@sadface >= 2) {
  922. my %hash = (
  923. nick => $sadface[1],
  924. per => $spercent{$sadface[1]}
  925. );
  926. my $text = $self->_template_text('sad2', %hash);
  927. _html("<br /><span class=\"small\">$text</span>");
  928. }
  929. _html("</td></tr>");
  930. } else {
  931. my $text = $self->_template_text('sad3');
  932. _html("<tr><td class=\"hicell\">$text</td></tr>");
  933. }
  934. }
  935. sub _mostop
  936. {
  937. my $self = shift;
  938. my @ops = sort { $self->{stats}->{gaveops}{$b} <=> $self->{stats}->{gaveops}{$a} }
  939. keys %{ $self->{stats}->{gaveops} };
  940. @ops = $self->_istoponly(@ops);
  941. my @deops = sort { $self->{stats}->{tookops}{$b} <=> $self->{stats}->{tookops}{$a} }
  942. keys %{ $self->{stats}->{tookops} };
  943. @deops = $self->_istoponly(@deops);
  944. if (@ops) {
  945. my %hash = (
  946. nick => $ops[0],
  947. ops => $self->{stats}->{gaveops}{$ops[0]}
  948. );
  949. my $text = $self->_template_text('mostop1', %hash);
  950. _html("<tr><td class=\"hicell\">$text");
  951. if (@ops >= 2) {
  952. my %hash = (
  953. nick => $ops[1],
  954. ops => $self->{stats}->{gaveops}{$ops[1]}
  955. );
  956. my $text = $self->_template_text('mostop2', %hash);
  957. _html("<br /><span class=\"small\">$text</span>");
  958. }
  959. _html("</td></tr>");
  960. } else {
  961. my $text = $self->_template_text('mostop3');
  962. _html("<tr><td class=\"hicell\">$text</td></tr>");
  963. }
  964. if (@deops) {
  965. my %hash = (
  966. nick => $deops[0],
  967. deops => $self->{stats}->{tookops}{$deops[0]}
  968. );
  969. my $text = $self->_template_text('mostdeop1', %hash);
  970. _html("<tr><td class=\"hicell\">$text");
  971. if (@deops >= 2) {
  972. my %hash = (
  973. nick => $deops[1],
  974. deops => $self->{stats}->{tookops}{$deops[1]}
  975. );
  976. my $text = $self->_template_text('mostdeop2', %hash);
  977. _html("<br /><span class=\"small\">$text</span>");
  978. }
  979. _html("</td></tr>");
  980. } else {
  981. my $text = $self->_template_text('mostdeop3');
  982. _html("<tr><td class=\"hicell\">$text</td></tr>");
  983. }
  984. }
  985. sub _mostvoice
  986. {
  987. my $self = shift;
  988. my @voice = sort { $self->{stats}->{gavevoice}{$b} <=> $self->{stats}->{gavevoice}{$a} }
  989. keys %{ $self->{stats}->{gavevoice} };
  990. @voice = $self->_istoponly(@voice);
  991. my @devoice = sort { $self->{stats}->{tookvoice}{$b} <=> $self->{stats}->{tookvoice}{$a} }
  992. keys %{ $self->{stats}->{tookvoice} };
  993. @devoice = $self->_istoponly(@devoice);
  994. if (@voice) {
  995. my %hash = (
  996. nick => $voice[0],
  997. voices => $self->{stats}->{gavevoice}{$voice[0]}
  998. );
  999. my $text = $self->_template_text('mostvoice1', %hash);
  1000. _html("<tr><td class=\"hicell\">$text");
  1001. if (@voice >= 2) {
  1002. my %hash = (
  1003. nick => $voice[1],
  1004. voices => $self->{stats}->{gavevoice}{$voice[1]}
  1005. );
  1006. my $text = $self->_template_text('mostvoice2', %hash);
  1007. _html("<br /><span class=\"small\">$text</span>");
  1008. }
  1009. _html("</td></tr>");
  1010. } else {
  1011. my $text = $self->_template_text('mostvoice3');
  1012. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1013. }
  1014. if (@devoice) {
  1015. my %hash = (
  1016. nick => $devoice[0],
  1017. devoices => $self->{stats}->{tookvoice}{$devoice[0]}
  1018. );
  1019. my $text = $self->_template_text('mostdevoice1', %hash);
  1020. _html("<tr><td class=\"hicell\">$text");
  1021. if (@devoice >= 2) {
  1022. my %hash = (
  1023. nick => $devoice[1],
  1024. devoices => $self->{stats}->{tookvoice}{$devoice[1]}
  1025. );
  1026. my $text = $self->_template_text('mostdevoice2', %hash);
  1027. _html("<br /><span class=\"small\">$text</span>");
  1028. }
  1029. _html("</td></tr>");
  1030. } else {
  1031. my $text = $self->_template_text('mostdevoice3');
  1032. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1033. }
  1034. }
  1035. sub _mosthalfop
  1036. {
  1037. my $self = shift;
  1038. my @halfops = sort { $self->{stats}->{gavehalfops}{$b} <=> $self->{stats}->{gavehalfops}{$a} }
  1039. keys %{ $self->{stats}->{gavehalfops} };
  1040. @halfops = $self->_istoponly(@halfops);
  1041. my @dehalfops = sort { $self->{stats}->{tookhalfops}{$b} <=> $self->{stats}->{tookhalfops}{$a} }
  1042. keys %{ $self->{stats}->{tookhalfops} };
  1043. @dehalfops = $self->_istoponly(@dehalfops);
  1044. if (@halfops) {
  1045. my %hash = (
  1046. nick => $halfops[0],
  1047. halfops => $self->{stats}->{gavehalfops}{$halfops[0]}
  1048. );
  1049. my $text = $self->_template_text('mosthalfop1', %hash);
  1050. _html("<tr><td class=\"hicell\">$text");
  1051. if (@halfops >= 2) {
  1052. my %hash = (
  1053. nick => $halfops[1],
  1054. halfops => $self->{stats}->{gavehalfops}{$halfops[1]}
  1055. );
  1056. my $text = $self->_template_text('mosthalfop2', %hash);
  1057. _html("<br /><span class=\"small\">$text</span>");
  1058. }
  1059. _html("</td></tr>");
  1060. } else {
  1061. my $text = $self->_template_text('mosthalfop3');
  1062. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1063. }
  1064. if (@dehalfops) {
  1065. my %hash = (
  1066. nick => $dehalfops[0],
  1067. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[0]}
  1068. );
  1069. my $text = $self->_template_text('mostdehalfop1', %hash);
  1070. _html("<tr><td class=\"hicell\">$text");
  1071. if (@dehalfops >= 2) {
  1072. my %hash = (
  1073. nick => $dehalfops[1],
  1074. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[1]}
  1075. );
  1076. my $text = $self->_template_text('mostdehalfop2', %hash);
  1077. _html("<br /><span class=\"small\">$text</span>");
  1078. }
  1079. _html("</td></tr>");
  1080. } else {
  1081. my $text = $self->_template_text('mostdehalfop3');
  1082. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1083. }
  1084. }
  1085. sub _mostactions
  1086. {
  1087. # The person who did the most /me's
  1088. my $self = shift;
  1089. my @actions = sort { $self->{stats}->{actions}{$b} <=> $self->{stats}->{actions}{$a} }
  1090. keys %{ $self->{stats}->{actions} };
  1091. @actions = $self->_istoponly(@actions);
  1092. if (@actions) {
  1093. my %linehash =
  1094. my %hash = (
  1095. nick => $actions[0],
  1096. actions => $self->{stats}->{actions}{$actions[0]},
  1097. line => $self->_format_line($self->{stats}->{actionlines}{$actions[0]})
  1098. );
  1099. my $text = $self->_template_text('action1', %hash);
  1100. if($self->{cfg}->{showactionline}) {
  1101. my $exttext = $self->_template_text('actiontext', %hash);
  1102. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  1103. } else {
  1104. _html("<tr><td class=\"hicell\">$text");
  1105. }
  1106. if (@actions >= 2) {
  1107. my %hash = (
  1108. nick => $actions[1],
  1109. actions => $self->{stats}->{actions}{$actions[1]}
  1110. );
  1111. my $text = $self->_template_text('action2', %hash);
  1112. _html("<br /><span class=\"small\">$text</span>");
  1113. }
  1114. _html("</td></tr>");
  1115. } else {
  1116. my $text = $self->_template_text('action3');
  1117. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1118. }
  1119. }
  1120. sub _mostsmiles
  1121. {
  1122. # The person(s) who smiled the most :-)
  1123. my $self = shift;
  1124. my %spercent;
  1125. foreach my $nick (sort keys %{ $self->{stats}->{smiles} }) {
  1126. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1127. if ($self->{stats}->{lines}{$nick} > 100) {
  1128. $spercent{$nick} = $self->{stats}->{smiles}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  1129. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1130. }
  1131. }
  1132. }
  1133. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1134. if (@smiles) {
  1135. my %hash = (
  1136. nick => $smiles[0],
  1137. per => $spercent{$smiles[0]}
  1138. );
  1139. my $text = $self->_template_text('smiles1', %hash);
  1140. _html("<tr><td class=\"hicell\">$text");
  1141. if (@smiles >= 2) {
  1142. my %hash = (
  1143. nick => $smiles[1],
  1144. per => $spercent{$smiles[1]}
  1145. );
  1146. my $text = $self->_template_text('smiles2', %hash);
  1147. _html("<br /><span class=\"small\">$text</span>");
  1148. }
  1149. _html("</td></tr>");
  1150. } else {
  1151. my $text = $self->_template_text('smiles3');
  1152. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1153. }
  1154. }
  1155. sub _lasttopics
  1156. {
  1157. my $self = shift;
  1158. if ($self->{stats}->{topics}) {
  1159. my %topic_seen;
  1160. my %hash = (
  1161. total => scalar @{ $self->{stats}->{topics} }
  1162. );
  1163. my $ltopic = $#{ $self->{stats}->{topics} };
  1164. my $tlimit = 0;
  1165. $self->{cfg}->{topichistory} -= 1;
  1166. if ($ltopic > $self->{cfg}->{topichistory}) {
  1167. $tlimit = $ltopic - $self->{cfg}->{topichistory};
  1168. }
  1169. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1170. my $topic = $self->{stats}->{topics}[$i]{topic};
  1171. # This code makes sure that we don't see the same topic twice
  1172. next if ($topic_seen{$topic});
  1173. $topic_seen{$topic} = 1;
  1174. # Strip off the quotes (')
  1175. $topic =~ s/^\'(.*)\'$/$1/;
  1176. my $nick = $self->{stats}->{topics}[$i]{nick};
  1177. my $hour = $self->{stats}->{topics}[$i]{hour};
  1178. my $min = $self->{stats}->{topics}[$i]{min};
  1179. $hash{nick} = $self->_format_word($nick);
  1180. $hash{time} = "$hour:$min";
  1181. _html('<tr><td class="hicell"><i>' . $self->_format_line($topic) . '</i></td>');
  1182. _html('<td class="hicell"><b>' . $self->_template_text('bylinetopic', %hash) . '</b></td></tr>');
  1183. }
  1184. _html("<tr><td align=\"center\" colspan=\"2\" class=\"asmall\">" . $self->_template_text('totaltopic', %hash) . "</td></tr>");
  1185. } else {
  1186. _html("<tr><td class=\"hicell\">" . $self->_template_text('notopic') ."</td></tr>");
  1187. }
  1188. }
  1189. sub _template_text
  1190. {
  1191. # This function is for the homemade template system. It receives a name
  1192. # of a template and a hash with the fields in the template to update to
  1193. # its corresponding value
  1194. my $self = shift;
  1195. my $template = shift;
  1196. my %hash = @_;
  1197. my $text;
  1198. unless ($text = $self->{tmps}->{lc($self->{cfg}->{lang})}{$template}) {
  1199. # Fall back to English if the language template doesn't exist
  1200. if ($text = $self->{tmps}->{en}{$template}) {
  1201. print "Note: No translation in '$self->{cfg}->{lang}' for '$template' - falling back to English..\n"
  1202. unless ($self->{cfg}->{silent});
  1203. } else {
  1204. die("No such template '$template' in language file.\n");
  1205. }
  1206. }
  1207. $hash{channel} = $self->{cfg}->{channel};
  1208. foreach my $key (sort keys %hash) {
  1209. $text =~ s/\[:$key\]/$hash{$key}/;
  1210. if ($self->{cfg}->{charset} =~ /iso-8859-1/i) {
  1211. $text =~ s/ü/&uuml;/go;
  1212. $text =~ s/ö/&ouml;/go;
  1213. $text =~ s/ä/&auml;/go;
  1214. $text =~ s/ß/&szlig;/go;
  1215. $text =~ s/å/&aring;/go;
  1216. $text =~ s/æ/&aelig;/go;
  1217. $text =~ s/ø/&oslash;/go;
  1218. $text =~ s/Å/&Aring;/go;
  1219. $text =~ s/Æ/&AElig;/go;
  1220. $text =~ s/Ø/&Oslash;/go;
  1221. }
  1222. }
  1223. if ($text =~ /\[:[^:]*?:[^:]*?:[^:]*?:\]/o) {
  1224. $text =~ s/\[:([^:]*?):([^:]*?):([^:]*?):\]/$self->_get_subst($1,$2,$3,\%hash)/geo;
  1225. }
  1226. if ($text =~ /\[:[^:]*?:[^:]*?:]/o) {
  1227. $text =~ s/\[:([^:]*?):([^:]*?):]/$self->_get_subst($1,$2,undef,\%hash)/geo;
  1228. }
  1229. return $text;
  1230. }
  1231. sub _format_word
  1232. {
  1233. # This function formats a word -- should ONLY be called on words used alone (EG: not whole line printed)
  1234. my ($self, $word) = @_;
  1235. $word = htmlentities($word, $self->{cfg}->{charset});
  1236. $word = $self->_replace_links($word);
  1237. return $word;
  1238. }
  1239. sub _format_line
  1240. {
  1241. # This function formats a action/normal line to be more readable, and calls any other function
  1242. # that should be executed on every line.
  1243. my ($self, $line) = @_;
  1244. my $hashref;
  1245. if ($hashref = $self->{cfg}->{analyzer}->{parser}->normalline($line)) {
  1246. $line = '<' . $hashref->{nick} . '> ' . $hashref->{saying};
  1247. } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->actionline($line)) {
  1248. $line = '* ' . $hashref->{nick} . ' ' . $hashref->{saying};
  1249. } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->thirdline($line)) {
  1250. if (defined($hashref->{kicker})) {
  1251. $line = '*** ' . $hashref->{nick} . ' was kicked by ' . $hashref->{kicker};
  1252. $line .= ' (' . $hashref->{kicktext} . ')'
  1253. if (defined($hashref->{kicktext}));
  1254. } elsif (defined($hashref->{newtopic})) {
  1255. $line = '*** ' . $hashref->{nick} . ' changes topic to \'' . $hashref->{newtopic} . '\'';
  1256. } elsif (defined($hashref->{newmode})) {
  1257. $line = '*** ' . $hashref->{nick} . ' sets mode ' . $hashref->{newmode};
  1258. $line .= ' ' . $hashref->{modechanges}
  1259. if (defined($hashref->{kicktext}));
  1260. } elsif (defined($hashref->{newjoin})) {
  1261. $line = '*** Joins: ' . $hashref->{nick};
  1262. } elsif (defined($hashref->{newnick})) {
  1263. $line = '*** ' . $hashref->{nick} . ' is now known as ' . $hashref->{newnick};
  1264. } elsif (defined($hashref->{newtopic})) {
  1265. $line = '*** ' . $hashref->{nick} . ' changes topic to: ' . $hashref->{newtopic};
  1266. }
  1267. }
  1268. $line = htmlentities($line, $self->{cfg}->{charset});
  1269. $line = $self->_replace_links($line);
  1270. return $line;
  1271. }
  1272. sub _get_subst
  1273. {
  1274. # This function looks at the user definition and see if there is sex
  1275. # defined. If yes, return the appropriate value. If no, just return the
  1276. # default he/she value.
  1277. my $self = shift;
  1278. my ($m,$f,$d,$hash) = @_;
  1279. if ($hash->{nick} && $self->{users}->{sex}{$hash->{nick}}) {
  1280. if ($self->{users}->{sex}{$hash->{nick}} eq 'm') {
  1281. return $m;
  1282. } elsif ($self->{users}->{sex}{$hash->{nick}} eq 'f') {
  1283. return $f;
  1284. }
  1285. }
  1286. return defined($d) ? $d : "$m/$f";
  1287. }
  1288. sub _mostusedword
  1289. {
  1290. # Word usage statistics
  1291. my $self = shift;
  1292. my %usages;
  1293. foreach my $word (keys %{ $self->{stats}->{wordcounts} }) {
  1294. # Skip people's nicks.
  1295. next if is_nick($word);
  1296. next if (length($word) < $self->{cfg}->{wordlength});
  1297. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1298. }
  1299. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1300. if (@popular) {
  1301. $self->_headline($self->_template_text('mostwordstopic'));
  1302. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1303. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('word') . "</b></td>");
  1304. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1305. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1306. my $count = 0;
  1307. for(my $i = 0; $count < $self->{cfg}->{wordhistory}; $i++) {
  1308. last unless $i < $#popular;
  1309. # Skip nicks. It's far more efficient to do this here than when
  1310. # @popular is created.
  1311. next if is_ignored($popular[$i]);
  1312. my $a = $count + 1;
  1313. my $popular = $self->_format_word($popular[$i]);
  1314. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1315. my $lastused = $self->_format_word($self->{stats}->{wordnicks}{$popular[$i]});
  1316. my $class;
  1317. if ($a == 1) {
  1318. $class = 'hirankc';
  1319. } else {
  1320. $class = 'rankc';
  1321. }
  1322. _html("<tr><td class=\"$class\">$a</td>");
  1323. _html("<td class=\"hicell\">$popular</td>");
  1324. _html("<td class=\"hicell\">$wordcount</td>");
  1325. _html("<td class=\"hicell\">$lastused</td>");
  1326. _html("</tr>");
  1327. $count++;
  1328. }
  1329. _html("</table>");
  1330. }
  1331. }
  1332. sub _mostwordsperline
  1333. {
  1334. # The person who got the most words per line
  1335. my $self = shift;
  1336. my %wpl = ();
  1337. my $numlines = 0;
  1338. my ($avg, $numwords);
  1339. foreach my $nick (keys %{ $self->{stats}->{words} }) {
  1340. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1341. $wpl{$nick} = sprintf("%.2f", $self->{stats}->{words}{$nick}/$self->{stats}->{lines}{$nick});
  1342. $numlines += $self->{stats}->{lines}{$nick};
  1343. $numwords += $self->{stats}->{words}{$nick};
  1344. }
  1345. }
  1346. if ($numlines > 0) {
  1347. $avg = sprintf("%.2f", $numwords/$numlines);
  1348. }
  1349. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  1350. if (@wpl) {
  1351. my %hash = (
  1352. nick => $wpl[0],
  1353. wpl => $wpl{$wpl[0]}
  1354. );
  1355. my $text = $self->_template_text('wpl1', %hash);
  1356. _html("<tr><td class=\"hicell\">$text");
  1357. $hash{avg} = $avg;
  1358. $text = $self->_template_text('wpl2', %hash);
  1359. _html("<br /><span class=\"small\">$text</span>");
  1360. _html("</td></tr>");
  1361. }
  1362. }
  1363. sub _mostreferencednicks
  1364. {
  1365. # List showing the most referenced nicks
  1366. my $self = shift;
  1367. my %usages;
  1368. foreach my $word (sort keys %{ $self->{stats}->{wordcounts} }) {
  1369. next if !exists $self->{stats}->{lines}{$word};
  1370. next if is_ignored($word);
  1371. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1372. }
  1373. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1374. if (@popular) {
  1375. $self->_headline($self->_template_text('referencetopic'));
  1376. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1377. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>");
  1378. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1379. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1380. for(my $i = 0; $i < $self->{cfg}->{nickhistory}; $i++) {
  1381. last unless $i < $#popular;
  1382. my $a = $i + 1;
  1383. my $popular = $popular[$i];
  1384. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1385. my $lastused = $self->{stats}->{wordnicks}{$popular[$i]};
  1386. my $class;
  1387. if ($a == 1) {
  1388. $class = 'hirankc';
  1389. } else {
  1390. $class = 'rankc';
  1391. }
  1392. _html("<tr><td class=\"$class\">$a</td>");
  1393. _html("<td class=\"hicell\">$popular</td>");
  1394. _html("<td class=\"hicell\">$wordcount</td>");
  1395. _html("<td class=\"hicell\">$lastused</td>");
  1396. _html("</tr>");
  1397. }
  1398. _html("</table>");
  1399. }
  1400. }
  1401. sub _mosturls
  1402. {
  1403. # List showing the most referenced URLs
  1404. my $self = shift;
  1405. my @sorturls = sort { $self->{stats}->{urlcounts}{$b} <=> $self->{stats}->{urlcounts}{$a} }
  1406. keys %{ $self->{stats}->{urlcounts} };
  1407. if (@sorturls) {
  1408. $self->_headline($self->_template_text('urlstopic'));
  1409. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1410. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('url') . "</b></td>");
  1411. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1412. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1413. for(my $i = 0; $i < $self->{cfg}->{urlhistory}; $i++) {
  1414. last unless $i < @sorturls;
  1415. my $a = $i + 1;
  1416. my $sorturl = $sorturls[$i];
  1417. my $urlcount = $self->{stats}->{urlcounts}{$sorturls[$i]};
  1418. my $lastused = $self->{stats}->{urlnicks}{$sorturls[$i]};
  1419. if (length($sorturl) > 60) {
  1420. $sorturl = substr($sorturl, 0, 60);
  1421. }
  1422. my $class;
  1423. if ($a == 1) {
  1424. $class = 'hirankc';
  1425. } else {
  1426. $class = 'rankc';
  1427. }
  1428. _html("<tr><td class=\"$class\">$a</td>");
  1429. _html("<td class=\"hicell\"><a href=\"$sorturls[$i]\">$sorturl</a></td>");
  1430. _html("<td class=\"hicell\">$urlcount</td>");
  1431. _html("<td class=\"hicell\">$lastused</td>");
  1432. _html("</tr>");
  1433. }
  1434. _html("</table>");
  1435. }
  1436. }
  1437. sub _legend
  1438. {
  1439. # A legend showing the timebars and their associated time.
  1440. my $self = shift;
  1441. _html("<table align=\"center\" border=\"0\" width=\"520\"><tr>");
  1442. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_0}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"0-5\" /> = 0-5</td>");
  1443. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_6}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"6-11\" /> = 6-11</td>");
  1444. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_12}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"12-17\" /> = 12-17</td>");
  1445. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_18}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"18-23\" /> = 18-23</td>");
  1446. _html("</tr></table>\n");
  1447. }
  1448. sub _replace_links
  1449. {
  1450. # Sub to replace urls and e-mail addys to links
  1451. my ($self, $str, $nick) = @_;
  1452. # Regular expressions are taken from match_urls() and match_email() in
  1453. # Common.pm
  1454. my $texturl = $self->_template_text("newwindow");
  1455. my $textmail = $self->_template_text("mailto");
  1456. my (@str) = split(/ /,$str);
  1457. foreach (@str) {
  1458. if (m/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_\/~:@]+\.[-a-zA-Z0-9.,_~=:&amp;@%?#\/+]+)/o) {
  1459. my $nick = $nick || $1 . $2;
  1460. $_ = "<a href=\"$1$2\" target=\"_blank\" title=\"$texturl $1$2\">" . $self->_split_long_text($nick) . '</a>';
  1461. } elsif (m/(^|[^:])\b([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9._]+)/o) {
  1462. my $nick = $nick || $1 . $2;
  1463. $_ = "$1<a href=\"mailto:$2\" title=\"$textmail $nick\">" . $self->_split_long_text($nick) . "<\/a>";
  1464. } else {
  1465. $_ = $self->_split_long_text($_);
  1466. }
  1467. }
  1468. return join(' ', @str);
  1469. }
  1470. sub _split_long_text
  1471. {
  1472. my ($self, $str) = @_;
  1473. $str =~ s/(\S{$self->{cfg}->{quotewidth}})(?!\s)/$1-<br \/>/og;
  1474. return($str);
  1475. }
  1476. sub _user_linetimes
  1477. {
  1478. my $self = shift;
  1479. my $nick = shift;
  1480. my $top = shift;
  1481. my $bar = "";
  1482. my $len = ($self->{stats}->{lines}{$nick} / $self->{stats}->{lines}{$top}) * 100;
  1483. for (my $i = 0; $i <= 3; $i++) {
  1484. next if not defined $self->{stats}->{line_times}{$nick}[$i];
  1485. my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * $len);
  1486. if ($w) {
  1487. my $pic = 'pic_h_'.(6*$i);
  1488. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />";
  1489. }
  1490. }
  1491. return "$bar&nbsp;$self->{stats}->{lines}{$nick}";
  1492. }
  1493. sub _user_wordtimes
  1494. {
  1495. my $self = shift;
  1496. my $nick = shift;
  1497. my $top = shift;
  1498. my $bar = "";
  1499. my $len = ($self->{stats}->{words}{$nick} / $self->{stats}->{words}{$top}) * 100;
  1500. for (my $i = 0; $i <= 3; $i++) {
  1501. next if not defined $self->{stats}->{word_times}{$nick}[$i];
  1502. my $w = int(($self->{stats}->{word_times}{$nick}[$i] / $self->{stats}->{words}{$nick}) * $len);
  1503. if ($w) {
  1504. my $pic = 'pic_h_'.(6*$i);
  1505. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />";
  1506. }
  1507. }
  1508. return "$bar&nbsp;$self->{stats}->{words}{$nick}";
  1509. }
  1510. sub _user_times
  1511. {
  1512. my $self = shift;
  1513. my ($nick) = @_;
  1514. my $bar = "";
  1515. my $itemstat = ($self->{cfg}->{sortbywords} ? 'words' : 'lines');
  1516. my $timestat = ($self->{cfg}->{sortbywords} ? 'word_times' : 'line_times');
  1517. for (my $i = 0; $i <= 3; $i++) {
  1518. next if not defined $self->{stats}->{$timestat}{$nick}[$i];
  1519. my $w = int(($self->{stats}->{$timestat}{$nick}[$i] / $self->{stats}->{$itemstat}{$nick}) * 40);
  1520. if ($w) {
  1521. my $pic = 'pic_h_'.(6*$i);
  1522. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\" />";
  1523. }
  1524. }
  1525. return $bar;
  1526. }
  1527. sub _mostnicks
  1528. {
  1529. # List showing the user with most used nicks
  1530. my $self = shift;
  1531. my @sortnicks = sort { keys %{ $self->{stats}->{nicks}->{$b} } <=> keys %{ $self->{stats}->{nicks}->{$a} } }
  1532. keys %{ $self->{stats}->{nicks} };
  1533. if (keys %{ $self->{stats}->{nicks}->{$sortnicks[0]} } > 1) {
  1534. $self->_headline($self->_template_text('mostnickstopic'));
  1535. my $names1 = $self->_template_text('names1');
  1536. my $names2 = $self->_template_text('names2');
  1537. my $nick_txt = $self->_template_text('nick');
  1538. my $names_txt = $self->_template_text('names');
  1539. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1540. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>$nick_txt</b></td>");
  1541. _html("<td class=\"tdtop\"><b>$names_txt</b></td></tr>");
  1542. for(my $i = 0; $i < $self->{cfg}->{mostnickshistory}; $i++) {
  1543. next if is_ignored($sortnicks[$i]);
  1544. last unless $i < @sortnicks;
  1545. my $nickcount = keys %{ $self->{stats}->{nicks}->{$sortnicks[$i]} };
  1546. my $nickused = join(", ", values %{ $self->{stats}->{nicks}->{$sortnicks[$i]} });
  1547. next unless ($nickcount > 1);
  1548. my $a = $i + 1;
  1549. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1550. my $n = $nickcount > 1 ? $names1 : $names2;
  1551. _html("<tr><td class=\"$class\">$a</td>");
  1552. if ($self->{cfg}->{mostnicksverbose}) {
  1553. _html("<td class=\"hicell10\">$sortnicks[$i]<br />($nickcount $n)</td>");
  1554. _html("<td class=\"hicell10\" valign='top'>$nickused</td>");
  1555. } else {
  1556. _html("<td class=\"hicell10\">$sortnicks[$i]</td>");
  1557. _html("<td class=\"hicell10\" valign='top'>$nickcount $n</td>");
  1558. }
  1559. _html("</tr>");
  1560. }
  1561. _html("</table>");
  1562. }
  1563. }
  1564. sub _mostactivebyhour
  1565. {
  1566. # Charts for most active nicks by hour (0-5, 6-11, 12-17, 18-23)
  1567. my $self = shift;
  1568. my $sortnicks;
  1569. my $lastline=-1;
  1570. my $maxlines=0;
  1571. foreach my $period (0,1,2,3) {
  1572. my @sortnicks =
  1573. sort
  1574. {
  1575. (defined $self->{stats}->{line_times}{$b}[$period]?$self->{stats}->{line_times}{$b}[$period]:0)
  1576. <=>
  1577. (defined $self->{stats}->{line_times}{$a}[$period]?$self->{stats}->{line_times}{$a}[$period]:0)
  1578. }
  1579. keys %{ $self->{stats}->{line_times} } ;
  1580. for(my $i = 0; $i < $self->{cfg}->{activenicksbyhour}; $i++) {
  1581. next if ! $sortnicks[$i];
  1582. next if is_ignored($sortnicks[$i]);
  1583. last unless $i < @sortnicks;
  1584. my $nick=$sortnicks[$i];
  1585. my $count=$self->{stats}->{line_times}{$nick}[$period] || 0;
  1586. last unless $nick;
  1587. last unless $count;
  1588. $sortnicks->[$period][$i]=$nick;
  1589. if ($lastline<$i) {
  1590. $lastline=$i;
  1591. }
  1592. if ($maxlines<$count) {
  1593. $maxlines=$count;
  1594. }
  1595. }
  1596. }
  1597. if ($lastline>=0) {
  1598. $self->_headline($self->_template_text('activenickbyhourtopic'));
  1599. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1600. _html("<td>&nbsp;</td>");
  1601. _html("<td class=\"tdtop\"><b>0-5</b></td>");
  1602. _html("<td class=\"tdtop\"><b>6-11</b></td>");
  1603. _html("<td class=\"tdtop\"><b>12-17</b></td>");
  1604. _html("<td class=\"tdtop\"><b>18-23</b></td>");
  1605. _html("</tr>");
  1606. for(my $i = 0; $i <= $lastline; $i++) {
  1607. my $a = $i + 1;
  1608. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1609. _html("<tr><td class=\"$class\">$a</td>");
  1610. foreach my $period (0,1,2,3) {
  1611. my $nick=$sortnicks->[$period][$i];
  1612. if ($nick) {
  1613. my $count=$self->{stats}->{line_times}{$nick}[$period];
  1614. if ($count) {
  1615. _html("<td class=\"hicell\">".$nick." - ".$count);
  1616. if ($self->{cfg}->{showmostactivebyhourgraph}) {
  1617. my $pic = 'pic_h_'.(6*$period);
  1618. my $w = int(($count / $maxlines) * 100);
  1619. _html("<br /><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />");
  1620. }
  1621. _html("</td>");
  1622. } else {
  1623. _html("<td class=\"hicell\">&nbsp;</td>");
  1624. }
  1625. } else {
  1626. _html("<td class=\"hicell\">&nbsp;</td>");
  1627. }
  1628. }
  1629. _html("</tr>");
  1630. }
  1631. _html("</table>");
  1632. }
  1633. }
  1634. sub _topactive {
  1635. my $self = shift;
  1636. my @top_active;
  1637. my $top_nicks;
  1638. if ($self->{cfg}->{sortbywords}) {
  1639. @top_active = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  1640. keys %{ $self->{stats}->{words} };
  1641. $top_nicks = scalar keys %{ $self->{stats}->{words} };
  1642. } else {
  1643. @top_active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} }
  1644. keys %{ $self->{stats}->{lines} };
  1645. $top_nicks = scalar keys %{ $self->{stats}->{lines} };
  1646. }
  1647. if ($self->{cfg}->{activenicks} > $top_nicks) {
  1648. $self->{cfg}->{activenicks} = $top_nicks;
  1649. }
  1650. if (($self->{cfg}->{activenicks}+$self->{cfg}->{activenicks2}) > $top_nicks) {
  1651. $self->{cfg}->{activenicks2} = $top_nicks-$self->{cfg}->{activenicks};
  1652. }
  1653. (@top_active) = @top_active[0..($self->{cfg}->{activenicks}+$self->{cfg}->{activenicks2}-1)];
  1654. foreach (@top_active) {
  1655. $self->{topactive}{$_} = 1;
  1656. }
  1657. }
  1658. sub _istoponly {
  1659. my $self = shift;
  1660. my (@nicks_tmp) = @_;
  1661. my @nicks;
  1662. my $cnt=0;
  1663. if ($self->{cfg}->{showonlytop}) {
  1664. foreach my $nick (@nicks_tmp) {
  1665. if ($self->{topactive}{$nick}) {
  1666. push(@nicks, $nick);
  1667. }
  1668. }
  1669. return(@nicks);
  1670. } else {
  1671. return(@nicks_tmp);
  1672. }
  1673. }
  1674. 1;
  1675. __END__
  1676. =head1 NAME
  1677. Pisg::HTMLGenerator - class to create a static HTML page out of data parsed
  1678. =head1 DESCRIPTION
  1679. C<Pisg::HTMLGenerator> uses the hash returned by Pisg::Parser::Logfile and turns it into a static HTML page.
  1680. =head1 SYNOPSIS
  1681. use Pisg::HTMLGenerator;
  1682. $generator = new Pisg::HTMLGenerator(
  1683. cfg => $cfg,
  1684. stats => $stats,
  1685. users => $users,
  1686. tmps => $tmps
  1687. );
  1688. =head1 CONSTRUCTOR
  1689. =over 4
  1690. =item new ( [ OPTIONS ] )
  1691. This is the constructor for a new Pisg::HTMLGenerator object. C<OPTIONS> are passed in a hash like fashion using key and value pairs.
  1692. Possible options are:
  1693. B<cfg> - hashref containing configuration variables, created by the Pisg module.
  1694. B<stats> - reference to the hash returned by Pisg::Parser::Logfile containing all stats.
  1695. B<users> - reference to a hash containg user information
  1696. B<tmps> - reference to a hash containing the language templates.
  1697. =back
  1698. =head1 AUTHOR
  1699. Morten Brix Pedersen <morten@wtf.dk>
  1700. =head1 COPYRIGHT
  1701. Copyright (C) 2001-2002 Morten Brix Pedersen. All rights reserved.
  1702. This program is free software; you can redistribute it and/or modify it
  1703. under the terms of the GPL, license is included with the distribution of
  1704. this file.
  1705. =cut