pisg.pl 62 KB

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