pisg.pl 69 KB

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