pisg.pl 71 KB

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