pisg.pl 62 KB

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