pisg.pl 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226
  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. # Default values for pisg. Their meanings are explained in CONFIG-README.
  23. #
  24. # If you are a user of pisg, you shouldn't change it here, but instead on
  25. # commandline or in pisg.cfg
  26. my $conf = {
  27. channel => "#channel",
  28. logfile => "channel.log",
  29. format => "mIRC",
  30. network => "SomeIRCNet",
  31. outputfile => "index.html",
  32. maintainer => "MAINTAINER",
  33. pagehead => "none",
  34. configfile => "pisg.cfg",
  35. imagepath => "",
  36. logdir => "",
  37. lang => 'EN',
  38. langfile => 'lang.txt',
  39. prefix => "",
  40. # Colors
  41. bgcolor => "#dedeee",
  42. bgpic => '',
  43. text => "black",
  44. hbgcolor => "#666699",
  45. hcolor => "white",
  46. hicell => "#BABADD",
  47. hicell2 => "#CCCCCC",
  48. tdcolor => "black",
  49. tdtop => "#C8C8DD",
  50. link => "#0b407a",
  51. vlink => "#0b407a",
  52. hlink => "#0b407a",
  53. headline => "#000000",
  54. rankc => "#CCCCCC",
  55. pic1 => "pipe-blue.png",
  56. pic2 => "pipe-purple.png",
  57. # Less important things
  58. minquote => "25",
  59. maxquote => "65",
  60. wordlength => "5",
  61. activenicks => "25",
  62. activenicks2 => "30",
  63. topichistory => "3",
  64. nicktracking => 0,
  65. timeoffset => "+0",
  66. # Misc settings
  67. foul => "ass fuck bitch shit scheisse scheiße kacke arsch ficker ficken schlampe",
  68. # Developer stuff
  69. debug => 0,
  70. debugfile => "debug.log",
  71. version => "v0.20-cvs",
  72. };
  73. my ($chans, $users);
  74. my ($lines, $smile, $time, $timestamp, %alias, $normalline, $actionline,
  75. $thirdline, @ignore, $processtime, @topics, %monologue, %kicked, %gotkick,
  76. %line, %length, %sadface, %smile, $nicks, %longlines, %mono, %times, %question,
  77. %loud, $totallength, %gaveop, %tookop, %joins, %actions, %sayings, %wordcount,
  78. %lastused, %gotban, %setban, %foul, $days, $oldtime, $lastline, $actions,
  79. $normals, %T, $repeated, $lastnormal, %shout, %slap, %slapped, %words);
  80. sub main
  81. {
  82. print "pisg $conf->{version} - Perl IRC Statistics Generator\n\n";
  83. init_config(); # Init config. (Aliases, ignores, other options etc.)
  84. get_language_templates(); # Get translations from lang.txt
  85. parse_channels(); # parse any channels in <channel> statements
  86. do_channel()
  87. unless ($conf->{chan_done}{$conf->{channel}});
  88. close_debug(); # Close the debugging file
  89. }
  90. sub do_channel
  91. {
  92. init_debug()
  93. unless ($conf->{debugstarted}); # Init the debugging file
  94. init_pisg(); # Init commandline arguments and other things
  95. init_words(); # Init words. (Foulwords etc)
  96. init_lineformats(); # Attempt to set line formats in compliance with user specification (--format)
  97. if ($conf->{logdir}) {
  98. parse_dir(); # Run through all logfiles in dir
  99. } else {
  100. parse_file($conf->{logfile}); # Run through the whole logfile
  101. }
  102. create_html(); # Create the HTML
  103. # (look here if you want to remove some of the
  104. # stats which you don't care about)
  105. print "\nFile parsed succesfully in $processtime on $time.\n";
  106. $conf->{chan_done}{$conf->{channel}} = 1;
  107. }
  108. sub parse_channels
  109. {
  110. my %origconf = %{ $conf };
  111. foreach my $channel (keys %{ $chans }) {
  112. foreach (keys %{ $chans->{$channel} }) {
  113. $conf->{$_} = $chans->{$channel}{$_};
  114. }
  115. do_channel();
  116. $origconf{chan_done} = $conf->{chan_done};
  117. %{ $conf } = %origconf;
  118. }
  119. }
  120. sub init_pisg
  121. {
  122. # Reset all variables
  123. undef $lastnormal;
  124. undef $lines;
  125. undef $smile;
  126. undef $normalline;
  127. undef $actionline;
  128. undef $thirdline;
  129. undef $processtime;
  130. undef @topics;
  131. undef %monologue;
  132. undef %kicked;
  133. undef %gotkick;
  134. undef %line;
  135. undef %length;
  136. undef %sadface;
  137. undef %smile;
  138. undef $nicks;
  139. undef %longlines;
  140. undef %mono;
  141. undef %times;
  142. undef %question;
  143. undef %loud;
  144. undef $totallength;
  145. undef %gaveop;
  146. undef %tookop;
  147. undef %joins;
  148. undef %actions;
  149. undef %sayings;
  150. undef %wordcount;
  151. undef %lastused;
  152. undef %gotban;
  153. undef %setban;
  154. undef %foul;
  155. undef $lastnormal;
  156. undef %shout;
  157. undef %slap;
  158. undef %slapped;
  159. undef %words;
  160. $timestamp = time;
  161. if ($conf->{timeoffset} =~ /\+(\d+)/) {
  162. # We must plus some hours to the time
  163. $timestamp += 3600 * $1; # 3600 seconds per hour
  164. } elsif ($conf->{timeoffset} =~ /-(\d+)/) {
  165. # We must remove some hours from the time
  166. $timestamp -= 3600 * $1; # 3600 seconds per hour
  167. }
  168. # Add trailing slash when it's not there..
  169. if (substr($conf->{imagepath}, -1) ne '/') {
  170. unless ($conf->{imagepath} eq '') {
  171. $conf->{imagepath} =~ s/(.*)/$1\//;
  172. }
  173. }
  174. # Set some values
  175. $days = 1;
  176. $oldtime = "00";
  177. $lastline = "";
  178. $actions = "0";
  179. $normals = "0";
  180. $time = localtime($timestamp);
  181. $repeated = 0;
  182. $conf->{start} = time(); # set start time of file parse
  183. print "Using language template: $conf->{lang}\n\n" if ($conf->{lang} ne 'EN');
  184. print "Statistics for channel $conf->{channel} \@ $conf->{network} by $conf->{maintainer}\n\n";
  185. }
  186. sub init_lineformats {
  187. # These are the regular expressions which matches the lines in the logfile,
  188. # and looks different if it's xchat, mIRC or whatever.
  189. # If you want to add support for a new format - you first have to add the
  190. # regex here, and then you also have to modify the parse subroutines called
  191. # 'parse_normalline()', 'parse_actionline()' and 'parse_thirdline()'
  192. if ($conf->{format} eq 'xchat') {
  193. $normalline = '^(\d+):\d+:\d+ <([^>]+)>\s+(.*)';
  194. $actionline = '^(\d+):\d+:\d+ \*\s+(\S+) (.*)';
  195. $thirdline = '^(\d+):(\d+):\d+ .--\s+(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)';
  196. } elsif ($conf->{format} eq 'mIRC') {
  197. $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
  198. $actionline = '^\[(\d+):\d+\] \* (\S+) (.*)';
  199. $thirdline = '^\[(\d+):(\d+)\] \*\*\* (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
  200. } elsif ($conf->{format} eq 'eggdrop') {
  201. $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
  202. $actionline = '^\[(\d+):\d+\] Action: (\S+) (.*)';
  203. $thirdline = '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+)(.*)';
  204. } elsif ($conf->{format} eq 'bxlog') {
  205. $normalline = '^\[\d+ \S+\/(\d+):\d+\] <([^>]+)> (.*)';
  206. $actionline = '^\[\d+ \S+\/(\d+):\d+\] \* (\S+) (.*)';
  207. $thirdline = '^\[\d+ \S+\/(\d+):(\d+)\] ([<>@!]) (.*)';
  208. } elsif ($conf->{format} eq 'grufti') {
  209. $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
  210. $actionline = '^\[(\d+):\d+\] \* (\S+) (.*)';
  211. $thirdline = '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
  212. } else {
  213. die("Logfile format not supported, check \$conf->{format} setting.\n");
  214. }
  215. }
  216. sub init_config
  217. {
  218. get_cmdlineoptions();
  219. if ((open(CONFIG, $conf->{configfile}) or open(CONFIG, $FindBin::Bin . "/$conf->{configfile}"))) {
  220. print "Using config file: $conf->{configfile}\n";
  221. my $lineno = 0;
  222. while (<CONFIG>)
  223. {
  224. $lineno++;
  225. my $line = $_;
  226. next if /^#/;
  227. if ($line =~ /<user.*>/) {
  228. my $nick;
  229. if ($line =~ /nick="([^"]+)"/) {
  230. $nick = $1;
  231. } else {
  232. print STDERR "Warning: no nick specified in $conf->{configfile} on line $lineno\n";
  233. next;
  234. }
  235. if ($line =~ /alias="([^"]+)"/) {
  236. my @thisalias = split(/\s+/, lc($1));
  237. foreach (@thisalias) {
  238. $_ =~ s/\*/\.\*/g;
  239. $alias{$_} = $nick;
  240. }
  241. }
  242. if ($line =~ /pic="([^"]+)"/) {
  243. $users->{userpics}{$nick} = $1;
  244. }
  245. if ($line =~ /link="([^"]+)"/) {
  246. $users->{userlinks}{$nick} = $1;
  247. }
  248. if ($line =~ /ignore="Y"/i) {
  249. push(@ignore, $nick);
  250. }
  251. } elsif ($line =~ /<set(.*)>/) {
  252. my $settings = $1;
  253. while ($settings =~ s/[ \t]([^=]+)=["']([^"']*)["']//) {
  254. my $var = lc($1); # Make the string lowercase
  255. unless (($conf->{$var} eq $2) || $conf->{cmdl}{$var}) {
  256. $conf->{$var} = $2;
  257. }
  258. debug("Conf: $var = $2");
  259. }
  260. } elsif ($line =~ /<channel=['"]([^'"]+)['"](.*)>/i) {
  261. my ($channel, $settings) = ($1, $2);
  262. $chans->{$channel}->{channel} = $channel;
  263. $conf->{chan_done}{$conf->{channel}} = 1; # don't parse channel in $conf->{channel} if a channel statement is present
  264. while ($settings =~ s/\s([^=]+)=["']([^"']*)["']//) {
  265. my $var = lc($1);
  266. $chans->{$channel}{$var} = $2;
  267. debug("Channel conf $channel: $var = $2");
  268. }
  269. while (<CONFIG>) {
  270. last if ($_ =~ /<\/*channel>/i);
  271. while ($_ =~ s/^\s*(\w+)\s*=\s*["']([^"']*)["']//) {
  272. my $var = lc($1);
  273. unless ($conf->{cmdl}{$var}) {
  274. $chans->{$channel}{$var} = $2;
  275. }
  276. debug("Conf $channel: $var = $2");
  277. }
  278. }
  279. }
  280. }
  281. close(CONFIG);
  282. }
  283. }
  284. sub init_words {
  285. $conf->{foul} =~ s/\s+/|/g;
  286. }
  287. sub init_debug
  288. {
  289. $conf->{debugstarted} = 1;
  290. if ($conf->{debug}) {
  291. print "[ Debugging => $conf->{debugfile} ]\n";
  292. open(DEBUG,"> $conf->{debugfile}") or print STDERR "$0: Unable to open debug
  293. file($conf->{debugfile}): $!\n";
  294. debug("*** pisg debug file for $conf->{logfile}\n");
  295. if ($conf->{debugqueue}) {
  296. print DEBUG $conf->{debugqueue};
  297. delete $conf->{debugqueue};
  298. }
  299. }
  300. }
  301. sub parse_dir
  302. {
  303. print "Going into $conf->{logdir} and parsing all files there...\n\n";
  304. my @filesarray;
  305. opendir(LOGDIR, $conf->{logdir}) or die("Can't opendir $conf->{logdir}: $!");
  306. unless (@filesarray = readdir(LOGDIR)) {
  307. die("No files in $conf->{logdir}!");
  308. }
  309. close(LOGDIR);
  310. # Add trailing slash when it's not there..
  311. if (substr($conf->{logdir}, -1) ne '/') {
  312. $conf->{logdir} =~ s/(.*)/$1\//;
  313. }
  314. my $parsed = 0;
  315. foreach my $file (grep /^$conf->{prefix}/, @filesarray) {
  316. unless ($file eq "." or $file eq "..") {
  317. $file = $conf->{logdir} . $file;
  318. parse_file($file);
  319. $parsed = 1;
  320. }
  321. }
  322. die "No files matched prefix $conf->{prefix} in directory $conf->{logdir}" unless ($parsed);
  323. }
  324. sub parse_file
  325. {
  326. my $file = shift;
  327. my $foulwords = $conf->{foul};
  328. # This parses the file..
  329. print "Analyzing log($file) in '$conf->{format}' format...\n";
  330. if ($file =~ /.bz$/ || $file =~ /.bz2$/) {
  331. open (LOGFILE, "bunzip2 -c $file |") or die("$0: Unable to open logfile($file): $!\n");
  332. } elsif ($file =~ /.gz$/) {
  333. open (LOGFILE, "gunzip -c $file |") or die("$0: Unable to open logfile($file): $!\n");
  334. } else {
  335. open (LOGFILE, $file) or die("$0: Unable to open logfile($file): $!\n");
  336. }
  337. while(my $line = <LOGFILE>) {
  338. $lines++; # Increment number of lines.
  339. $line = strip_mirccodes($line);
  340. my $hashref;
  341. # Match normal lines.
  342. if ($hashref = parse_normalline($line)) {
  343. my ($hour, $nick, $saying, $i);
  344. for ($i = 0; $i <= $repeated; $i++) {
  345. if ($i > 0) {
  346. $hashref = parse_normalline($lastnormal);
  347. $lines++; #Increment number of lines for repeated lines
  348. }
  349. $hour = $hashref->{hour};
  350. $nick = find_alias($hashref->{nick});
  351. $saying = $hashref->{saying};
  352. # Timestamp collecting
  353. $times{$hour}++;
  354. unless (grep /^\Q$nick\E$/i, @ignore) {
  355. $normals++;
  356. $line{$nick}++;
  357. # Count up monologues
  358. if ($lastline eq $nick) {
  359. $mono{$nick}++;
  360. if ($mono{$nick} == "5") {
  361. $monologue{$nick}++;
  362. $mono{$nick} = 0;
  363. }
  364. } else {
  365. $mono{$nick} = 0;
  366. }
  367. $lastline = $nick;
  368. my $l = length($saying);
  369. if ($l > $conf->{minquote} && $l < $conf->{maxquote}) {
  370. # Creates $hash{nick}[n] - a hash of an array.
  371. push (@{ $sayings{$nick} }, htmlentities($saying));
  372. $longlines{$nick}++;
  373. }
  374. $question{$nick}++
  375. if ($saying =~ /\?/);
  376. $loud{$nick}++
  377. if ($saying =~ /!/);
  378. $shout{$nick}++
  379. if ($saying =~ /[A-Z]+/ and $saying !~ /[a-z0-9:]/);
  380. $foul{$nick}++
  381. if ($saying =~ /$foulwords/i);
  382. # Who smiles the most?
  383. # A regex matching al lot of smilies
  384. $smile{$nick}++
  385. if ($saying =~ /[8;:=][ ^-o]?[)pPD}\]>]/);
  386. $sadface{$nick}++
  387. if ($saying =~ /[8;:=][ ^-]?[\(\[\\\/{]/);
  388. # Don't count http:// as a :/ face
  389. $sadface{$nick}--
  390. if ($saying =~ /\w+:\/\//);
  391. foreach my $word (split(/[\s,!?.:;)(]+/, $saying)) {
  392. $words{$nick}++;
  393. # remove uninteresting words
  394. next unless (length($word) >= $conf->{wordlength});
  395. # ignore contractions
  396. next if ($word =~ m/'..?$/);
  397. $wordcount{htmlentities($word)}++ unless (grep /^\Q$word\E$/i, @ignore);
  398. $lastused{htmlentities($word)} = $nick;
  399. }
  400. $length{$nick} += $l;
  401. $totallength += $l;
  402. }
  403. }
  404. $lastnormal = $line;
  405. $repeated = 0;
  406. }
  407. # Match action lines.
  408. elsif ($hashref = parse_actionline($line)) {
  409. my ($hour, $nick, $saying);
  410. $hour = $hashref->{hour};
  411. $nick = find_alias($hashref->{nick});
  412. $saying = $hashref->{saying};
  413. # Timestamp collecting
  414. $times{$hour}++;
  415. unless (grep /^\Q$nick\E$/i, @ignore) {
  416. $actions++;
  417. $line{$nick}++;
  418. if($saying =~ /^slaps (\S+)/) {
  419. $slap{$nick}++;
  420. $slapped{$1}++;
  421. }
  422. my $len = length($saying);
  423. $length{$nick} += $len;
  424. $totallength += $len;
  425. foreach my $word (split(/[\s,!?.:;)(]+/, $saying)) {
  426. $words{$nick}++;
  427. # remove uninteresting words
  428. next unless (length($word) > $conf->{wordlength});
  429. # ignore contractions
  430. next if ($word =~ m/'..?$/);
  431. $wordcount{htmlentities($word)}++ unless (grep /^\Q$word\E$/i, @ignore);
  432. $lastused{htmlentities($word)} = $nick;
  433. }
  434. }
  435. }
  436. # Match *** lines.
  437. elsif (($hashref = parse_thirdline($line)) && $hashref->{nick}) {
  438. my ($hour, $min, $nick, $kicker, $newtopic, $newmode, $newjoin, $newnick);
  439. $hour = $hashref->{hour};
  440. $min = $hashref->{min};
  441. $nick = find_alias($hashref->{nick});
  442. $kicker = $hashref->{kicker};
  443. $newtopic = $hashref->{newtopic};
  444. $newmode = $hashref->{newmode};
  445. $newjoin = $hashref->{newjoin};
  446. $newnick = $hashref->{newnick};
  447. # Timestamp collecting
  448. $times{$hour}++;
  449. unless (grep /^\Q$nick\E$/i, @ignore) {
  450. if (defined($kicker)) {
  451. unless (grep /^\Q$kicker\E$/i, @ignore) {
  452. $gotkick{$nick}++;
  453. $kicked{$kicker}++;
  454. }
  455. } elsif (defined($newtopic)) {
  456. unless ($newtopic eq '') {
  457. my $tcount = @topics;
  458. $topics[$tcount]{topic} = htmlentities($newtopic);
  459. $topics[$tcount]{nick} = $nick;
  460. $topics[$tcount]{hour} = $hour;
  461. $topics[$tcount]{min} = $min;
  462. # Strip off the quotes (')
  463. $topics[$tcount]{topic} =~ s/^\'(.*)\'$/$1/;
  464. }
  465. } elsif (defined($newmode)) {
  466. my @opchange = opchanges($newmode);
  467. $gaveop{$nick} += $opchange[0] if $opchange[0];
  468. $tookop{$nick} += $opchange[1] if $opchange[1];
  469. } elsif (defined($newjoin)) {
  470. $joins{$nick}++;
  471. } elsif (defined($newnick) && ($conf->{nicktracking} == 1)) {
  472. my $lcnewnick = lc($newnick);
  473. my $lcnick = lc($nick);
  474. unless (defined($alias{$lcnewnick})) {
  475. if (defined($alias{$lcnick}) && !defined($alias{$lcnewnick})) {
  476. $alias{$lcnewnick} = $nick;
  477. } elsif (defined($alias{$lcnewnick}) && !defined($alias{$lcnick})) {
  478. $alias{$lcnick} = $newnick;
  479. } elsif ($nick =~ /Guest/) {
  480. $alias{$lcnick} = $newnick;
  481. } else {
  482. $alias{$lcnewnick} = $nick;
  483. }
  484. }
  485. }
  486. }
  487. if ($hour < $oldtime) { $days++ }
  488. $oldtime = $hour;
  489. }
  490. }
  491. close(LOGFILE);
  492. my ($sec,$min,$hour) = gmtime(time - $conf->{start});
  493. $processtime = sprintf("%02d hours, %02d minutes and %02d seconds", $hour, $min, $sec);
  494. $nicks = scalar keys %line;
  495. print "Finished analyzing log, $days days total.\n";
  496. }
  497. # Here is the 3 parse sub routines, their function is to return a hash with
  498. # the elements in the line. This is where we add the format dependent stuff.
  499. sub parse_normalline
  500. {
  501. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  502. my $line = shift;
  503. my %hash;
  504. if ($line =~ /$normalline/) {
  505. debug("[$lines] Normal: $1 $2 $3");
  506. if (($conf->{format} eq 'mIRC') || ($conf->{format} eq 'xchat') || ($conf->{format} eq
  507. 'eggdrop') || ($conf->{format} eq 'bxlog') || ($conf->{format} eq 'grufti')) {
  508. $hash{hour} = $1;
  509. $hash{nick} = $2;
  510. $hash{saying} = $3;
  511. } else {
  512. die("Format not supported?!\n");
  513. }
  514. return \%hash;
  515. } else {
  516. return;
  517. }
  518. }
  519. sub parse_actionline
  520. {
  521. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  522. my $line = shift;
  523. my %hash;
  524. if ($line =~ /$actionline/) {
  525. debug("[$lines] Action: $1 $2 $3");
  526. if (($conf->{format} eq 'mIRC') || ($conf->{format} eq 'xchat') || ($conf->{format} eq
  527. 'eggdrop') || $conf->{format} eq 'bxlog' || ($conf->{format} eq 'grufti')) {
  528. $hash{hour} = $1;
  529. $hash{nick} = $2;
  530. $hash{saying} = $3;
  531. } else {
  532. die("Format not supported?!\n");
  533. }
  534. return \%hash;
  535. } else {
  536. return;
  537. }
  538. }
  539. sub parse_thirdline
  540. {
  541. # Parses the 'third' line - (the third line is everything else, like
  542. # topic changes, mode changes, kicks, etc.)
  543. # parse_thirdline() have to return a hash with the following keys, for
  544. # every format:
  545. # hour - the hour we're in (for timestamp loggin)
  546. # min - the minute we're in (for timestamp loggin)
  547. # nick - the nick
  548. # kicker - the nick which were kicked (if any)
  549. # newtopic - the new topic (if any)
  550. # newmode - deops or ops, must be '+o' or '-o', or '+ooo'
  551. # newjoin - a new nick which has joined the channel
  552. # newnick - a person has changed nick and this is the new nick
  553. my $line = shift;
  554. my %hash;
  555. if ($line =~ /$thirdline/) {
  556. if ($7) {
  557. debug("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
  558. } elsif ($5) {
  559. debug("[$lines] ***: $1 $2 $3 $4 $5 $6");
  560. } else {
  561. debug("[$lines] ***: $1 $2 $3 $4");
  562. }
  563. if ($conf->{format} eq 'mIRC') {
  564. $hash{hour} = $1;
  565. $hash{min} = $2;
  566. $hash{nick} = $3;
  567. if (($4.$5) eq 'waskicked') {
  568. $hash{kicker} = $7;
  569. } elsif (($4.$5) eq 'changestopic') {
  570. $hash{newtopic} = "$7 $8";
  571. } elsif (($4.$5) eq 'setsmode:') {
  572. $hash{newmode} = $6;
  573. } elsif (($4.$5) eq 'hasjoined') {
  574. $hash{newjoin} = $3;
  575. } elsif (($4.$5) eq 'nowknown') {
  576. $hash{newnick} = $8;
  577. }
  578. } elsif ($conf->{format} eq 'xchat') {
  579. $hash{hour} = $1;
  580. $hash{min} = $2;
  581. $hash{nick} = $3;
  582. if (($4.$5) eq 'haskicked') {
  583. $hash{kicker} = $3;
  584. $hash{nick} = $6;
  585. } elsif (($4.$5) eq 'haschanged') {
  586. $hash{newtopic} = $9;
  587. } elsif (($4.$5) eq 'giveschannel') {
  588. $hash{newmode} = '+o';
  589. } elsif (($4.$5) eq 'removeschannel') {
  590. $hash{newmode} = '-o';
  591. } elsif (($5.$6) eq 'hasjoined') {
  592. $hash{newjoin} = $1;
  593. } elsif (($5.$6) eq 'nowknown') {
  594. $hash{newnick} = $8;
  595. }
  596. } elsif ($conf->{format} eq 'eggdrop') {
  597. $hash{hour} = $1;
  598. $hash{min} = $2;
  599. $hash{nick} = $3;
  600. if (($4.$5) eq 'kickedfrom') {
  601. $7 =~ /^ by ([\S]+):.*/;
  602. $hash{kicker} = $1;
  603. } elsif ($3 eq 'Topic') {
  604. $7 =~ /^ by ([\S]+)![\S]+: (.*)/;
  605. $hash{nick} = $1;
  606. $hash{newtopic} = $2;
  607. } elsif (($4.$5) eq 'modechange') {
  608. my $newmode = $6;
  609. if ($7 =~ /^ .+ by ([\S]+)!.*/) {
  610. $hash{nick} = $1;
  611. $newmode =~ s/^\'//;
  612. $hash{newmode} = $newmode;
  613. }
  614. } elsif ($5 eq 'joined') {
  615. $hash{newjoin} = $3;
  616. } elsif (($3.$4) eq 'Nickchange:') {
  617. $hash{nick} = $5;
  618. $7 =~ /([\S]+)/;
  619. $hash{newnick} = $1;
  620. } elsif (($3.$4.$5) eq 'Lastmessagerepeated') {
  621. $repeated = $6;
  622. }
  623. } elsif ($conf->{format} eq 'bxlog') {
  624. $hash{hour} = $1;
  625. $hash{min} = $2;
  626. if ($3 eq '<') {
  627. if ($4 =~ /^([^!]+)!([\S+]) was kicked off (\S+) by ([^!]+)!(\S+) \(([^)]+)\)$/) {
  628. $hash{kicker} = $4;
  629. $hash{nick} = $1;
  630. }
  631. } elsif ($3 eq '>') {
  632. if ($4 =~ /^([^!])+!(\S+) has joined (\S+)$/) {
  633. $hash{nick} = $1;
  634. $hash{newjoin} = $1;
  635. }
  636. } elsif ($3 eq '@') {
  637. if ($4 =~ /^Topic by ([^!:])[!:]*: (.*)$/) {
  638. $hash{nick} = $1;
  639. $hash{newtopic} = $2;
  640. } elsif ($4 =~ /^mode \S+ \[([\S]+) [^\]]+\] by ([^!]+)!\S+$/) {
  641. $hash{newmode} = $1;
  642. $hash{nick} = $2;
  643. }
  644. } elsif ($3 eq '!') {
  645. if ($4 =~ /^(\S+) is known as (\S+)$/) {
  646. $hash{nick} = $1;
  647. $hash{newnick} = $2;
  648. }
  649. }
  650. } elsif ($conf->{format} eq 'grufti') {
  651. $hash{hour} = $1;
  652. $hash{min} = $2;
  653. $hash{nick} = $3;
  654. if ($5 eq 'kicked') {
  655. $hash{kicker} = $3;
  656. $hash{nick} = $6;
  657. } elsif (($4.$5) eq 'haschanged') {
  658. $hash{newtopic} = $9;
  659. } elsif (($4.$5) eq 'modechange') {
  660. $hash{newmode} = substr($6, 1);
  661. $hash{nick} = $9;
  662. $hash{nick} =~ /.*[by ](\S+)/;
  663. $hash{nick} = $1;
  664. } elsif ($5 eq 'joined') {
  665. $hash{newjoin} = $1;
  666. } elsif (($3.$4) eq 'Nickchange') {
  667. $hash{nick} = $7;
  668. $hash{newnick} = $9;
  669. }
  670. } else {
  671. die("Format not supported?!\n");
  672. }
  673. return \%hash;
  674. } else {
  675. return;
  676. }
  677. }
  678. sub opchanges
  679. {
  680. my @modes = split(//, $_[0]);
  681. my ($mode,$plus) = ("",0);
  682. my ($gaveop,$tookop) = (0,0);
  683. foreach (@modes) {
  684. if (/^\+$/) { $plus = 1; next; }
  685. elsif (/^-$/) { $plus = 0; next; }
  686. else { next unless /^o$/ }
  687. if ($plus) { $gaveop++ } else { $tookop++ }
  688. }
  689. return ($gaveop,$tookop);
  690. }
  691. sub strip_mirccodes
  692. {
  693. my $line = shift;
  694. my $boldcode = chr(2);
  695. my $colorcode = chr(3);
  696. my $plaincode = chr(15);
  697. my $reversecode = chr(22);
  698. my $underlinecode = chr(31);
  699. # Strip mIRC color codes
  700. $line =~ s/$colorcode\d{1,2},\d{1,2}//g;
  701. $line =~ s/$colorcode\d{0,2}//g;
  702. # Strip mIRC bold, plain, reverse and underline codes
  703. $line =~ s/[$boldcode$underlinecode$reversecode$plaincode]//g;
  704. return $line;
  705. }
  706. sub htmlentities
  707. {
  708. my $str = shift;
  709. $str =~ s/\&/\&amp;/g;
  710. $str =~ s/\</\&lt;/g;
  711. $str =~ s/\>/\&gt;/g;
  712. $str =~ s/ü/&uuml;/g;
  713. $str =~ s/ö/&ouml;/g;
  714. $str =~ s/ä/&auml;/g;
  715. $str =~ s/ß/&szlig;/g;
  716. $str =~ s/å/&aring;/g;
  717. $str =~ s/æ/&aelig;/g;
  718. $str =~ s/ø/&oslash;/g;
  719. return $str;
  720. }
  721. sub html
  722. {
  723. my $html = shift;
  724. print OUTPUT $html . "\n";
  725. }
  726. sub template_text
  727. {
  728. # This function is for the homemade template system. It receives a name
  729. # of a template and a hash with the fields in the template to update to
  730. # its corresponding value
  731. my $template = shift;
  732. my %hash = @_;
  733. my $text;
  734. $text = $T{$conf->{lang}}{$template};
  735. if (!$T{$conf->{lang}}{$template}) {
  736. # Fall back to English if the language template doesn't exist
  737. if ($T{EN}{$template}) {
  738. print "Note: There was no translation in $conf->{lang} for '$template' - falling back to English..\n";
  739. $text = $T{EN}{$template};
  740. } else {
  741. die("No such template '$template' in language file.\n");
  742. }
  743. }
  744. foreach my $key (sort keys %hash) {
  745. $text =~ s/\[:$key\]/$hash{$key}/;
  746. $text =~ s/ü/&uuml;/g;
  747. $text =~ s/ö/&ouml;/g;
  748. $text =~ s/ä/&auml;/g;
  749. $text =~ s/ß/&szlig;/g;
  750. $text =~ s/å/&aring;/g;
  751. $text =~ s/æ/&aelig;/g;
  752. $text =~ s/ø/&oslash;/g;
  753. }
  754. return $text;
  755. }
  756. sub replace_links
  757. {
  758. # Sub to replace urls and e-mail addys to links
  759. my $str = shift;
  760. my $nick = shift;
  761. if ($nick) {
  762. $str =~ s/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_]+.[-a-zA-Z0-9.,_~=:;&@%?#\/+]+)/<a href="$1$2" target="_blank" title="Open in new window: $1$2">$nick<\/a>/g;
  763. $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="Mail to $nick">$nick<\/a>/g;
  764. } else {
  765. $str =~ s/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_]+.[-a-zA-Z0-9.,_~=:;&@%?#\/+]+)/<a href="$1$2" target="_blank" title="Open in new window: $1$2">$1$2<\/a>/g;
  766. $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="Mail to $1">$1<\/a>/g;
  767. }
  768. return $str;
  769. }
  770. sub debug
  771. {
  772. if ($conf->{debug}) {
  773. my $debugline = $_[0] . "\n";
  774. if ($conf->{debugstarted}) {
  775. print DEBUG $debugline;
  776. } else {
  777. $conf->{debugqueue} .= $debugline;
  778. }
  779. }
  780. }
  781. sub find_alias
  782. {
  783. my $nick = shift;
  784. my $lcnick = lc($nick);
  785. if ($alias{$lcnick}) {
  786. return $alias{$lcnick};
  787. } else {
  788. foreach (keys %alias) {
  789. if (($_ =~ /\.\*/) && ($nick =~ /^$_$/i)) {
  790. return $alias{$_};
  791. }
  792. }
  793. }
  794. return $nick;
  795. }
  796. sub create_html
  797. {
  798. # This is where all subroutines get executed, you can actually design
  799. # your own layout here, the lines should be self-explainable
  800. print "Now generating HTML($conf->{outputfile})...\n";
  801. open (OUTPUT, "> $conf->{outputfile}") or die("$0: Unable to open outputfile($conf->{outputfile}): $!\n");
  802. htmlheader();
  803. pageheader();
  804. activetimes();
  805. activenicks();
  806. headline(template_text('bignumtopic'));
  807. html("<table width=\"614\">\n"); # Needed for sections
  808. questions();
  809. loudpeople();
  810. shoutpeople();
  811. slap();
  812. mostsmiles();
  813. mostsad();
  814. longlines();
  815. shortlines();
  816. mostwords();
  817. mostwordsperline();
  818. html("</table>"); # Needed for sections
  819. mostusedword();
  820. mostreferenced();
  821. headline(template_text('othernumtopic'));
  822. html("<table width=\"614\">\n"); # Needed for sections
  823. gotkicks();
  824. mostkicks();
  825. mostop();
  826. mostmonologues();
  827. mostjoins();
  828. mostfoul();
  829. html("</table>"); # Needed for sections
  830. headline(template_text('latesttopic'));
  831. html("<table width=\"614\">\n"); # Needed for sections
  832. lasttopics();
  833. html("</table>"); # Needed for sections
  834. my %hash = ( lines => $lines );
  835. html(template_text('totallines', %hash) . "<br><br>");
  836. htmlfooter();
  837. close(OUTPUT);
  838. }
  839. sub activetimes
  840. {
  841. # The most actives times on the channel
  842. my (%output, $tbgcolor);
  843. &headline(template_text('activetimestopic'));
  844. my @toptime = sort { $times{$b} <=> $times{$a} } keys %times;
  845. my $highest_value = $times{$toptime[0]};
  846. my @now = localtime($timestamp);
  847. my $image;
  848. for my $hour (sort keys %times) {
  849. debug("Time: $hour => ". $times{$hour});
  850. if ($toptime[0] == $hour) {
  851. $image = $conf->{pic2};
  852. } else {
  853. $image = $conf->{pic1};
  854. }
  855. my $size = ($times{$hour} / $highest_value) * 100;
  856. my $percent = ($times{$hour} / $lines) * 100;
  857. $percent =~ s/(\.\d)\d+/$1/;
  858. if ($size < 1 && $size != 0) {
  859. # Opera doesn't understand '0.xxxx' in the height="xx" attr,
  860. # so we simply round up to 1.0 here.
  861. $size = 1.0;
  862. }
  863. if ($conf->{timeoffset} =~ /\+(\d+)/) {
  864. # We must plus some hours to the time
  865. $hour += $1;
  866. $hour = $hour % 24;
  867. if ($hour < 10) { $hour = "0" . $hour; }
  868. } elsif ($conf->{timeoffset} =~ /-(\d+)/) {
  869. # We must remove some hours from the time
  870. $hour -= $1;
  871. $hour = $hour % 24;
  872. if ($hour < 10) { $hour = "0" . $hour; }
  873. }
  874. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br><img src=\"$image\" width=\"15\" height=\"$size\" alt=\"$percent\"></td>\n";
  875. }
  876. html("<table border=\"0\" width=\"614\"><tr>\n");
  877. for ($b = 0; $b < 24; $b++) {
  878. if ($b < 10) { $a = "0" . $b; } else { $a = $b; }
  879. if (!defined($output{$a}) || $output{$a} eq "") {
  880. html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  881. } else {
  882. html($output{$a});
  883. }
  884. }
  885. html("</tr><tr>");
  886. for ($b = 0; $b < 24; $b++) {
  887. if ($now[2] == $b) { $tbgcolor = "\#AAAAAA"; } else { $tbgcolor = "\#CCCCCC"; }
  888. html("<td bgcolor=\"$tbgcolor\" align=\"center\" class=\"small\">$b</td>");
  889. }
  890. html("</tr></table>");
  891. }
  892. sub activenicks
  893. {
  894. # The most active nicks (those who wrote most lines)
  895. headline(template_text('activenickstopic'));
  896. html("<table border=\"0\" width=\"614\"><tr>");
  897. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('nick') . "</b></td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberlines') ."</b></td><td bgcolor=\"$conf->{tdtop}\"><b>". template_text('randquote') ."</b></td>");
  898. if (scalar keys %{$users->{userpics}} > 0) {
  899. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('userpic') ."</b></td>");
  900. }
  901. html("</tr>");
  902. my @active = sort { $line{$b} <=> $line{$a} } keys %line;
  903. if ($conf->{activenicks} > $nicks) {
  904. $conf->{activenicks} = $nicks;
  905. print "Note: There was less nicks in the logfile than your specificied there to be in most active nicks...\n";
  906. }
  907. my ($nick, $visiblenick, $randomline);
  908. my $i = 1;
  909. for (my $c = 0; $c < $conf->{activenicks}; $c++) {
  910. $nick = $active[$c];
  911. $visiblenick = $active[$c];
  912. if (!$longlines{$nick}) {
  913. $randomline = "";
  914. } else {
  915. my $rand = rand($longlines{$nick});
  916. $randomline = $sayings{$nick}[$rand];
  917. }
  918. # Convert URLs and e-mail addys to links
  919. $randomline = replace_links($randomline);
  920. # Add a link to the nick if there is any
  921. if ($users->{userlinks}{$nick}) {
  922. $visiblenick = replace_links($users->{userlinks}{$nick}, $nick);
  923. }
  924. my $h = $conf->{hicell};
  925. $h =~ s/^#//;
  926. $h = hex $h;
  927. my $h2 = $conf->{hicell2};
  928. $h2 =~ s/^#//;
  929. $h2 = hex $h2;
  930. my $f_b = $h & 0xff;
  931. my $f_g = ($h & 0xff00) >> 8;
  932. my $f_r = ($h & 0xff0000) >> 16;
  933. my $t_b = $h2 & 0xff;
  934. my $t_g = ($h2 & 0xff00) >> 8;
  935. my $t_r = ($h2 & 0xff0000) >> 16;
  936. my $col_b = sprintf "%0.2x", abs int(((($t_b - $f_b) / $conf->{activenicks}) * +$c) + $f_b);
  937. my $col_g = sprintf "%0.2x", abs int(((($t_g - $f_g) / $conf->{activenicks}) * +$c) + $f_g);
  938. my $col_r = sprintf "%0.2x", abs int(((($t_r - $f_r) / $conf->{activenicks}) * +$c) + $f_r);
  939. html("<tr><td bgcolor=\"$conf->{rankc}\" align=\"left\">");
  940. my $line = $line{$nick};
  941. html("$i</td><td bgcolor=\"#$col_r$col_g$col_b\">$visiblenick</td><td bgcolor=\"#$col_r$col_g$col_b\">$line</td><td bgcolor=\"#$col_r$col_g$col_b\">");
  942. html("\"$randomline\"</td>");
  943. if ($users->{userpics}{$nick}) {
  944. html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$conf->{imagepath}$users->{userpics}{$nick}\"></td>");
  945. }
  946. html("</tr>");
  947. $i++;
  948. }
  949. html("</table><br>");
  950. # Almost as active nicks ('These didn't make it to the top..')
  951. my $nickstoshow = $conf->{activenicks} + $conf->{activenicks2};
  952. unless ($nickstoshow > $nicks) {
  953. html("<br><b><i>" . template_text('nottop') . "</i></b><table><tr>");
  954. for (my $c = $conf->{activenicks}; $c < $nickstoshow; $c++) {
  955. unless ($c % 5) { unless ($c == $conf->{activenicks}) { html("</tr><tr>"); } }
  956. html("<td bgcolor=\"$conf->{rankc}\" class=\"small\">");
  957. my $nick = $active[$c];
  958. my $lines = $line{$nick};
  959. html("$nick ($lines)</td>");
  960. }
  961. html("</table>");
  962. }
  963. }
  964. sub mostusedword
  965. {
  966. # Lao the infamous word usage statistics
  967. my %usages;
  968. foreach my $word (sort keys %wordcount) {
  969. next if exists $line{$word};
  970. $usages{$word} = $wordcount{$word};
  971. }
  972. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  973. if (@popular) {
  974. &headline(template_text('mostwordstopic'));
  975. html("<table border=\"0\" width=\"614\"><tr>");
  976. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('word') . "</b></td>");
  977. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  978. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  979. for(my $i = 0; $i < 10; $i++) {
  980. last unless $i < $#popular;
  981. my $a = $i + 1;
  982. my $popular = $popular[$i];
  983. my $wordcount = $wordcount{$popular[$i]};
  984. my $lastused = $lastused{$popular[$i]};
  985. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  986. html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
  987. html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
  988. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  989. html("</tr>");
  990. }
  991. html("</table>");
  992. }
  993. }
  994. sub mostwordsperline
  995. {
  996. # The person who got words the most
  997. my %wpl = ();
  998. my ($numlines,$avg,$numwords);
  999. foreach my $n (keys %words) {
  1000. $wpl{$n} = sprintf("%.2f", $words{$n}/$line{$n});
  1001. $numlines += $line{$n};
  1002. $numwords += $words{$n};
  1003. }
  1004. $avg = sprintf("%.2f", $numwords/$numlines);
  1005. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  1006. if (@wpl) {
  1007. my %hash = (
  1008. nick => $wpl[0],
  1009. wpl => $wpl{$wpl[0]}
  1010. );
  1011. my $text = template_text('wpl1', %hash);
  1012. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1013. %hash = (
  1014. avg => $avg
  1015. );
  1016. $text = template_text('wpl2', %hash);
  1017. html("<br><span class=\"small\">$text</span>");
  1018. html("</td></tr>");
  1019. } else {
  1020. my $text = template_text('wpl3');
  1021. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1022. }
  1023. }
  1024. sub mostreferenced
  1025. {
  1026. my %usages;
  1027. foreach my $word (sort keys %wordcount) {
  1028. next unless exists $line{$word};
  1029. $usages{$word} = $wordcount{$word};
  1030. }
  1031. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1032. if (@popular) {
  1033. &headline(template_text('referencetopic'));
  1034. html("<table border=\"0\" width=\"614\"><tr>");
  1035. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('nick') . "</b></td>");
  1036. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  1037. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  1038. for(my $i = 0; $i < 5; $i++) {
  1039. last unless $i < $#popular;
  1040. my $a = $i + 1;
  1041. my $popular = $popular[$i];
  1042. my $wordcount = $wordcount{$popular[$i]};
  1043. my $lastused = $lastused{$popular[$i]};
  1044. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  1045. html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
  1046. html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
  1047. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  1048. html("</tr>");
  1049. }
  1050. html("</table>");
  1051. }
  1052. }
  1053. sub questions
  1054. {
  1055. # Persons who asked the most questions
  1056. my %qpercent;
  1057. foreach my $nick (sort keys %question) {
  1058. if ($line{$nick} > 100) {
  1059. $qpercent{$nick} = ($question{$nick} / $line{$nick}) * 100;
  1060. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  1061. }
  1062. }
  1063. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  1064. if (@question) {
  1065. my %hash = (
  1066. nick => $question[0],
  1067. per => $qpercent{$question[0]}
  1068. );
  1069. my $text = template_text('question1', %hash);
  1070. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1071. if (@question >= 2) {
  1072. my %hash = (
  1073. nick => $question[1],
  1074. per => $qpercent{$question[1]}
  1075. );
  1076. my $text = template_text('question2', %hash);
  1077. html("<br><span class=\"small\">$text</span>");
  1078. }
  1079. html("</td></tr>");
  1080. } else {
  1081. html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('question3') . "</td></tr>");
  1082. }
  1083. }
  1084. sub loudpeople
  1085. {
  1086. # The ones who speak LOUDLY!
  1087. my %lpercent;
  1088. foreach my $nick (sort keys %loud) {
  1089. if ($line{$nick} > 100) {
  1090. $lpercent{$nick} = ($loud{$nick} / $line{$nick}) * 100;
  1091. $lpercent{$nick} =~ s/(\.\d)\d+/$1/;
  1092. }
  1093. }
  1094. my @loud = sort { $lpercent{$b} <=> $lpercent{$a} } keys %lpercent;
  1095. if (@loud) {
  1096. my %hash = (
  1097. nick => $loud[0],
  1098. per => $lpercent{$loud[0]}
  1099. );
  1100. my $text = template_text('loud1', %hash);
  1101. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1102. if (@loud >= 2) {
  1103. my %hash = (
  1104. nick => $loud[1],
  1105. per => $lpercent{$loud[1]}
  1106. );
  1107. my $text = template_text('loud2', %hash);
  1108. html("<br><span class=\"small\">$text</span>");
  1109. }
  1110. html("</td></tr>");
  1111. } else {
  1112. my $text = template_text('loud3');
  1113. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1114. }
  1115. }
  1116. sub shoutpeople
  1117. {
  1118. # The ones who speak SHOUTED!
  1119. my %spercent;
  1120. foreach my $nick (sort keys %shout) {
  1121. if ($line{$nick} > 100) {
  1122. $spercent{$nick} = ($shout{$nick} / $line{$nick}) * 100;
  1123. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1124. }
  1125. }
  1126. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1127. if (@shout) {
  1128. my %hash = (
  1129. nick => $shout[0],
  1130. per => $spercent{$shout[0]}
  1131. );
  1132. my $text = template_text('shout1', %hash);
  1133. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1134. if (@shout >= 2) {
  1135. my %hash = (
  1136. nick => $shout[1],
  1137. per => $spercent{$shout[1]}
  1138. );
  1139. my $text = template_text('shout2', %hash);
  1140. html("<br><span class=\"small\">$text</span>");
  1141. }
  1142. html("</td></tr>");
  1143. } else {
  1144. my $text = template_text('shout3');
  1145. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1146. }
  1147. }
  1148. sub slap
  1149. {
  1150. # They slapped around
  1151. my @slaps;
  1152. foreach my $nick (sort keys %slap) {
  1153. @slaps = sort { $slap{$b} <=> $slap{$a} } keys %slap;
  1154. }
  1155. if(@slaps) {
  1156. my %hash = (
  1157. nick => $slaps[0],
  1158. slaps => $slap{$slaps[0]}
  1159. );
  1160. my $text = template_text('slap1', %hash);
  1161. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1162. if (@slaps >= 2) {
  1163. my %hash = (
  1164. nick => $slaps[1],
  1165. slaps => $slap{$slaps[1]}
  1166. );
  1167. my $text = template_text('slap2', %hash);
  1168. html("<br><span class=\"small\">$text</span>");
  1169. }
  1170. html("</td></tr>");
  1171. } else {
  1172. my $text = template_text('slap3');
  1173. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1174. }
  1175. # They got slapped
  1176. foreach my $nick (sort keys %slapped) {
  1177. @slaps = sort { $slapped{$b} <=> $slapped{$a} } keys %slapped;
  1178. }
  1179. if(@slaps) {
  1180. my %hash = (
  1181. nick => $slaps[0],
  1182. slaps => $slapped{$slaps[0]}
  1183. );
  1184. my $text = template_text('slapped1', %hash);
  1185. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1186. if (@slaps >= 2) {
  1187. my %hash = (
  1188. nick => $slaps[1],
  1189. slaps => $slapped{$slaps[1]}
  1190. );
  1191. my $text = template_text('slapped2', %hash);
  1192. html("<br><span class=\"small\">$text</span>");
  1193. }
  1194. html("</td></tr>");
  1195. } else {
  1196. my $text = template_text('slapped3');
  1197. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1198. }
  1199. }
  1200. sub gotkicks
  1201. {
  1202. # The persons who got kicked the most
  1203. my @gotkick = sort { $gotkick{$b} <=> $gotkick{$a} } keys %gotkick;
  1204. if (@gotkick) {
  1205. my %hash = (
  1206. nick => $gotkick[0],
  1207. kicks => $gotkick{$gotkick[0]}
  1208. );
  1209. my $text = template_text('gotkick1', %hash);
  1210. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1211. if (@gotkick >= 2) {
  1212. my %hash = (
  1213. nick => $gotkick[1],
  1214. kicks => $gotkick{$gotkick[1]}
  1215. );
  1216. my $text = template_text('gotkick2', %hash);
  1217. html("<br><span class=\"small\">$text</span>");
  1218. }
  1219. html("</td></tr>");
  1220. }
  1221. }
  1222. sub mostjoins
  1223. {
  1224. my @joins = sort { $joins{$b} <=> $joins{$a} } keys %joins;
  1225. if (@joins) {
  1226. my %hash = (
  1227. nick => $joins[0],
  1228. joins => $joins{$joins[0]}
  1229. );
  1230. my $text = template_text('joins', %hash);
  1231. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1232. }
  1233. }
  1234. sub mostwords
  1235. {
  1236. # The person who got words the most
  1237. my @words = sort { $words{$b} <=> $words{$a} } keys %words;
  1238. if (@words) {
  1239. my %hash = (
  1240. nick => $words[0],
  1241. words => $words{$words[0]}
  1242. );
  1243. my $text = template_text('words1', %hash);
  1244. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1245. if (@words >= 2) {
  1246. my %hash = (
  1247. oldnick => $words[0],
  1248. nick => $words[1],
  1249. words => $words{$words[1]}
  1250. );
  1251. my $text = template_text('words2', %hash);
  1252. html("<br><span class=\"small\">$text</span>");
  1253. }
  1254. html("</td></tr>");
  1255. } else {
  1256. my $text = template_text('kick3');
  1257. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1258. }
  1259. }
  1260. sub mostkicks
  1261. {
  1262. # The person who got kicked the most
  1263. my @kicked = sort { $kicked{$b} <=> $kicked{$a} } keys %kicked;
  1264. if (@kicked) {
  1265. my %hash = (
  1266. nick => $kicked[0],
  1267. kicked => $kicked{$kicked[0]}
  1268. );
  1269. my $text = template_text('kick1', %hash);
  1270. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1271. if (@kicked >= 2) {
  1272. my %hash = (
  1273. oldnick => $kicked[0],
  1274. nick => $kicked[1],
  1275. kicked => $kicked{$kicked[1]}
  1276. );
  1277. my $text = template_text('kick2', %hash);
  1278. html("<br><span class=\"small\">$text</span>");
  1279. }
  1280. html("</td></tr>");
  1281. } else {
  1282. my $text = template_text('kick3');
  1283. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1284. }
  1285. }
  1286. sub mostmonologues
  1287. {
  1288. # The person who had the most monologues (speaking to himself)
  1289. my @monologue = sort { $monologue{$b} <=> $monologue{$a} } keys %monologue;
  1290. if (@monologue) {
  1291. my %hash = (
  1292. nick => $monologue[0],
  1293. monos => $monologue{$monologue[0]}
  1294. );
  1295. my $text = template_text('mono1', %hash);
  1296. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1297. if (@monologue >= 2) {
  1298. my %hash = (
  1299. nick => $monologue[1],
  1300. monos => $monologue{$monologue[1]}
  1301. );
  1302. my $text = template_text('mono2', %hash);
  1303. if ($monologue{$monologue[1]} == 1 && $conf->{lang} eq 'EN') {
  1304. $text = substr $text, 0, -1;
  1305. }
  1306. html("<br><span class=\"small\">$text</span>");
  1307. }
  1308. html("</td></tr>");
  1309. }
  1310. }
  1311. sub longlines
  1312. {
  1313. # The person(s) who wrote the longest lines
  1314. my %len;
  1315. foreach my $nick (sort keys %length) {
  1316. if ($line{$nick} > 100) {
  1317. $len{$nick} = $length{$nick} / $line{$nick};
  1318. $len{$nick} =~ s/(\.\d)\d+/$1/;
  1319. }
  1320. }
  1321. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  1322. my $all_lines = $normals + $actions;
  1323. my $totalaverage;
  1324. if ($all_lines > 0) {
  1325. $totalaverage = $totallength / $all_lines;
  1326. $totalaverage =~ s/(\.\d)\d+/$1/;
  1327. }
  1328. if (@len) {
  1329. my %hash = (
  1330. nick => $len[0],
  1331. letters => $len{$len[0]}
  1332. );
  1333. my $text = template_text('long1', %hash);
  1334. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
  1335. if (@len >= 2) {
  1336. %hash = (
  1337. channel => $conf->{channel},
  1338. avg => $totalaverage
  1339. );
  1340. $text = template_text('long2', %hash);
  1341. html("<span class=\"small\">$text</span></td></tr>");
  1342. }
  1343. }
  1344. }
  1345. sub shortlines
  1346. {
  1347. # This sub should be combined with the longlines sub at some point.. it
  1348. # does basically the same thing.
  1349. my %len;
  1350. # The person(s) who wrote the shortest lines
  1351. foreach my $nick (sort keys %length) {
  1352. if ($line{$nick} > 5) {
  1353. $len{$nick} = $length{$nick} / $line{$nick};
  1354. $len{$nick} =~ s/(\.\d)\d+/$1/;
  1355. }
  1356. }
  1357. my @len = sort { $len{$a} <=> $len{$b} } keys %len;
  1358. if (@len) {
  1359. my %hash = (
  1360. nick => $len[0],
  1361. letters => $len{$len[0]}
  1362. );
  1363. my $text = template_text('short1', %hash);
  1364. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
  1365. if (@len >= 2) {
  1366. %hash = (
  1367. nick => $len[1],
  1368. letters => $len{$len[1]}
  1369. );
  1370. $text = template_text('short2', %hash);
  1371. html("<span class=\"small\">$text</span></td></tr>");
  1372. }
  1373. }
  1374. }
  1375. sub mostfoul
  1376. {
  1377. my %spercent;
  1378. foreach my $nick (sort keys %foul) {
  1379. if ($line{$nick} > 15) {
  1380. $spercent{$nick} = ($foul{$nick} / $line{$nick}) * 100;
  1381. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1382. }
  1383. }
  1384. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1385. if (@foul) {
  1386. my %hash = (
  1387. nick => $foul[0],
  1388. per => $spercent{$foul[0]}
  1389. );
  1390. my $text = template_text('foul1', %hash);
  1391. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1392. if (@foul >= 2) {
  1393. my %hash = (
  1394. nick => $foul[1],
  1395. per => $spercent{$foul[1]}
  1396. );
  1397. my $text = template_text('foul2', %hash);
  1398. html("<br><span class=\"small\">$text</span>");
  1399. }
  1400. html("</td></tr>");
  1401. } else {
  1402. my %hash = (
  1403. channel => $conf->{channel}
  1404. );
  1405. my $text = template_text('foul3', %hash);
  1406. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1407. }
  1408. }
  1409. sub mostsad
  1410. {
  1411. my %spercent;
  1412. foreach my $nick (sort keys %sadface) {
  1413. if ($line{$nick} > 100) {
  1414. $spercent{$nick} = ($sadface{$nick} / $line{$nick}) * 100;
  1415. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1416. }
  1417. }
  1418. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1419. if (@sadface) {
  1420. my %hash = (
  1421. nick => $sadface[0],
  1422. per => $spercent{$sadface[0]}
  1423. );
  1424. my $text = template_text('sad1', %hash);
  1425. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1426. if (@sadface >= 2) {
  1427. my %hash = (
  1428. nick => $sadface[1],
  1429. per => $spercent{$sadface[1]}
  1430. );
  1431. my $text = template_text('sad2', %hash);
  1432. html("<br><span class=\"small\">$text</span>");
  1433. }
  1434. html("</td></tr>");
  1435. } else {
  1436. my %hash = (
  1437. channel => $conf->{channel}
  1438. );
  1439. my $text = template_text('sad3', %hash);
  1440. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1441. }
  1442. }
  1443. sub mostop
  1444. {
  1445. my @ops = sort { $gaveop{$b} <=> $gaveop{$a} } keys %gaveop;
  1446. my @deops = sort { $tookop{$b} <=> $tookop{$a} } keys %tookop;
  1447. if (@ops) {
  1448. my %hash = (
  1449. nick => $ops[0],
  1450. ops => $gaveop{$ops[0]}
  1451. );
  1452. my $text = template_text('mostop1', %hash);
  1453. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1454. if (@ops >= 2) {
  1455. my %hash = (
  1456. nick => $ops[1],
  1457. ops => $gaveop{$ops[1]}
  1458. );
  1459. my $text = template_text('mostop2', %hash);
  1460. html("<br><span class=\"small\">$text</span>");
  1461. }
  1462. html("</td></tr>");
  1463. } else {
  1464. my %hash = ( channel => $conf->{channel} );
  1465. my $text = template_text('mostop3', %hash);
  1466. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1467. }
  1468. if (@deops) {
  1469. my %hash = (
  1470. channel => $conf->{channel},
  1471. nick => $deops[0],
  1472. deops => $tookop{$deops[0]}
  1473. );
  1474. my $text = template_text('mostdeop1', %hash);
  1475. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1476. if (@deops >= 2) {
  1477. my %hash = (
  1478. nick => $deops[1],
  1479. deops => $tookop{$deops[1]}
  1480. );
  1481. my $text = template_text('mostdeop2', %hash);
  1482. html("<br><span class=\"small\">$text</span>");
  1483. }
  1484. html("</td></tr>");
  1485. } else {
  1486. my %hash = ( channel => $conf->{channel} );
  1487. my $text = template_text('mostdeop3', %hash);
  1488. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1489. }
  1490. }
  1491. sub mostsmiles
  1492. {
  1493. # The person(s) who smiled the most :-)
  1494. my %spercent;
  1495. foreach my $nick (sort keys %smile) {
  1496. if ($line{$nick} > 100) {
  1497. $spercent{$nick} = ($smile{$nick} / $line{$nick}) * 100;
  1498. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1499. }
  1500. }
  1501. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1502. if (@smiles) {
  1503. my %hash = (
  1504. nick => $smiles[0],
  1505. per => $spercent{$smiles[0]}
  1506. );
  1507. my $text = template_text('smiles1', %hash);
  1508. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1509. if (@smiles >= 2) {
  1510. my %hash = (
  1511. nick => $smiles[1],
  1512. per => $spercent{$smiles[1]}
  1513. );
  1514. my $text = template_text('smiles2', %hash);
  1515. html("<br><span class=\"small\">$text</span>");
  1516. }
  1517. html("</td></tr>");
  1518. } else {
  1519. my %hash = (
  1520. channel => $conf->{channel}
  1521. );
  1522. my $text = template_text('smiles3', %hash);
  1523. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1524. }
  1525. }
  1526. sub lasttopics
  1527. {
  1528. debug("Total number of topics: ". scalar @topics);
  1529. if (@topics) {
  1530. my $ltopic = @topics - 1;
  1531. my $tlimit = 0;
  1532. $conf->{topichistory} -= 1;
  1533. if ($ltopic > $conf->{topichistory}) { $tlimit = $ltopic - $conf->{topichistory}; }
  1534. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1535. $topics[$i]{"topic"} = replace_links($topics[$i]{"topic"});
  1536. my $topic = $topics[$i]{topic};
  1537. my $nick = $topics[$i]{nick};
  1538. my $hour = $topics[$i]{hour};
  1539. my $min = $topics[$i]{min};
  1540. html("<tr><td bgcolor=\"$conf->{hicell}\"><i>$topic</i></td>");
  1541. html("<td bgcolor=\"$conf->{hicell}\">By <b>$nick</b> at <b>$hour:$min</b></td></tr>");
  1542. }
  1543. } else {
  1544. html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('notopic') ."</td></tr>");
  1545. }
  1546. }
  1547. # Some HTML subs
  1548. sub htmlheader
  1549. {
  1550. my $bgpic = "";
  1551. if ($conf->{bgpic}) {
  1552. $bgpic = " background=\"$conf->{bgpic}\"";
  1553. }
  1554. print OUTPUT <<HTML;
  1555. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  1556. <html>
  1557. <head>
  1558. <title>$conf->{channel} @ $conf->{network} channel statistics</title>
  1559. <style type="text/css">
  1560. a { text-decoration: none }
  1561. a:link { color: $conf->{link}; }
  1562. a:visited { color: $conf->{vlink}; }
  1563. a:hover { text-decoration: underline; color: $conf->{hlink} }
  1564. body {
  1565. background-color: $conf->{bgcolor};
  1566. font-family: verdana, arial, sans-serif;
  1567. font-size: 13px;
  1568. color: $conf->{text};
  1569. }
  1570. td {
  1571. font-family: verdana, arial, sans-serif;
  1572. font-size: 13px;
  1573. color: $conf->{tdcolor};
  1574. }
  1575. .title {
  1576. font-family: tahoma, arial, sans-serif;
  1577. font-size: 16px;
  1578. font-weight: bold;
  1579. }
  1580. .headline { color: $conf->{hcolor}; }
  1581. .small { font-family: verdana, arial, sans-serif; font-size: 10px; }
  1582. .asmall { font-family: arial narrow, sans-serif; font-size: 10px }
  1583. </style></head>
  1584. <body$bgpic>
  1585. <div align="center">
  1586. HTML
  1587. my %hash = (
  1588. channel => $conf->{channel},
  1589. network => $conf->{network},
  1590. maintainer => $conf->{maintainer},
  1591. time => $time,
  1592. days => $days,
  1593. nicks => $nicks,
  1594. channel => $conf->{channel}
  1595. );
  1596. print OUTPUT "<span class=\"title\">" . template_text('pagetitle1', %hash) . "</span><br>";
  1597. print OUTPUT "<br>" . template_text('pagetitle2', %hash) . "<br>";
  1598. print OUTPUT template_text('pagetitle3', %hash) . "<br><br>";
  1599. }
  1600. sub htmlfooter
  1601. {
  1602. print OUTPUT <<HTML;
  1603. <span class="small">
  1604. Stats generated by <a href="http://pisg.sourceforge.net/" title="Go to the pisg homepage">pisg</a> $conf->{version}<br>
  1605. pisg by <a href="http://www.wtf.dk/hp/" title="Go to the authors homepage">Morten "LostStar" Brix Pedersen</a> and others<br>
  1606. Stats generated in $processtime
  1607. </span>
  1608. </div>
  1609. </body>
  1610. </html>
  1611. HTML
  1612. }
  1613. sub headline
  1614. {
  1615. my ($title) = @_;
  1616. print OUTPUT <<HTML;
  1617. <br>
  1618. <table width="610" cellpadding="1" cellspacing="0" border="0">
  1619. <tr>
  1620. <td bgcolor="$conf->{headline}">
  1621. <table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">
  1622. <tr>
  1623. <td bgcolor="$conf->{hbgcolor}" class="text10">
  1624. <div align="center" class="headline"><b>$title</b></div>
  1625. </td>
  1626. </tr>
  1627. </table>
  1628. </td>
  1629. </tr>
  1630. </table>
  1631. HTML
  1632. }
  1633. sub pageheader
  1634. {
  1635. if ($conf->{pagehead} ne 'none') {
  1636. open(PAGEHEAD, $conf->{pagehead}) or die("$0: Unable to open $conf->{pagehead} for reading: $!\n");
  1637. while (<PAGEHEAD>) {
  1638. html($_);
  1639. }
  1640. }
  1641. }
  1642. sub close_debug
  1643. {
  1644. if ($conf->{debug}) {
  1645. close(DEBUG) or print STDERR "$0: Cannot close debugfile($conf->{debugfile}): $!\n";
  1646. }
  1647. }
  1648. sub get_cmdlineoptions
  1649. {
  1650. my $tmp;
  1651. # Commandline options
  1652. my ($channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help);
  1653. my $usage = <<END_USAGE;
  1654. Usage: pisg.pl [-c channel] [-l logfile] [-o outputfile] [-m
  1655. maintainer] [-f format] [-n network] [-d logdir] [-a aliasfile]
  1656. [-i ignorefile] [-h]
  1657. -ch --channel=xxx : Set channel name
  1658. -l --logfile=xxx : Log file to parse
  1659. -o --outfile=xxx : Name of html file to create
  1660. -m --maintainer=xxx : Channel/statistics maintainer
  1661. -f --format=xxx : Logfile format [see FORMATS file]
  1662. -n --network=xxx : IRC Network this channel is on.
  1663. -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
  1664. -p --prefix=xxx : Analyse only files starting with xxx in dir.
  1665. Only works with --dir
  1666. -co --configfile=xxx : Config file
  1667. -h --help : Output this message and exit (-? also works).
  1668. Example:
  1669. \$ pisg.pl -n IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
  1670. As always, all options may also be defined by editing the source and calling
  1671. pisg without arguments.
  1672. END_USAGE
  1673. if (GetOptions('channel=s' => \$channel,
  1674. 'logfile=s' => \$logfile,
  1675. 'format=s' => \$format,
  1676. 'network=s' => \$network,
  1677. 'maintainer=s' => \$maintainer,
  1678. 'outfile=s' => \$outputfile,
  1679. 'dir=s' => \$logdir,
  1680. 'prefix=s' => \$prefix,
  1681. 'ignorefile=s' => \$tmp,
  1682. 'aliasfile=s' => \$tmp,
  1683. 'configfile=s' => \$configfile,
  1684. 'help|?' => \$help
  1685. ) == 0 or $help) {
  1686. die($usage);
  1687. }
  1688. if (@ARGV) {
  1689. if ($ARGV[0]) { $conf->{channel} = $ARGV[0]; }
  1690. if ($ARGV[1]) { $conf->{logfile} = $ARGV[1]; }
  1691. if ($ARGV[2]) { $conf->{outputfile} = $ARGV[2]; }
  1692. if ($ARGV[3]) { $conf->{maintainer} = $ARGV[3]; }
  1693. }
  1694. if ($tmp) {
  1695. die("The aliasfile and ignorefile has been obsoleted by the new
  1696. pisg.cfg, please use that instead [look in pisg.cfg]\n");
  1697. }
  1698. if ($channel) {
  1699. $conf->{channel} = $channel;
  1700. $conf->{cmdl}{channel} = 1;
  1701. }
  1702. if ($logfile) {
  1703. $conf->{logfile} = $logfile;
  1704. $conf->{cmdl}{logfile} = 1;
  1705. }
  1706. if ($format) {
  1707. $conf->{format} = $format;
  1708. $conf->{cmdl}{format} = 1;
  1709. }
  1710. if ($network) {
  1711. $conf->{network} = $network;
  1712. $conf->{cmdl}{network} = 1;
  1713. }
  1714. if ($maintainer) {
  1715. $conf->{maintainer} = $maintainer;
  1716. $conf->{cmdl}{maintainer} = 1;
  1717. }
  1718. if ($outputfile) {
  1719. $conf->{outputfile} = $outputfile;
  1720. $conf->{cmdl}{outputfile} = 1;
  1721. }
  1722. if ($logdir) {
  1723. $conf->{logdir} = $logdir;
  1724. $conf->{cmdl}{logdir} = 1;
  1725. }
  1726. if ($prefix) {
  1727. $conf->{prefix} = $prefix;
  1728. $conf->{cmdl}{prefix} = 1;
  1729. }
  1730. if ($configfile) {
  1731. $conf->{configfile} = $configfile;
  1732. $conf->{cmdl}{configfile} = 1;
  1733. }
  1734. }
  1735. sub get_language_templates
  1736. {
  1737. open(FILE, $conf->{langfile}) or open (FILE, $FindBin::Bin . "/$conf->{langfile}") or die("$0: Unable to open language file($conf->{langfile}): $!\n");
  1738. while (<FILE>)
  1739. {
  1740. my $line = $_;
  1741. next if /^#/;
  1742. if ($line =~ /<lang name=\"([^"]+)\">/) {
  1743. # Found start tag, setting the current language
  1744. my $current_lang = $1;
  1745. while (<FILE>) {
  1746. last if ($_ =~ /<\/lang>/i);
  1747. # Get 'template = "Text"' in language file:
  1748. if ($_ =~ /(\w+)\s+=\s+"(.*)"\s*$/) {
  1749. $T{$current_lang}{$1} = $2;
  1750. }
  1751. }
  1752. }
  1753. }
  1754. close(FILE);
  1755. }
  1756. &main(); # Run the script