pisg.pl 64 KB

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