pisg.pl 69 KB

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