Apache-SetWWWTheme
view release on metacpan or search on metacpan
SetWWWTheme.pm view on Meta::CPAN
unless(/<HEAD[^>]*?>/i) # unless we find a <HEAD> tag,
{
if (/<HTML[^>]*?>/i) # if there is an <HTML> tag...
{
s|(<HTML[^>]*?>)|$1<HEAD>|i; # add <HEAD> afterwards.
}
else # and if there isn't a <HTML> tag
{
$_ = "<HEAD>" . $_; # put the <HEAD> tag at the very top
}
}
s|<HEAD>|<HEAD></HEAD>|i unless (/<\/HEAD>/i); # close with </HEAD> if we need to
s|</HEAD>|</HEAD><BODY>|i unless (/<BODY[^>]*?/i); # drop in a <BODY> tag if we need to
$_ = "<HTML>" . $_ unless (/<HTML[^>]*?>/i); # now put <HTML></HTML> around the
$_ .= "</HTML>" unless (/<\/HTML>/i); # entire doc if necessary
s|</HTML>|</BODY></HTML>|i unless (/<\/BODY>/i); # and close the </BODY> if we need to
# Jolly good. We've fixed up the HTML so that we can depend on the existence
# of <HTML>, <HEAD>, and <BODY>, and also that they're closed properly.
# It's time to start creating the stuff we're going to insert into the HTML
my $newbody;
$newbody = MakeBody() unless ($nosidebar); # make the replacement if necessary.
unless($newbody) # This piece is used if we're not creating
{ # a sidebar. It just recreates a normal body
# as before, except it still uses the table.
$newbody = "<BODY ";
($BGCOLOR) && ($newbody .= "BGCOLOR=\"$BGCOLOR\" ");
($bgpicture) && ($newbody .= "BACKGROUND=\"$bgpicture\" ");
($alink) && ($newbody .= "ALINK=\"$alink\" ");
($link) && ($newbody .= "LINK=\"$link\" ");
($text) && ($newbody .= "TEXT=\"$text\" ");
($vlink) && ($newbody .= "VLINK=\"$vlink\" ");
$newbody .= "><DIV><TABLE><TR><TD>";
}
# now we'll make up a copyright notice to insert into our page.
my $copyrightnotice =
"<!-- BEGINNING OF APACHE GENERATED HTML\n" .
"***************************************\n" .
"This is Apache::SetWWWTheme\n" .
"Copyright (C) 2000 Chad Hogan <chogan\@uvastro.phys.uvic.ca>\n" .
"Copyright (C) 2000 Joint Astronomy Centre\n" .
"All Rights Reserved.\n" .
"Apache::SetWWWTheme is free software, licensed under the GNU General\n" .
"Public License as published by the Free Software Foundation. Please\n" .
"see the source code for details.\n" .
"-->\n";
$newbody = $copyrightnotice . $newbody;
if ($topbar) # if we have a top links bar, we'll put it in
{
# first, we'll clean up the vars and remove all escapes before semicolons.
my $marker;
for ($marker = 0; $marker <= $#topbottomlinks; $marker++)
{
$topbottomlinks[$marker] =~ s/\\;/;/;
}
# now that our vars are clean, we'll use them.
$Theme->SetTopBottomLinks(\@topbottomlinks) if (@topbottomlinks);
$newbody .= $Theme->MakeTopBottomBar();
}
if ($usenavbar) # This puts the top/bottom nav bars into the
{ # newly-created HTML
# first we have to remove the escapes from our strings.
$nextlink =~ s/\\;/;/g;
$lastlink =~ s/\\;/;/g;
$uplink =~ s/\\;/;/g;
# now we'll do our stuff.
$Theme->SetNextLink($nextlink) if $nextlink;
$Theme->SetLastLink($lastlink) if $lastlink;
$Theme->SetUpLink($uplink) if $uplink;
$newbody .= $Theme->MakeNavBar();
}
s/<BODY[^>]*?>/$newbody/i; # now sub in our generated HTML!
my $newendbody; # This will contain the end of our generated HTML
# if we're using top/bottom navbars, we'll tack on the
# bottom navbar piece.
$newendbody .= $Theme->MakeNavBar() if ($usenavbar);
if ($bottombar) # now we stick in the bottom bar, if required
{
$Theme->SetTopBottomLinks(\@topbottomlinks) if (@topbottomlinks);
$newendbody .= $Theme->MakeTopBottomBar();
}
$newendbody .= MakeEndBody(); # Them we make the closing endbody.
s/<\/BODY[^>]*?>/$newendbody/i; # And finally, we replace the </BODY> with our new HTML
$r->print($_); # we've made our changes, so we'll give it back to apache
}
return OK;
}
#############################################################################
# this makes the very last part of the page
# it must close off all the table stuff neatly, or else the page won't render.
sub MakeEndBody
{
return $Theme->MakeFooter();
}
#############################################################################
# this grabs all the server-side defaults. This is stuff that only the
# maintainers can set, and lives in a file that's pointed to by the
# PerlSetVar in the httpd.conf file. It's meant to be the controlling file.
# Get_LocalDefaults will get the local defaults that are user-definable.
sub Get_ServerDefaults
{
my $configfile = shift;
open (CONFIG, $configfile)|| ($r->log_error("Can't read $configfile"), return 0);
local $/ = undef; # whole file
SetWWWTheme.pm view on Meta::CPAN
if ($allowsidebarmod)
# if users are allowed to change the sidebar, then we'll go ahead and read in the changes
# that the users specify in their local configuration files.
{
( /\@SIDEBARTOP\s*=\s*(.*?[^\\]);/s ) && ($sidebartop = $1);
( /\@SIDEBARMENUTITLE\s*=\s*(.*?[^\\]);/s ) && ($sidebarmenutitle = $1);
( /\@SIDEBARMENULINKS\s*=\s*(.*?[^\\]);/s ) && (@sidebarmenulinks = split(',',$1));
( /\@SIDEBARSEARCHBOX\s*=\s*(.*?[^\\]);/s ) && ($sidebarsearchbox = $1);
( /\@SEARCHTEMPLATE\s*=\s*(.*?[^\\]);/s ) && ($searchtemplate = $1);
( /\@SIDEBARCOLOR\s*=\s*(.*?[^\\]);/s ) && ($sidebarcolor = $1);
( /\@SIDEBARWIDTH\s*=\s*(.*?[^\\]);/s ) && ($sidebarwidth = $1);
( /\@MORELINKSTITLE\s*=\s*(.*?[^\\]);/s ) && ($morelinkstitle = $1);
( /\@NOSIDEBAREXTRAS\s*=\s*(.*?[^\\]);/s ) && ($nosidebarextras = $1);
}
}
close CONFIG;
return 1;
}
#############################################################################
# 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
}
SetWWWTheme.pm view on Meta::CPAN
=item Server-level configuration
At the server level, the webmaster has full access to all directives. These
tags are specified in a file that is set in the httpd.conf file. If a
webmaster would like his/her subtree to use the module, a <LOCATION> tag is
used to activate the module. A PerlSetVar is used to tell the module the
name of the configuration file. Here is an example:
<Location />
SetHandler perl-script
PerlHandler Apache::SetWWWTheme
PerlSetVar CONFIG_FILE /WWW/ServerConfig
</Location>
This example will use the module for the entire document tree. The
CONFIG_FILE variable is used by the module to look for the file that
controls the defaults for the entire site. Please note that CONFIG_FILE
takes the full path to the file name on the file-system -- do not list this
file relative to the document root.
The creation of printable versions of pages has been greatly simplified.
No longer is any configuration required -- the page is automatically
generated using a GET method. Adding "?printable" to a URI will
cause the page to be displayed in a printable manner, for example.
The server-level configuration is primarily to set defaults. It is also to
set restrictions on the configurability of the rest of the site. The
server-level configuration decides whether or not individual authours will
be permitted to, for example, change the background colour and background
image of their web pages.
Once again, the server configuration may make use of all of the following
directives. The server then decides which of these the users may override.
Local configuration
Any authour may create a text file containing directives. The name of this file
is set by the server directive @LOCALCONFIGFILE, with a default of
LookAndFeelConfig. This file will
affect all HTML files within that directory, as well as any subdirectories.
These directives are subject to the restrictions placed by the server-level
configuration. This file is intended to be used to set common settings for a
tree. For example, one may wish to set the background colour for an entire
tree to white. Then a @BGCOLOR=#FFFFFF; directive in the local config file.
file will set this. Directives that are explicitly set override the server
settings (if allowed). Otherwise, the server's settings persist.
Individual file configuration
This is the final level of configuration. Any authour may embed directives
within a comment tag in an HTML file, as long as this tag appears before the
<BODY> tag. Directives that are explicitly set override the local
configuration and/or server settings (if allowed). Otherwise, the local
settings and the server settings persist.
=item Module directives
Directives consist of a series of tags within a text file, or within an html
comment block before the <BODY> tag. Valid directive tags are always
terminated with a semicolon. For tags that accept lists as values, elements
are separated by commas. Semicolons may be escaped within a tag. Any
semicolon preceded by a backslash will be considered text, and will not terminate
the directive. The final text will have the escaped semicolon replaced with
a bare semicolon.
@DIRECTIVE=Some string of text\; semicolons are escaped.;
The above directive would set a value of "Some string of text; semicolons
are escaped."
=item @ALINK
HTML and local configuration subject to server configuration
This tag is used to set the HTML BODY setting "alink". This is the
active link color. It is subject to the setting of the @ALLOWBODYMOD
tag. If @ALLOWBODYMOD is set to a non-zero value, @ALINK will set this
attribute in the page. Here is an example:
@ALINK=#FF00FF;
=item @ALLOWBODYMOD
Server configuration only
This tag is used to allow or disallow users from changing BODY
elements. These include "alink", "vlink", "link", "text", "bgcolor",
and "background" items using the directives @ALINK, @VLINK, @LINK,
@TEXT, @BGCOLOR and @BGPICTURE respectively. If it is set to a non-zero
value, the user's directives will be read and used. Otherwise, user
settings will be ignored, and only the server configuration values will
be used in creating the <BODY> tag for the page. Here is an example:
@ALLOWBODYMOD=1;
=item @ALLOWBGCOLOR L<Deprecated>
Server configuration only
This tag is used to allow or disallow users from changing the
background colours of their pages. By default it is set to 0, meaning
that users are not allowed to change their background colours. If it is
not set to a non-zero value, only the server's @BGCOLOR directives will
be used. This directive is deprecated. Administrators should use
@ALLOWBODYMOD instead. Here is an example:
@ALLOWBGCOLOR=0;
=item @ALLOWBGPICTURE L<Deprecated>
Server configuration only
This tag is used to allow or disallow users from changing the
background picture of their pages. By default it is set to 0, meaning
that users are not allowed to change their background colours. If it is
not set to a non-zero value, only the server's @BGPICTURE directives
will be used. This directive is deprecated. Administrators should use
@ALLOWBODYMOD instead Here is an example:
@ALLOWBGPICTURE=0;
=item @ALLOWNOSIDEBAR L<Deprecated>
Server configuration only. I<Use @ALLOWSIDEBARTOGGLE instead>.
This tag is used to allow or disallow users from turning on/off the left
sidebar. By default, it is set to 0, meaning that users are not allowed to
toggle the sidebar. If is not set to a true value (1 is recommended), only the
server's @NOSIDEBAR directives will be used. Here is an example:
@ALLOWNOSIDEBAR=0;
=item @ALLOWSIDEBARTOGGLE
( run in 2.972 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )