pisg.pl 69 KB

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