pisg.pl 71 KB

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