# -------------------------------------------------------------------------------------
# flo::plugin::Robots
# -------------------------------------------------------------------------------------
#
#       Author : Alexandre Girard (agirard@popmail.com)
#    Copyright : (c) MKDoc Holdings Ltd, 2001
# 
#      Unauthorized modification, use, reuse, distribution or redistribution
#      of this module is stricly forbidden
#
#    Description:
#
#      A plugin that is used to avoid search engine browsing sitemap and
#      search engine
#
# -------------------------------------------------------------------------------------
package flo::plugin::Robots;
use lib::Config;
use flo::Object;
use flo::Standard;
use vars qw /@ISA/;
@ISA = qw /flo::Object/;
use strict;


sub main
{
    my $class = shift;
    my $cgi = lib::cgi::CGI->get;
    
    # if this module is not concerned, let's return ASAP
    my $config = $class->config;
    my $http_name = $config->{http_name};
    my $q_http_name = quotemeta ($http_name);
    my $raw_path_info = raw_path_info;
    return unless ( ($raw_path_info =~ /.*\/$q_http_name$/o) );
    
    # if we are in admin mode, we want to disallow everything
    if (defined $MKDoc::CFG->get ('flo::plugin::explorer::Admin'))
    {
	print "Content-Type: text/plain\r\n\r\n";
	print "User-agent: *\n";
	print "Disallow: *\n";
    }
    
    # else, we just want to disallow some stuff
    else
    {
	# retrieve names to block for each document
	my @http_names = map { (/^.+\..+$/) ? $_ : () } keys %{$config};
	
	# retrieve all the document, in order to add them for the plugin url
	my $document_table = table ('Document');
	my @full_paths = map { $_->{Full_Path} } $document_table->select (cols => 'Full_Path')->fetch_all;
	
	print "Content-Type: text/plain\r\n\r\n";
	print "User-agent: *\n";
	foreach my $full_path (@full_paths)
	{
	    foreach my $http_name (@http_names)
	    {
		print "Disallow: " . $full_path . $http_name . "\n";
	    }
	}
    }
    return 'TERMINATE';
}


1;








