HTMLGenerator.pm 66 KB

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