pisg.pl 72 KB

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