pisg.pl 72 KB

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