pisg.pl 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Getopt::Long;
  4. use FindBin;
  5. # pisg - Perl IRC Statistics Generator
  6. #
  7. # Copyright (C) 2001 <Morten 'LostStar' Brix Pedersen> - morten@wtf.dk
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. my ($debug);
  23. # Default values for pisg. Their meanings are explained in CONFIG-README.
  24. #
  25. # If you are a user of pisg, you shouldn't change it here, but instead on
  26. # commandline or in pisg.cfg
  27. my $conf = {
  28. channel => "#channel",
  29. logtype => "Logfile",
  30. logfile => "channel.log",
  31. format => "mIRC",
  32. network => "SomeIRCNet",
  33. outputfile => "index.html",
  34. maintainer => "MAINTAINER",
  35. pagehead => "none",
  36. configfile => "pisg.cfg",
  37. imagepath => "",
  38. logdir => "",
  39. lang => 'EN',
  40. langfile => 'lang.txt',
  41. prefix => "",
  42. modules_dir => $FindBin::Bin . "/modules", # Module search path
  43. # Colors / Layout
  44. bgcolor => "#dedeee",
  45. bgpic => '',
  46. text => "black",
  47. hbgcolor => "#666699",
  48. hcolor => "white",
  49. hicell => "#BABADD",
  50. hicell2 => "#CCCCCC",
  51. tdcolor => "black",
  52. tdtop => "#C8C8DD",
  53. link => "#0b407a",
  54. vlink => "#0b407a",
  55. hlink => "#0b407a",
  56. headline => "#000000",
  57. rankc => "#CCCCCC",
  58. pic_v_0 => "blue-v.png",
  59. pic_v_6 => "green-v.png",
  60. pic_v_12 => "yellow-v.png",
  61. pic_v_18 => "red-v.png",
  62. pic_h_0 => "blue-h.png",
  63. pic_h_6 => "green-h.png",
  64. pic_h_12 => "yellow-h.png",
  65. pic_h_18 => "red-h.png",
  66. # Stats settings
  67. show_linetime => 0,
  68. show_time => 1,
  69. show_words => 0,
  70. show_wpl => 0,
  71. show_cpl => 0,
  72. show_legend => 1,
  73. show_kickline => 1,
  74. show_actionline => 1,
  75. show_shoutline => 1,
  76. show_violentlines => 1,
  77. # Less important things
  78. minquote => 25,
  79. maxquote => 65,
  80. wordlength => 5,
  81. activenicks => 25,
  82. activenicks2 => 30,
  83. topichistory => 3,
  84. nicktracking => 0,
  85. timeoffset => "+0",
  86. # Misc settings
  87. foul => 'ass fuck bitch shit scheisse scheiße kacke arsch ficker ficken schlampe',
  88. violent => 'slaps beats smacks',
  89. ignorewords => '',
  90. tablewidth => 614,
  91. regexp_aliases => 0,
  92. # Developer stuff
  93. debug => 0,
  94. debugfile => "debug.log",
  95. version => "v0.22-cvs",
  96. };
  97. my ($chans, $users);
  98. my ($timestamp, $time, $nicks, $totallength, $oldtime, $actions, $normals, %T);
  99. sub load_modules {
  100. push @INC, $conf->{modules_dir};
  101. require Pisg::Common;
  102. Pisg::Common->import();
  103. Pisg::Common::init_common($debug);
  104. }
  105. sub main {
  106. print "pisg $conf->{version} - Perl IRC Statistics Generator\n\n";
  107. get_cmdlineoptions();
  108. load_modules(); # Add modules, now that their location is known.
  109. init_config(); # Init config. (Aliases, ignores, other options etc.)
  110. init_debug()
  111. unless ($conf->{debugstarted}); # Init the debugging file
  112. get_language_templates(); # Get translations from lang.txt
  113. parse_channels(); # parse any channels in <channel> statements
  114. do_channel()
  115. unless ($conf->{chan_done}{$conf->{channel}});
  116. close_debug(); # Close the debugging file
  117. }
  118. sub do_channel
  119. {
  120. init_pisg(); # Init commandline arguments and other things
  121. init_words(); # Init words. (Foulwords etc)
  122. # Pick our stats generator.
  123. my $analyzer;
  124. eval <<_END;
  125. use Pisg::Parser::$conf->{logtype};
  126. \$analyzer = new Pisg::Parser::$conf->{logtype}(\$conf, \$debug);
  127. _END
  128. if ($@) {
  129. print STDERR "Could not load stats generator for '$conf->{logtype}': $@\n";
  130. return undef;
  131. }
  132. my $stats = $analyzer->analyze();
  133. create_html($stats)
  134. if (defined $stats and $stats->{lines} > 0);# Create the HTML
  135. # (look here if you want to remove some of the
  136. # stats which you don't care about)
  137. $conf->{chan_done}{$conf->{channel}} = 1;
  138. }
  139. sub parse_channels
  140. {
  141. my %origconf = %{ $conf };
  142. foreach my $channel (keys %{ $chans }) {
  143. foreach (keys %{ $chans->{$channel} }) {
  144. $conf->{$_} = $chans->{$channel}{$_};
  145. }
  146. do_channel();
  147. $origconf{chan_done} = $conf->{chan_done};
  148. %{ $conf } = %origconf;
  149. }
  150. }
  151. sub init_pisg
  152. {
  153. # Reset all variables
  154. undef $totallength;
  155. $timestamp = time();
  156. $conf->{start} = time();
  157. if ($conf->{timeoffset} =~ /\+(\d+)/) {
  158. # We must plus some hours to the time
  159. $timestamp += 3600 * $1; # 3600 seconds per hour
  160. } elsif ($conf->{timeoffset} =~ /-(\d+)/) {
  161. # We must remove some hours from the time
  162. $timestamp -= 3600 * $1; # 3600 seconds per hour
  163. }
  164. # Add trailing slash when it's not there..
  165. $conf->{imagepath} =~ s/([^\/])$/$1\//;
  166. # Set some values
  167. $oldtime = "00";
  168. $actions = "0";
  169. $normals = "0";
  170. print "Using language template: $conf->{lang}\n\n" if ($conf->{lang} ne 'EN');
  171. print "Statistics for channel $conf->{channel} \@ $conf->{network} by $conf->{maintainer}\n\n";
  172. }
  173. sub init_config
  174. {
  175. if ((open(CONFIG, $conf->{configfile}) or open(CONFIG, $FindBin::Bin . "/$conf->{configfile}"))) {
  176. print "Using config file: $conf->{configfile}\n";
  177. my $lineno = 0;
  178. while (my $line = <CONFIG>)
  179. {
  180. $lineno++;
  181. next if ($line =~ /^#/);
  182. if ($line =~ /<user.*>/) {
  183. my $nick;
  184. if ($line =~ /nick="([^"]+)"/) {
  185. $nick = $1;
  186. add_alias($nick, $nick);
  187. } else {
  188. print STDERR "Warning: no nick specified in $conf->{configfile} on line $lineno\n";
  189. next;
  190. }
  191. if ($line =~ /alias="([^"]+)"/) {
  192. my @thisalias = split(/\s+/, lc($1));
  193. foreach (@thisalias) {
  194. if ($conf->{regexp_aliases} and /[\|\[\]\{\}\(\)\?\+\.\*\^\\]/) {
  195. add_aliaswild($nick, $_);
  196. } elsif (not $conf->{regexp_aliases} and s/\*/\.\*/g) {
  197. # quote it if it is a wildcard
  198. s/([\|\[\]\{\}\(\)\?\+\^\\])/\\$1/g;
  199. add_aliaswild($nick, $_);
  200. } else {
  201. add_alias($nick, $_);
  202. }
  203. }
  204. }
  205. if ($line =~ /pic="([^"]+)"/) {
  206. $users->{userpics}{$nick} = $1;
  207. }
  208. if ($line =~ /link="([^"]+)"/) {
  209. $users->{userlinks}{$nick} = $1;
  210. }
  211. if ($line =~ /ignore="Y"/i) {
  212. add_ignore($nick);
  213. }
  214. if ($line =~ /sex="([MmFf])"/i) {
  215. $users->{sex}{$nick} = lc($1);
  216. }
  217. } elsif ($line =~ /<set(.*)>/) {
  218. my $settings = $1;
  219. while ($settings =~ s/[ \t]([^=]+)=["']([^"']*)["']//) {
  220. my $var = lc($1); # Make the string lowercase
  221. unless (($conf->{$var} eq $2) || $conf->{cmdl}{$var}) {
  222. $conf->{$var} = $2;
  223. }
  224. $debug->("Conf: $var = $2");
  225. }
  226. } elsif ($line =~ /<channel=['"]([^'"]+)['"](.*)>/i) {
  227. my ($channel, $settings) = ($1, $2);
  228. $chans->{$channel}->{channel} = $channel;
  229. $conf->{chan_done}{$conf->{channel}} = 1; # don't parse channel in $conf->{channel} if a channel statement is present
  230. while ($settings =~ s/\s([^=]+)=["']([^"']*)["']//) {
  231. my $var = lc($1);
  232. $chans->{$channel}{$var} = $2;
  233. $debug->("Channel conf $channel: $var = $2");
  234. }
  235. while (<CONFIG>) {
  236. last if ($_ =~ /<\/*channel>/i);
  237. while ($_ =~ s/^\s*(\w+)\s*=\s*["']([^"']*)["']//) {
  238. my $var = lc($1);
  239. unless ($conf->{cmdl}{$var}) {
  240. $chans->{$channel}{$var} = $2;
  241. }
  242. $debug->("Conf $channel: $var = $2");
  243. }
  244. }
  245. }
  246. }
  247. close(CONFIG);
  248. }
  249. }
  250. sub init_words {
  251. $conf->{foul} =~ s/\s+/|/g;
  252. foreach (split /\s+/, $conf->{ignorewords}) {
  253. $conf->{ignoreword}{$_} = 1;
  254. }
  255. $conf->{violent} =~ s/\s+/|/g;
  256. }
  257. sub init_debug
  258. {
  259. $conf->{debugstarted} = 1;
  260. if ($conf->{debug}) {
  261. print "[ Debugging => $conf->{debugfile} ]\n";
  262. open(DEBUG,"> $conf->{debugfile}") or print STDERR "$0: Unable to open debug
  263. file($conf->{debugfile}): $!\n";
  264. $debug->("*** pisg debug file for $conf->{logfile}\n");
  265. if ($conf->{debugqueue}) {
  266. print DEBUG $conf->{debugqueue};
  267. delete $conf->{debugqueue};
  268. }
  269. } else {
  270. $debug = sub {};
  271. }
  272. }
  273. sub htmlentities
  274. {
  275. my $str = shift;
  276. $str =~ s/\&/\&amp;/go;
  277. $str =~ s/\</\&lt;/go;
  278. $str =~ s/\>/\&gt;/go;
  279. $str =~ s/ü/&uuml;/go;
  280. $str =~ s/ö/&ouml;/go;
  281. $str =~ s/ä/&auml;/go;
  282. $str =~ s/ß/&szlig;/go;
  283. $str =~ s/å/&aring;/go;
  284. $str =~ s/æ/&aelig;/go;
  285. $str =~ s/ø/&oslash;/go;
  286. return $str;
  287. }
  288. sub html
  289. {
  290. my $html = shift;
  291. print OUTPUT "$html\n";
  292. }
  293. sub template_text
  294. {
  295. # This function is for the homemade template system. It receives a name
  296. # of a template and a hash with the fields in the template to update to
  297. # its corresponding value
  298. my $template = shift;
  299. my %hash = @_;
  300. my $text;
  301. unless ($text = $T{$conf->{lang}}{$template}) {
  302. # Fall back to English if the language template doesn't exist
  303. if ($text = $T{EN}{$template}) {
  304. print "Note: There was no translation in $conf->{lang} for '$template' - falling back to English..\n";
  305. } else {
  306. die("No such template '$template' in language file.\n");
  307. }
  308. }
  309. $hash{channel} = $conf->{channel};
  310. foreach my $key (sort keys %hash) {
  311. $text =~ s/\[:$key\]/$hash{$key}/;
  312. $text =~ s/ü/&uuml;/go;
  313. $text =~ s/ö/&ouml;/go;
  314. $text =~ s/ä/&auml;/go;
  315. $text =~ s/ß/&szlig;/go;
  316. $text =~ s/å/&aring;/go;
  317. $text =~ s/æ/&aelig;/go;
  318. $text =~ s/ø/&oslash;/go;
  319. }
  320. if ($text =~ /\[:.*?:.*?:\]/o) {
  321. $text =~ s/\[:(.*?):(.*?):\]/get_subst($1,$2,\%hash)/geo;
  322. }
  323. return $text;
  324. }
  325. sub get_subst {
  326. my ($m,$f,$hash) = @_;
  327. if ($hash->{nick} && $users->{sex}{$hash->{nick}}) {
  328. if ($users->{sex}{$hash->{nick}} eq 'm') {
  329. return $m;
  330. } elsif ($users->{sex}{$hash->{nick}} eq 'f') {
  331. return $f;
  332. }
  333. }
  334. return "$m/$f";
  335. }
  336. sub replace_links {
  337. # Sub to replace urls and e-mail addys to links
  338. my $str = shift;
  339. my $nick = shift;
  340. my ($url, $email);
  341. if ($nick) {
  342. if ($url = match_url($str)) {
  343. $str =~ s/(\Q$url\E)/<a href="$1" target="_blank" title="Open in new window: $1">$nick<\/a>/g;
  344. }
  345. if ($email = match_email($str)) {
  346. $str =~ s/(\Q$email\E)/<a href="mailto:$1" title="Mail to $nick">$nick<\/a>/g;
  347. }
  348. } else {
  349. if ($url = match_url($str)) {
  350. $str =~ s/(\Q$url\E)/<a href="$1" target="_blank" title="Open in new window: $1">$1<\/a>/g;
  351. }
  352. if ($email = match_email($str)) {
  353. $str =~ s/(\Q$email\E)/<a href="mailto:$1" title="Mail to $1">$1<\/a>/g;
  354. }
  355. }
  356. return $str;
  357. }
  358. $debug = sub {
  359. if ($conf->{debug} or not $conf->{debugstarted}) {
  360. my $debugline = $_[0] . "\n";
  361. if ($conf->{debugstarted}) {
  362. print DEBUG $debugline;
  363. } else {
  364. $conf->{debugqueue} .= $debugline;
  365. }
  366. }
  367. };
  368. sub create_html {
  369. # This is where all subroutines get executed, you can actually design
  370. # your own layout here, the lines should be self-explainable
  371. my ($stats) = @_;
  372. print "Now generating HTML($conf->{outputfile})...\n";
  373. open (OUTPUT, "> $conf->{outputfile}") or
  374. die("$0: Unable to open outputfile($conf->{outputfile}): $!\n");
  375. if ($conf->{show_time}) {
  376. $conf->{tablewidth} += 40;
  377. }
  378. if ($conf->{show_words}) {
  379. $conf->{tablewidth} += 40;
  380. }
  381. if ($conf->{show_wpl}) {
  382. $conf->{tablewidth} += 40;
  383. }
  384. if ($conf->{show_cpl}) {
  385. $conf->{tablewidth} += 40;
  386. }
  387. $conf->{headwidth} = $conf->{tablewidth} - 4;
  388. htmlheader($stats);
  389. pageheader($stats);
  390. activetimes($stats);
  391. activenicks($stats);
  392. headline(template_text('bignumtopic'));
  393. html("<table width=\"$conf->{tablewidth}\">\n"); # Needed for sections
  394. questions($stats);
  395. shoutpeople($stats);
  396. capspeople($stats);
  397. violent($stats);
  398. mostsmiles($stats);
  399. mostsad($stats);
  400. linelengths($stats);
  401. mostwords($stats);
  402. mostwordsperline($stats);
  403. html("</table>"); # Needed for sections
  404. mostusedword($stats);
  405. mostreferencednicks($stats);
  406. mosturls($stats);
  407. headline(template_text('othernumtopic'));
  408. html("<table width=\"$conf->{tablewidth}\">\n"); # Needed for sections
  409. gotkicks($stats);
  410. mostkicks($stats);
  411. mostop($stats);
  412. mostactions($stats);
  413. mostmonologues($stats);
  414. mostjoins($stats);
  415. mostfoul($stats);
  416. html("</table>"); # Needed for sections
  417. headline(template_text('latesttopic'));
  418. html("<table width=\"$conf->{tablewidth}\">\n"); # Needed for sections
  419. lasttopics($stats);
  420. html("</table>"); # Needed for sections
  421. my %hash = ( lines => $stats->{totallines} );
  422. html(template_text('totallines', %hash) . "<br><br>");
  423. htmlfooter($stats);
  424. close(OUTPUT);
  425. }
  426. sub activetimes {
  427. # The most actives times on the channel
  428. my ($stats) = @_;
  429. my (%output, $tbgcolor);
  430. &headline(template_text('activetimestopic'));
  431. my @toptime = sort { $stats->{times}{$b} <=> $stats->{times}{$a} } keys %{ $stats->{times} };
  432. my $highest_value = $stats->{times}{$toptime[0]};
  433. my @now = localtime($timestamp);
  434. my $image;
  435. for my $hour (sort keys %{ $stats->{times} }) {
  436. $debug->("Time: $hour => ". $stats->{times}{$hour});
  437. my $size = ($stats->{times}{$hour} / $highest_value) * 100;
  438. my $percent = ($stats->{times}{$hour} / $stats->{totallines}) * 100;
  439. $percent =~ s/(\.\d)\d+/$1/;
  440. if ($size < 1 && $size != 0) {
  441. # Opera doesn't understand '0.xxxx' in the height="xx" attr,
  442. # so we simply round up to 1.0 here.
  443. $size = 1.0;
  444. }
  445. if ($conf->{timeoffset} =~ /\+(\d+)/) {
  446. # We must plus some hours to the time
  447. $hour += $1;
  448. $hour = $hour % 24;
  449. if ($hour < 10) { $hour = "0" . $hour; }
  450. } elsif ($conf->{timeoffset} =~ /-(\d+)/) {
  451. # We must remove some hours from the time
  452. $hour -= $1;
  453. $hour = $hour % 24;
  454. if ($hour < 10) { $hour = "0" . $hour; }
  455. }
  456. $image = "pic_v_".(int($hour/6)*6);
  457. $image = $conf->{$image};
  458. $debug->("Image: $image");
  459. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br><img src=\"$image\" width=\"15\" height=\"$size\" alt=\"$percent\"></td>\n";
  460. }
  461. html("<table border=\"0\" width=\"$conf->{tablewidth}\"><tr>\n");
  462. for ($b = 0; $b < 24; $b++) {
  463. if ($b < 10) { $a = "0" . $b; } else { $a = $b; }
  464. if (!defined($output{$a}) || $output{$a} eq "") {
  465. html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  466. } else {
  467. html($output{$a});
  468. }
  469. }
  470. html("</tr><tr>");
  471. for ($b = 0; $b < 24; $b++) {
  472. if ($now[2] == $b) { $tbgcolor = "\#AAAAAA"; } else { $tbgcolor = "\#CCCCCC"; }
  473. html("<td bgcolor=\"$tbgcolor\" align=\"center\" class=\"small\">$b</td>");
  474. }
  475. html("</tr></table>");
  476. if($conf->{show_legend} == 1) {
  477. &legend();
  478. }
  479. }
  480. sub legend
  481. {
  482. html("<table align=\"center\" border=\"0\" width=\"520\"><tr>");
  483. html("<td align=\"center\" class=\"asmall\"><img src=\"$conf->{pic_h_0}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 0-5</td>");
  484. html("<td align=\"center\" class=\"asmall\"><img src=\"$conf->{pic_h_6}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 6-11</td>");
  485. html("<td align=\"center\" class=\"asmall\"><img src=\"$conf->{pic_h_12}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 12-17</td>");
  486. html("<td align=\"center\" class=\"asmall\"><img src=\"$conf->{pic_h_18}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 18-23</td>");
  487. html("</tr></table>\n");
  488. }
  489. sub activenicks {
  490. # The most active nicks (those who wrote most lines)
  491. my ($stats) = @_;
  492. headline(template_text('activenickstopic'));
  493. html("<table border=\"0\" width=\"$conf->{tablewidth}\"><tr>");
  494. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>"
  495. . template_text('nick') . "</b></td><td bgcolor=\"$conf->{tdtop}\"><b>"
  496. . template_text('numberlines')
  497. . "</b></td><td bgcolor=\"$conf->{tdtop}\"><b>"
  498. . ($conf->{show_time} ? template_text('show_time')."</b></td><td bgcolor=\"$conf->{tdtop}\"><b>" : "")
  499. . ($conf->{show_words} ? template_text('show_words')."</b></td><td bgcolor=\"$conf->{tdtop}\"><b>" : "")
  500. . ($conf->{show_wpl} ? template_text('show_wpl')."</b></td><td bgcolor=\"$conf->{tdtop}\"><b>" : "")
  501. . ($conf->{show_cpl} ? template_text('show_cpl')."</b></td><td bgcolor=\"$conf->{tdtop}\"><b>" : "")
  502. . template_text('randquote') ."</b></td>");
  503. if (scalar keys %{$users->{userpics}} > 0) {
  504. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('userpic') ."</b></td>");
  505. }
  506. html("</tr>");
  507. my @active = sort { $stats->{lines}{$b} <=> $stats->{lines}{$a} } keys %{ $stats->{lines} };
  508. my $nicks = scalar keys %{ $stats->{lines} };
  509. if ($conf->{activenicks} > $nicks) {
  510. $conf->{activenicks} = $nicks;
  511. print "Note: There were fewer nicks in the logfile than your specificied there to be in most active nicks...\n";
  512. }
  513. my ($nick, $visiblenick, $randomline, %hash);
  514. my $i = 1;
  515. for (my $c = 0; $c < $conf->{activenicks}; $c++) {
  516. $nick = $active[$c];
  517. $visiblenick = $active[$c];
  518. if (not defined $stats->{sayings}{$nick}) {
  519. $randomline = "";
  520. } else {
  521. $randomline = htmlentities($stats->{sayings}{$nick});
  522. }
  523. # Convert URLs and e-mail addys to links
  524. $randomline = replace_links($randomline);
  525. # Add a link to the nick if there is any
  526. if ($users->{userlinks}{$nick}) {
  527. $visiblenick = replace_links($users->{userlinks}{$nick}, $nick);
  528. }
  529. my $h = $conf->{hicell};
  530. $h =~ s/^#//;
  531. $h = hex $h;
  532. my $h2 = $conf->{hicell2};
  533. $h2 =~ s/^#//;
  534. $h2 = hex $h2;
  535. my $f_b = $h & 0xff;
  536. my $f_g = ($h & 0xff00) >> 8;
  537. my $f_r = ($h & 0xff0000) >> 16;
  538. my $t_b = $h2 & 0xff;
  539. my $t_g = ($h2 & 0xff00) >> 8;
  540. my $t_r = ($h2 & 0xff0000) >> 16;
  541. my $col_b = sprintf "%0.2x", abs int(((($t_b - $f_b) / $conf->{activenicks}) * +$c) + $f_b);
  542. my $col_g = sprintf "%0.2x", abs int(((($t_g - $f_g) / $conf->{activenicks}) * +$c) + $f_g);
  543. my $col_r = sprintf "%0.2x", abs int(((($t_r - $f_r) / $conf->{activenicks}) * +$c) + $f_r);
  544. html("<tr><td bgcolor=\"$conf->{rankc}\" align=\"left\">");
  545. my $line = $stats->{lines}{$nick};
  546. my $w = $stats->{words}{$nick};
  547. my $ch = $stats->{lengths}{$nick};
  548. html("$i</td><td bgcolor=\"#$col_r$col_g$col_b\">$visiblenick</td>"
  549. . ($conf->{show_linetime} ?
  550. "<td bgcolor=\"$col_r$col_g$col_b\">".user_linetimes($stats,$nick,$active[0])."</td>"
  551. : "<td bgcolor=\"#$col_r$col_g$col_b\">$line</td>")
  552. . ($conf->{show_time} ?
  553. "<td bgcolor=\"$col_r$col_g$col_b\">".user_times($stats,$nick)."</td>"
  554. : "")
  555. . ($conf->{show_words} ?
  556. "<td bgcolor=\"#$col_r$col_g$col_b\">$w</td>"
  557. : "")
  558. . ($conf->{show_wpl} ?
  559. "<td bgcolor=\"#$col_r$col_g$col_b\">".sprintf("%.1f",$w/$line)."</td>"
  560. : "")
  561. . ($conf->{show_cpl} ?
  562. "<td bgcolor=\"#$col_r$col_g$col_b\">".sprintf("%.1f",$ch/$line)."</td>"
  563. : "")
  564. ."<td bgcolor=\"#$col_r$col_g$col_b\">");
  565. html("\"$randomline\"</td>");
  566. if ($users->{userpics}{$nick}) {
  567. html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$conf->{imagepath}$users->{userpics}{$nick}\"></td>");
  568. }
  569. html("</tr>");
  570. $i++;
  571. }
  572. html("</table><br>");
  573. # Almost as active nicks ('These didn't make it to the top..')
  574. my $nickstoshow = $conf->{activenicks} + $conf->{activenicks2};
  575. $hash{totalnicks} = $nicks - $nickstoshow;
  576. unless ($nickstoshow > $nicks) {
  577. html("<br><b><i>" . template_text('nottop') . "</i></b><table><tr>");
  578. for (my $c = $conf->{activenicks}; $c < $nickstoshow; $c++) {
  579. unless ($c % 5) { unless ($c == $conf->{activenicks}) { html("</tr><tr>"); } }
  580. html("<td bgcolor=\"$conf->{rankc}\" class=\"small\">");
  581. my $nick = $active[$c];
  582. my $lines = $stats->{lines}{$nick};
  583. html("$nick ($lines)</td>");
  584. }
  585. html("</table>");
  586. }
  587. if($hash{totalnicks} > 0) {
  588. html("<br><b>" . template_text('totalnicks', %hash) . "</b><br>");
  589. }
  590. }
  591. sub user_linetimes {
  592. my $stats = shift;
  593. my $nick = shift;
  594. my $top = shift;
  595. my $bar = "";
  596. my $len = ($stats->{lines}{$nick} / $stats->{lines}{$top}) * 100;
  597. my $debuglen = 0;
  598. for (my $i = 0; $i <= 3; $i++) {
  599. next if not defined $stats->{line_times}{$nick}[$i];
  600. my $w = int(($stats->{line_times}{$nick}[$i] / $stats->{lines}{$nick}) * $len);
  601. $debuglen += $w;
  602. if ($w) {
  603. my $pic = 'pic_h_'.(6*$i);
  604. $bar .= "<img src=\"$conf->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\">";
  605. }
  606. }
  607. $debug->("Length='$len', Sum='$debuglen'");
  608. return "$bar&nbsp;$stats->{lines}{$nick}";
  609. }
  610. sub user_times {
  611. my ($stats, $nick) = @_;
  612. my $bar = "";
  613. for (my $i = 0; $i <= 3; $i++) {
  614. next if not defined $stats->{line_times}{$nick}[$i];
  615. my $w = int(($stats->{line_times}{$nick}[$i] / $stats->{lines}{$nick}) * 40);
  616. if ($w) {
  617. my $pic = 'pic_h_'.(6*$i);
  618. $bar .= "<img src=\"$conf->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\">";
  619. }
  620. }
  621. return $bar;
  622. }
  623. sub mostusedword {
  624. # Lao the infamous word usage statistics
  625. my ($stats) = @_;
  626. my %usages;
  627. foreach my $word (keys %{ $stats->{wordcounts} }) {
  628. # Skip people's nicks.
  629. next if exists $stats->{lines}{$word};
  630. $usages{$word} = $stats->{wordcounts}{$word};
  631. }
  632. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  633. if (@popular) {
  634. &headline(template_text('mostwordstopic'));
  635. html("<table border=\"0\" width=\"$conf->{tablewidth}\"><tr>");
  636. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('word') . "</b></td>");
  637. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  638. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  639. my $count = 0;
  640. for(my $i = 0; $count < 10; $i++) {
  641. last unless $i < $#popular;
  642. # Skip nicks. It's far more efficient to do this here than when
  643. # @popular is created.
  644. next if is_ignored($popular[$i]);
  645. next if exists $stats->{lines}{find_alias($popular[$i])};
  646. my $a = $count + 1;
  647. my $popular = htmlentities($popular[$i]);
  648. my $wordcount = $stats->{wordcounts}{$popular[$i]};
  649. my $lastused = htmlentities($stats->{wordnicks}{$popular[$i]});
  650. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  651. html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
  652. html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
  653. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  654. html("</tr>");
  655. $count++;
  656. }
  657. html("</table>");
  658. }
  659. }
  660. sub mostwordsperline {
  661. # The person who got words the most
  662. my ($stats) = @_;
  663. my %wpl = ();
  664. my ($numlines,$avg,$numwords);
  665. foreach my $n (keys %{ $stats->{words} }) {
  666. $wpl{$n} = sprintf("%.2f", $stats->{words}{$n}/$stats->{lines}{$n});
  667. $numlines += $stats->{lines}{$n};
  668. $numwords += $stats->{words}{$n};
  669. }
  670. $avg = sprintf("%.2f", $numwords/$numlines);
  671. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  672. if (@wpl) {
  673. my %hash = (
  674. nick => $wpl[0],
  675. wpl => $wpl{$wpl[0]}
  676. );
  677. my $text = template_text('wpl1', %hash);
  678. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  679. %hash = (
  680. avg => $avg
  681. );
  682. $text = template_text('wpl2', %hash);
  683. html("<br><span class=\"small\">$text</span>");
  684. html("</td></tr>");
  685. }
  686. }
  687. sub mostreferencednicks {
  688. my ($stats) = @_;
  689. my (%usages);
  690. foreach my $word (sort keys %{ $stats->{wordcounts} }) {
  691. next unless exists $stats->{lines}{$word};
  692. next if is_ignored($word);
  693. $usages{$word} = $stats->{wordcounts}{$word};
  694. }
  695. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  696. if (@popular) {
  697. &headline(template_text('referencetopic'));
  698. html("<table border=\"0\" width=\"$conf->{tablewidth}\"><tr>");
  699. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('nick') . "</b></td>");
  700. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  701. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  702. for(my $i = 0; $i < 5; $i++) {
  703. last unless $i < $#popular;
  704. my $a = $i + 1;
  705. my $popular = $popular[$i];
  706. my $wordcount = $stats->{wordcounts}{$popular[$i]};
  707. my $lastused = $stats->{wordnicks}{$popular[$i]};
  708. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  709. html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
  710. html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
  711. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  712. html("</tr>");
  713. }
  714. html("</table>");
  715. }
  716. }
  717. sub mosturls {
  718. my ($stats) = @_;
  719. my @sorturls = sort { $stats->{urlcounts}{$b} <=> $stats->{urlcounts}{$a} }
  720. keys %{ $stats->{urlcounts} };
  721. if (@sorturls) {
  722. &headline(template_text('urlstopic'));
  723. html("<table border=\"0\" width=\"$conf->{tablewidth}\"><tr>");
  724. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('url') . "</b></td>");
  725. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  726. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  727. for(my $i = 0; $i < 5; $i++) {
  728. last unless $i < $#sorturls;
  729. my $a = $i + 1;
  730. my $sorturl = $sorturls[$i];
  731. my $urlcount = $stats->{urlcounts}{$sorturls[$i]};
  732. my $lastused = $stats->{urlnicks}{$sorturls[$i]};
  733. if (length($sorturl) > 60) {
  734. $sorturl = substr($sorturl, 0, 60);
  735. }
  736. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  737. html("<td bgcolor=\"$conf->{hicell}\"><a href=\"$sorturls[$i]\">$sorturl</a></td>");
  738. html("<td bgcolor=\"$conf->{hicell}\">$urlcount</td>");
  739. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  740. html("</tr>");
  741. }
  742. html("</table>");
  743. }
  744. }
  745. sub questions {
  746. # Persons who asked the most questions
  747. my ($stats) = @_;
  748. my %qpercent;
  749. foreach my $nick (sort keys %{ $stats->{questions} }) {
  750. if ($stats->{lines}{$nick} > 100) {
  751. $qpercent{$nick} = ($stats->{questions}{$nick} / $stats->{lines}{$nick}) * 100;
  752. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  753. }
  754. }
  755. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  756. if (@question) {
  757. my %hash = (
  758. nick => $question[0],
  759. per => $qpercent{$question[0]}
  760. );
  761. my $text = template_text('question1', %hash);
  762. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  763. if (@question >= 2) {
  764. my %hash = (
  765. nick => $question[1],
  766. per => $qpercent{$question[1]}
  767. );
  768. my $text = template_text('question2', %hash);
  769. html("<br><span class=\"small\">$text</span>");
  770. }
  771. html("</td></tr>");
  772. } else {
  773. html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('question3') . "</td></tr>");
  774. }
  775. }
  776. sub shoutpeople {
  777. # The ones who speak with exclamation points!
  778. my ($stats) = @_;
  779. my %spercent;
  780. foreach my $nick (sort keys %{ $stats->{shouts} }) {
  781. if ($stats->{lines}{$nick} > 100) {
  782. $spercent{$nick} = ($stats->{shouts}{$nick} / $stats->{lines}{$nick}) * 100;
  783. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  784. }
  785. }
  786. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  787. if (@shout) {
  788. my %hash = (
  789. nick => $shout[0],
  790. per => $spercent{$shout[0]}
  791. );
  792. my $text = template_text('shout1', %hash);
  793. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  794. if (@shout >= 2) {
  795. my %hash = (
  796. nick => $shout[1],
  797. per => $spercent{$shout[1]}
  798. );
  799. my $text = template_text('shout2', %hash);
  800. html("<br><span class=\"small\">$text</span>");
  801. }
  802. html("</td></tr>");
  803. } else {
  804. my $text = template_text('shout3');
  805. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  806. }
  807. }
  808. sub capspeople {
  809. # The ones who speak ALL CAPS.
  810. my ($stats) = @_;
  811. my %cpercent;
  812. foreach my $nick (sort keys %{ $stats->{allcaps} }) {
  813. if ($stats->{lines}{$nick} > 100) {
  814. $cpercent{$nick} = $stats->{allcaps}{$nick} / $stats->{lines}{$nick} * 100;
  815. $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
  816. }
  817. }
  818. my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent;
  819. if (@caps) {
  820. my %hash = (
  821. nick => $caps[0],
  822. per => $cpercent{$caps[0]},
  823. line => htmlentities($stats->{allcaplines}{$caps[0]})
  824. );
  825. my $text = template_text('allcaps1', %hash);
  826. if($conf->{show_shoutline}) {
  827. my $exttext = template_text('allcapstext', %hash);
  828. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  829. } else {
  830. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  831. }
  832. if (@caps >= 2) {
  833. my %hash = (
  834. nick => $caps[1],
  835. per => $cpercent{$caps[1]}
  836. );
  837. my $text = template_text('allcaps2', %hash);
  838. html("<br><span class=\"small\">$text</span>");
  839. }
  840. html("</td></tr>");
  841. } else {
  842. my $text = template_text('allcaps3');
  843. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  844. }
  845. }
  846. sub violent {
  847. # They attacked others
  848. my ($stats) = @_;
  849. my @aggressors;
  850. @aggressors = sort { $stats->{violence}{$b} <=> $stats->{violence}{$a} }
  851. keys %{ $stats->{violence} };
  852. if(@aggressors) {
  853. my %hash = (
  854. nick => $aggressors[0],
  855. attacks => $stats->{violence}{$aggressors[0]},
  856. line => htmlentities($stats->{violencelines}{$aggressors[0]})
  857. );
  858. my $text = template_text('violent1', %hash);
  859. if($conf->{show_violentlines}) {
  860. my $exttext = template_text('violenttext', %hash);
  861. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  862. } else {
  863. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  864. }
  865. if (@aggressors >= 2) {
  866. my %hash = (
  867. nick => $aggressors[1],
  868. attacks => $stats->{violence}{$aggressors[1]}
  869. );
  870. my $text = template_text('violent2', %hash);
  871. html("<br><span class=\"small\">$text</span>");
  872. }
  873. html("</td></tr>");
  874. } else {
  875. my $text = template_text('violent3');
  876. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  877. }
  878. # They got attacked
  879. my @victims;
  880. @victims = sort { $stats->{attacked}{$b} <=> $stats->{attacked}{$a} }
  881. keys %{ $stats->{attacked} };
  882. if(@victims) {
  883. my %hash = (
  884. nick => $victims[0],
  885. attacks => $stats->{attacked}{$victims[0]},
  886. line => htmlentities($stats->{attackedlines}{$victims[0]})
  887. );
  888. my $text = template_text('attacked1', %hash);
  889. if($conf->{show_violentlines}) {
  890. my $exttext = template_text('attackedtext', %hash);
  891. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  892. } else {
  893. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  894. }
  895. if (@victims >= 2) {
  896. my %hash = (
  897. nick => $victims[1],
  898. attacks => $stats->{attacked}{$victims[1]}
  899. );
  900. my $text = template_text('attacked2', %hash);
  901. html("<br><span class=\"small\">$text</span>");
  902. }
  903. html("</td></tr>");
  904. }
  905. }
  906. sub gotkicks {
  907. # The persons who got kicked the most
  908. my ($stats) = @_;
  909. my @gotkick = sort { $stats->{gotkicked}{$b} <=> $stats->{gotkicked}{$a} }
  910. keys %{ $stats->{gotkicked} };
  911. if (@gotkick) {
  912. my %hash = (
  913. nick => $gotkick[0],
  914. kicks => $stats->{gotkicked}{$gotkick[0]},
  915. line => $stats->{kicklines}{$gotkick[0]}
  916. );
  917. my $text = template_text('gotkick1', %hash);
  918. if ($conf->{show_kickline}) {
  919. my $exttext = template_text('kicktext', %hash);
  920. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  921. } else {
  922. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  923. }
  924. if (@gotkick >= 2) {
  925. my %hash = (
  926. nick => $gotkick[1],
  927. kicks => $stats->{gotkicked}{$gotkick[1]}
  928. );
  929. my $text = template_text('gotkick2', %hash);
  930. html("<br><span class=\"small\">$text</span>");
  931. }
  932. html("</td></tr>");
  933. }
  934. }
  935. sub mostjoins {
  936. my ($stats) = @_;
  937. my @joins = sort { $stats->{joins}{$b} <=> $stats->{joins}{$a} }
  938. keys %{ $stats->{joins} };
  939. if (@joins) {
  940. my %hash = (
  941. nick => $joins[0],
  942. joins => $stats->{joins}{$joins[0]}
  943. );
  944. my $text = template_text('joins', %hash);
  945. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  946. }
  947. }
  948. sub mostwords {
  949. # The person who got words the most
  950. my ($stats) = @_;
  951. my @words = sort { $stats->{words}{$b} <=> $stats->{words}{$a} }
  952. keys %{ $stats->{words} };
  953. if (@words) {
  954. my %hash = (
  955. nick => $words[0],
  956. words => $stats->{words}{$words[0]}
  957. );
  958. my $text = template_text('words1', %hash);
  959. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  960. if (@words >= 2) {
  961. my %hash = (
  962. oldnick => $words[0],
  963. nick => $words[1],
  964. words => $stats->{words}{$words[1]}
  965. );
  966. my $text = template_text('words2', %hash);
  967. html("<br><span class=\"small\">$text</span>");
  968. }
  969. html("</td></tr>");
  970. } else {
  971. my $text = template_text('kick3');
  972. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  973. }
  974. }
  975. sub mostkicks {
  976. # The person who got kicked the most
  977. my ($stats) = @_;
  978. my @kicked = sort { $stats->{kicked}{$b} <=> $stats->{kicked}{$a} }
  979. keys %{ $stats->{kicked} };
  980. if (@kicked) {
  981. my %hash = (
  982. nick => $kicked[0],
  983. kicked => $stats->{kicked}{$kicked[0]}
  984. );
  985. my $text = template_text('kick1', %hash);
  986. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  987. if (@kicked >= 2) {
  988. my %hash = (
  989. oldnick => $kicked[0],
  990. nick => $kicked[1],
  991. kicked => $stats->{kicked}{$kicked[1]}
  992. );
  993. my $text = template_text('kick2', %hash);
  994. html("<br><span class=\"small\">$text</span>");
  995. }
  996. html("</td></tr>");
  997. } else {
  998. my $text = template_text('kick3');
  999. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1000. }
  1001. }
  1002. sub mostmonologues {
  1003. # The person who had the most monologues (speaking to himself)
  1004. my ($stats) = @_;
  1005. my @monologue = sort { $stats->{monologues}{$b} <=> $stats->{monologues}{$a} } keys %{ $stats->{monologues} };
  1006. if (@monologue) {
  1007. my %hash = (
  1008. nick => $monologue[0],
  1009. monos => $stats->{monologues}{$monologue[0]}
  1010. );
  1011. my $text = template_text('mono1', %hash);
  1012. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1013. if (@monologue >= 2) {
  1014. my %hash = (
  1015. nick => $monologue[1],
  1016. monos => $stats->{monologues}{$monologue[1]}
  1017. );
  1018. my $text = template_text('mono2', %hash);
  1019. html("<br><span class=\"small\">$text</span>");
  1020. }
  1021. html("</td></tr>");
  1022. }
  1023. }
  1024. sub linelengths {
  1025. # The person(s) who wrote the longest lines
  1026. my ($stats) = @_;
  1027. my %len;
  1028. foreach my $nick (sort keys %{ $stats->{lengths} }) {
  1029. if ($stats->{lines}{$nick} > 100) {
  1030. $len{$nick} = $stats->{lengths}{$nick} / $stats->{lines}{$nick};
  1031. $len{$nick} =~ s/(\.\d)\d+/$1/;
  1032. }
  1033. }
  1034. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  1035. my $all_lines;
  1036. my $totallength;
  1037. foreach my $nick (keys %{ $stats->{lines} }) {
  1038. $all_lines += $stats->{lines}{$nick};
  1039. $totallength += $stats->{lengths}{$nick};
  1040. }
  1041. my $totalaverage;
  1042. if ($all_lines > 0) {
  1043. $totalaverage = $totallength / $all_lines;
  1044. $totalaverage =~ s/(\.\d)\d+/$1/;
  1045. }
  1046. if (@len) {
  1047. my %hash = (
  1048. nick => $len[0],
  1049. letters => $len{$len[0]}
  1050. );
  1051. my $text = template_text('long1', %hash);
  1052. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
  1053. if (@len >= 2) {
  1054. %hash = (
  1055. avg => $totalaverage
  1056. );
  1057. $text = template_text('long2', %hash);
  1058. html("<span class=\"small\">$text</span></td></tr>");
  1059. }
  1060. }
  1061. # The person(s) who wrote the shortest lines
  1062. if (@len) {
  1063. my %hash = (
  1064. nick => $len[$#len],
  1065. letters => $len{$len[$#len]}
  1066. );
  1067. my $text = template_text('short1', %hash);
  1068. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
  1069. if (@len >= 2) {
  1070. %hash = (
  1071. nick => $len[$#len - 1],
  1072. letters => $len{$len[$#len - 1]}
  1073. );
  1074. $text = template_text('short2', %hash);
  1075. html("<span class=\"small\">$text</span></td></tr>");
  1076. }
  1077. }
  1078. }
  1079. sub mostfoul {
  1080. my ($stats) = @_;
  1081. my %spercent;
  1082. foreach my $nick (sort keys %{ $stats->{foul} }) {
  1083. if ($stats->{lines}{$nick} > 15) {
  1084. $spercent{$nick} = $stats->{foul}{$nick} / $stats->{lines}{$nick} * 100;
  1085. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1086. }
  1087. }
  1088. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1089. if (@foul) {
  1090. my %hash = (
  1091. nick => $foul[0],
  1092. per => $spercent{$foul[0]}
  1093. );
  1094. my $text = template_text('foul1', %hash);
  1095. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1096. if (@foul >= 2) {
  1097. my %hash = (
  1098. nick => $foul[1],
  1099. per => $spercent{$foul[1]}
  1100. );
  1101. my $text = template_text('foul2', %hash);
  1102. html("<br><span class=\"small\">$text</span>");
  1103. }
  1104. html("</td></tr>");
  1105. } else {
  1106. my $text = template_text('foul3');
  1107. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1108. }
  1109. }
  1110. sub mostsad {
  1111. my ($stats) = @_;
  1112. my %spercent;
  1113. foreach my $nick (sort keys %{ $stats->{frowns} }) {
  1114. if ($stats->{lines}{$nick} > 100) {
  1115. $spercent{$nick} = $stats->{frowns}{$nick} / $stats->{lines}{$nick} * 100;
  1116. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1117. }
  1118. }
  1119. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1120. if (@sadface) {
  1121. my %hash = (
  1122. nick => $sadface[0],
  1123. per => $spercent{$sadface[0]}
  1124. );
  1125. my $text = template_text('sad1', %hash);
  1126. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1127. if (@sadface >= 2) {
  1128. my %hash = (
  1129. nick => $sadface[1],
  1130. per => $spercent{$sadface[1]}
  1131. );
  1132. my $text = template_text('sad2', %hash);
  1133. html("<br><span class=\"small\">$text</span>");
  1134. }
  1135. html("</td></tr>");
  1136. } else {
  1137. my $text = template_text('sad3');
  1138. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1139. }
  1140. }
  1141. sub mostop {
  1142. my ($stats) = @_;
  1143. my @ops = sort { $stats->{gaveops}{$b} <=> $stats->{gaveops}{$a} }
  1144. keys %{ $stats->{gaveops} };
  1145. my @deops = sort { $stats->{tookops}{$b} <=> $stats->{tookops}{$a} }
  1146. keys %{ $stats->{tookops} };
  1147. if (@ops) {
  1148. my %hash = (
  1149. nick => $ops[0],
  1150. ops => $stats->{gaveops}{$ops[0]}
  1151. );
  1152. my $text = template_text('mostop1', %hash);
  1153. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1154. if (@ops >= 2) {
  1155. my %hash = (
  1156. nick => $ops[1],
  1157. ops => $stats->{gaveops}{$ops[1]}
  1158. );
  1159. my $text = template_text('mostop2', %hash);
  1160. html("<br><span class=\"small\">$text</span>");
  1161. }
  1162. html("</td></tr>");
  1163. } else {
  1164. my $text = template_text('mostop3');
  1165. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1166. }
  1167. if (@deops) {
  1168. my %hash = (
  1169. nick => $deops[0],
  1170. deops => $stats->{tookops}{$deops[0]}
  1171. );
  1172. my $text = template_text('mostdeop1', %hash);
  1173. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1174. if (@deops >= 2) {
  1175. my %hash = (
  1176. nick => $deops[1],
  1177. deops => $stats->{tookops}{$deops[1]}
  1178. );
  1179. my $text = template_text('mostdeop2', %hash);
  1180. html("<br><span class=\"small\">$text</span>");
  1181. }
  1182. html("</td></tr>");
  1183. } else {
  1184. my $text = template_text('mostdeop3');
  1185. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1186. }
  1187. }
  1188. sub mostactions {
  1189. # The person who did the most /me's
  1190. my ($stats) = @_;
  1191. my @actions = sort { $stats->{actions}{$b} <=> $stats->{actions}{$a} }
  1192. keys %{ $stats->{actions} };
  1193. if (@actions) {
  1194. my %hash = (
  1195. nick => $actions[0],
  1196. actions => $stats->{actions}{$actions[0]},
  1197. line => htmlentities($stats->{actionlines}{$actions[0]})
  1198. );
  1199. my $text = template_text('action1', %hash);
  1200. if($conf->{show_actionline}) {
  1201. my $exttext = template_text('actiontext', %hash);
  1202. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  1203. } else {
  1204. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1205. }
  1206. if (@actions >= 2) {
  1207. my %hash = (
  1208. nick => $actions[1],
  1209. actions => $stats->{actions}{$actions[1]}
  1210. );
  1211. my $text = template_text('action2', %hash);
  1212. html("<br><span class=\"small\">$text</span>");
  1213. }
  1214. html("</td></tr>");
  1215. } else {
  1216. my $text = template_text('action3');
  1217. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1218. }
  1219. }
  1220. sub mostsmiles {
  1221. # The person(s) who smiled the most :-)
  1222. my ($stats) = @_;
  1223. my %spercent;
  1224. foreach my $nick (sort keys %{ $stats->{smiles} }) {
  1225. if ($stats->{lines}{$nick} > 100) {
  1226. $spercent{$nick} = $stats->{smiles}{$nick} / $stats->{lines}{$nick} * 100;
  1227. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1228. }
  1229. }
  1230. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1231. if (@smiles) {
  1232. my %hash = (
  1233. nick => $smiles[0],
  1234. per => $spercent{$smiles[0]}
  1235. );
  1236. my $text = template_text('smiles1', %hash);
  1237. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1238. if (@smiles >= 2) {
  1239. my %hash = (
  1240. nick => $smiles[1],
  1241. per => $spercent{$smiles[1]}
  1242. );
  1243. my $text = template_text('smiles2', %hash);
  1244. html("<br><span class=\"small\">$text</span>");
  1245. }
  1246. html("</td></tr>");
  1247. } else {
  1248. my $text = template_text('smiles3');
  1249. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1250. }
  1251. }
  1252. sub lasttopics {
  1253. my ($stats) = @_;
  1254. if ($stats->{topics}) {
  1255. $debug->("Total number of topics: " . scalar @{ $stats->{topics} });
  1256. my %hash = (
  1257. total => scalar @{ $stats->{topics} }
  1258. );
  1259. my $ltopic = $#{ $stats->{topics} };
  1260. my $tlimit = 0;
  1261. $conf->{topichistory} -= 1;
  1262. if ($ltopic > $conf->{topichistory}) {
  1263. $tlimit = $ltopic - $conf->{topichistory};
  1264. }
  1265. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1266. my $topic = htmlentities($stats->{topics}[$i]{topic});
  1267. $topic = replace_links($stats->{topics}[$i]{topic});
  1268. # Strip off the quotes (')
  1269. $topic =~ s/^\'(.*)\'$/$1/;
  1270. my $nick = $stats->{topics}[$i]{nick};
  1271. my $hour = $stats->{topics}[$i]{hour};
  1272. my $min = $stats->{topics}[$i]{min};
  1273. html("<tr><td bgcolor=\"$conf->{hicell}\"><i>$topic</i></td>");
  1274. html("<td bgcolor=\"$conf->{hicell}\">By <b>$nick</b> at <b>$hour:$min</b></td></tr>");
  1275. }
  1276. html("<tr><td align=\"center\" colspan=\"2\" class=\"asmall\">" . template_text('totaltopic', %hash) . "</td></tr>");
  1277. } else {
  1278. html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('notopic') ."</td></tr>");
  1279. }
  1280. }
  1281. # Some HTML subs
  1282. sub htmlheader {
  1283. my ($stats) = @_;
  1284. my $bgpic = "";
  1285. if ($conf->{bgpic}) {
  1286. $bgpic = " background=\"$conf->{bgpic}\"";
  1287. }
  1288. print OUTPUT <<HTML;
  1289. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  1290. <html>
  1291. <head>
  1292. <title>$conf->{channel} @ $conf->{network} channel statistics</title>
  1293. <style type="text/css">
  1294. a { text-decoration: none }
  1295. a:link { color: $conf->{link}; }
  1296. a:visited { color: $conf->{vlink}; }
  1297. a:hover { text-decoration: underline; color: $conf->{hlink} }
  1298. body {
  1299. background-color: $conf->{bgcolor};
  1300. font-family: verdana, arial, sans-serif;
  1301. font-size: 13px;
  1302. color: $conf->{text};
  1303. }
  1304. td {
  1305. font-family: verdana, arial, sans-serif;
  1306. font-size: 13px;
  1307. color: $conf->{tdcolor};
  1308. }
  1309. .title {
  1310. font-family: tahoma, arial, sans-serif;
  1311. font-size: 16px;
  1312. font-weight: bold;
  1313. }
  1314. .headline { color: $conf->{hcolor}; }
  1315. .small { font-family: verdana, arial, sans-serif; font-size: 10px; }
  1316. .asmall {
  1317. font-family: arial narrow, sans-serif;
  1318. font-size: 10px;
  1319. color: $conf->{text};
  1320. }
  1321. </style></head>
  1322. <body$bgpic>
  1323. <div align="center">
  1324. HTML
  1325. my %hash = (
  1326. network => $conf->{network},
  1327. maintainer => $conf->{maintainer},
  1328. time => $time,
  1329. days => $stats->{days},
  1330. nicks => scalar keys %{ $stats->{lines} }
  1331. );
  1332. print OUTPUT "<span class=\"title\">" . template_text('pagetitle1', %hash) . "</span><br>";
  1333. print OUTPUT "<br>";
  1334. print OUTPUT template_text('pagetitle2', %hash);
  1335. sub timefix {
  1336. my ($timezone, $sec, $min, $hour, $mday, $mon, $year, $wday, $month, $day, $tday, $wdisplay, @month, @day, $timefixx, %hash);
  1337. $month = template_text('month', %hash);
  1338. $day = template_text('day', %hash);
  1339. @month=split / /, $month;
  1340. @day=split / /, $day;
  1341. # Get the Date from the users computer
  1342. $timezone = $conf->{timeoffset} * 3600;
  1343. ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+$timezone);
  1344. $year += 1900; # Y2K Patch
  1345. $min =~ s/^(.)$/0$1/; # Fixes the display of mins/secs below
  1346. $sec =~ s/^(.)$/0$1/; # it displays 03 instead of 3
  1347. if($hour > '23') { # Checks to see if it Midnight
  1348. $hour = 12; # Makes it display the hour 12
  1349. $tday = "AM"; # Display AM
  1350. }
  1351. elsif($hour > '12') { # Get rid of the Military time and
  1352. $hour -= 12; # put it into normal time
  1353. $tday = "PM"; # If past Noon and before Midnight set
  1354. } # the time as PM
  1355. else {
  1356. $tday = "AM"; # If it's past Midnight and before Noon
  1357. } # set the time as AM
  1358. # Use 24 hours pr. day
  1359. if($tday eq "PM" && $hour < '12') {
  1360. $hour += 12;
  1361. }
  1362. print OUTPUT "$day[$wday] $mday $month[$mon] $year - $hour:$min:$sec\n";
  1363. }
  1364. timefix();
  1365. print OUTPUT "<br>" . template_text('pagetitle3', %hash) . "<br><br>";
  1366. }
  1367. sub htmlfooter {
  1368. my ($stats) = @_;
  1369. print OUTPUT <<HTML;
  1370. <span class="small">
  1371. Stats generated by <a href="http://pisg.sourceforge.net/" title="Go to the pisg homepage">pisg</a> $conf->{version}<br>
  1372. pisg by <a href="http://www.wtf.dk/hp/" title="Go to the authors homepage">Morten "LostStar" Brix Pedersen</a> and others<br>
  1373. Stats generated in $stats->{processtime}
  1374. </span>
  1375. </div>
  1376. </body>
  1377. </html>
  1378. HTML
  1379. }
  1380. sub headline
  1381. {
  1382. my ($title) = @_;
  1383. print OUTPUT <<HTML;
  1384. <br>
  1385. <table width="$conf->{headwidth}" cellpadding="1" cellspacing="0" border="0">
  1386. <tr>
  1387. <td bgcolor="$conf->{headline}">
  1388. <table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">
  1389. <tr>
  1390. <td bgcolor="$conf->{hbgcolor}" class="text10">
  1391. <div align="center" class="headline"><b>$title</b></div>
  1392. </td>
  1393. </tr>
  1394. </table>
  1395. </td>
  1396. </tr>
  1397. </table>
  1398. HTML
  1399. }
  1400. sub pageheader
  1401. {
  1402. if ($conf->{pagehead} ne 'none') {
  1403. open(PAGEHEAD, $conf->{pagehead}) or die("$0: Unable to open $conf->{pagehead} for reading: $!\n");
  1404. while (<PAGEHEAD>) {
  1405. html($_);
  1406. }
  1407. }
  1408. }
  1409. sub close_debug
  1410. {
  1411. if ($conf->{debug}) {
  1412. close(DEBUG) or print STDERR "$0: Cannot close debugfile($conf->{debugfile}): $!\n";
  1413. }
  1414. }
  1415. sub get_cmdlineoptions
  1416. {
  1417. my $tmp;
  1418. # Commandline options
  1419. my ($moduledir, $channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help);
  1420. my $usage = <<END_USAGE;
  1421. Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma
  1422. maintainer] [-f format] [-n network] [-d logdir] [-a aliasfile]
  1423. [-i ignorefile] [-mo moduledir] [-h]
  1424. -ch --channel=xxx : Set channel name
  1425. -l --logfile=xxx : Log file to parse
  1426. -o --outfile=xxx : Name of html file to create
  1427. -ma --maintainer=xxx : Channel/statistics maintainer
  1428. -f --format=xxx : Logfile format [see FORMATS file]
  1429. -n --network=xxx : IRC Network this channel is on.
  1430. -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
  1431. -p --prefix=xxx : Analyse only files starting with xxx in dir.
  1432. Only works with --dir
  1433. -mo --moduledir=xxx : Directory containing pisg's modules.
  1434. -co --configfile=xxx : Config file
  1435. -h --help : Output this message and exit (-? also works).
  1436. Example:
  1437. \$ pisg.pl -n IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
  1438. As always, all options may also be defined by editing the source and calling
  1439. pisg without arguments.
  1440. END_USAGE
  1441. #'
  1442. if (GetOptions('channel=s' => \$channel,
  1443. 'logfile=s' => \$logfile,
  1444. 'format=s' => \$format,
  1445. 'network=s' => \$network,
  1446. 'maintainer=s' => \$maintainer,
  1447. 'outfile=s' => \$outputfile,
  1448. 'dir=s' => \$logdir,
  1449. 'prefix=s' => \$prefix,
  1450. 'ignorefile=s' => \$tmp,
  1451. 'aliasfile=s' => \$tmp,
  1452. 'moduledir=s' => \$moduledir,
  1453. 'configfile=s' => \$configfile,
  1454. 'help|?' => \$help
  1455. ) == 0 or $help) {
  1456. die($usage);
  1457. }
  1458. if ($tmp) {
  1459. die("The aliasfile and ignorefile has been obsoleted by the new
  1460. pisg.cfg, please use that instead [look in pisg.cfg]\n");
  1461. }
  1462. if ($channel) {
  1463. $conf->{channel} = $channel;
  1464. $conf->{cmdl}{channel} = 1;
  1465. }
  1466. if ($logfile) {
  1467. $conf->{logfile} = $logfile;
  1468. $conf->{cmdl}{logfile} = 1;
  1469. }
  1470. if ($format) {
  1471. $conf->{format} = $format;
  1472. $conf->{cmdl}{format} = 1;
  1473. }
  1474. if ($network) {
  1475. $conf->{network} = $network;
  1476. $conf->{cmdl}{network} = 1;
  1477. }
  1478. if ($maintainer) {
  1479. $conf->{maintainer} = $maintainer;
  1480. $conf->{cmdl}{maintainer} = 1;
  1481. }
  1482. if ($outputfile) {
  1483. $conf->{outputfile} = $outputfile;
  1484. $conf->{cmdl}{outputfile} = 1;
  1485. }
  1486. if ($logdir) {
  1487. $conf->{logdir} = $logdir;
  1488. $conf->{cmdl}{logdir} = 1;
  1489. }
  1490. if ($prefix) {
  1491. $conf->{prefix} = $prefix;
  1492. $conf->{cmdl}{prefix} = 1;
  1493. }
  1494. if ($moduledir) {
  1495. $conf->{modules_dir} = $moduledir;
  1496. $conf->{cmdl}{modules_dir} = 1;
  1497. }
  1498. if ($configfile) {
  1499. $conf->{configfile} = $configfile;
  1500. $conf->{cmdl}{configfile} = 1;
  1501. }
  1502. }
  1503. sub get_language_templates
  1504. {
  1505. open(FILE, $conf->{langfile}) or open (FILE, $FindBin::Bin . "/$conf->{langfile}") or die("$0: Unable to open language file($conf->{langfile}): $!\n");
  1506. while (my $line = <FILE>)
  1507. {
  1508. next if ($line =~ /^#/);
  1509. if ($line =~ /<lang name=\"([^"]+)\">/) {
  1510. # Found start tag, setting the current language
  1511. my $current_lang = $1;
  1512. while (<FILE>) {
  1513. last if ($_ =~ /<\/lang>/i);
  1514. # Get 'template = "Text"' in language file:
  1515. if ($_ =~ /(\w+)\s+=\s+"(.*)"\s*$/) {
  1516. $T{$current_lang}{$1} = $2;
  1517. }
  1518. }
  1519. }
  1520. }
  1521. close(FILE);
  1522. }
  1523. &main(); # Run the script