pisg.pl 69 KB

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