pisg.pl 69 KB

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