Apache-SetWWWTheme
view release on metacpan or search on metacpan
SetWWWTheme.pm view on Meta::CPAN
$printable = ($ENV{"QUERY_STRING"} =~ /$printabletag/i);
$printable && MakePrintable() && return OK; # if we have ?printable, then the whole thing stops
# right here, because OK is returned.
# failing that, we'll get configuration stuff, and construct our
# printable uri that we can stick into the "real" page.
# So, to get a printable version of http://www.somewhere.com/index.html
# we use http://www.somewhere.com/index.html?printable
$printableuri = $r->uri . "?$printabletag";
# Now that we have created a usable printable URL, we'll tell HTML::WWWTheme about it.
$Theme->SetPrintableName($printableuri) if ($printableuri);
# and now we grab the server configuration as usual.
#
# We start by getting our config_file as set out in CONFIG_FILE
$serverconfig = $r->dir_config->{'CONFIG_FILE'};
$r->log_error("Invalid server configuration file") unless ($serverconfig);
# Now we'll set up our defaults from the various spots. First we'll go
# for the server defaults, and then we'll grab the local config if
# we found one.
Get_ServerDefaults($serverconfig) if ($serverconfig);
# this block will go down the directory tree until it finds a Local config file.
# if it doesn't find one before the dirs run out, it'll be undef.
my $index = 1;
my $path;
my @bits = split("/", $filename);
while ( !($localconfig) && ($index <= $#bits) )
{
$path = join("/", @bits[0..$#bits-$index]);
$localconfig = "$path/$shortlocal" if (-f "$path/$shortlocal");
$index++;
}
Get_LocalDefaults($localconfig) if ($localconfig);
# Now the usual Apache module stuff.
my $fh; # grab a filehandle for our HTML file
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 at once.
while (<$fh>) # I suppose this while isn't necessary.
{
# this block looks through the HTML to find our comment block that contains directives
# for controlling the "Look and Feel" of the pages.
(/\@NAVBAR\s*=\s*(.*?[^\\]);/) && ($usenavbar = $1);
(/\@TOPBAR\s*=\s*(.*?[^\\]);/) && ($topbar = $1);
(/\@BOTTOMBAR\s*=\s*(.*?[^\\]);/) && ($bottombar = $1);
# this is the part where we let the HTML override the server-set defaults
# A few things we may or may not be able to change (like the BGCOLOR)
( /\@NEXTLINK\s*?=\s*?(.*?[^\\]);/s ) && ($nextlink = $1);
( /\@LASTLINK\s*?=\s*?(.*?[^\\]);/s ) && ($lastlink = $1);
( /\@UPLINK\s*?=\s*?(.*?[^\\]);/s ) && ($uplink = $1);
( /\@INFO\s*?=\s*?(.*?[^\\]);/s ) && (@infolinks = split(',',$1));
( /\@TOPBOTTOMLINKS\s*?=\s*?(.*?[^\\]);/s ) && (@topbottomlinks = split(',',$1));
( /\@NOSIDEBAREXTRAS\s*?=\s*?(.*?[^\\]);/s ) && ($nosidebarextras = $1);
($allowsidebartoggle) && ( /\@NOSIDEBAR\s*?=\s*?(.*?[^\\]);/s) && ($nosidebar = $1);
# these next two are relics. They are from the days before we had an "allowbodymod" directive
# we'll support them for a bit. They might even be useful on their own.. we'll see.
# Do you have an opinion one way or another? Email me: chogan@uvastro.phys.uvic.ca
($allowBGCOLOR) && ( /\@BGCOLOR\s*?=\s*?(.*?[^\\]);/s ) && ($BGCOLOR = $1);
($allowbgpicture) && ( /\@BGPICTURE\s*?=\s*?(.*?[^\\]);/s ) && ($bgpicture = $1);
if ($allowbodymod) # here is where we do all of our body modification if allowed
{
# first we'll look for existing <BODY> settings, then afterwards we'll check
# for commented directives. Unless they're overridden, we want to preserve the
# look of a legacy HTML file (IE one that wasn't written with this module in mind).
/<BODY[^>]+?BGCOLOR=(.*?[^\\])[\s|>]/is && ($BGCOLOR = $1) && $BGCOLOR =~ s/\"//g;
/<BODY[^>]+?BACKGROUND=(.*?[^\\])[\s|>]/is && ($bgpicture = $1) && $bgpicture =~ s/\"//g;
/<BODY[^>]+?ALINK=(.*?[^\\])[\s|>]/is && ($alink = $1) && $alink =~ s/\"//g;
/<BODY[^>]+?LINK=(.*?[^\\])[\s|>]/is && ($link = $1) && $link =~ s/\"//g;
/<BODY[^>]+?TEXT=(.*?[^\\])[\s|>]/is && ($text = $1) && $text =~ s/\"//g;
/<BODY[^>]+?VLINK=(.*?[^\\])[\s|>]/is && ($vlink = $1) && $vlink =~ s/\"//g;
# now we're using the directives in the comment tags. These override BODY settings.
/\@BGCOLOR\s*=\s*(.*?[^\\]);/s && ($BGCOLOR = $1);
/\@BGPICTURE\s*=\s*(.*?[^\\]);/s && ($bgpicture = $1);
/\@ALINK\s*=\s*(.*?[^\\]);/s && ($alink = $1);
/\@LINK\s*=\s*(.*?[^\\]);/s && ($link = $1);
/\@TEXT\s*=\s*(.*?[^\\]);/s && ($text = $1);
/\@VLINK\s*=\s*(.*?[^\\]);/s && ($vlink = $1);
}
# These are all of the sidebar modifications that may be performed, if allowed.
if ($allowsidebarmod)
{
( /\@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);
( /\@SIDEBARCOLOR\s*=\s*(.*?[^\\]);/s ) && ($sidebarcolor = $1);
( /\@SIDEBARWIDTH\s*=\s*(.*?[^\\]);/s ) && ($sidebarwidth = $1);
( /\@SEARCHTEMPLATE\s*=\s*(.*?[^\\]);/s) && ($searchtemplate = $1);
SetWWWTheme.pm view on Meta::CPAN
{
( /\@NAVBAR\s*=\s*(.*?[^\\]);/s ) && ($usenavbar = $1);
( /\@NEXTLINK\s*?=\s*?(.*?[^\\]);/s ) && ($nextlink = $1);
( /\@LASTLINK\s*?=\s*?(.*?[^\\]);/s ) && ($lastlink = $1);
( /\@UPLINK\s*?=\s*?(.*?[^\\]);/s ) && ($uplink = $1);
( /\@INFO\s*?=\s*?(.*?[^\\]);/s ) && (@infolinks = split(',',$1));
( /\@TOPBAR\s*=\s*(.*?[^\\]);/s ) && ($topbar = $1);
( /\@BOTTOMBAR\s*=\s*(.*?[^\\]);/s ) && ($bottombar = $1);
( /\@TOPBOTTOMLINKS\s*=\s*(.*?[^\\]);/s) && (@topbottomlinks = split(',',$1));
# these next two are left in so old pages won't break. Actually, it's not
# necessarily a bad thing to allow this like this anyhow.....
($allowBGCOLOR) && ( /\@BGCOLOR\s*=\s*(.*?[^\\]);/s ) && ($BGCOLOR = $1);
($allowbgpicture) && ( /\@BGPICTURE\s*=\s*(.*?[^\\]);/s ) && ($bgpicture = $1);
($allowsidebartoggle) && ( /\@NOSIDEBAR\s*?=\s*?(.*?[^\\]);/s ) && ($1) && ($nosidebar = $1);
if ($allowbodymod) # here is where we do all of our body modification if allowed
{
( /\@BGCOLOR\s*=\s*(.*?[^\\]);/s ) && ($BGCOLOR = $1);
( /\@BGPICTURE\s*=\s*(.*?[^\\]);/s ) && ($bgpicture = $1);
( /\@ALINK\s*=\s*(.*?[^\\]);/s ) && ($alink = $1);
( /\@LINK\s*=\s*(.*?[^\\]);/s ) && ($link = $1);
( /\@TEXT\s*=\s*(.*?[^\\]);/s ) && ($text = $1);
( /\@VLINK\s*=\s*(.*?[^\\]);/s ) && ($vlink = $1);
}
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();
}
###############################################
SetWWWTheme.pm view on Meta::CPAN
=item @BGPICTURE
HTML and local configuration subject to server configuration
This tag may be used to set the background image of a page (or a group
of pages, in the case of a local and server configuration. @BGPICTURE
is subject to the server directive @ALLOWBGPICTURE. If @ALLOWBGPICTURE
is not set to a non-zero value by server directives, the @BGPICTURE
directive will have no effect whatsoever when used in local and HTML
configuration. @BGPICTURE will always work when used in a server
configuration. Here is an example:
@BGPICTURE=/images/paperbackground.gif;
=item @BLANKGIF
Server configuration only
This tag is used to specify the location of the blank.gif image file.
This image is a 1x1 transparent gif that is used to space the tables
properly. This should be set to the path of the image file with respect
to the server's document root. So, if the apache document root is /WWW
and the file is /WWW/images/blank.gif then the proper use of this tag
would be:
@BLANKGIF=/images/blank.gif;
=item @BOTTOMBAR
Valid in HTML, local configuration, and server configuration. This
tag is used to toggle a navigation bar at the bottom of the page. This
bottom navigation bar contains the links defined with the @TOPBOTTOMLINKS
directive. If @BOTTOMBAR is set to something non-zero, it will appear
in the document.
@BOTTOMBAR=1;
=item @INFO
Valid in HTML, local configuration, and server configuration
This tag is used to customize the "More links" section in the left
sidebar. To use this tag, supply a comma-separated list of valid HTML
links terminated with a semi-colon. The links supplied will appear in
the "More Links" section. Here is an example:
@INFO=<A HREF="http://www.sun.com">Sun</a>,
<A HREF="http://www.slashdot.org">Slashdot</a>;
=item @LINK
Valid in HTML, local configuration, and server configuration
This tag is used to set the HTML BODY setting "link". This is the
normal link color. It is subject to the setting of the @ALLOWBODYMOD
tag. If @ALLOWBODYMOD is set to a non-zero value, @LINK will set this
attribute in the page. Here is an example:
@LINK=#FFFFFF;
=item @LOCALCONFIGFILE
Valid only in server configuration. This directive tells the module what
file to look for when it looks for local configuration files. The default is
LookAndFeelConfig. It may be set to any valid filename.
@LOCALCONFIGFILE=LOOKANDFEEL;
=item @MORELINKSTITLE
Valid in HTML, local configuration, and server configuration, subject
to the server's configuration (@ALLOWSIDEBARMOD must be on in the server's
configuration in order for local and HTML directives to be obeyed).
=item @NAVBAR
Valid in HTML, local configuration, and server configuration
This tag gives the switch setting for the top and bottom navigation
bars. The top and bottom navigation bars are also known as the
"previous/up/next" bars. If this is set to 0, the top and bottom bars
are not shown. If this is set to a non-zero value (1 is recommended)
then the bars will be shown. If this switch is non-zero, it is
recommended that the @NEXTLINK, @UPLINK, and @LASTLINK directives be
set. Here is an example:
@NAVBAR=0;
=item @NEXTLINK, @LASTLINK, @UPLINK
Valid in HTML, local configuration, and server configuration
These tags control the behaviour of the top navigation bar. These tags
should be set in conjunction with the @NAVBAR directive. They should
contain valid text and linking information. Here is an example:
@NEXTLINK=<A HREF="/pages/page3.html">Page 3</a>;
@UPLINK=<A HREF="/pages/toc.html">Table of contents</a>;
@LASTLINK=<A HREF="/pages/page1.html">Page 1</a>;
=item @NOSIDEBAR
HTML and local configuration subject to server configuration
This tag may be used to turn off the left sidebar by setting it to a
non-zero value. This tag is subject to the server directive
@ALLOWNOSIDEBAR. If the server configuration has not set the
@ALLOWNOSIDEBAR to a non-zero value, the @NOSIDEBAR directive will have
no effect whatsoever. Here is an example:
@NOSIDEBAR=1;
=item @SIDEBARCOLOR
HTML and local configuration subject to server configuration
This tag is used to set the color of the sidebar. Local and HTML
configuration is subject to the server directive @ALLOWSIDEBARMOD. Here
is an example:
@SIDEBARCOLOR=#CCCCCC;
=item @SIDEBARWIDTH
HTML and local configuration subject to server configuration.
This tag is used to set the width of the sidebar in pixels. Local
and HTML configuration is subject to the server directive @ALLOWSIDEBARMOD.
( run in 0.658 second using v1.01-cache-2.11-cpan-39bf76dae61 )