##
##  wml::std::logo - Logo Insertion
##  Copyright (c) 1997-2001 Ralf S. Engelschall, All Rights Reserved. 
##

#  The <preserve>/<restore> tags with multiple arguments require WML 2.0.3
#use wml::mod::version
<require 2.0.3 />

#use wml::std::tags

#
#  Insert a Logo image
#
<define-tag logo>
<preserve name base file format target notag />
<set-var notag=* />
<set-var %attributes />
<defvar name wml />
<defvar base <or <get-var LOGO_BASE /> <get-var IMAGE_BASE /> /> />
<defvar format <or <get-var IMAGE_FORMAT /> png /> />
<perl>
    my $name   = '<get-var name />';
    my $ext    = '<get-var format />';
    my $base   = '<get-var base />';
    my $file   = '<get-var file />';
    my $target = '<get-var target />';
    my $notag  = (qq|<get-var notag />| eq '' ? 1 : 0);

    my $imgfile  = "$(WML_LOC_LIBDIR)/data/logos/logo-$name.$ext";
    my $infofile = "$(WML_LOC_LIBDIR)/data/logos/logo-$name.info";

    #   make sure the logo exists
    if (! -f $imgfile or ! -f $infofile) {
        print STDERR "Error: No such logo named '$name'.\n";
        exit(1);
    }

    #   create the output filename
    if ($file eq '') {
        if ($base ne '' && $base !~ m|/$|) {
            if (-d $base) {
                $base .= '/';
            }
            else {
                $base .= '.';
            }
        }
        $file = sprintf("%slogo-%s.%s", $base, $name, $ext);
    }

    open(FH_LOGO, "<$infofile");
    my $alt  = <*FH_LOGO>; $alt  =~ s|^\s+||; $alt  =~ s|\n$||; $alt  =~ s|\s+$||;
    my $hint = <*FH_LOGO>; $hint =~ s|^\s+||; $hint =~ s|\n$||; $hint =~ s|\s+$||;
    my $url  = <*FH_LOGO>; $url  =~ s|^\s+||; $url  =~ s|\n$||; $url  =~ s|\s+$||;
    close(FH_LOGO);

    #   create the logo image copy
    my $error = `cp $imgfile $file`;
    if ($? >> 8) {
        print STDERR "** wml::std::logo:\n$error";
        exit(1);
    }

    #   insert the markup code
    if (not $notag) {
        <perl:print>\
           <*a href="$url" \
              onmouseover="self.status='$hint';return true" \
              onmouseout="self.status='';return true" \
              onfocus="self.status='$hint';return true" \
              onblur="self.status='';return true"\
        </perl:print>
        if ($target ne '') {
          <perl:print> target="$target"</perl:print>
        }
        <perl:print>\
           ><img src="$file" alt="$alt" border=0 /><*/a>\
        </perl:print>
    }
</perl>
<restore  name base file format target notag />
</define-tag>

##EOF##
__END__

=head1 NAME

wml::std::logo - Logo Insertion

=head1 SYNOPSIS

 #use wml::std::logo

 <logo [attributes]>

=head1 DESCRIPTION

This include file provides the C<E<lt>logoE<gt>> tag to insert logo images.
The logo is selected via attribute C<name>. The following logos are available:

  Name      Inserted Hint                  Inserted URL
  --------  ------------------------------ ----------------------------
  apache    Apache Webserver Project       http://www.apache.org/
  freebsd   FreeBSD Operating System       http://www.freebsd.org/
  gimp      GNU Image Manipulation Program http://www.gimp.org/
  htdig     Internet search engine         http://www.htdig.org/
  linux     Linux Operating System         http://www.linux.org/
  netbsd    NetBSD Operating System        http://www.netbsd.org/
  openbsd   OpenBSD Operating System       http://www.openbsd.org/
  php       PHP Hypertext Preprocessor     http://www.php.net/
  vim       Vi Improved Editor             http://www.vim.org/
  wml       Website META Language          http://www.engelschall.com/sw/wml/
  xemacs    XEmacs Editor                  http://www.xemacs.org/

=head1 ATTRIBUTES

=over 4

=item C<name>

The C<name> attribute selects which logo is wanted. The table above lists
valid names, and I<wml> is used by default.

=item C<base>

Usually the logos are copied into F<logo-xxxxxx.png> where C<xxxxxx> is
the name of the logo.  When you use a C<base=foo> attribute, then the
resulting files are named F<foo.logo-xxxxxx.png>.  Actually you can even
use a complete filename including a directory prefix, i.e. when you use
C<base=../../common/foo> attribute, then the images are created as
F<../../common/foo.logo-xxxxxx.png>. 

And for most flexibility when no base is specified and the variable
C<LOGO_BASE> is defined (usually from within a F<.wmlrc> file via
C<-LOGO_BASE~path/to/logo/dir/base>) it is used.  Use this feature to
copy the logos to a particular directory.

You may also use the variable C<IMAGE_BASE> which defines in a single line
all base names for images generated by WML.

=item C<format>

Logos are available in PNG or GIF formats. This attribute is the
filename extension of the desired format, i.e. respectively C<png> and C<gif>.
Default is C<png> extension ; this default can be changed via the C<IMAGE_FORMAT>
variable.

=item C<file>

This attribute defines the logo filename. It overrides all other computed
values.

=item C<target>

If the C<target> attribute is used, it refers to a target frame or window
where the hyperlink is redirected to.

=item C<notag>

This forces C<E<lt>logoE<gt>> to expand to nothing, i.e. no resulting
C<E<lt>imgE<gt>> tag. The image itself is still generated. In combination with
the above C<file> attribute this can be used to generate images to particular
files which can be used at other positions, for instance inside
C<E<lt>rolloverE<gt>> (see wml::des::rollover(3)) tags.

=back

=head1 EXAMPLE

This example only copy the vim logo to C<$(IMAGES)/logo-vim.png> without
any output:

 <logo name=vim format=png base="$(IMAGES)/logo" notag>

=head1 AUTHORS

 Ralf S. Engelschall
 rse@engelschall.com
 www.engelschall.com

 Denis Barbier
 barbier@engelschall.com

=head1 REQUIRES

 Internal: P1, P2, P3
 External: --

=head1 HISTORY

 For backward compatibility a logo named "php3" is also available.
 Inluding the version number was not a really good idea, use the 
 logo "php" instead. Expect that the logo "php3" will be removed in 
 future releases.

=head1 SEE ALSO

wml(1)

=cut

