pisg.pl 66 KB

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