pisg.pl 66 KB

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