pisg.pl 69 KB

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