pisg.pl 67 KB

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