pisg.pl 70 KB

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