# Plugin.pm
#
# Based on Andrew's sample plugin.
# written by Sarah Luebke
# 07/15/99

BEGIN { unshift(@INC, "/home/rebelsky/public_html/Blazers/Annotations/Summer1999/"); }

use Insert;
use URI::URL;
use Top;

sub Execute
  {
    # Read in parameters
    my $user = shift;       # ID of user requesting page
    my $user_info = shift;  # user information (string)
    my $request = shift;    # request from the client (LWP::Request)
    my $response = shift;   # the response so far (LWP::Response)

    # Other variables
    my $headers;
    my $content;
    my $page;
    my $url;
    my $user_email;
    my @groups;

    # Is it HTML?
    $headers = $response->headers;
    $content = $headers->header("content-type");

    if ($content eq "text/html") 
      {


        # Get the page
        $page = $response->content;
        # Check for a frameset
        if ($page !~ m/<FRAMESET.*>/i) {

        # parse the string of user information
          $user_info =~ m/<EMAIL>(.*)<\/EMAIL>/;
          $user_email = $1;
          $user_info =~ m/<GROUPLIST>(.*)<\/GROUPLIST>/;
          @groups = $1;
          $url = $request->url;
          #$url = $url->abs($url);
          # Call insert with the url, html, name, email and groups
          $page = Insert::main($url, $page, $user, $user_email, @groups); 
          $response->content($page);
        } # if ($page !~ m/<FRAMESET>/)
      }                     # if ($content eq "text/html")

  }                         # sub Execute

#register virtual urls
main::RegisterVirtualURL("Annotation/top.cgi",\&Top->main);


# We're done, so return true - Should I return the new html instead?
return 1;

