pisg.pl 61 KB

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