pisg.pl 72 KB

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