pisg.pl 70 KB

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