pisg.pl 61 KB

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