pisg.pl 57 KB

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