pisg.pl 71 KB

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