pisg.pl 62 KB

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