pisg.pl 62 KB

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