pisg.pl 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889
  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. my ($debug);
  23. # Default values for pisg. Their meanings are explained in CONFIG-README.
  24. #
  25. # If you are a user of pisg, you shouldn't change it here, but instead on
  26. # commandline or in pisg.cfg
  27. my $conf = {
  28. channel => "#channel",
  29. logtype => "Logfile",
  30. logfile => "channel.log",
  31. format => "mIRC",
  32. network => "SomeIRCNet",
  33. outputfile => "index.html",
  34. maintainer => "MAINTAINER",
  35. pagehead => "none",
  36. configfile => "pisg.cfg",
  37. imagepath => "",
  38. logdir => "",
  39. lang => 'EN',
  40. langfile => 'lang.txt',
  41. prefix => "",
  42. modules_dir => $FindBin::Bin . "/modules", # Module search path
  43. # Colors / Layout
  44. bgcolor => "#dedeee",
  45. bgpic => '',
  46. text => "black",
  47. hbgcolor => "#666699",
  48. hcolor => "white",
  49. hicell => "#BABADD",
  50. hicell2 => "#CCCCCC",
  51. tdcolor => "black",
  52. tdtop => "#C8C8DD",
  53. link => "#0b407a",
  54. vlink => "#0b407a",
  55. hlink => "#0b407a",
  56. headline => "#000000",
  57. rankc => "#CCCCCC",
  58. pic_v_0 => "blue-v.png",
  59. pic_v_6 => "green-v.png",
  60. pic_v_12 => "yellow-v.png",
  61. pic_v_18 => "red-v.png",
  62. pic_h_0 => "blue-h.png",
  63. pic_h_6 => "green-h.png",
  64. pic_h_12 => "yellow-h.png",
  65. pic_h_18 => "red-h.png",
  66. # Stats settings
  67. show_linetime => 0,
  68. show_time => 1,
  69. show_words => 0,
  70. show_wpl => 0,
  71. show_cpl => 0,
  72. show_legend => 1,
  73. show_kickline => 1,
  74. show_actionline => 1,
  75. show_shoutline => 1,
  76. show_violentlines => 1,
  77. # Less important things
  78. minquote => 25,
  79. maxquote => 65,
  80. wordlength => 5,
  81. activenicks => 25,
  82. activenicks2 => 30,
  83. topichistory => 3,
  84. nicktracking => 0,
  85. timeoffset => "+0",
  86. # Misc settings
  87. foul => 'ass fuck bitch shit scheisse scheiße kacke arsch ficker ficken schlampe',
  88. violent => 'slaps beats smacks',
  89. ignorewords => '',
  90. tablewidth => 614,
  91. regexp_aliases => 0,
  92. # Developer stuff
  93. debug => 0,
  94. debugfile => "debug.log",
  95. version => "v0.22-cvs",
  96. };
  97. my ($chans, $users);
  98. my ($timestamp, $time, $nicks, $totallength, $oldtime, $actions, $normals, %T);
  99. sub load_modules {
  100. push @INC, $conf->{modules_dir};
  101. require Pisg::Common;
  102. Pisg::Common->import();
  103. }
  104. sub main {
  105. print "pisg $conf->{version} - Perl IRC Statistics Generator\n\n";
  106. get_cmdlineoptions();
  107. load_modules(); # Add modules, now that their location is known.
  108. init_config(); # Init config. (Aliases, ignores, other options etc.)
  109. init_debug()
  110. unless ($conf->{debugstarted}); # Init the debugging file
  111. get_language_templates(); # Get translations from lang.txt
  112. parse_channels(); # parse any channels in <channel> statements
  113. do_channel()
  114. unless ($conf->{chan_done}{$conf->{channel}});
  115. close_debug(); # Close the debugging file
  116. }
  117. sub do_channel
  118. {
  119. init_pisg(); # Init commandline arguments and other things
  120. init_words(); # Init words. (Foulwords etc)
  121. # Pick our stats generator.
  122. my $analyzer;
  123. eval <<_END;
  124. use Pisg::$conf->{logtype};
  125. \$analyzer = new Pisg::$conf->{logtype}(\$conf, \$debug);
  126. _END
  127. if ($@) {
  128. print STDERR "Could not load stats generator for '$conf->{logtype}': $@\n";
  129. return undef;
  130. }
  131. my $stats = $analyzer->analyze();
  132. create_html($stats)
  133. if (defined $stats and $stats->{lines} > 0);# Create the HTML
  134. # (look here if you want to remove some of the
  135. # stats which you don't care about)
  136. $conf->{chan_done}{$conf->{channel}} = 1;
  137. }
  138. sub parse_channels
  139. {
  140. my %origconf = %{ $conf };
  141. foreach my $channel (keys %{ $chans }) {
  142. foreach (keys %{ $chans->{$channel} }) {
  143. $conf->{$_} = $chans->{$channel}{$_};
  144. }
  145. do_channel();
  146. $origconf{chan_done} = $conf->{chan_done};
  147. %{ $conf } = %origconf;
  148. }
  149. }
  150. sub init_pisg
  151. {
  152. # Reset all variables
  153. undef $totallength;
  154. $timestamp = time();
  155. $conf->{start} = time();
  156. if ($conf->{timeoffset} =~ /\+(\d+)/) {
  157. # We must plus some hours to the time
  158. $timestamp += 3600 * $1; # 3600 seconds per hour
  159. } elsif ($conf->{timeoffset} =~ /-(\d+)/) {
  160. # We must remove some hours from the time
  161. $timestamp -= 3600 * $1; # 3600 seconds per hour
  162. }
  163. # Add trailing slash when it's not there..
  164. $conf->{imagepath} =~ s/([^\/])$/$1\//;
  165. # Set some values
  166. $oldtime = "00";
  167. $actions = "0";
  168. $normals = "0";
  169. print "Using language template: $conf->{lang}\n\n" if ($conf->{lang} ne 'EN');
  170. print "Statistics for channel $conf->{channel} \@ $conf->{network} by $conf->{maintainer}\n\n";
  171. }
  172. sub init_config
  173. {
  174. if ((open(CONFIG, $conf->{configfile}) or open(CONFIG, $FindBin::Bin . "/$conf->{configfile}"))) {
  175. print "Using config file: $conf->{configfile}\n";
  176. my $lineno = 0;
  177. while (my $line = <CONFIG>)
  178. {
  179. $lineno++;
  180. next if ($line =~ /^#/);
  181. if ($line =~ /<user.*>/) {
  182. my $nick;
  183. if ($line =~ /nick="([^"]+)"/) {
  184. $nick = $1;
  185. add_alias($nick, $nick);
  186. } else {
  187. print STDERR "Warning: no nick specified in $conf->{configfile} on line $lineno\n";
  188. next;
  189. }
  190. if ($line =~ /alias="([^"]+)"/) {
  191. my @thisalias = split(/\s+/, lc($1));
  192. foreach (@thisalias) {
  193. if ($conf->{regexp_aliases} and /[\|\[\]\{\}\(\)\?\+\.\*\^\\]/) {
  194. add_aliaswild($nick, $_);
  195. } elsif (not $conf->{regexp_aliases} and s/\*/\.\*/g) {
  196. # quote it if it is a wildcard
  197. s/([\|\[\]\{\}\(\)\?\+\^\\])/\\$1/g;
  198. add_aliaswild($nick, $_);
  199. } else {
  200. add_alias($nick, $_);
  201. }
  202. }
  203. }
  204. if ($line =~ /pic="([^"]+)"/) {
  205. $users->{userpics}{$nick} = $1;
  206. }
  207. if ($line =~ /link="([^"]+)"/) {
  208. $users->{userlinks}{$nick} = $1;
  209. }
  210. if ($line =~ /ignore="Y"/i) {
  211. add_ignore($nick);
  212. }
  213. if ($line =~ /sex="([MmFf])"/i) {
  214. $users->{sex}{$nick} = lc($1);
  215. }
  216. } elsif ($line =~ /<set(.*)>/) {
  217. my $settings = $1;
  218. while ($settings =~ s/[ \t]([^=]+)=["']([^"']*)["']//) {
  219. my $var = lc($1); # Make the string lowercase
  220. unless (($conf->{$var} eq $2) || $conf->{cmdl}{$var}) {
  221. $conf->{$var} = $2;
  222. }
  223. $debug->("Conf: $var = $2");
  224. }
  225. } elsif ($line =~ /<channel=['"]([^'"]+)['"](.*)>/i) {
  226. my ($channel, $settings) = ($1, $2);
  227. $chans->{$channel}->{channel} = $channel;
  228. $conf->{chan_done}{$conf->{channel}} = 1; # don't parse channel in $conf->{channel} if a channel statement is present
  229. while ($settings =~ s/\s([^=]+)=["']([^"']*)["']//) {
  230. my $var = lc($1);
  231. $chans->{$channel}{$var} = $2;
  232. $debug->("Channel conf $channel: $var = $2");
  233. }
  234. while (<CONFIG>) {
  235. last if ($_ =~ /<\/*channel>/i);
  236. while ($_ =~ s/^\s*(\w+)\s*=\s*["']([^"']*)["']//) {
  237. my $var = lc($1);
  238. unless ($conf->{cmdl}{$var}) {
  239. $chans->{$channel}{$var} = $2;
  240. }
  241. $debug->("Conf $channel: $var = $2");
  242. }
  243. }
  244. }
  245. }
  246. close(CONFIG);
  247. }
  248. }
  249. sub init_words {
  250. $conf->{foul} =~ s/\s+/|/g;
  251. foreach (split /\s+/, $conf->{ignorewords}) {
  252. $conf->{ignoreword}{$_} = 1;
  253. }
  254. $conf->{violent} =~ s/\s+/|/g;
  255. }
  256. sub init_debug
  257. {
  258. $conf->{debugstarted} = 1;
  259. if ($conf->{debug}) {
  260. print "[ Debugging => $conf->{debugfile} ]\n";
  261. open(DEBUG,"> $conf->{debugfile}") or print STDERR "$0: Unable to open debug
  262. file($conf->{debugfile}): $!\n";
  263. $debug->("*** pisg debug file for $conf->{logfile}\n");
  264. if ($conf->{debugqueue}) {
  265. print DEBUG $conf->{debugqueue};
  266. delete $conf->{debugqueue};
  267. }
  268. } else {
  269. $debug = sub {};
  270. }
  271. }
  272. sub htmlentities
  273. {
  274. my $str = shift;
  275. $str =~ s/\&/\&amp;/go;
  276. $str =~ s/\</\&lt;/go;
  277. $str =~ s/\>/\&gt;/go;
  278. $str =~ s/ü/&uuml;/go;
  279. $str =~ s/ö/&ouml;/go;
  280. $str =~ s/ä/&auml;/go;
  281. $str =~ s/ß/&szlig;/go;
  282. $str =~ s/å/&aring;/go;
  283. $str =~ s/æ/&aelig;/go;
  284. $str =~ s/ø/&oslash;/go;
  285. return $str;
  286. }
  287. sub html
  288. {
  289. my $html = shift;
  290. print OUTPUT "$html\n";
  291. }
  292. sub template_text
  293. {
  294. # This function is for the homemade template system. It receives a name
  295. # of a template and a hash with the fields in the template to update to
  296. # its corresponding value
  297. my $template = shift;
  298. my %hash = @_;
  299. my $text;
  300. unless ($text = $T{$conf->{lang}}{$template}) {
  301. # Fall back to English if the language template doesn't exist
  302. if ($text = $T{EN}{$template}) {
  303. print "Note: There was no translation in $conf->{lang} for '$template' - falling back to English..\n";
  304. } else {
  305. die("No such template '$template' in language file.\n");
  306. }
  307. }
  308. $hash{channel} = $conf->{channel};
  309. foreach my $key (sort keys %hash) {
  310. $text =~ s/\[:$key\]/$hash{$key}/;
  311. $text =~ s/ü/&uuml;/go;
  312. $text =~ s/ö/&ouml;/go;
  313. $text =~ s/ä/&auml;/go;
  314. $text =~ s/ß/&szlig;/go;
  315. $text =~ s/å/&aring;/go;
  316. $text =~ s/æ/&aelig;/go;
  317. $text =~ s/ø/&oslash;/go;
  318. }
  319. if ($text =~ /\[:.*?:.*?:\]/o) {
  320. $text =~ s/\[:(.*?):(.*?):\]/get_subst($1,$2,\%hash)/geo;
  321. }
  322. return $text;
  323. }
  324. sub get_subst {
  325. my ($m,$f,$hash) = @_;
  326. if ($hash->{nick} && $users->{sex}{$hash->{nick}}) {
  327. if ($users->{sex}{$hash->{nick}} eq 'm') {
  328. return $m;
  329. } elsif ($users->{sex}{$hash->{nick}} eq 'f') {
  330. return $f;
  331. }
  332. }
  333. return "$m/$f";
  334. }
  335. sub replace_links {
  336. # Sub to replace urls and e-mail addys to links
  337. my $str = shift;
  338. my $nick = shift;
  339. my ($url, $email);
  340. if ($nick) {
  341. if ($url = match_url($str)) {
  342. $str =~ s/(\Q$url\E)/<a href="$1" target="_blank" title="Open in new window: $1">$nick<\/a>/g;
  343. }
  344. if ($email = match_email($str)) {
  345. $str =~ s/(\Q$email\E)/<a href="mailto:$1" title="Mail to $nick">$nick<\/a>/g;
  346. }
  347. } else {
  348. if ($url = match_url($str)) {
  349. $str =~ s/(\Q$url\E)/<a href="$1" target="_blank" title="Open in new window: $1">$1<\/a>/g;
  350. }
  351. if ($email = match_email($str)) {
  352. $str =~ s/(\Q$email\E)/<a href="mailto:$1" title="Mail to $1">$1<\/a>/g;
  353. }
  354. }
  355. return $str;
  356. }
  357. $debug = sub {
  358. if ($conf->{debug} or not $conf->{debugstarted}) {
  359. my $debugline = $_[0] . "\n";
  360. if ($conf->{debugstarted}) {
  361. print DEBUG $debugline;
  362. } else {
  363. $conf->{debugqueue} .= $debugline;
  364. }
  365. }
  366. };
  367. sub create_html {
  368. # This is where all subroutines get executed, you can actually design
  369. # your own layout here, the lines should be self-explainable
  370. my ($stats) = @_;
  371. print "Now generating HTML($conf->{outputfile})...\n";
  372. open (OUTPUT, "> $conf->{outputfile}") or
  373. die("$0: Unable to open outputfile($conf->{outputfile}): $!\n");
  374. if ($conf->{show_time}) {
  375. $conf->{tablewidth} += 40;
  376. }
  377. if ($conf->{show_words}) {
  378. $conf->{tablewidth} += 40;
  379. }
  380. if ($conf->{show_wpl}) {
  381. $conf->{tablewidth} += 40;
  382. }
  383. if ($conf->{show_cpl}) {
  384. $conf->{tablewidth} += 40;
  385. }
  386. $conf->{headwidth} = $conf->{tablewidth} - 4;
  387. htmlheader($stats);
  388. pageheader($stats);
  389. activetimes($stats);
  390. activenicks($stats);
  391. headline(template_text('bignumtopic'));
  392. html("<table width=\"$conf->{tablewidth}\">\n"); # Needed for sections
  393. questions($stats);
  394. shoutpeople($stats);
  395. capspeople($stats);
  396. violent($stats);
  397. mostsmiles($stats);
  398. mostsad($stats);
  399. linelengths($stats);
  400. mostwords($stats);
  401. mostwordsperline($stats);
  402. html("</table>"); # Needed for sections
  403. mostusedword($stats);
  404. mostreferencednicks($stats);
  405. mosturls($stats);
  406. headline(template_text('othernumtopic'));
  407. html("<table width=\"$conf->{tablewidth}\">\n"); # Needed for sections
  408. gotkicks($stats);
  409. mostkicks($stats);
  410. mostop($stats);
  411. mostactions($stats);
  412. mostmonologues($stats);
  413. mostjoins($stats);
  414. mostfoul($stats);
  415. html("</table>"); # Needed for sections
  416. headline(template_text('latesttopic'));
  417. html("<table width=\"$conf->{tablewidth}\">\n"); # Needed for sections
  418. lasttopics($stats);
  419. html("</table>"); # Needed for sections
  420. my %hash = ( lines => $stats->{totallines} );
  421. html(template_text('totallines', %hash) . "<br><br>");
  422. htmlfooter($stats);
  423. close(OUTPUT);
  424. }
  425. sub activetimes {
  426. # The most actives times on the channel
  427. my ($stats) = @_;
  428. my (%output, $tbgcolor);
  429. &headline(template_text('activetimestopic'));
  430. my @toptime = sort { $stats->{times}{$b} <=> $stats->{times}{$a} } keys %{ $stats->{times} };
  431. my $highest_value = $stats->{times}{$toptime[0]};
  432. my @now = localtime($timestamp);
  433. my $image;
  434. for my $hour (sort keys %{ $stats->{times} }) {
  435. $debug->("Time: $hour => ". $stats->{times}{$hour});
  436. $image = "pic_v_".(int($hour/6)*6);
  437. $image = $conf->{$image};
  438. $debug->("Image: $image");
  439. my $size = ($stats->{times}{$hour} / $highest_value) * 100;
  440. my $percent = ($stats->{times}{$hour} / $stats->{totallines}) * 100;
  441. $percent =~ s/(\.\d)\d+/$1/;
  442. if ($size < 1 && $size != 0) {
  443. # Opera doesn't understand '0.xxxx' in the height="xx" attr,
  444. # so we simply round up to 1.0 here.
  445. $size = 1.0;
  446. }
  447. if ($conf->{timeoffset} =~ /\+(\d+)/) {
  448. # We must plus some hours to the time
  449. $hour += $1;
  450. $hour = $hour % 24;
  451. if ($hour < 10) { $hour = "0" . $hour; }
  452. } elsif ($conf->{timeoffset} =~ /-(\d+)/) {
  453. # We must remove some hours from the time
  454. $hour -= $1;
  455. $hour = $hour % 24;
  456. if ($hour < 10) { $hour = "0" . $hour; }
  457. }
  458. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br><img src=\"$image\" width=\"15\" height=\"$size\" alt=\"$percent\"></td>\n";
  459. }
  460. html("<table border=\"0\" width=\"$conf->{tablewidth}\"><tr>\n");
  461. for ($b = 0; $b < 24; $b++) {
  462. if ($b < 10) { $a = "0" . $b; } else { $a = $b; }
  463. if (!defined($output{$a}) || $output{$a} eq "") {
  464. html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  465. } else {
  466. html($output{$a});
  467. }
  468. }
  469. html("</tr><tr>");
  470. for ($b = 0; $b < 24; $b++) {
  471. if ($now[2] == $b) { $tbgcolor = "\#AAAAAA"; } else { $tbgcolor = "\#CCCCCC"; }
  472. html("<td bgcolor=\"$tbgcolor\" align=\"center\" class=\"small\">$b</td>");
  473. }
  474. html("</tr></table>");
  475. if($conf->{show_legend} == 1) {
  476. &legend();
  477. }
  478. }
  479. sub legend
  480. {
  481. html("<table align=\"center\" border=\"0\" width=\"520\"><tr>");
  482. html("<td align=\"center\" class=\"asmall\"><img src=\"$conf->{pic_h_0}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 0-5</td>");
  483. html("<td align=\"center\" class=\"asmall\"><img src=\"$conf->{pic_h_6}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 6-11</td>");
  484. html("<td align=\"center\" class=\"asmall\"><img src=\"$conf->{pic_h_12}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 12-17</td>");
  485. html("<td align=\"center\" class=\"asmall\"><img src=\"$conf->{pic_h_18}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"\"> = 18-23</td>");
  486. html("</tr></table>\n");
  487. }
  488. sub activenicks {
  489. # The most active nicks (those who wrote most lines)
  490. my ($stats) = @_;
  491. headline(template_text('activenickstopic'));
  492. html("<table border=\"0\" width=\"$conf->{tablewidth}\"><tr>");
  493. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>"
  494. . template_text('nick') . "</b></td><td bgcolor=\"$conf->{tdtop}\"><b>"
  495. . template_text('numberlines')
  496. . "</b></td><td bgcolor=\"$conf->{tdtop}\"><b>"
  497. . ($conf->{show_time} ? template_text('show_time')."</b></td><td bgcolor=\"$conf->{tdtop}\"><b>" : "")
  498. . ($conf->{show_words} ? template_text('show_words')."</b></td><td bgcolor=\"$conf->{tdtop}\"><b>" : "")
  499. . ($conf->{show_wpl} ? template_text('show_wpl')."</b></td><td bgcolor=\"$conf->{tdtop}\"><b>" : "")
  500. . ($conf->{show_cpl} ? template_text('show_cpl')."</b></td><td bgcolor=\"$conf->{tdtop}\"><b>" : "")
  501. . template_text('randquote') ."</b></td>");
  502. if (scalar keys %{$users->{userpics}} > 0) {
  503. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('userpic') ."</b></td>");
  504. }
  505. html("</tr>");
  506. my @active = sort { $stats->{lines}{$b} <=> $stats->{lines}{$a} } keys %{ $stats->{lines} };
  507. my $nicks = scalar keys %{ $stats->{lines} };
  508. if ($conf->{activenicks} > $nicks) {
  509. $conf->{activenicks} = $nicks;
  510. print "Note: There were fewer nicks in the logfile than your specificied there to be in most active nicks...\n";
  511. }
  512. my ($nick, $visiblenick, $randomline, %hash);
  513. my $i = 1;
  514. for (my $c = 0; $c < $conf->{activenicks}; $c++) {
  515. $nick = $active[$c];
  516. $visiblenick = $active[$c];
  517. if (not defined $stats->{sayings}{$nick}) {
  518. $randomline = "";
  519. } else {
  520. $randomline = htmlentities($stats->{sayings}{$nick});
  521. }
  522. # Convert URLs and e-mail addys to links
  523. $randomline = replace_links($randomline);
  524. # Add a link to the nick if there is any
  525. if ($users->{userlinks}{$nick}) {
  526. $visiblenick = replace_links($users->{userlinks}{$nick}, $nick);
  527. }
  528. my $h = $conf->{hicell};
  529. $h =~ s/^#//;
  530. $h = hex $h;
  531. my $h2 = $conf->{hicell2};
  532. $h2 =~ s/^#//;
  533. $h2 = hex $h2;
  534. my $f_b = $h & 0xff;
  535. my $f_g = ($h & 0xff00) >> 8;
  536. my $f_r = ($h & 0xff0000) >> 16;
  537. my $t_b = $h2 & 0xff;
  538. my $t_g = ($h2 & 0xff00) >> 8;
  539. my $t_r = ($h2 & 0xff0000) >> 16;
  540. my $col_b = sprintf "%0.2x", abs int(((($t_b - $f_b) / $conf->{activenicks}) * +$c) + $f_b);
  541. my $col_g = sprintf "%0.2x", abs int(((($t_g - $f_g) / $conf->{activenicks}) * +$c) + $f_g);
  542. my $col_r = sprintf "%0.2x", abs int(((($t_r - $f_r) / $conf->{activenicks}) * +$c) + $f_r);
  543. html("<tr><td bgcolor=\"$conf->{rankc}\" align=\"left\">");
  544. my $line = $stats->{lines}{$nick};
  545. my $w = $stats->{words}{$nick};
  546. my $ch = $stats->{lengths}{$nick};
  547. html("$i</td><td bgcolor=\"#$col_r$col_g$col_b\">$visiblenick</td>"
  548. . ($conf->{show_linetime} ?
  549. "<td bgcolor=\"$col_r$col_g$col_b\">".user_linetimes($stats,$nick,$active[0])."</td>"
  550. : "<td bgcolor=\"#$col_r$col_g$col_b\">$line</td>")
  551. . ($conf->{show_time} ?
  552. "<td bgcolor=\"$col_r$col_g$col_b\">".user_times($stats,$nick)."</td>"
  553. : "")
  554. . ($conf->{show_words} ?
  555. "<td bgcolor=\"#$col_r$col_g$col_b\">$w</td>"
  556. : "")
  557. . ($conf->{show_wpl} ?
  558. "<td bgcolor=\"#$col_r$col_g$col_b\">".sprintf("%.1f",$w/$line)."</td>"
  559. : "")
  560. . ($conf->{show_cpl} ?
  561. "<td bgcolor=\"#$col_r$col_g$col_b\">".sprintf("%.1f",$ch/$line)."</td>"
  562. : "")
  563. ."<td bgcolor=\"#$col_r$col_g$col_b\">");
  564. html("\"$randomline\"</td>");
  565. if ($users->{userpics}{$nick}) {
  566. html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$conf->{imagepath}$users->{userpics}{$nick}\"></td>");
  567. }
  568. html("</tr>");
  569. $i++;
  570. }
  571. html("</table><br>");
  572. # Almost as active nicks ('These didn't make it to the top..')
  573. my $nickstoshow = $conf->{activenicks} + $conf->{activenicks2};
  574. $hash{totalnicks} = $nicks - $nickstoshow;
  575. unless ($nickstoshow > $nicks) {
  576. html("<br><b><i>" . template_text('nottop') . "</i></b><table><tr>");
  577. for (my $c = $conf->{activenicks}; $c < $nickstoshow; $c++) {
  578. unless ($c % 5) { unless ($c == $conf->{activenicks}) { html("</tr><tr>"); } }
  579. html("<td bgcolor=\"$conf->{rankc}\" class=\"small\">");
  580. my $nick = $active[$c];
  581. my $lines = $stats->{lines}{$nick};
  582. html("$nick ($lines)</td>");
  583. }
  584. html("</table>");
  585. }
  586. if($hash{totalnicks} > 0) {
  587. html("<br><b>" . template_text('totalnicks', %hash) . "</b><br>");
  588. }
  589. }
  590. sub user_linetimes {
  591. my $stats = shift;
  592. my $nick = shift;
  593. my $top = shift;
  594. my $bar = "";
  595. my $len = ($stats->{lines}{$nick} / $stats->{lines}{$top}) * 100;
  596. my $debuglen = 0;
  597. for (my $i = 0; $i <= 3; $i++) {
  598. next if not defined $stats->{line_times}{$nick}[$i];
  599. my $w = int(($stats->{line_times}{$nick}[$i] / $stats->{lines}{$nick}) * $len);
  600. $debuglen += $w;
  601. if ($w) {
  602. my $pic = 'pic_h_'.(6*$i);
  603. $bar .= "<img src=\"$conf->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\">";
  604. }
  605. }
  606. $debug->("Length='$len', Sum='$debuglen'");
  607. return "$bar&nbsp;$stats->{lines}{$nick}";
  608. }
  609. sub user_times {
  610. my ($stats, $nick) = @_;
  611. my $bar = "";
  612. for (my $i = 0; $i <= 3; $i++) {
  613. next if not defined $stats->{line_times}{$nick}[$i];
  614. my $w = int(($stats->{line_times}{$nick}[$i] / $stats->{lines}{$nick}) * 40);
  615. if ($w) {
  616. my $pic = 'pic_h_'.(6*$i);
  617. $bar .= "<img src=\"$conf->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\">";
  618. }
  619. }
  620. return $bar;
  621. }
  622. sub mostusedword {
  623. # Lao the infamous word usage statistics
  624. my ($stats) = @_;
  625. my %usages;
  626. foreach my $word (keys %{ $stats->{wordcounts} }) {
  627. # Skip people's nicks.
  628. next if exists $stats->{lines}{$word};
  629. $usages{$word} = $stats->{wordcounts}{$word};
  630. }
  631. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  632. if (@popular) {
  633. &headline(template_text('mostwordstopic'));
  634. html("<table border=\"0\" width=\"$conf->{tablewidth}\"><tr>");
  635. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('word') . "</b></td>");
  636. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  637. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  638. my $count = 0;
  639. for(my $i = 0; $count < 10; $i++) {
  640. last unless $i < $#popular;
  641. # Skip nicks. It's far more efficient to do this here than when
  642. # @popular is created.
  643. next if is_ignored($popular[$i]);
  644. next if exists $stats->{lines}{find_alias($popular[$i])};
  645. my $a = $count + 1;
  646. my $popular = htmlentities($popular[$i]);
  647. my $wordcount = $stats->{wordcounts}{$popular[$i]};
  648. my $lastused = htmlentities($stats->{wordnicks}{$popular[$i]});
  649. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  650. html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
  651. html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
  652. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  653. html("</tr>");
  654. $count++;
  655. }
  656. html("</table>");
  657. }
  658. }
  659. sub mostwordsperline {
  660. # The person who got words the most
  661. my ($stats) = @_;
  662. my %wpl = ();
  663. my ($numlines,$avg,$numwords);
  664. foreach my $n (keys %{ $stats->{words} }) {
  665. $wpl{$n} = sprintf("%.2f", $stats->{words}{$n}/$stats->{lines}{$n});
  666. $numlines += $stats->{lines}{$n};
  667. $numwords += $stats->{words}{$n};
  668. }
  669. $avg = sprintf("%.2f", $numwords/$numlines);
  670. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  671. if (@wpl) {
  672. my %hash = (
  673. nick => $wpl[0],
  674. wpl => $wpl{$wpl[0]}
  675. );
  676. my $text = template_text('wpl1', %hash);
  677. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  678. %hash = (
  679. avg => $avg
  680. );
  681. $text = template_text('wpl2', %hash);
  682. html("<br><span class=\"small\">$text</span>");
  683. html("</td></tr>");
  684. }
  685. }
  686. sub mostreferencednicks {
  687. my ($stats) = @_;
  688. my (%usages);
  689. foreach my $word (sort keys %{ $stats->{wordcounts} }) {
  690. next unless exists $stats->{lines}{$word};
  691. next if is_ignored($word);
  692. $usages{$word} = $stats->{wordcounts}{$word};
  693. }
  694. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  695. if (@popular) {
  696. &headline(template_text('referencetopic'));
  697. html("<table border=\"0\" width=\"$conf->{tablewidth}\"><tr>");
  698. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('nick') . "</b></td>");
  699. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  700. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  701. for(my $i = 0; $i < 5; $i++) {
  702. last unless $i < $#popular;
  703. my $a = $i + 1;
  704. my $popular = $popular[$i];
  705. my $wordcount = $stats->{wordcounts}{$popular[$i]};
  706. my $lastused = $stats->{wordnicks}{$popular[$i]};
  707. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  708. html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
  709. html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
  710. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  711. html("</tr>");
  712. }
  713. html("</table>");
  714. }
  715. }
  716. sub mosturls {
  717. my ($stats) = @_;
  718. my @sorturls = sort { $stats->{urlcounts}{$b} <=> $stats->{urlcounts}{$a} }
  719. keys %{ $stats->{urlcounts} };
  720. if (@sorturls) {
  721. &headline(template_text('urlstopic'));
  722. html("<table border=\"0\" width=\"$conf->{tablewidth}\"><tr>");
  723. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('url') . "</b></td>");
  724. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  725. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  726. for(my $i = 0; $i < 5; $i++) {
  727. last unless $i < $#sorturls;
  728. my $a = $i + 1;
  729. my $sorturl = $sorturls[$i];
  730. my $urlcount = $stats->{urlcounts}{$sorturls[$i]};
  731. my $lastused = $stats->{urlnicks}{$sorturls[$i]};
  732. if (length($sorturl) > 60) {
  733. $sorturl = substr($sorturl, 0, 60);
  734. }
  735. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  736. html("<td bgcolor=\"$conf->{hicell}\"><a href=\"$sorturls[$i]\">$sorturl</a></td>");
  737. html("<td bgcolor=\"$conf->{hicell}\">$urlcount</td>");
  738. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  739. html("</tr>");
  740. }
  741. html("</table>");
  742. }
  743. }
  744. sub questions {
  745. # Persons who asked the most questions
  746. my ($stats) = @_;
  747. my %qpercent;
  748. foreach my $nick (sort keys %{ $stats->{questions} }) {
  749. if ($stats->{lines}{$nick} > 100) {
  750. $qpercent{$nick} = ($stats->{questions}{$nick} / $stats->{lines}{$nick}) * 100;
  751. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  752. }
  753. }
  754. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  755. if (@question) {
  756. my %hash = (
  757. nick => $question[0],
  758. per => $qpercent{$question[0]}
  759. );
  760. my $text = template_text('question1', %hash);
  761. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  762. if (@question >= 2) {
  763. my %hash = (
  764. nick => $question[1],
  765. per => $qpercent{$question[1]}
  766. );
  767. my $text = template_text('question2', %hash);
  768. html("<br><span class=\"small\">$text</span>");
  769. }
  770. html("</td></tr>");
  771. } else {
  772. html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('question3') . "</td></tr>");
  773. }
  774. }
  775. sub shoutpeople {
  776. # The ones who speak with exclamation points!
  777. my ($stats) = @_;
  778. my %spercent;
  779. foreach my $nick (sort keys %{ $stats->{shouts} }) {
  780. if ($stats->{lines}{$nick} > 100) {
  781. $spercent{$nick} = ($stats->{shouts}{$nick} / $stats->{lines}{$nick}) * 100;
  782. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  783. }
  784. }
  785. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  786. if (@shout) {
  787. my %hash = (
  788. nick => $shout[0],
  789. per => $spercent{$shout[0]}
  790. );
  791. my $text = template_text('shout1', %hash);
  792. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  793. if (@shout >= 2) {
  794. my %hash = (
  795. nick => $shout[1],
  796. per => $spercent{$shout[1]}
  797. );
  798. my $text = template_text('shout2', %hash);
  799. html("<br><span class=\"small\">$text</span>");
  800. }
  801. html("</td></tr>");
  802. } else {
  803. my $text = template_text('shout3');
  804. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  805. }
  806. }
  807. sub capspeople {
  808. # The ones who speak ALL CAPS.
  809. my ($stats) = @_;
  810. my %cpercent;
  811. foreach my $nick (sort keys %{ $stats->{allcaps} }) {
  812. if ($stats->{lines}{$nick} > 100) {
  813. $cpercent{$nick} = $stats->{allcaps}{$nick} / $stats->{lines}{$nick} * 100;
  814. $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
  815. }
  816. }
  817. my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent;
  818. if (@caps) {
  819. my %hash = (
  820. nick => $caps[0],
  821. per => $cpercent{$caps[0]},
  822. line => htmlentities($stats->{allcaplines}{$caps[0]})
  823. );
  824. my $text = template_text('allcaps1', %hash);
  825. if($conf->{show_shoutline}) {
  826. my $exttext = template_text('allcapstext', %hash);
  827. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  828. } else {
  829. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  830. }
  831. if (@caps >= 2) {
  832. my %hash = (
  833. nick => $caps[1],
  834. per => $cpercent{$caps[1]}
  835. );
  836. my $text = template_text('allcaps2', %hash);
  837. html("<br><span class=\"small\">$text</span>");
  838. }
  839. html("</td></tr>");
  840. } else {
  841. my $text = template_text('allcaps3');
  842. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  843. }
  844. }
  845. sub violent {
  846. # They attacked others
  847. my ($stats) = @_;
  848. my @aggressors;
  849. @aggressors = sort { $stats->{violence}{$b} <=> $stats->{violence}{$a} }
  850. keys %{ $stats->{violence} };
  851. if(@aggressors) {
  852. my %hash = (
  853. nick => $aggressors[0],
  854. attacks => $stats->{violence}{$aggressors[0]},
  855. line => htmlentities($stats->{violencelines}{$aggressors[0]})
  856. );
  857. my $text = template_text('violent1', %hash);
  858. if($conf->{show_violentlines}) {
  859. my $exttext = template_text('violenttext', %hash);
  860. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  861. } else {
  862. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  863. }
  864. if (@aggressors >= 2) {
  865. my %hash = (
  866. nick => $aggressors[1],
  867. attacks => $stats->{violence}{$aggressors[1]}
  868. );
  869. my $text = template_text('violent2', %hash);
  870. html("<br><span class=\"small\">$text</span>");
  871. }
  872. html("</td></tr>");
  873. } else {
  874. my $text = template_text('violent3');
  875. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  876. }
  877. # They got attacked
  878. my @victims;
  879. @victims = sort { $stats->{attacked}{$b} <=> $stats->{attacked}{$a} }
  880. keys %{ $stats->{attacked} };
  881. if(@victims) {
  882. my %hash = (
  883. nick => $victims[0],
  884. attacks => $stats->{attacked}{$victims[0]},
  885. line => htmlentities($stats->{attackedlines}{$victims[0]})
  886. );
  887. my $text = template_text('attacked1', %hash);
  888. if($conf->{show_violentlines}) {
  889. my $exttext = template_text('attackedtext', %hash);
  890. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  891. } else {
  892. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  893. }
  894. if (@victims >= 2) {
  895. my %hash = (
  896. nick => $victims[1],
  897. attacks => $stats->{attacked}{$victims[1]}
  898. );
  899. my $text = template_text('attacked2', %hash);
  900. html("<br><span class=\"small\">$text</span>");
  901. }
  902. html("</td></tr>");
  903. }
  904. }
  905. sub gotkicks {
  906. # The persons who got kicked the most
  907. my ($stats) = @_;
  908. my @gotkick = sort { $stats->{gotkicked}{$b} <=> $stats->{gotkicked}{$a} }
  909. keys %{ $stats->{gotkicked} };
  910. if (@gotkick) {
  911. my %hash = (
  912. nick => $gotkick[0],
  913. kicks => $stats->{gotkicked}{$gotkick[0]},
  914. line => $stats->{kicklines}{$gotkick[0]}
  915. );
  916. my $text = template_text('gotkick1', %hash);
  917. if ($conf->{show_kickline}) {
  918. my $exttext = template_text('kicktext', %hash);
  919. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  920. } else {
  921. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  922. }
  923. if (@gotkick >= 2) {
  924. my %hash = (
  925. nick => $gotkick[1],
  926. kicks => $stats->{gotkicked}{$gotkick[1]}
  927. );
  928. my $text = template_text('gotkick2', %hash);
  929. html("<br><span class=\"small\">$text</span>");
  930. }
  931. html("</td></tr>");
  932. }
  933. }
  934. sub mostjoins {
  935. my ($stats) = @_;
  936. my @joins = sort { $stats->{joins}{$b} <=> $stats->{joins}{$a} }
  937. keys %{ $stats->{joins} };
  938. if (@joins) {
  939. my %hash = (
  940. nick => $joins[0],
  941. joins => $stats->{joins}{$joins[0]}
  942. );
  943. my $text = template_text('joins', %hash);
  944. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  945. }
  946. }
  947. sub mostwords {
  948. # The person who got words the most
  949. my ($stats) = @_;
  950. my @words = sort { $stats->{words}{$b} <=> $stats->{words}{$a} }
  951. keys %{ $stats->{words} };
  952. if (@words) {
  953. my %hash = (
  954. nick => $words[0],
  955. words => $stats->{words}{$words[0]}
  956. );
  957. my $text = template_text('words1', %hash);
  958. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  959. if (@words >= 2) {
  960. my %hash = (
  961. oldnick => $words[0],
  962. nick => $words[1],
  963. words => $stats->{words}{$words[1]}
  964. );
  965. my $text = template_text('words2', %hash);
  966. html("<br><span class=\"small\">$text</span>");
  967. }
  968. html("</td></tr>");
  969. } else {
  970. my $text = template_text('kick3');
  971. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  972. }
  973. }
  974. sub mostkicks {
  975. # The person who got kicked the most
  976. my ($stats) = @_;
  977. my @kicked = sort { $stats->{kicked}{$b} <=> $stats->{kicked}{$a} }
  978. keys %{ $stats->{kicked} };
  979. if (@kicked) {
  980. my %hash = (
  981. nick => $kicked[0],
  982. kicked => $stats->{kicked}{$kicked[0]}
  983. );
  984. my $text = template_text('kick1', %hash);
  985. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  986. if (@kicked >= 2) {
  987. my %hash = (
  988. oldnick => $kicked[0],
  989. nick => $kicked[1],
  990. kicked => $stats->{kicked}{$kicked[1]}
  991. );
  992. my $text = template_text('kick2', %hash);
  993. html("<br><span class=\"small\">$text</span>");
  994. }
  995. html("</td></tr>");
  996. } else {
  997. my $text = template_text('kick3');
  998. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  999. }
  1000. }
  1001. sub mostmonologues {
  1002. # The person who had the most monologues (speaking to himself)
  1003. my ($stats) = @_;
  1004. my @monologue = sort { $stats->{monologues}{$b} <=> $stats->{monologues}{$a} } keys %{ $stats->{monologues} };
  1005. if (@monologue) {
  1006. my %hash = (
  1007. nick => $monologue[0],
  1008. monos => $stats->{monologues}{$monologue[0]}
  1009. );
  1010. my $text = template_text('mono1', %hash);
  1011. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1012. if (@monologue >= 2) {
  1013. my %hash = (
  1014. nick => $monologue[1],
  1015. monos => $stats->{monologues}{$monologue[1]}
  1016. );
  1017. my $text = template_text('mono2', %hash);
  1018. html("<br><span class=\"small\">$text</span>");
  1019. }
  1020. html("</td></tr>");
  1021. }
  1022. }
  1023. sub linelengths {
  1024. # The person(s) who wrote the longest lines
  1025. my ($stats) = @_;
  1026. my %len;
  1027. foreach my $nick (sort keys %{ $stats->{lengths} }) {
  1028. if ($stats->{lines}{$nick} > 100) {
  1029. $len{$nick} = $stats->{lengths}{$nick} / $stats->{lines}{$nick};
  1030. $len{$nick} =~ s/(\.\d)\d+/$1/;
  1031. }
  1032. }
  1033. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  1034. my $all_lines;
  1035. my $totallength;
  1036. foreach my $nick (keys %{ $stats->{lines} }) {
  1037. $all_lines += $stats->{lines}{$nick};
  1038. $totallength += $stats->{lengths}{$nick};
  1039. }
  1040. my $totalaverage;
  1041. if ($all_lines > 0) {
  1042. $totalaverage = $totallength / $all_lines;
  1043. $totalaverage =~ s/(\.\d)\d+/$1/;
  1044. }
  1045. if (@len) {
  1046. my %hash = (
  1047. nick => $len[0],
  1048. letters => $len{$len[0]}
  1049. );
  1050. my $text = template_text('long1', %hash);
  1051. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
  1052. if (@len >= 2) {
  1053. %hash = (
  1054. avg => $totalaverage
  1055. );
  1056. $text = template_text('long2', %hash);
  1057. html("<span class=\"small\">$text</span></td></tr>");
  1058. }
  1059. }
  1060. # The person(s) who wrote the shortest lines
  1061. if (@len) {
  1062. my %hash = (
  1063. nick => $len[$#len],
  1064. letters => $len{$len[$#len]}
  1065. );
  1066. my $text = template_text('short1', %hash);
  1067. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
  1068. if (@len >= 2) {
  1069. %hash = (
  1070. nick => $len[$#len - 1],
  1071. letters => $len{$len[$#len - 1]}
  1072. );
  1073. $text = template_text('short2', %hash);
  1074. html("<span class=\"small\">$text</span></td></tr>");
  1075. }
  1076. }
  1077. }
  1078. sub mostfoul {
  1079. my ($stats) = @_;
  1080. my %spercent;
  1081. foreach my $nick (sort keys %{ $stats->{foul} }) {
  1082. if ($stats->{lines}{$nick} > 15) {
  1083. $spercent{$nick} = $stats->{foul}{$nick} / $stats->{lines}{$nick} * 100;
  1084. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1085. }
  1086. }
  1087. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1088. if (@foul) {
  1089. my %hash = (
  1090. nick => $foul[0],
  1091. per => $spercent{$foul[0]}
  1092. );
  1093. my $text = template_text('foul1', %hash);
  1094. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1095. if (@foul >= 2) {
  1096. my %hash = (
  1097. nick => $foul[1],
  1098. per => $spercent{$foul[1]}
  1099. );
  1100. my $text = template_text('foul2', %hash);
  1101. html("<br><span class=\"small\">$text</span>");
  1102. }
  1103. html("</td></tr>");
  1104. } else {
  1105. my $text = template_text('foul3');
  1106. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1107. }
  1108. }
  1109. sub mostsad {
  1110. my ($stats) = @_;
  1111. my %spercent;
  1112. foreach my $nick (sort keys %{ $stats->{frowns} }) {
  1113. if ($stats->{lines}{$nick} > 100) {
  1114. $spercent{$nick} = $stats->{frowns}{$nick} / $stats->{lines}{$nick} * 100;
  1115. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1116. }
  1117. }
  1118. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1119. if (@sadface) {
  1120. my %hash = (
  1121. nick => $sadface[0],
  1122. per => $spercent{$sadface[0]}
  1123. );
  1124. my $text = template_text('sad1', %hash);
  1125. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1126. if (@sadface >= 2) {
  1127. my %hash = (
  1128. nick => $sadface[1],
  1129. per => $spercent{$sadface[1]}
  1130. );
  1131. my $text = template_text('sad2', %hash);
  1132. html("<br><span class=\"small\">$text</span>");
  1133. }
  1134. html("</td></tr>");
  1135. } else {
  1136. my $text = template_text('sad3');
  1137. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1138. }
  1139. }
  1140. sub mostop {
  1141. my ($stats) = @_;
  1142. my @ops = sort { $stats->{gaveops}{$b} <=> $stats->{gaveops}{$a} }
  1143. keys %{ $stats->{gaveops} };
  1144. my @deops = sort { $stats->{tookops}{$b} <=> $stats->{tookops}{$a} }
  1145. keys %{ $stats->{tookops} };
  1146. if (@ops) {
  1147. my %hash = (
  1148. nick => $ops[0],
  1149. ops => $stats->{gaveops}{$ops[0]}
  1150. );
  1151. my $text = template_text('mostop1', %hash);
  1152. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1153. if (@ops >= 2) {
  1154. my %hash = (
  1155. nick => $ops[1],
  1156. ops => $stats->{gaveops}{$ops[1]}
  1157. );
  1158. my $text = template_text('mostop2', %hash);
  1159. html("<br><span class=\"small\">$text</span>");
  1160. }
  1161. html("</td></tr>");
  1162. } else {
  1163. my $text = template_text('mostop3');
  1164. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1165. }
  1166. if (@deops) {
  1167. my %hash = (
  1168. nick => $deops[0],
  1169. deops => $stats->{tookops}{$deops[0]}
  1170. );
  1171. my $text = template_text('mostdeop1', %hash);
  1172. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1173. if (@deops >= 2) {
  1174. my %hash = (
  1175. nick => $deops[1],
  1176. deops => $stats->{tookops}{$deops[1]}
  1177. );
  1178. my $text = template_text('mostdeop2', %hash);
  1179. html("<br><span class=\"small\">$text</span>");
  1180. }
  1181. html("</td></tr>");
  1182. } else {
  1183. my $text = template_text('mostdeop3');
  1184. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1185. }
  1186. }
  1187. sub mostactions {
  1188. # The person who did the most /me's
  1189. my ($stats) = @_;
  1190. my @actions = sort { $stats->{actions}{$b} <=> $stats->{actions}{$a} }
  1191. keys %{ $stats->{actions} };
  1192. if (@actions) {
  1193. my %hash = (
  1194. nick => $actions[0],
  1195. actions => $stats->{actions}{$actions[0]},
  1196. line => htmlentities($stats->{actionlines}{$actions[0]})
  1197. );
  1198. my $text = template_text('action1', %hash);
  1199. if($conf->{show_actionline}) {
  1200. my $exttext = template_text('actiontext', %hash);
  1201. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br><span class=\"small\">$exttext</span><br>");
  1202. } else {
  1203. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1204. }
  1205. if (@actions >= 2) {
  1206. my %hash = (
  1207. nick => $actions[1],
  1208. actions => $stats->{actions}{$actions[1]}
  1209. );
  1210. my $text = template_text('action2', %hash);
  1211. html("<br><span class=\"small\">$text</span>");
  1212. }
  1213. html("</td></tr>");
  1214. } else {
  1215. my $text = template_text('action3');
  1216. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1217. }
  1218. }
  1219. sub mostsmiles {
  1220. # The person(s) who smiled the most :-)
  1221. my ($stats) = @_;
  1222. my %spercent;
  1223. foreach my $nick (sort keys %{ $stats->{smiles} }) {
  1224. if ($stats->{lines}{$nick} > 100) {
  1225. $spercent{$nick} = $stats->{smiles}{$nick} / $stats->{lines}{$nick} * 100;
  1226. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1227. }
  1228. }
  1229. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1230. if (@smiles) {
  1231. my %hash = (
  1232. nick => $smiles[0],
  1233. per => $spercent{$smiles[0]}
  1234. );
  1235. my $text = template_text('smiles1', %hash);
  1236. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1237. if (@smiles >= 2) {
  1238. my %hash = (
  1239. nick => $smiles[1],
  1240. per => $spercent{$smiles[1]}
  1241. );
  1242. my $text = template_text('smiles2', %hash);
  1243. html("<br><span class=\"small\">$text</span>");
  1244. }
  1245. html("</td></tr>");
  1246. } else {
  1247. my $text = template_text('smiles3');
  1248. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1249. }
  1250. }
  1251. sub lasttopics {
  1252. my ($stats) = @_;
  1253. if ($stats->{topics}) {
  1254. $debug->("Total number of topics: " . scalar @{ $stats->{topics} });
  1255. my %hash = (
  1256. total => scalar @{ $stats->{topics} }
  1257. );
  1258. my $ltopic = $#{ $stats->{topics} };
  1259. my $tlimit = 0;
  1260. $conf->{topichistory} -= 1;
  1261. if ($ltopic > $conf->{topichistory}) {
  1262. $tlimit = $ltopic - $conf->{topichistory};
  1263. }
  1264. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1265. my $topic = htmlentities($stats->{topics}[$i]{topic});
  1266. $topic = replace_links($stats->{topics}[$i]{topic});
  1267. # Strip off the quotes (')
  1268. $topic =~ s/^\'(.*)\'$/$1/;
  1269. my $nick = $stats->{topics}[$i]{nick};
  1270. my $hour = $stats->{topics}[$i]{hour};
  1271. my $min = $stats->{topics}[$i]{min};
  1272. html("<tr><td bgcolor=\"$conf->{hicell}\"><i>$topic</i></td>");
  1273. html("<td bgcolor=\"$conf->{hicell}\">By <b>$nick</b> at <b>$hour:$min</b></td></tr>");
  1274. }
  1275. html("<tr><td align=\"center\" colspan=\"2\" class=\"asmall\">" . template_text('totaltopic', %hash) . "</td></tr>");
  1276. } else {
  1277. html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('notopic') ."</td></tr>");
  1278. }
  1279. }
  1280. # Some HTML subs
  1281. sub htmlheader {
  1282. my ($stats) = @_;
  1283. my $bgpic = "";
  1284. if ($conf->{bgpic}) {
  1285. $bgpic = " background=\"$conf->{bgpic}\"";
  1286. }
  1287. print OUTPUT <<HTML;
  1288. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  1289. <html>
  1290. <head>
  1291. <title>$conf->{channel} @ $conf->{network} channel statistics</title>
  1292. <style type="text/css">
  1293. a { text-decoration: none }
  1294. a:link { color: $conf->{link}; }
  1295. a:visited { color: $conf->{vlink}; }
  1296. a:hover { text-decoration: underline; color: $conf->{hlink} }
  1297. body {
  1298. background-color: $conf->{bgcolor};
  1299. font-family: verdana, arial, sans-serif;
  1300. font-size: 13px;
  1301. color: $conf->{text};
  1302. }
  1303. td {
  1304. font-family: verdana, arial, sans-serif;
  1305. font-size: 13px;
  1306. color: $conf->{tdcolor};
  1307. }
  1308. .title {
  1309. font-family: tahoma, arial, sans-serif;
  1310. font-size: 16px;
  1311. font-weight: bold;
  1312. }
  1313. .headline { color: $conf->{hcolor}; }
  1314. .small { font-family: verdana, arial, sans-serif; font-size: 10px; }
  1315. .asmall {
  1316. font-family: arial narrow, sans-serif;
  1317. font-size: 10px;
  1318. color: $conf->{text};
  1319. }
  1320. </style></head>
  1321. <body$bgpic>
  1322. <div align="center">
  1323. HTML
  1324. my %hash = (
  1325. network => $conf->{network},
  1326. maintainer => $conf->{maintainer},
  1327. time => $time,
  1328. days => $stats->{days},
  1329. nicks => scalar keys %{ $stats->{lines} }
  1330. );
  1331. print OUTPUT "<span class=\"title\">" . template_text('pagetitle1', %hash) . "</span><br>";
  1332. print OUTPUT "<br>";
  1333. print OUTPUT template_text('pagetitle2', %hash);
  1334. sub timefix {
  1335. my ($timezone, $sec, $min, $hour, $mday, $mon, $year, $wday, $month, $day, $tday, $wdisplay, @month, @day, $timefixx, %hash);
  1336. $month = template_text('month', %hash);
  1337. $day = template_text('day', %hash);
  1338. @month=split / /, $month;
  1339. @day=split / /, $day;
  1340. # Get the Date from the users computer
  1341. $timezone = $conf->{timeoffset} * 3600;
  1342. ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+$timezone);
  1343. $year += 1900; # Y2K Patch
  1344. $min =~ s/^(.)$/0$1/; # Fixes the display of mins/secs below
  1345. $sec =~ s/^(.)$/0$1/; # it displays 03 instead of 3
  1346. if($hour > '23') { # Checks to see if it Midnight
  1347. $hour = 12; # Makes it display the hour 12
  1348. $tday = "AM"; # Display AM
  1349. }
  1350. elsif($hour > '12') { # Get rid of the Military time and
  1351. $hour -= 12; # put it into normal time
  1352. $tday = "PM"; # If past Noon and before Midnight set
  1353. } # the time as PM
  1354. else {
  1355. $tday = "AM"; # If it's past Midnight and before Noon
  1356. } # set the time as AM
  1357. # Use 24 hours pr. day
  1358. if($tday eq "PM" && $hour < '12') {
  1359. $hour += 12;
  1360. }
  1361. print OUTPUT "$day[$wday] $mday $month[$mon] $year - $hour:$min:$sec\n";
  1362. }
  1363. timefix();
  1364. print OUTPUT "<br>" . template_text('pagetitle3', %hash) . "<br><br>";
  1365. }
  1366. sub htmlfooter {
  1367. my ($stats) = @_;
  1368. print OUTPUT <<HTML;
  1369. <span class="small">
  1370. Stats generated by <a href="http://pisg.sourceforge.net/" title="Go to the pisg homepage">pisg</a> $conf->{version}<br>
  1371. pisg by <a href="http://www.wtf.dk/hp/" title="Go to the authors homepage">Morten "LostStar" Brix Pedersen</a> and others<br>
  1372. Stats generated in $stats->{processtime}
  1373. </span>
  1374. </div>
  1375. </body>
  1376. </html>
  1377. HTML
  1378. }
  1379. sub headline
  1380. {
  1381. my ($title) = @_;
  1382. print OUTPUT <<HTML;
  1383. <br>
  1384. <table width="$conf->{headwidth}" cellpadding="1" cellspacing="0" border="0">
  1385. <tr>
  1386. <td bgcolor="$conf->{headline}">
  1387. <table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">
  1388. <tr>
  1389. <td bgcolor="$conf->{hbgcolor}" class="text10">
  1390. <div align="center" class="headline"><b>$title</b></div>
  1391. </td>
  1392. </tr>
  1393. </table>
  1394. </td>
  1395. </tr>
  1396. </table>
  1397. HTML
  1398. }
  1399. sub pageheader
  1400. {
  1401. if ($conf->{pagehead} ne 'none') {
  1402. open(PAGEHEAD, $conf->{pagehead}) or die("$0: Unable to open $conf->{pagehead} for reading: $!\n");
  1403. while (<PAGEHEAD>) {
  1404. html($_);
  1405. }
  1406. }
  1407. }
  1408. sub close_debug
  1409. {
  1410. if ($conf->{debug}) {
  1411. close(DEBUG) or print STDERR "$0: Cannot close debugfile($conf->{debugfile}): $!\n";
  1412. }
  1413. }
  1414. sub get_cmdlineoptions
  1415. {
  1416. my $tmp;
  1417. # Commandline options
  1418. my ($moduledir, $channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help);
  1419. my $usage = <<END_USAGE;
  1420. Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma
  1421. maintainer] [-f format] [-n network] [-d logdir] [-a aliasfile]
  1422. [-i ignorefile] [-mo moduledir] [-h]
  1423. -ch --channel=xxx : Set channel name
  1424. -l --logfile=xxx : Log file to parse
  1425. -o --outfile=xxx : Name of html file to create
  1426. -ma --maintainer=xxx : Channel/statistics maintainer
  1427. -f --format=xxx : Logfile format [see FORMATS file]
  1428. -n --network=xxx : IRC Network this channel is on.
  1429. -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
  1430. -p --prefix=xxx : Analyse only files starting with xxx in dir.
  1431. Only works with --dir
  1432. -mo --moduledir=xxx : Directory containing pisg's modules.
  1433. -co --configfile=xxx : Config file
  1434. -h --help : Output this message and exit (-? also works).
  1435. Example:
  1436. \$ pisg.pl -n IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
  1437. As always, all options may also be defined by editing the source and calling
  1438. pisg without arguments.
  1439. END_USAGE
  1440. #'
  1441. if (GetOptions('channel=s' => \$channel,
  1442. 'logfile=s' => \$logfile,
  1443. 'format=s' => \$format,
  1444. 'network=s' => \$network,
  1445. 'maintainer=s' => \$maintainer,
  1446. 'outfile=s' => \$outputfile,
  1447. 'dir=s' => \$logdir,
  1448. 'prefix=s' => \$prefix,
  1449. 'ignorefile=s' => \$tmp,
  1450. 'aliasfile=s' => \$tmp,
  1451. 'moduledir=s' => \$moduledir,
  1452. 'configfile=s' => \$configfile,
  1453. 'help|?' => \$help
  1454. ) == 0 or $help) {
  1455. die($usage);
  1456. }
  1457. if ($tmp) {
  1458. die("The aliasfile and ignorefile has been obsoleted by the new
  1459. pisg.cfg, please use that instead [look in pisg.cfg]\n");
  1460. }
  1461. if ($channel) {
  1462. $conf->{channel} = $channel;
  1463. $conf->{cmdl}{channel} = 1;
  1464. }
  1465. if ($logfile) {
  1466. $conf->{logfile} = $logfile;
  1467. $conf->{cmdl}{logfile} = 1;
  1468. }
  1469. if ($format) {
  1470. $conf->{format} = $format;
  1471. $conf->{cmdl}{format} = 1;
  1472. }
  1473. if ($network) {
  1474. $conf->{network} = $network;
  1475. $conf->{cmdl}{network} = 1;
  1476. }
  1477. if ($maintainer) {
  1478. $conf->{maintainer} = $maintainer;
  1479. $conf->{cmdl}{maintainer} = 1;
  1480. }
  1481. if ($outputfile) {
  1482. $conf->{outputfile} = $outputfile;
  1483. $conf->{cmdl}{outputfile} = 1;
  1484. }
  1485. if ($logdir) {
  1486. $conf->{logdir} = $logdir;
  1487. $conf->{cmdl}{logdir} = 1;
  1488. }
  1489. if ($prefix) {
  1490. $conf->{prefix} = $prefix;
  1491. $conf->{cmdl}{prefix} = 1;
  1492. }
  1493. if ($moduledir) {
  1494. $conf->{modules_dir} = $moduledir;
  1495. $conf->{cmdl}{modules_dir} = 1;
  1496. }
  1497. if ($configfile) {
  1498. $conf->{configfile} = $configfile;
  1499. $conf->{cmdl}{configfile} = 1;
  1500. }
  1501. }
  1502. sub get_language_templates
  1503. {
  1504. open(FILE, $conf->{langfile}) or open (FILE, $FindBin::Bin . "/$conf->{langfile}") or die("$0: Unable to open language file($conf->{langfile}): $!\n");
  1505. while (my $line = <FILE>)
  1506. {
  1507. next if ($line =~ /^#/);
  1508. if ($line =~ /<lang name=\"([^"]+)\">/) {
  1509. # Found start tag, setting the current language
  1510. my $current_lang = $1;
  1511. while (<FILE>) {
  1512. last if ($_ =~ /<\/lang>/i);
  1513. # Get 'template = "Text"' in language file:
  1514. if ($_ =~ /(\w+)\s+=\s+"(.*)"\s*$/) {
  1515. $T{$current_lang}{$1} = $2;
  1516. }
  1517. }
  1518. }
  1519. }
  1520. close(FILE);
  1521. }
  1522. &main(); # Run the script