pisg.pl 61 KB

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