#!/usr/bin/perl

# CGI to allow users to see all current faces in a single page.

use strict;

#
# Configuration
#
my $web_base = "http://www.hacksrus.com/~ginda/chatzilla/motifs";
my $file_base = "/home/ginda/public_html/chatzilla/motifs";

use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $p = new CGI;

print $p->header;

print <<EOM;
<HTML>
<HEAD>
<TITLE>moznet faces</TITLE>
</HEAD>
<BODY>

<H2><a href="irc://moznet/">moznet</a> <a href="#faces">faces</a>...</H2>

EOM

my @users = get_files("$file_base/faces/");
@users = sort (@users);

print <<EOM;
Here are some faces behind the nicks on <a href="irc://moznet/">moznet</a>.  If
you are using the
<a href="http://www.mozilla.org/projects/rt-messaging/chatzilla/">mozilla irc
client</a> (aka ChatZilla), you can
<a href="http://www.hacksrus.com/~ginda/chatzilla/screenshots/comichatzilla.gif">see</a> all these gorgeous images right
next to the nickname by dragging <a href="$web_base/output-dark-faces.css">this link</a>
into the message pane, or by typing <tt>/css $web_base/output-dark-faces.css</tt>.
<p>
To get the best effect, select <b>View</b>-&gt;<b>Collapse Consecutive Messages</b>,
to list consecutive messages from the same user under a single image.
<p>
There are three color scheme variations with faces listed below.  Drag a
``Motif'' link into the ChatZilla window to try it out, or click ``Sample'' to
see a sample channel log.  For more motifs (including some without faces) visit
<a href="http://www.hacksrus.com/~ginda/chatzilla/motifs/">http://www.hacksrus.com/~ginda/chatzilla/motifs/</a>, and drag any of the .css files into ChatZilla.
<ul>
 <li>(<a href="$web_base/output-default-faces.css">Motif</a> |
<a href="sample-log.html?motifs/output-default-faces.css">Sample</a>)
The <b>Default Colors with Faces</b>
motif will use your default foreground, background, and link colors.

 <li>(<a href="$web_base/output-light-faces.css">Motif</a> |
<a href="sample-log.html?motifs/output-light-faces.css">Sample</a>)
The <b>Light Background with Faces</b>
motif has a light backround and colors that match
<a href="www.google.com">Google</a>.

 <li>(<a href="$web_base/output-dark-faces.css">Motif</a> |
<a href="sample-log.html?motifs/output-dark-faces.css">Sample</a>)
The <b>Dark Background with Faces</b>
motif has a black background and light text.
</ul>
EOM

my $i;
print "<hr><a name='faces'>$#users faces...<center><table>\n<tr>";
for $i (0 .. $#users) {
    my $filename = $users[$i];
    if ($filename =~ /(.*)\.png/) {
        print "<td align='center'><img src='$web_base/faces/$filename'><br>$1</td>\n";
    } else {
        print "huh? : $filename";
    }
    if ((++$i % 7) == 0) {
        print "</tr><tr>\n";
    }
}

print "<td colspan=`10`></td></tr></table></center>\n";


print <<EOM;
<hr>
If you'd like to make your own CSS files
with or without faces, see the
<a href="http://www.mozilla.org/projects/rt-messaging/chatzilla/style.html">Stylin' ChatZilla</a> document.
The scripts used here are available from
<a href="http://www.hacksrus.com/~ginda/chatzilla/facesrv/">http://www.hacksrus.com/~ginda/chatzilla/facesrv/</a>

</body></html>
EOM
#
# given a directory, return an array of all the files that are in it.
#
sub get_files {
    my ($subdir) = @_;
    my (@file_array, @subdir_files);

    opendir (SUBDIR, $subdir) || die ("couldn't open directory $subdir: $!");
    @subdir_files = readdir(SUBDIR);
    closedir(SUBDIR);

    foreach (@subdir_files) {
        my $file = $_;
        if (!($file =~ /[\#~]$/) && -f "$subdir$file") {
            $file_array[$#file_array+1] = $file;
        }
    }

    return @file_array;
}

