pisg.pl 62 KB

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