pisg.pl 64 KB

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