# -------------------------------------------------------------------------------------
# flo::Template::BrowserDetect ( deprecated )
# -------------------------------------------------------------------------------------
#
#       Author : Jean-Michel Hiver (jhiver@cisedi.com).
#    Copyright : (c) MKDoc Holdings Ltd, 2000.
# 
#      Unauthorized modification, use, reuse, distribution or redistribution
#      of this module is stricly forbidden.
#
#    Description:
#
#      This tags allows you to detect older or broken navigators.
#      Note: this is deprecated because of the web caches / proxies which don't
#            seem to bother too much about the browser version.
#
#      Usage  : <% browser_detect set="Browser" %>
#               <% if name="Browser:IE3" %> IE 3 stuff
#               <% elsif name="Browser:NN4 %> Netscape 4 stuff
#               <% elsif name="Browser:TV %> WebTV stuff
#               <% else %> Normal stuff
#               <% end-if %>
# -------------------------------------------------------------------------------------
package flo::Template::BrowserDetect;
use lib::Template::AbstractTag;
use lib::Exception;
use lib::Template;
use strict;
use vars qw /@ISA/;
@ISA = qw /lib::Template::AbstractTag/;


##
# $obj->main;
# -----------
##
sub main
{
    my $self   = shift;
    my $result = $self->result;
    my $tokens = $self->tokens;
    my ($token_name, $token_hash) = $self->parse_tag (shift @{$tokens});
    
    my $symbol = $token_hash->{set} or
        throw (new lib::Exception ( code => 'VARIABLE_NOT_SET',
                                    info => "$token_name should have a 'symbol' attribute" ) );
    
    my $ie3 = $self->ie3;
    my $nn4 = $self->nn4;
    my $tv  = $self->tv;
    
    $lib::Template::STASH->{$symbol} = {};
    $lib::Template::STASH->{$symbol}->{IE3} = 1 if $ie3;
    $lib::Template::STASH->{$symbol}->{NN4} = 1 if $nn4;
    $lib::Template::STASH->{$symbol}->{TV}  = 1 if $tv;
}


##
# $self->ie3;
# -----------
#   Returns TRUE if the navigator is IE3 (excluding WebTV),
#   FALSE otherwise
##
sub ie3
{
    my $self = shift;
    $_ = $ENV{HTTP_USER_AGENT} || "";
    if (/Mozilla/ and /MSIE/)
    {
        my ($nb) = $_ =~ /MSIE.([0-9.]+)/;
        return ($nb < 4 and not $self->tv);
    }
}


##
# $self->nn4;
# -----------
#   Returns TRUE if the navigator is Netscape 4,
#   FALSE otherwise
##
sub nn4
{
    my $self = shift;
    $_ = $ENV{HTTP_USER_AGENT} || "";
    if (/Mozilla\/([0-9\.]+)/ and not /MSIE/) { return ($1 >= 4 and $1 < 5) }
    return;
}


##
# $self->tv;
# ----------
#   Returns TRUE if the navigator is a WebTV
#   FALSE otherwise
##
sub tv
{
    my $self = shift;
    $_ = $ENV{HTTP_USER_AGENT} || "";
    return /WebTV/;
}


1;







