pisg.pl 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192
  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+/, $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. unless (defined($alias{$newnick})) {
  502. if (defined($alias{$nick}) && !defined($alias{$newnick})) {
  503. $alias{$newnick} = $nick;
  504. } elsif (defined($alias{$newnick}) && !defined($alias{$nick})) {
  505. $alias{$nick} = $newnick;
  506. } elsif ($nick =~ /Guest/) {
  507. $alias{$nick} = $newnick;
  508. } else {
  509. $alias{$newnick} = $nick;
  510. }
  511. }
  512. }
  513. }
  514. if ($hour < $oldtime) { $days++ }
  515. $oldtime = $hour;
  516. }
  517. }
  518. close(LOGFILE);
  519. my ($sec,$min,$hour) = gmtime(time - $^T);
  520. $processtime = sprintf("%02d hours, %02d minutes and %02d seconds", $hour, $min, $sec);
  521. $nicks = scalar keys %line;
  522. print "Finished analyzing log, $days days total.\n";
  523. }
  524. # Here is the 3 parse sub routines, their function is to return a hash with
  525. # the elements in the line. This is where we add the format dependent stuff.
  526. sub parse_normalline
  527. {
  528. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  529. my $line = shift;
  530. my %hash;
  531. if ($line =~ /$normalline/) {
  532. debug("[$lines] Normal: $1 $2 $3");
  533. if (($conf->{format} eq 'mIRC') || ($conf->{format} eq 'xchat') || ($conf->{format} eq
  534. 'eggdrop') || ($conf->{format} eq 'bxlog') || ($conf->{format} eq 'grufti')) {
  535. $hash{hour} = $1;
  536. $hash{nick} = $2;
  537. $hash{saying} = $3;
  538. } else {
  539. die("Format not supported?!\n");
  540. }
  541. return \%hash;
  542. } else {
  543. return;
  544. }
  545. }
  546. sub parse_actionline
  547. {
  548. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  549. my $line = shift;
  550. my %hash;
  551. if ($line =~ /$actionline/) {
  552. debug("[$lines] Action: $1 $2 $3");
  553. if (($conf->{format} eq 'mIRC') || ($conf->{format} eq 'xchat') || ($conf->{format} eq
  554. 'eggdrop') || $conf->{format} eq 'bxlog' || ($conf->{format} eq 'grufti')) {
  555. $hash{hour} = $1;
  556. $hash{nick} = $2;
  557. $hash{saying} = $3;
  558. } else {
  559. die("Format not supported?!\n");
  560. }
  561. return \%hash;
  562. } else {
  563. return;
  564. }
  565. }
  566. sub parse_thirdline
  567. {
  568. # Parses the 'third' line - (the third line is everything else, like
  569. # topic changes, mode changes, kicks, etc.)
  570. # parse_thirdline() have to return a hash with the following keys, for
  571. # every format:
  572. # hour - the hour we're in (for timestamp loggin)
  573. # min - the minute we're in (for timestamp loggin)
  574. # nick - the nick
  575. # kicker - the nick which were kicked (if any)
  576. # newtopic - the new topic (if any)
  577. # newmode - deops or ops, must be '+o' or '-o', or '+ooo'
  578. # newjoin - a new nick which has joined the channel
  579. # newnick - a person has changed nick and this is the new nick
  580. my $line = shift;
  581. my %hash;
  582. if ($line =~ /$thirdline/) {
  583. if ($7) {
  584. debug("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
  585. } elsif ($5) {
  586. debug("[$lines] ***: $1 $2 $3 $4 $5 $6");
  587. } else {
  588. debug("[$lines] ***: $1 $2 $3 $4");
  589. }
  590. if ($conf->{format} eq 'mIRC') {
  591. $hash{hour} = $1;
  592. $hash{min} = $2;
  593. $hash{nick} = $3;
  594. if (($4.$5) eq 'waskicked') {
  595. $hash{kicker} = $7;
  596. } elsif (($4.$5) eq 'changestopic') {
  597. $hash{newtopic} = "$7 $8";
  598. } elsif (($4.$5) eq 'setsmode:') {
  599. $hash{newmode} = $6;
  600. } elsif (($4.$5) eq 'hasjoined') {
  601. $hash{newjoin} = $3;
  602. } elsif (($4.$5) eq 'nowknown') {
  603. $hash{newnick} = $8;
  604. }
  605. } elsif ($conf->{format} eq 'xchat') {
  606. $hash{hour} = $1;
  607. $hash{min} = $2;
  608. $hash{nick} = $3;
  609. if (($4.$5) eq 'haskicked') {
  610. $hash{kicker} = $3;
  611. $hash{nick} = $6;
  612. } elsif (($4.$5) eq 'haschanged') {
  613. $hash{newtopic} = $9;
  614. } elsif (($4.$5) eq 'giveschannel') {
  615. $hash{newmode} = '+o';
  616. } elsif (($4.$5) eq 'removeschannel') {
  617. $hash{newmode} = '-o';
  618. } elsif (($5.$6) eq 'hasjoined') {
  619. $hash{newjoin} = $1;
  620. } elsif (($5.$6) eq 'nowknown') {
  621. $hash{newnick} = $8;
  622. }
  623. } elsif ($conf->{format} eq 'eggdrop') {
  624. $hash{hour} = $1;
  625. $hash{min} = $2;
  626. $hash{nick} = $3;
  627. if (($4.$5) eq 'kickedfrom') {
  628. $7 =~ /^ by ([\S]+):.*/;
  629. $hash{kicker} = $1;
  630. } elsif ($3 eq 'Topic') {
  631. $7 =~ /^ by ([\S]+)![\S]+: (.*)/;
  632. $hash{nick} = $1;
  633. $hash{newtopic} = $2;
  634. } elsif (($4.$5) eq 'modechange') {
  635. my $newmode = $6;
  636. if ($7 =~ /^ .+ by ([\S]+)!.*/) {
  637. $hash{nick} = $1;
  638. $newmode =~ s/^\'//;
  639. $hash{newmode} = $newmode;
  640. }
  641. } elsif ($5 eq 'joined') {
  642. $hash{newjoin} = $3;
  643. } elsif (($3.$4) eq 'Nickchange:') {
  644. $hash{nick} = $5;
  645. $7 =~ /([\S]+)/;
  646. $hash{newnick} = $1;
  647. } elsif (($3.$4.$5) eq 'Lastmessagerepeated') {
  648. $repeated = $6;
  649. }
  650. } elsif ($conf->{format} eq 'bxlog') {
  651. $hash{hour} = $1;
  652. $hash{min} = $2;
  653. if ($3 eq '<') {
  654. if ($4 =~ /^([^!]+)!([\S+]) was kicked off (\S+) by ([^!]+)!(\S+) \(([^)]+)\)$/) {
  655. $hash{kicker} = $4;
  656. $hash{nick} = $1;
  657. }
  658. } elsif ($3 eq '>') {
  659. if ($4 =~ /^([^!])+!(\S+) has joined (\S+)$/) {
  660. $hash{nick} = $1;
  661. $hash{newjoin} = $1;
  662. }
  663. } elsif ($3 eq '@') {
  664. if ($4 =~ /^Topic by ([^!:])[!:]*: (.*)$/) {
  665. $hash{nick} = $1;
  666. $hash{newtopic} = $2;
  667. } elsif ($4 =~ /^mode \S+ \[([\S]+) [^\]]+\] by ([^!]+)!\S+$/) {
  668. $hash{newmode} = $1;
  669. $hash{nick} = $2;
  670. }
  671. } elsif ($3 eq '!') {
  672. if ($4 =~ /^(\S+) is known as (\S+)$/) {
  673. $hash{nick} = $1;
  674. $hash{newnick} = $2;
  675. }
  676. }
  677. } elsif ($conf->{format} eq 'grufti') {
  678. $hash{hour} = $1;
  679. $hash{min} = $2;
  680. $hash{nick} = $3;
  681. if ($5 eq 'kicked') {
  682. $hash{kicker} = $3;
  683. $hash{nick} = $6;
  684. } elsif (($4.$5) eq 'haschanged') {
  685. $hash{newtopic} = $9;
  686. } elsif (($4.$5) eq 'modechange') {
  687. $hash{newmode} = substr($6, 1);
  688. $hash{nick} = $9;
  689. $hash{nick} =~ /.*[by ](\S+)/;
  690. $hash{nick} = $1;
  691. } elsif ($5 eq 'joined') {
  692. $hash{newjoin} = $1;
  693. } elsif (($3.$4) eq 'Nickchange') {
  694. $hash{nick} = $7;
  695. $hash{newnick} = $9;
  696. }
  697. } else {
  698. die("Format not supported?!\n");
  699. }
  700. return \%hash;
  701. } else {
  702. return;
  703. }
  704. }
  705. sub opchanges
  706. {
  707. my @modes = split(//, $_[0]);
  708. my ($mode,$plus) = ("",0);
  709. my ($gaveop,$tookop) = (0,0);
  710. foreach (@modes) {
  711. if (/^\+$/) { $plus = 1; next; }
  712. elsif (/^-$/) { $plus = 0; next; }
  713. else { next unless /^o$/ }
  714. if ($plus) { $gaveop++ } else { $tookop++ }
  715. }
  716. return ($gaveop,$tookop);
  717. }
  718. sub strip_mirccodes
  719. {
  720. my $line = shift;
  721. my $boldcode = chr(2);
  722. my $colorcode = chr(3);
  723. my $plaincode = chr(15);
  724. my $reversecode = chr(22);
  725. my $underlinecode = chr(31);
  726. # Strip mIRC color codes
  727. $line =~ s/$colorcode\d{1,2},\d{1,2}//g;
  728. $line =~ s/$colorcode\d{0,2}//g;
  729. # Strip mIRC bold, plain, reverse and underline codes
  730. $line =~ s/[$boldcode$underlinecode$reversecode$plaincode]//g;
  731. return $line;
  732. }
  733. sub htmlentities
  734. {
  735. my $str = shift;
  736. $str =~ s/\&/\&amp;/g;
  737. $str =~ s/\</\&lt;/g;
  738. $str =~ s/\>/\&gt;/g;
  739. $str =~ s/ü/&uuml;/g;
  740. $str =~ s/ö/&ouml;/g;
  741. $str =~ s/ä/&auml;/g;
  742. $str =~ s/ß/&szlig;/g;
  743. $str =~ s/å/&aring;/g;
  744. $str =~ s/æ/&aelig;/g;
  745. $str =~ s/ø/&oslash;/g;
  746. return $str;
  747. }
  748. sub html
  749. {
  750. my $html = shift;
  751. print OUTPUT $html . "\n";
  752. }
  753. sub template_text
  754. {
  755. # This function is for the homemade template system. It receives a name
  756. # of a template and a hash with the fields in the template to update to
  757. # its corresponding value
  758. my $template = shift;
  759. my %hash = @_;
  760. my $text;
  761. if (!$T{$conf->{lang}}{$template}) {
  762. # Fall back to English if the language template doesn't exist
  763. $text = $T{EN}{$template};
  764. }
  765. $text = $T{$conf->{lang}}{$template};
  766. if (!$text) {
  767. die("No such template '$template' in language file.\n");
  768. }
  769. foreach my $key (sort keys %hash) {
  770. $text =~ s/\[:$key\]/$hash{$key}/;
  771. $text =~ s/ü/&uuml;/g;
  772. $text =~ s/ö/&ouml;/g;
  773. $text =~ s/ä/&auml;/g;
  774. $text =~ s/ß/&szlig;/g;
  775. $text =~ s/å/&aring;/g;
  776. $text =~ s/æ/&aelig;/g;
  777. $text =~ s/ø/&oslash;/g;
  778. }
  779. return $text;
  780. }
  781. sub replace_links
  782. {
  783. # Sub to replace urls and e-mail addys to links
  784. my $str = shift;
  785. my $nick = shift;
  786. if ($nick) {
  787. $str =~ s/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_]+.[-a-zA-Z0-9.,_~=:;&@%?#\/+]+)/<a href="$1$2" target="_blank" title="Open in new window: $1$2">$nick<\/a>/g;
  788. $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="Mail to $nick">$nick<\/a>/g;
  789. } else {
  790. $str =~ s/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_]+.[-a-zA-Z0-9.,_~=:;&@%?#\/+]+)/<a href="$1$2" target="_blank" title="Open in new window: $1$2">$1$2<\/a>/g;
  791. $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="Mail to $1">$1<\/a>/g;
  792. }
  793. return $str;
  794. }
  795. sub debug
  796. {
  797. if ($conf->{debug}) {
  798. my $debugline = $_[0] . "\n";
  799. if ($conf->{debugstarted}) {
  800. print DEBUG $debugline;
  801. } else {
  802. $conf->{debugqueue} .= $debugline;
  803. }
  804. }
  805. }
  806. sub find_alias
  807. {
  808. my $nick = shift;
  809. if ($alias{$nick}) {
  810. return $alias{$nick};
  811. } else {
  812. foreach (keys %alias) {
  813. if (($_ =~ /\.\*/) && ($nick =~ /^$_$/)) {
  814. return $alias{$_};
  815. }
  816. }
  817. }
  818. return $nick;
  819. }
  820. sub create_html
  821. {
  822. # This is where all subroutines get executed, you can actually design
  823. # your own layout here, the lines should be self-explainable
  824. print "Now generating HTML($conf->{outputfile})...\n";
  825. open (OUTPUT, "> $conf->{outputfile}") or die("$0: Unable to open outputfile($conf->{outputfile}): $!\n");
  826. htmlheader();
  827. pageheader();
  828. activetimes();
  829. activenicks();
  830. headline(template_text('bignumtopic'));
  831. html("<table width=\"614\">\n"); # Needed for sections
  832. questions();
  833. loudpeople();
  834. shoutpeople();
  835. slap();
  836. mostsmiles();
  837. mostsad();
  838. longlines();
  839. shortlines();
  840. mostwords();
  841. html("</table>"); # Needed for sections
  842. mostusedword();
  843. mostreferenced();
  844. headline(template_text('othernumtopic'));
  845. html("<table width=\"614\">\n"); # Needed for sections
  846. gotkicks();
  847. mostkicks();
  848. mostop();
  849. mostmonologues();
  850. mostjoins();
  851. mostfoul();
  852. html("</table>"); # Needed for sections
  853. headline(template_text('latesttopic'));
  854. html("<table width=\"614\">\n"); # Needed for sections
  855. lasttopics();
  856. html("</table>"); # Needed for sections
  857. my %hash = ( lines => $lines );
  858. html(template_text('totallines', %hash) . "<br><br>");
  859. htmlfooter();
  860. close(OUTPUT);
  861. }
  862. sub activetimes
  863. {
  864. # The most actives times on the channel
  865. my (%output, $tbgcolor);
  866. &headline(template_text('activetimestopic'));
  867. my @toptime = sort { $times{$b} <=> $times{$a} } keys %times;
  868. my $highest_value = $times{$toptime[0]};
  869. my @now = localtime($timestamp);
  870. my $image;
  871. for my $hour (sort keys %times) {
  872. debug("Time: $hour => ". $times{$hour});
  873. if ($toptime[0] == $hour) {
  874. $image = $conf->{pic2};
  875. } else {
  876. $image = $conf->{pic1};
  877. }
  878. my $size = ($times{$hour} / $highest_value) * 100;
  879. my $percent = ($times{$hour} / $lines) * 100;
  880. $percent =~ s/(\.\d)\d+/$1/;
  881. if ($conf->{timeoffset} =~ /\+(\d+)/) {
  882. # We must plus some hours to the time
  883. $hour += $1;
  884. $hour = $hour % 24;
  885. if ($hour < 10) { $hour = "0" . $hour; }
  886. } elsif ($conf->{timeoffset} =~ /-(\d+)/) {
  887. # We must remove some hours from the time
  888. $hour -= $1;
  889. $hour = $hour % 24;
  890. if ($hour < 10) { $hour = "0" . $hour; }
  891. }
  892. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br><img src=\"$image\" width=\"15\" height=\"$size\" alt=\"$percent\"></td>\n";
  893. }
  894. html("<table border=\"0\" width=\"614\"><tr>\n");
  895. for ($b = 0; $b < 24; $b++) {
  896. if ($b < 10) { $a = "0" . $b; } else { $a = $b; }
  897. if (!defined($output{$a}) || $output{$a} eq "") {
  898. html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  899. } else {
  900. html($output{$a});
  901. }
  902. }
  903. html("</tr><tr>");
  904. for ($b = 0; $b < 24; $b++) {
  905. if ($now[2] == $b) { $tbgcolor = "\#AAAAAA"; } else { $tbgcolor = "\#CCCCCC"; }
  906. html("<td bgcolor=\"$tbgcolor\" align=\"center\" class=\"small\">$b</td>");
  907. }
  908. html("</tr></table>");
  909. }
  910. sub activenicks
  911. {
  912. # The most active nicks (those who wrote most lines)
  913. headline(template_text('activenickstopic'));
  914. html("<table border=\"0\" width=\"614\"><tr>");
  915. 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>");
  916. if (%userpics) {
  917. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('userpic') ."</b></td>");
  918. }
  919. html("</tr>");
  920. my @active = sort { $line{$b} <=> $line{$a} } keys %line;
  921. if ($conf->{activenicks} > $nicks) {
  922. $conf->{activenicks} = $nicks;
  923. print "Note: There was less nicks in the logfile than your specificied there to be in most active nicks...\n";
  924. }
  925. my ($nick, $visiblenick, $randomline);
  926. my $i = 1;
  927. for (my $c = 0; $c < $conf->{activenicks}; $c++) {
  928. $nick = $active[$c];
  929. $visiblenick = $active[$c];
  930. if (!$longlines{$nick}) {
  931. $randomline = "";
  932. } else {
  933. my $rand = rand($longlines{$nick});
  934. $randomline = $sayings{$nick}[$rand];
  935. }
  936. # Convert URLs and e-mail addys to links
  937. $randomline = replace_links($randomline);
  938. # Add a link to the nick if there is any
  939. if ($userlinks{$nick}) {
  940. $visiblenick = replace_links($userlinks{$nick}, $nick);
  941. }
  942. my $h = $conf->{hicell};
  943. $h =~ s/^#//;
  944. $h = hex $h;
  945. my $h2 = $conf->{hicell2};
  946. $h2 =~ s/^#//;
  947. $h2 = hex $h2;
  948. my $f_b = $h & 0xff;
  949. my $f_g = ($h & 0xff00) >> 8;
  950. my $f_r = ($h & 0xff0000) >> 16;
  951. my $t_b = $h2 & 0xff;
  952. my $t_g = ($h2 & 0xff00) >> 8;
  953. my $t_r = ($h2 & 0xff0000) >> 16;
  954. my $col_b = sprintf "%0.2x", abs int(((($t_b - $f_b) / $conf->{activenicks}) * +$c) + $f_b);
  955. my $col_g = sprintf "%0.2x", abs int(((($t_g - $f_g) / $conf->{activenicks}) * +$c) + $f_g);
  956. my $col_r = sprintf "%0.2x", abs int(((($t_r - $f_r) / $conf->{activenicks}) * +$c) + $f_r);
  957. html("<tr><td bgcolor=\"$conf->{rankc}\" align=\"left\">");
  958. my $line = $line{$nick};
  959. 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\">");
  960. html("\"$randomline\"</td>");
  961. if ($userpics{$nick}) {
  962. html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$conf->{imagepath}$userpics{$nick}\"></td>");
  963. }
  964. html("</tr>");
  965. $i++;
  966. }
  967. html("</table><br>");
  968. # Almost as active nicks ('These didn't make it to the top..')
  969. my $nickstoshow = $conf->{activenicks} + $conf->{activenicks2};
  970. unless ($nickstoshow > $nicks) {
  971. html("<br><b><i>" . template_text('nottop') . "</i></b><table><tr>");
  972. for (my $c = $conf->{activenicks}; $c < $nickstoshow; $c++) {
  973. unless ($c % 5) { unless ($c == $conf->{activenicks}) { html("</tr><tr>"); } }
  974. html("<td bgcolor=\"$conf->{rankc}\" class=\"small\">");
  975. my $nick = $active[$c];
  976. my $lines = $line{$nick};
  977. html("$nick ($lines)</td>");
  978. }
  979. html("</table>");
  980. }
  981. }
  982. sub mostusedword
  983. {
  984. # Lao the infamous word usage statistics
  985. my %usages;
  986. foreach my $word (sort keys %wordcount) {
  987. next if exists $line{$word};
  988. $usages{$word} = $wordcount{$word};
  989. }
  990. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  991. if (@popular) {
  992. &headline(template_text('mostwordstopic'));
  993. html("<table border=\"0\" width=\"614\"><tr>");
  994. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('word') . "</b></td>");
  995. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  996. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  997. for(my $i = 0; $i < 10; $i++) {
  998. last unless $i < $#popular;
  999. my $a = $i + 1;
  1000. my $popular = $popular[$i];
  1001. my $wordcount = $wordcount{$popular[$i]};
  1002. my $lastused = $lastused{$popular[$i]};
  1003. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  1004. html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
  1005. html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
  1006. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  1007. html("</tr>");
  1008. }
  1009. html("</table>");
  1010. }
  1011. }
  1012. sub mostreferenced
  1013. {
  1014. my %usages;
  1015. foreach my $word (sort keys %wordcount) {
  1016. next unless exists $line{$word};
  1017. $usages{$word} = $wordcount{$word};
  1018. }
  1019. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1020. if (@popular) {
  1021. &headline(template_text('referencetopic'));
  1022. html("<table border=\"0\" width=\"614\"><tr>");
  1023. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('nick') . "</b></td>");
  1024. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  1025. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  1026. for(my $i = 0; $i < 5; $i++) {
  1027. last unless $i < $#popular;
  1028. my $a = $i + 1;
  1029. my $popular = $popular[$i];
  1030. my $wordcount = $wordcount{$popular[$i]};
  1031. my $lastused = $lastused{$popular[$i]};
  1032. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  1033. html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
  1034. html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
  1035. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  1036. html("</tr>");
  1037. }
  1038. html("</table>");
  1039. }
  1040. }
  1041. sub questions
  1042. {
  1043. # Persons who asked the most questions
  1044. foreach my $nick (sort keys %question) {
  1045. if ($line{$nick} > 100) {
  1046. $qpercent{$nick} = ($question{$nick} / $line{$nick}) * 100;
  1047. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  1048. }
  1049. }
  1050. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  1051. if (@question) {
  1052. my %hash = (
  1053. nick => $question[0],
  1054. per => $qpercent{$question[0]}
  1055. );
  1056. my $text = template_text('question1', %hash);
  1057. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1058. if (@question >= 2) {
  1059. my %hash = (
  1060. nick => $question[1],
  1061. per => $qpercent{$question[1]}
  1062. );
  1063. my $text = template_text('question2', %hash);
  1064. html("<br><span class=\"small\">$text</span>");
  1065. }
  1066. html("</td></tr>");
  1067. } else {
  1068. html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('question3') . "</td></tr>");
  1069. }
  1070. }
  1071. sub loudpeople
  1072. {
  1073. # The ones who speak LOUDLY!
  1074. foreach my $nick (sort keys %loud) {
  1075. if ($line{$nick} > 100) {
  1076. $lpercent{$nick} = ($loud{$nick} / $line{$nick}) * 100;
  1077. $lpercent{$nick} =~ s/(\.\d)\d+/$1/;
  1078. }
  1079. }
  1080. my @loud = sort { $lpercent{$b} <=> $lpercent{$a} } keys %lpercent;
  1081. if (@loud) {
  1082. my %hash = (
  1083. nick => $loud[0],
  1084. per => $lpercent{$loud[0]}
  1085. );
  1086. my $text = template_text('loud1', %hash);
  1087. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1088. if (@loud >= 2) {
  1089. my %hash = (
  1090. nick => $loud[1],
  1091. per => $lpercent{$loud[1]}
  1092. );
  1093. my $text = template_text('loud2', %hash);
  1094. html("<br><span class=\"small\">$text</span>");
  1095. }
  1096. html("</td></tr>");
  1097. } else {
  1098. my $text = template_text('loud3');
  1099. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1100. }
  1101. }
  1102. sub shoutpeople
  1103. {
  1104. # The ones who speak SHOUTED!
  1105. foreach my $nick (sort keys %shout) {
  1106. if ($line{$nick} > 100) {
  1107. $spercent{$nick} = ($shout{$nick} / $line{$nick}) * 100;
  1108. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1109. }
  1110. }
  1111. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1112. if (@shout) {
  1113. my %hash = (
  1114. nick => $shout[0],
  1115. per => $spercent{$shout[0]}
  1116. );
  1117. my $text = template_text('shout1', %hash);
  1118. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1119. if (@shout >= 2) {
  1120. my %hash = (
  1121. nick => $shout[1],
  1122. per => $spercent{$shout[1]}
  1123. );
  1124. my $text = template_text('shout2', %hash);
  1125. html("<br><span class=\"small\">$text</span>");
  1126. }
  1127. html("</td></tr>");
  1128. } else {
  1129. my $text = template_text('shout3');
  1130. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1131. }
  1132. }
  1133. sub slap
  1134. {
  1135. my @slaps;
  1136. # They slapped around
  1137. foreach my $nick (sort keys %slap) {
  1138. @slaps = sort { $slap{$b} <=> $slap{$a} } keys %slap;
  1139. }
  1140. if(@slaps) {
  1141. my %hash = (
  1142. nick => $slaps[0],
  1143. slaps => $slap{$slaps[0]}
  1144. );
  1145. my $text = template_text('slap1', %hash);
  1146. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1147. if (@slaps >= 2) {
  1148. my %hash = (
  1149. nick => $slaps[1],
  1150. slaps => $slap{$slaps[1]}
  1151. );
  1152. my $text = template_text('slap2', %hash);
  1153. html("<br><span class=\"small\">$text</span>");
  1154. }
  1155. html("</td></tr>");
  1156. } else {
  1157. my $text = template_text('slap3');
  1158. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1159. }
  1160. # They got slapped
  1161. foreach my $nick (sort keys %slapped) {
  1162. @slaps = sort { $slapped{$b} <=> $slapped{$a} } keys %slapped;
  1163. }
  1164. if(@slaps) {
  1165. my %hash = (
  1166. nick => $slaps[0],
  1167. slaps => $slapped{$slaps[0]}
  1168. );
  1169. my $text = template_text('slapped1', %hash);
  1170. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1171. if (@slaps >= 2) {
  1172. my %hash = (
  1173. nick => $slaps[1],
  1174. slaps => $slapped{$slaps[1]}
  1175. );
  1176. my $text = template_text('slapped2', %hash);
  1177. html("<br><span class=\"small\">$text</span>");
  1178. }
  1179. html("</td></tr>");
  1180. } else {
  1181. my $text = template_text('slapped3');
  1182. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1183. }
  1184. }
  1185. sub gotkicks
  1186. {
  1187. # The persons who got kicked the most
  1188. my @gotkick = sort { $gotkick{$b} <=> $gotkick{$a} } keys %gotkick;
  1189. if (@gotkick) {
  1190. my %hash = (
  1191. nick => $gotkick[0],
  1192. kicks => $gotkick{$gotkick[0]}
  1193. );
  1194. my $text = template_text('gotkick1', %hash);
  1195. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1196. if (@gotkick >= 2) {
  1197. my %hash = (
  1198. nick => $gotkick[1],
  1199. kicks => $gotkick{$gotkick[1]}
  1200. );
  1201. my $text = template_text('gotkick2', %hash);
  1202. html("<br><span class=\"small\">$text</span>");
  1203. }
  1204. html("</td></tr>");
  1205. }
  1206. }
  1207. sub mostjoins
  1208. {
  1209. my @joins = sort { $joins{$b} <=> $joins{$a} } keys %joins;
  1210. if (@joins) {
  1211. my %hash = (
  1212. nick => $joins[0],
  1213. joins => $joins{$joins[0]}
  1214. );
  1215. my $text = template_text('joins', %hash);
  1216. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1217. }
  1218. }
  1219. sub mostwords
  1220. {
  1221. # The person who got words the most
  1222. my @words = sort { $words{$b} <=> $words{$a} } keys %words;
  1223. if (@words) {
  1224. my %hash = (
  1225. nick => $words[0],
  1226. words => $words{$words[0]}
  1227. );
  1228. my $text = template_text('words1', %hash);
  1229. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1230. if (@words >= 2) {
  1231. my %hash = (
  1232. oldnick => $words[0],
  1233. nick => $words[1],
  1234. words => $words{$words[1]}
  1235. );
  1236. my $text = template_text('words2', %hash);
  1237. html("<br><span class=\"small\">$text</span>");
  1238. }
  1239. html("</td></tr>");
  1240. } else {
  1241. my $text = template_text('kick3');
  1242. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1243. }
  1244. }
  1245. sub mostkicks
  1246. {
  1247. # The person who got kicked the most
  1248. my @kicked = sort { $kicked{$b} <=> $kicked{$a} } keys %kicked;
  1249. if (@kicked) {
  1250. my %hash = (
  1251. nick => $kicked[0],
  1252. kicked => $kicked{$kicked[0]}
  1253. );
  1254. my $text = template_text('kick1', %hash);
  1255. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1256. if (@kicked >= 2) {
  1257. my %hash = (
  1258. oldnick => $kicked[0],
  1259. nick => $kicked[1],
  1260. kicked => $kicked{$kicked[1]}
  1261. );
  1262. my $text = template_text('kick2', %hash);
  1263. html("<br><span class=\"small\">$text</span>");
  1264. }
  1265. html("</td></tr>");
  1266. } else {
  1267. my $text = template_text('kick3');
  1268. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1269. }
  1270. }
  1271. sub mostmonologues
  1272. {
  1273. # The person who had the most monologues (speaking to himself)
  1274. my @monologue = sort { $monologue{$b} <=> $monologue{$a} } keys %monologue;
  1275. if (@monologue) {
  1276. my %hash = (
  1277. nick => $monologue[0],
  1278. monos => $monologue{$monologue[0]}
  1279. );
  1280. my $text = template_text('mono1', %hash);
  1281. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1282. if (@monologue >= 2) {
  1283. my %hash = (
  1284. nick => $monologue[1],
  1285. monos => $monologue{$monologue[1]}
  1286. );
  1287. my $text = template_text('mono2', %hash);
  1288. if ($monologue{$monologue[1]} == 1 && $conf->{lang} eq 'EN') {
  1289. $text = substr $text, 0, -1;
  1290. }
  1291. html("<br><span class=\"small\">$text</span>");
  1292. }
  1293. html("</td></tr>");
  1294. }
  1295. }
  1296. sub longlines
  1297. {
  1298. my %len;
  1299. # The person(s) who wrote the longest lines
  1300. foreach my $nick (sort keys %length) {
  1301. if ($line{$nick} > 100) {
  1302. $len{$nick} = $length{$nick} / $line{$nick};
  1303. $len{$nick} =~ s/(\.\d)\d+/$1/;
  1304. }
  1305. }
  1306. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  1307. my $all_lines = $normals + $actions;
  1308. my $totalaverage;
  1309. if ($all_lines > 0) {
  1310. $totalaverage = $totallength / $all_lines;
  1311. $totalaverage =~ s/(\.\d)\d+/$1/;
  1312. }
  1313. if (@len) {
  1314. my %hash = (
  1315. nick => $len[0],
  1316. letters => $len{$len[0]}
  1317. );
  1318. my $text = template_text('long1', %hash);
  1319. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
  1320. if (@len >= 2) {
  1321. %hash = (
  1322. channel => $conf->{channel},
  1323. avg => $totalaverage
  1324. );
  1325. $text = template_text('long2', %hash);
  1326. html("<span class=\"small\">$text</span></td></tr>");
  1327. }
  1328. }
  1329. }
  1330. sub shortlines
  1331. {
  1332. # This sub should be combined with the longlines sub at some point.. it
  1333. # does basically the same thing.
  1334. my %len;
  1335. # The person(s) who wrote the shortest lines
  1336. foreach my $nick (sort keys %length) {
  1337. if ($line{$nick} > 5) {
  1338. $len{$nick} = $length{$nick} / $line{$nick};
  1339. $len{$nick} =~ s/(\.\d)\d+/$1/;
  1340. }
  1341. }
  1342. my @len = sort { $len{$a} <=> $len{$b} } keys %len;
  1343. if (@len) {
  1344. my %hash = (
  1345. nick => $len[0],
  1346. letters => $len{$len[0]}
  1347. );
  1348. my $text = template_text('short1', %hash);
  1349. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
  1350. if (@len >= 2) {
  1351. %hash = (
  1352. nick => $len[1],
  1353. letters => $len{$len[1]}
  1354. );
  1355. $text = template_text('short2', %hash);
  1356. html("<span class=\"small\">$text</span></td></tr>");
  1357. }
  1358. }
  1359. }
  1360. sub mostfoul
  1361. {
  1362. my %spercent;
  1363. foreach my $nick (sort keys %foul) {
  1364. if ($line{$nick} > 15) {
  1365. $spercent{$nick} = ($foul{$nick} / $line{$nick}) * 100;
  1366. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1367. }
  1368. }
  1369. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1370. if (@foul) {
  1371. my %hash = (
  1372. nick => $foul[0],
  1373. per => $spercent{$foul[0]}
  1374. );
  1375. my $text = template_text('foul1', %hash);
  1376. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1377. if (@foul >= 2) {
  1378. my %hash = (
  1379. nick => $foul[1],
  1380. per => $spercent{$foul[1]}
  1381. );
  1382. my $text = template_text('foul2', %hash);
  1383. html("<br><span class=\"small\">$text</span>");
  1384. }
  1385. html("</td></tr>");
  1386. } else {
  1387. my %hash = (
  1388. channel => $conf->{channel}
  1389. );
  1390. my $text = template_text('foul3', %hash);
  1391. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1392. }
  1393. }
  1394. sub mostsad
  1395. {
  1396. my %spercent;
  1397. foreach my $nick (sort keys %sadface) {
  1398. if ($line{$nick} > 100) {
  1399. $spercent{$nick} = ($sadface{$nick} / $line{$nick}) * 100;
  1400. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1401. }
  1402. }
  1403. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1404. if (@sadface) {
  1405. my %hash = (
  1406. nick => $sadface[0],
  1407. per => $spercent{$sadface[0]}
  1408. );
  1409. my $text = template_text('sad1', %hash);
  1410. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1411. if (@sadface >= 2) {
  1412. my %hash = (
  1413. nick => $sadface[1],
  1414. per => $spercent{$sadface[1]}
  1415. );
  1416. my $text = template_text('sad2', %hash);
  1417. html("<br><span class=\"small\">$text</span>");
  1418. }
  1419. html("</td></tr>");
  1420. } else {
  1421. my %hash = (
  1422. channel => $conf->{channel}
  1423. );
  1424. my $text = template_text('sad3', %hash);
  1425. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1426. }
  1427. }
  1428. sub mostop
  1429. {
  1430. my @ops = sort { $gaveop{$b} <=> $gaveop{$a} } keys %gaveop;
  1431. my @deops = sort { $tookop{$b} <=> $tookop{$a} } keys %tookop;
  1432. if (@ops) {
  1433. my %hash = (
  1434. nick => $ops[0],
  1435. ops => $gaveop{$ops[0]}
  1436. );
  1437. my $text = template_text('mostop1', %hash);
  1438. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1439. if (@ops >= 2) {
  1440. my %hash = (
  1441. nick => $ops[1],
  1442. ops => $gaveop{$ops[1]}
  1443. );
  1444. my $text = template_text('mostop2', %hash);
  1445. html("<br><span class=\"small\">$text</span>");
  1446. }
  1447. html("</td></tr>");
  1448. } else {
  1449. my %hash = ( channel => $conf->{channel} );
  1450. my $text = template_text('mostop3', %hash);
  1451. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1452. }
  1453. if (@deops) {
  1454. my %hash = (
  1455. channel => $conf->{channel},
  1456. nick => $deops[0],
  1457. deops => $tookop{$deops[0]}
  1458. );
  1459. my $text = template_text('mostdeop1', %hash);
  1460. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1461. if (@deops >= 2) {
  1462. my %hash = (
  1463. nick => $deops[1],
  1464. deops => $tookop{$deops[1]}
  1465. );
  1466. my $text = template_text('mostdeop2', %hash);
  1467. html("<br><span class=\"small\">$text</span>");
  1468. }
  1469. html("</td></tr>");
  1470. } else {
  1471. my %hash = ( channel => $conf->{channel} );
  1472. my $text = template_text('mostdeop3', %hash);
  1473. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1474. }
  1475. }
  1476. sub mostsmiles
  1477. {
  1478. # The person(s) who smiled the most :-)
  1479. my %spercent;
  1480. foreach my $nick (sort keys %smile) {
  1481. if ($line{$nick} > 100) {
  1482. $spercent{$nick} = ($smile{$nick} / $line{$nick}) * 100;
  1483. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1484. }
  1485. }
  1486. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1487. if (@smiles) {
  1488. my %hash = (
  1489. nick => $smiles[0],
  1490. per => $spercent{$smiles[0]}
  1491. );
  1492. my $text = template_text('smiles1', %hash);
  1493. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1494. if (@smiles >= 2) {
  1495. my %hash = (
  1496. nick => $smiles[1],
  1497. per => $spercent{$smiles[1]}
  1498. );
  1499. my $text = template_text('smiles2', %hash);
  1500. html("<br><span class=\"small\">$text</span>");
  1501. }
  1502. html("</td></tr>");
  1503. } else {
  1504. my %hash = (
  1505. channel => $conf->{channel}
  1506. );
  1507. my $text = template_text('smiles3', %hash);
  1508. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1509. }
  1510. }
  1511. sub lasttopics
  1512. {
  1513. debug("Total number of topics: ". scalar @topics);
  1514. if (@topics) {
  1515. my $ltopic = @topics - 1;
  1516. my $tlimit = 0;
  1517. $conf->{topichistory} -= 1;
  1518. if ($ltopic > $conf->{topichistory}) { $tlimit = $ltopic - $conf->{topichistory}; }
  1519. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1520. $topics[$i]{"topic"} = replace_links($topics[$i]{"topic"});
  1521. my $topic = $topics[$i]{topic};
  1522. my $nick = $topics[$i]{nick};
  1523. my $hour = $topics[$i]{hour};
  1524. my $min = $topics[$i]{min};
  1525. html("<tr><td bgcolor=\"$conf->{hicell}\"><i>$topic</i></td>");
  1526. html("<td bgcolor=\"$conf->{hicell}\">By <b>$nick</b> at <b>$hour:$min</b></td></tr>");
  1527. }
  1528. } else {
  1529. html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('notopic') ."</td></tr>");
  1530. }
  1531. }
  1532. # Some HTML subs
  1533. sub htmlheader
  1534. {
  1535. print OUTPUT <<HTML;
  1536. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  1537. <html>
  1538. <head>
  1539. <title>$conf->{channel} @ $conf->{network} channel statistics</title>
  1540. <style type="text/css">
  1541. a { text-decoration: none }
  1542. a:link { color: $conf->{link}; }
  1543. a:visited { color: $conf->{vlink}; }
  1544. a:hover { text-decoration: underline; color: $conf->{hlink} }
  1545. body {
  1546. background-color: $conf->{bgcolor};
  1547. font-family: verdana, arial, sans-serif;
  1548. font-size: 13px;
  1549. color: $conf->{text};
  1550. }
  1551. td {
  1552. font-family: verdana, arial, sans-serif;
  1553. font-size: 13px;
  1554. color: $conf->{tdcolor};
  1555. }
  1556. .title {
  1557. font-family: tahoma, arial, sans-serif;
  1558. font-size: 16px;
  1559. font-weight: bold;
  1560. }
  1561. .headline { color: $conf->{hcolor}; }
  1562. .small { font-family: verdana, arial, sans-serif; font-size: 10px; }
  1563. .asmall { font-family: arial narrow, sans-serif; font-size: 10px }
  1564. </style></head>
  1565. <body>
  1566. <div align="center">
  1567. HTML
  1568. my %hash = (
  1569. channel => $conf->{channel},
  1570. network => $conf->{network},
  1571. maintainer => $conf->{maintainer},
  1572. time => $time,
  1573. days => $days,
  1574. nicks => $nicks,
  1575. channel => $conf->{channel}
  1576. );
  1577. print OUTPUT "<span class=\"title\">" . template_text('pagetitle1', %hash) . "</span><br>";
  1578. print OUTPUT "<br>" . template_text('pagetitle2', %hash) . "<br>";
  1579. print OUTPUT template_text('pagetitle3', %hash) . "<br><br>";
  1580. }
  1581. sub htmlfooter
  1582. {
  1583. print OUTPUT <<HTML;
  1584. <span class="small">
  1585. 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>
  1586. pisg by <a href="http://www.wtf.dk/hp/" title="Go to the authors homepage">Morten "LostStar" Brix Pedersen</a> and others<br>
  1587. Stats generated in $processtime
  1588. </span>
  1589. </div>
  1590. </body>
  1591. </html>
  1592. HTML
  1593. }
  1594. sub headline
  1595. {
  1596. my ($title) = @_;
  1597. print OUTPUT <<HTML;
  1598. <br>
  1599. <table width="610" cellpadding="1" cellspacing="0" border="0">
  1600. <tr>
  1601. <td bgcolor="$conf->{headline}">
  1602. <table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">
  1603. <tr>
  1604. <td bgcolor="$conf->{hbgcolor}" class="text10">
  1605. <div align="center" class="headline"><b>$title</b></div>
  1606. </td>
  1607. </tr>
  1608. </table>
  1609. </td>
  1610. </tr>
  1611. </table>
  1612. HTML
  1613. }
  1614. sub pageheader
  1615. {
  1616. if ($conf->{pagehead} ne 'none') {
  1617. open(PAGEHEAD, $conf->{pagehead}) or die("$0: Unable to open $conf->{pagehead} for reading: $!\n");
  1618. while (<PAGEHEAD>) {
  1619. html($_);
  1620. }
  1621. }
  1622. }
  1623. sub close_debug
  1624. {
  1625. if ($conf->{debug}) {
  1626. close(DEBUG) or print STDERR "$0: Cannot close debugfile($conf->{debugfile}): $!\n";
  1627. }
  1628. }
  1629. sub get_cmdlineoptions
  1630. {
  1631. my $tmp;
  1632. # Commandline options
  1633. my ($channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help);
  1634. my $usage = <<END_USAGE;
  1635. Usage: pisg.pl [-c channel] [-l logfile] [-o outputfile] [-m
  1636. maintainer] [-f format] [-n network] [-d logdir] [-a aliasfile]
  1637. [-i ignorefile] [-h]
  1638. -ch --channel=xxx : Set channel name
  1639. -l --logfile=xxx : Log file to parse
  1640. -o --outfile=xxx : Name of html file to create
  1641. -m --maintainer=xxx : Channel/statistics maintainer
  1642. -f --format=xxx : Logfile format [see FORMATS file]
  1643. -n --network=xxx : IRC Network this channel is on.
  1644. -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
  1645. -p --prefix=xxx : Analyse only files starting with xxx in dir.
  1646. Only works with --dir
  1647. -co --configfile=xxx : Config file
  1648. -h --help : Output this message and exit (-? also works).
  1649. Example:
  1650. \$ pisg.pl -n IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
  1651. As always, all options may also be defined by editing the source and calling
  1652. pisg without arguments.
  1653. END_USAGE
  1654. if (GetOptions('channel=s' => \$channel,
  1655. 'logfile=s' => \$logfile,
  1656. 'format=s' => \$format,
  1657. 'network=s' => \$network,
  1658. 'maintainer=s' => \$maintainer,
  1659. 'outfile=s' => \$outputfile,
  1660. 'dir=s' => \$logdir,
  1661. 'prefix=s' => \$prefix,
  1662. 'ignorefile=s' => \$tmp,
  1663. 'aliasfile=s' => \$tmp,
  1664. 'configfile=s' => \$configfile,
  1665. 'help|?' => \$help
  1666. ) == 0 or $help) {
  1667. die($usage);
  1668. }
  1669. if (@ARGV) {
  1670. if ($ARGV[0]) { $conf->{channel} = $ARGV[0]; }
  1671. if ($ARGV[1]) { $conf->{logfile} = $ARGV[1]; }
  1672. if ($ARGV[2]) { $conf->{outputfile} = $ARGV[2]; }
  1673. if ($ARGV[3]) { $conf->{maintainer} = $ARGV[3]; }
  1674. }
  1675. if ($tmp) {
  1676. die("The aliasfile and ignorefile has been obsoleted by the new
  1677. pisg.cfg, please use that instead [look in pisg.cfg]\n");
  1678. }
  1679. if ($channel) {
  1680. $conf->{channel} = $channel;
  1681. $conf->{cmdl}{channel} = 1;
  1682. }
  1683. if ($logfile) {
  1684. $conf->{logfile} = $logfile;
  1685. $conf->{cmdl}{logfile} = 1;
  1686. }
  1687. if ($format) {
  1688. $conf->{format} = $format;
  1689. $conf->{cmdl}{format} = 1;
  1690. }
  1691. if ($network) {
  1692. $conf->{network} = $network;
  1693. $conf->{cmdl}{network} = 1;
  1694. }
  1695. if ($maintainer) {
  1696. $conf->{maintainer} = $maintainer;
  1697. $conf->{cmdl}{maintainer} = 1;
  1698. }
  1699. if ($outputfile) {
  1700. $conf->{outputfile} = $outputfile;
  1701. $conf->{cmdl}{outputfile} = 1;
  1702. }
  1703. if ($logdir) {
  1704. $conf->{logdir} = $logdir;
  1705. $conf->{cmdl}{logdir} = 1;
  1706. }
  1707. if ($prefix) {
  1708. $conf->{prefix} = $prefix;
  1709. $conf->{cmdl}{prefix} = 1;
  1710. }
  1711. if ($configfile) {
  1712. $conf->{configfile} = $configfile;
  1713. $conf->{cmdl}{configfile} = 1;
  1714. }
  1715. }
  1716. sub get_language_templates
  1717. {
  1718. use FindBin;
  1719. open(FILE, $conf->{langfile}) or open (FILE, $FindBin::Bin . "/$conf->{langfile}") or die("$0: Unable to open language file($conf->{langfile}): $!\n");
  1720. my $current_lang;
  1721. while (<FILE>)
  1722. {
  1723. my $line = $_;
  1724. next if /^#/;
  1725. if ($line =~ /<lang name=\"([^"]+)\">/) {
  1726. # Found start tag, setting the current language
  1727. $current_lang = "$1";
  1728. }
  1729. elsif ($line =~ /<\/lang>/) {
  1730. # Found end tag, resetting the current language
  1731. $current_lang = '';
  1732. }
  1733. elsif ($line =~ /(\w+)\s+=\s+"(.*)"\s*$/ && $current_lang ne '') {
  1734. $T{$current_lang}{$1} = $2;
  1735. }
  1736. }
  1737. close(FILE);
  1738. print "Using language template: $conf->{lang}\n\n" if ($conf->{lang} ne 'EN');
  1739. }
  1740. &main(); # Run the script