pisg.pl 67 KB

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