3 # irclog2html.pl Version 1.5 - 11th May 2000
4 # Copyright (C) 2000, Jeffrey W. Waugh
7 # Jeff Waugh <jdub@aphid.net>
10 # Rick Welykochy <rick@praxis.com.au>
11 # Alexander Else <aelse@uu.net>
12 # Tim Riker <Tim@Rikers.org>
14 # Released under the terms of the GNU GPL
15 # http://www.gnu.org/copyleft/gpl.html
17 # Modified by Tim Riker <Tim@Rikers.org>
18 # to work with infobot logs
20 # Usage: irclog2html <date> < logfile
22 # irclog2html will write out a colourised irc log, appending a .html
23 # extension to the output file.
25 ####################################################################################
29 $^W = 1; #RW# turn on warnings
30 use POSIX qw(strftime);
32 ####################################################################################
35 # Comment out the "table" assignment to use the plain version
38 #my $STYLE = "simplett";
40 my $STYLE = "simpletable";
42 my $colour_left = "#000099"; # nick leaving channel
43 my $colour_joined = "#009900"; # nick joining channel
44 my $colour_server = "#009900"; # server message (***)
45 my $colour_nickchange = "#009900"; # nick change
46 my $colour_action = "#CC00CC"; # nick action (/me waves)
48 my %prefs_colour_nick = (
50 "cantanker" => "#006600",
51 "chuckd" => "#339999",
54 ####################################################################################
58 my ( $channel, $date ) = @_;
62 qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
65 <title>IRC log for $channel on $date</title>
66 <meta name="generator" content="irclog2html.pl">
67 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
69 <body text="#000000" bgcolor="#ffffff">
70 <h1>IRC log for $channel on $date</h1>
73 if ( $STYLE =~ /table/ ) {
74 $return .= "<table cellspacing=3 cellpadding=2 border=0>\n";
81 if ( $STYLE =~ /table/ ) {
82 $return .= "</table>\n";
86 <br>Generated by irclog2html.pl
87 Modified by <a href="http://Rikers.org">Tim Riker</a> to work with
88 <a href="http://infobot.sourceforge.net/">infobot</a>.
99 return if not $lastdate;
101 my @files = `ls $lastdate.html */$lastdate.html`;
102 foreach $filename (@files) {
104 if ( !open( OUTPUT, ">>$filename" ) ) {
105 print "Cannot open $filename for writing!\n\n";
108 print OUTPUT footer();
114 my ( $date, $time, $channel, $lineout ) = @_;
116 add_footers() if $lastdate ne $date;
120 $filename .= "$channel/" if $channel;
121 $filename .= "$date.html";
123 mkdir( $channel, oct('755') ) if ( $channel && !-d $channel );
124 if ( !open( OUTPUT, ">>$filename" ) ) {
126 #print "Cannot open $filename for writing!\n\n";
131 print OUTPUT header( $channel, $date ) if -z $filename;
133 print OUTPUT $lineout;
138 sub output_timenicktext {
139 my ( $date, $time, $channel, $nick, $text, $htmlcolour ) = @_;
142 if ( $STYLE eq "table" ) {
145 "<td bgcolor=\"$htmlcolour\"><font color=\"#ffffff\"><tt>$time</tt></font></td>"
148 "<td bgcolor=\"$htmlcolour\"><font color=\"#ffffff\"><tt>$nick</tt></font></td>";
150 "<td width=\"100%\" bgcolor=\"#eeeeee\"><tt><font color=\"$htmlcolour\">$text<\/font></tt></td></tr>\n";
152 elsif ( $STYLE eq "simpletable" ) {
153 $lineout .= "<tr bgcolor=\"#eeeeee\">";
154 $lineout .= "<td><tt>$time</tt></td>" if $time;
156 "<td><font color=\"$htmlcolour\"><tt>$nick</tt></font></td>";
157 $lineout .= "<td width=\"100%\"><tt>$text</tt></td></tr>\n";
159 elsif ( $STYLE eq "simplett" ) {
160 $lineout .= "$time " if $time;
161 $lineout .= "<\;$nick>\; $text<br>\n";
164 $lineout .= "$time " if $time;
166 "<font color=\"$htmlcolour\"><\;$nick>\; $text<\/font><br>\n";
168 output_line( $date, $time, $channel, $lineout );
171 sub output_timeservermsg {
172 my ( $date, $time, $channel, $line ) = @_;
175 if ( $STYLE =~ /table/ ) {
177 $lineout .= "<td><tt>$time</tt></td>" if $time;
178 $lineout .= "<td colspan=2><tt>$line</tt></td></tr>\n";
181 $lineout .= "$time " if $time;
182 $lineout .= "$line<br>\n";
184 output_line( $date, $time, $channel, $lineout );
188 my ( $i, $ncolours ) = @_;
189 $ncolours = 1 if $ncolours == 0;
191 my $rgbmax = 125; # tune these two for the outmost ranges of colour depth
195 0.95; # tune these for the starting and ending concentrations of R,G,B
207 my $m = $rgbmin + ( $rgbmax - $rgbmin ) * ( $ncolours - $i ) / $ncolours;
209 my $r = $rgb->[$n][0] * $m;
210 my $g = $rgb->[$n][1] * $m;
211 my $b = $rgb->[$n][2] * $m;
212 sprintf( "#%02x%02x%02x", $r, $g, $b );
215 ####################################################################################
233 my %colour_nick = %prefs_colour_nick;
235 while ( $line = <STDIN> ) {
239 if ( !$line eq "" ) {
242 if ( $line =~ s/^([0-9:\.]*) (.*)$/$2/ ) {
250 # Replace ampersands, pointies, control characters #
251 $line =~ s/&/&\;/g;
252 $line =~ s/</<\;/g;
253 $line =~ s/>/>\;/g;
254 $line =~ s/\e\[[0-1]*m//g;
255 $line =~ s/[\x00-\x1f]+//g;
257 # Replace possible URLs with links #
259 s/((http|https|ftp|gopher|news):\/\/\S*)/<a href="$1">$1<\/a>/g;
261 # Colourise the comments
262 if ( $line =~ /^<\;[^\/]*?\/\#.*?>\; .*$/ ) {
264 # Split $nick, $channel and $line
266 $nick =~ s/^<\;([^\/]*?)\/\#.*?>\; .*$/$1/;
268 $channel =~ s/^<\;[^\/]*?\/(\#.*?)>\; .*$/$1/;
270 # $nick =~ tr/[A-Z]/[a-z]/;
271 # <======= move this into another function when getting nick colour
274 $text =~ s/^<\;.*?>\; (.*)$/$1/;
275 $text =~ s/^ .*/<\;PROTECTED>\;/g;
276 $text =~ s/ / \; \;/g;
278 $htmlcolour = $colour_nick{$nick};
279 if ( !defined($htmlcolour) ) {
284 # if we've exceeded our estimate of the number of nicks, double it
285 $NICKMAX *= 2 if $nickcount >= $NICKMAX;
287 $htmlcolour = $colour_nick{$nick} =
288 html_rgb( $nickcount, $NICKMAX );
290 output_timenicktext( $date, $time, $channel, $nick, $text, $htmlcolour );
292 elsif ( $line =~ /^\* ([^ \/]+)\/(\#[^ ]+) (.+)/ ) {
293 # Colourise the /me's #
296 $text="<font color=\"$colour_action\">$3</font>";
297 $htmlcolour = $colour_nick{$nick};
298 if ( !defined($htmlcolour) ) {
303 # if we've exceeded our estimate of the number of nicks, double it
304 $NICKMAX *= 2 if $nickcount >= $NICKMAX;
306 $htmlcolour = $colour_nick{$nick} =
307 html_rgb( $nickcount, $NICKMAX );
309 output_timenicktext( $date, $time, $channel, $nick, $text, $htmlcolour );
311 elsif ( $line =~ /^>\;>\;>\; / ) {
312 $line =~ s/^>\;>\;>\; /\*\*\* /;
314 # Process changed nick results, and remember colours accordingly #
315 if ( $line =~ /\*\*\* (.*?) materializes into (.*)/ ) {
320 #$nick_old =~ s/\*\*\* (.*?) materializes into .*/$1/;
322 #$nick_new =~ s/\*\*\* (.*?) materializes into (.*)/$2/;
324 $colour_nick{$nick_new} = $colour_nick{$nick_old};
325 $colour_nick{$nick_old} = undef;
327 $line =~ s/(\*\*\* .*)/<font color=\"$colour_nickchange\">$1<\/font>/;
329 elsif ( $line =~ /\*\*\* (join|mode|topic)\/(.*?) .*/ ) {
332 s/(\*\*\* .*)/<font color=\"$colour_joined\">$1<\/font>/;
334 elsif ( $line =~ /\*\*\* (part|kick|banned)\/(.*?) .*/ ) {
337 s/(\*\*\* .*)/<font color=\"$colour_left\">$1<\/font>/;
339 elsif ( $line =~ /\*\*\* .* has signed off IRC .*/ ) {
341 # Colourise joined/left/server messages #
343 s/(\*\*\* .*)/<font color=\"$colour_left\">$1<\/font>/;
345 elsif ( $line =~ /\*\*\* / ) {
347 s/(\*\*\* .*)$/<font color=\"$colour_server\">$1<\/font>/;
349 elsif ( $line =~ /^\* .*$/ ) {
351 # Colourise the /me's #
353 s/^(\*.*)$/<font color=\"$colour_action\">$1<\/font>/;
356 output_timeservermsg( $date, $time, $channel, $line );
366 if ( !scalar @ARGV ) {
367 print "Usage: irclog2html.pl <date> < logfile\n";
369 "Example: bzcat log/2002/1104.bz2 | irclog2html.pl 20021104\n";
375 # vim:ts=4:sw=4:expandtab:tw=80