pisg.pl 71 KB

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