pisg.pl 69 KB

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