pisg.pl 64 KB

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