Apache-SetWWWTheme

 view release on metacpan or  search on metacpan

SetWWWTheme.pm  view on Meta::CPAN

# this constructs the side nav bar.  First we set the settings appropriately,
# then we grab a sidebar from it.  We use the JAC::Theme module to make a body
# given all of these settings.  We set them all manually according to the settings
# that we've collected from the server, the file, and the HTML.  

sub MakeBody
  {
    
    # First, we have to clean up the variables.  Since we've started escaping out
    # semicolons, we'll have to replace everything that looks like \; with ;

    $BGCOLOR      =~ s/\\;/;/g;
    $bgpicture    =~ s/\\;/;/g;
    $alink        =~ s/\\;/;/g;
    $link         =~ s/\\;/;/g;
    $text         =~ s/\\;/;/g;
    $vlink        =~ s/\\;/;/g;
    $sidebarcolor =~ s/\\;/;/g;
    $sidebarwidth =~ s/\\;/;/g;
    $blankgif     =~ s/\\;/;/g;

    my $marker;
    for ($marker=0; $marker <= $#infolinks; $marker++)
      {
	$infolinks[$marker] =~ s/\\;/;/g;
      }

    $sidebartop      =~ s/\\;/;/g;
    $nosidebarextras =~ s/\\;/;/g;
    $searchtemplate  =~ s/\\;/;/g;
   
    for ($marker = 0; $marker <= $#sidebarmenulinks; $marker++)
      {
	$sidebarmenulinks[$marker] =~ s/\\;/;/g;
      }

    $sidebarmenutitle =~ s/\\;/;/g;
    $morelinkstitle   =~ s/\\;/;/g;

    # Ok, now we have cleaned up all the escaped semicolons.  It's time to feed these to
    # our module and have fun.


    $Theme->SetBGColor($BGCOLOR)                    if ($BGCOLOR);
    $Theme->SetBGPicture($bgpicture)                if ($bgpicture);
    $Theme->SetALink($alink)                        if ($alink);
    $Theme->SetLink($link)                          if ($link);
    $Theme->SetText($text)                          if ($text);
    $Theme->SetVLink($vlink)                        if ($vlink);

    $Theme->SetSideBarColor($sidebarcolor)          if ($sidebarcolor);
    $Theme->SetSideBarWidth($sidebarwidth)          if ($sidebarwidth);
    $Theme->SetBlankGif($blankgif)                  if ($blankgif);
    $Theme->SetInfoLinks(\@infolinks)               if (@infolinks);
    $Theme->SetSideBarTop($sidebartop)              if ($sidebartop);
    $Theme->SetNoSideBarExtras($nosidebarextras)    if ($nosidebarextras);

    $Theme->SetSideBarSearchBox($sidebarsearchbox);
    $Theme->SetSearchTemplate($searchtemplate)      if ($searchtemplate);
    
    $Theme->SetSideBarMenuLinks(\@sidebarmenulinks) if (@sidebarmenulinks);
    $Theme->SetSideBarMenuTitle($sidebarmenutitle)  if ($sidebarmenutitle);
    $Theme->SetMoreLinksTitle($morelinkstitle)      if ($morelinkstitle);

    return $Theme->MakeHeader();
    
}


###############################################
#
# This sub makes a printable version of a page.  It strips out the 
# HTML link stuff so that people don't surf around in the 
# printable versions of pages, thus subverting the entire theme stuff.

sub MakePrintable
{
  my $fh;                                       # grab a filehandle
  unless ($fh = Apache::File->new($filename))
    {
      $r->log_error("Couldn't open $filename for reading: $!");
      return SERVER_ERROR;
    }
  
  $r->register_cleanup(sub {close $fh});        # register a cleanup for the filehandle
  
  local $/ = undef;                             # Read in the whole schmear.
  
  while (<$fh>)
    {
      s|<A\W+HREF[^>]+>||ig;                         # wipes out our links
      s|</A>||ig;
      
      my $return = $r->uri;

      s|</BODY>|<A HREF=\"$return\"><H6>return...</H6></A></BODY>|ig;

      $r->print($_);                            # dumps the results to apache
    }	
  
  return 1;                                    # and tell it we finished.
  
}	



1;

# May a thousand locusts descend upon pod.

=head1 NAME

Apache::SetWWWTheme - Standard theme generation, including sidebars and navigation bars

=head1 SYNOPSIS

Within the httpd.conf or other apache configuration file:
    
 <Location /some/subtree>
 SetHandler perl-script
 PerlHandler Apache::SetWWWTheme
 PerlSetVar CONFIG_FILE /WWWroot/configfile



( run in 0.813 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )