pisg.pl 70 KB

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