pisg.pl 72 KB

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