pisg.pl 62 KB

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