package PageFormatterTemplate;
use Exporter;
@ISA = qw(Exporter);
use strict;
use lib "/pathToYourWebspace/cgi-bin/gnu";
use CGI::Carp qw( fatalsToBrowser);
use MainIndex;
use WorkInProgressSideIndex;
use MostRecentSideIndex;
sub new {
# page calling sequence
# PageFormatterTemplate->new($cgiObj,$indexGroup,$sideIndexObj,$commentsObj,$pageFileName,$pageTitle,$metaKeywords,$metaDescription);
my $invocant = shift @_;
my $className = ref($invocant) || $invocant;
my $self = {};
bless ($self, $className);
# save passed parameters
$self->{CGI_OBJ} = shift; # $cgiObj - perhpas one might need this, already called in calling prog
$self->{INDEX_GROUP} = shift; # $indexGroup
# url is the pictureGroup string in ..../pictureGroup/pageFilename
# e.g. "landscapes" in /cgi-bin/site_files/landscapes/dunaffHead.pl
$self->{SIDE_INDEX_OBJ} = shift; # $sideIndexObj : SideIndex.pm in current group directory
# reference to object with index data for this group
$self->{COMMENTS_OBJ} = shift; # $commentsObj : Comments.pm in the site directory
# reference to object with comments data sent by visitor to this page
$self->{PAGE_FILE_NAME} = shift; # $pageFileName : program file name
# e.g. dunaffHead.pl in ..../landscapes/dunaffHead.pl
$self->{PAGE_TITLE} = shift; # $pageTitle <title>$pageTitle</title>
$self->{META_KEYWORDS} = shift; # $metaKeywords <meta name="keywords" content="$metaKeywords">
$self->{META_DESCRIPTION} = shift; # $metaDescription <meta name="description" content="$metaDescription">
# constants
$self->{URL_ROOT} = "http://yourWebsiteDotCom/cgi-bin/gnu/"; # for creating urls in indexes
$self->{FILE_ACCESS_ROOT} = "/pathToYourWebspace/cgi-bin/gnu/"; # for accessing program files
# e.g. for determining the current program's last update date
# which is displayed at bottom of the displayed html page
$self->{WORK_IN_PROGRESS} = "http://yourWebsiteDotCom/cgi-bin/gnu/";
$self->{WORK_IN_PROGRESS} .= WorkInProgressSideIndex::getFirstPageUrl() . "/WorkInProgressSideIndex";
$self->{MOST_RECENT_SIDE_INDEX} = "http://yourWebsiteDotCom/cgi-bin/gnu/";
$self->{MOST_RECENT_SIDE_INDEX} .= MostRecentSideIndex::getFirstPageUrl() . "/MostRecentSideIndex";
#print "self->{MOST_RECENT_SIDE_INDEX} = $self->{MOST_RECENT_SIDE_INDEX}";
# variables for storing html code segments
$self->{PAGE_HEAD} = undef;
$self->{LHS_INDEX} = undef;
$self->{CONTENT} = undef;
$self->{MAIN_INDEX_TABLE} = undef;
$self->{COMMENTS_FORM} = undef;
$self->{FRIENDS_EMAIL_FORM} = undef;
$self->{FILE_LAST_MODIFIED} = undef;
$self->{PAGE_FOOTER} = undef;
$self->{PAGE_END} = undef;
$self->{PRINT_OF_PICTURE_CAN_BE_ARRANGED} = undef; # contains text if not $self->{PAYPAL_BUTTON_EXISTS}
# variables used in determining whether to put text into $self->{PRINT_OF_PICTURE_CAN_BE_ARRANGED}
$self->{PAYPAL_BUTTON_EXISTS} = undef; # flag is set in setContent=>setPaintingExhibitContent
$self->{NUMBER_OF_PICTURES} = 0; # number of pictures on page
# used to generate singular or plural of word "picture"
# in text of $self->{PRINT_OF_PICTURE_CAN_BE_ARRANGED}
return $self;
} # end new
# content setting routines
# called from ..../gnu/groupName/pageName.pl
sub standardContent {
# Create a standard page.
# Calling sequence
# $pageObj->standardContent(\@contentAry,optional_CSS_file_name);
my $self = shift;
my $contentAryRef = shift;
my $pageCSS = undef;
if (@_) {
$pageCSS = shift; # allows calling program to specify an alternative css file
} # end if
# get page data and turn it into html content segments
# format header text <title>, <meta keywords>, <meta description>, <link rel stylesheet>
setStandardHeader($self,$pageCSS); # text = $self->{PAGE_HEAD}
# format content data
setContent($self,$contentAryRef); # text = $self->{CONTENT}
# produce a message: print of this picture can be arranged - this to appear if no PayPal buttons are on the page
$self->{PRINT_OF_PICTURE_CAN_BE_ARRANGED} = setAbsenceOfPayPalPictureCanBePrinted($self); # text = $self->{PRINT_OF_PICTURE_CAN_BE_ARRANGED}
# format comment data
$self->{MAIN_INDEX_TABLE} = MainIndex->mainContentLayout(); # text = $self->{MAIN_INDEX_TABLE}
# format comment data, this includes error messages if any
setStandardPageComments($self); # text = $self->{COMMENTS_FORM}
# format sideIndex data (includes sideIndex header)
setSideIndex($self); # text = $self->{LHS_INDEX}
# source file last updated
fileLastModified($self); # text = $self->{FILE_LAST_MODIFIED}
# format footer
setWC3PageFooter($self); # text = $self->{PAGE_FOOTER}
# end page
setSlashBodySlashHtml($self); # text = $self->{PAGE_END}
# interweave the html content segments with structural <div> tags into single html text ready for output
my $text = "";
$text .= $self->{PAGE_HEAD};
$text .= "<div class='twoColumns'>\n";
$text .= "<div class='spacer'>\n";
$text .= "<!-- this is a separation of style and content within the content! -->\n";
$text .= "</div> <!-- end class=spacer -->\n";
$text .= "<div class='contentColumn'>\n";
$text .= "<div class='content'>\n";
$text .= $self->{CONTENT};
$text .= $self->{PRINT_OF_PICTURE_CAN_BE_ARRANGED};
$text .= "</div> <!-- class=content -->\n";
$text .= "<div class='getComments'>\n";
$text .= $self->{COMMENTS_FORM};
$text .= "</div> <!-- class=getComments -->\n";
$text .= "<div class='standardPageMainIndex'>\n";
$text .= $self->{MAIN_INDEX_TABLE};
$text .= "</div> <!-- class=standardPageMainIndex -->\n";
$text .= "<div class='content'>\n";
$text .= $self->{FILE_LAST_MODIFIED};
$text .= "</div> <!-- class=content -->\n";
$text .= "</div> <!-- class='contentColumn'-->\n";
$text .= "<div class='indexColumn'>\n";
# start with the site title which goes at top of lhs index
$text .= "<div id='siteTitle'>\n";
$text .= $self->{TOP_OF_INDEX_SITE_TITLE}; # set in new()
$text .= "</div> <!-- end id=siteTitle -->\n";
$text .= "<div id='lhsIndex'>\n";
$text .= $self->{LHS_INDEX};
$text .= "</div> <!-- end id=lhsIndex -->\n";
$text .= "</div> <!-- class=indexColumn -->\n";
$text .= "<div class='spacer'>\n";
$text .= "<!-- this is a separation of style and content within the content! -->\n";
$text .= "</div> <!-- end class=spacer -->\n";
$text .= "</div> <!-- class=twoColumns -->\n";
$text .= "<div class='spacer'>\n";
$text .= "<!-- this is a separation of style and content within the content! -->\n";
$text .= "</div> <!-- end class=spacer -->\n";
$text .= "<div class='footer'>\n";
$text .= $self->{PAGE_FOOTER};
$text .= "</div> <!-- end class='footer' -->\n";
$text .= $self->{PAGE_END};
print $text;
# email any comments previously entered by visitor but only these are error free
my $commentsObj = $self->{COMMENTS_OBJ};
if ( $commentsObj->commentReceived() ) {
if ( ! $commentsObj->textErrors() ) {
sendCommentEmail($self,$commentsObj);
} # end if
} # end if
} # end standardContent
sub printContent {
# Provide a page in printer friendly format.
# This contains no side index, no bottom index, and no comments.
# However all links within the content are retained.
# Additionally puts the page url at top of page
# Calling sequence:
# $pageObj->printContent(\@contentAry,optional $cssUrl);
my $self = shift;
my $contentAryRef = shift;
my $pageCSS = undef;
if (@_) {
$pageCSS = shift;
} # end if
# get page data and turn it into html content segments
# format header text <title>, <meta keywords>, <meta description>, <link rel stylesheet>
setPrintHeader($self,$pageCSS); # text = $self->{PAGE_HEAD}
# format content data
setContent($self,$contentAryRef); # text = $self->{CONTENT}}
# source file last updated
fileLastModified($self); # text = $self->{FILE_LAST_MODIFIED}
# end page
setSlashBodySlashHtml($self); # text = $self->{PAGE_END}
# interweave the html content segments with structural <div> tags into single html text ready for output
my $text = "";
$text .= $self->{PAGE_HEAD};
$text .= "<div class='contentColumn'>\n";
$text .= "<div class='content'>\n";
my $heading = "<h3 class='content'>" . $self->{PAGE_TITLE} . "</h3>\n";
my $urlHeading = "<h3 class='content'>" . $self->{URL_ROOT} . $self->{INDEX_GROUP} . "/" . $self->{PAGE_FILE_NAME} . "</h3>\n";
$text .= $heading . $urlHeading;
$text .= $self->{CONTENT};
$text .= $self->{FILE_LAST_MODIFIED};
$text .= "</div> <!-- class=content -->\n";
$text .= "</div> <!-- class='contentColumn'-->\n";
$text .= $self->{PAGE_END};
print $text;
} # end printContent
sub mainIndexContent {
# Create a page which only contains the main index and the side index of the page from which the main index page was requested.
# Calling sequence
# $pageObj = PageFormatterTemplate->new($cgiObj,$indexGroup,$sideIndexObj,$commentsObj,$pageFileName,$pageTitle,$metaKeywords,$metaDescription,$myBrowserIdentifier);
# $pageObj->mainIndexContent();
my $self = shift;
my $mainContentLayout = shift;
# get page data and turn it into html content segments
# format header text <title>, <meta keywords>, <meta description>, <link rel stylesheet>
setMainIndexHead($self); # text = $self->{PAGE_HEAD}
# format content data
setMainIndexContent($self,$mainContentLayout); # text = $self->{CONTENT}
# format comment data
setMainIndexComments($self); # text = $self->{COMMENTS_FORM}
# format sideIndex data (includes sideIndex header)
setSideIndex($self); # text = $self->{LHS_INDEX}
# format footer
setWC3PageFooter($self); # text = $self->{PAGE_FOOTER}
# end page
setSlashBodySlashHtml($self); # text = $self->{PAGE_END}
# interweave the html content segments with structural <div> tags into single html text ready for output
my $text = "";
$text .= $self->{PAGE_HEAD};
$text .= "<div class='twoColumns'>\n";
$text .= "<div class='spacer'>\n";
$text .= "<!-- this is a separation of style and content within the content! -->\n";
$text .= "</div> <!-- end class=spacer -->\n";
$text .= "<div class='contentColumn'>\n";
$text .= $self->{CONTENT};
$text .= "<div class='rowSpacer'>\n";
$text .= " \n";
$text .= "</div> <!-- class=rowSpacer -->\n";
$text .= "<div class='getComments'>\n";
$text .= $self->{COMMENTS_FORM};
$text .= "</div> <!-- class=getComments -->\n";
$text .= "</div> <!-- class='contentColumn'-->\n";
$text .= "<div class='indexColumn'>\n";
# start with the site title which goes at top of lhs index
$text .= "<div id='siteTitle'>\n";
$text .= $self->{TOP_OF_INDEX_SITE_TITLE}; # set in new()
$text .= "</div> <!-- end id=siteTitle -->\n";
$text .= "<div id='lhsIndex'>\n";
$text .= $self->{LHS_INDEX};
$text .= "</div> <!-- end id=lhsIndex -->\n";
$text .= "</div> <!-- class=indexColumn -->\n";
$text .= "<div class='spacer'>\n";
$text .= "<!-- this is a separation of style and content within the content! -->\n";
$text .= "</div> <!-- end class=spacer -->\n";
$text .= "</div> <!-- class=twoColumns -->\n";
$text .= "<div class='spacer'>\n";
$text .= "<!-- this is a separation of style and content within the content! -->\n";
$text .= "</div> <!-- end class=spacer -->\n";
$text .= "<div class='footer'>\n";
$text .= $self->{PAGE_FOOTER};
$text .= "</div> <!-- end class='footer' -->\n";
$text .= $self->{PAGE_END};
print $text;
# email any comments previously entered by visitor but only these are error free
my $commentsObj = $self->{COMMENTS_OBJ};
if ( $commentsObj->commentReceived() ) {
if ( ! $commentsObj->textErrors() ) {
sendCommentEmail($self,$commentsObj);
} # end if
} # end if
} # end mainIndexContent
# ===================================================================
# subs for creating html content segments
# ===================================================================
sub setMainIndexContent {
# called from: mainIndexContent
my $self = shift;
my $mainContentLayout = shift;
my $text = "";
$text .= "<div class='mainIndex'>\n";
$text .= $mainContentLayout . "\n";
$text .= "</div> <!-- class=mainIndex> -->\n";
$self->{CONTENT} = $text;
} # end setMainIndexContent
sub setContent {
# called by: standardContent and by printContent
my $self = shift;
my $pContentAryRef = shift;
my $text = "";
foreach my $hashRef ( @{$pContentAryRef} ) {
if ($hashRef->{contentType} eq "titledPainting") {
$text .= titledPainting($hashRef);
$self->{NUMBER_OF_PICTURES}++;
} elsif ($hashRef->{contentType} eq "payPalPainting") {
$text .= payPalPainting($hashRef);
} elsif ($hashRef->{contentType} eq "payPalPrintOneItemButton") {
$text .= payPalPrintOneItemButton($hashRef);
$self->{PAYPAL_BUTTON_EXISTS} = "true";
} elsif ($hashRef->{contentType} eq "payPalButtonMyText") {
$text .= payPalButtonMyText($hashRef);
$self->{PAYPAL_BUTTON_EXISTS} = "true";
} elsif ($hashRef->{contentType} eq "paragraphSequence") {
$text .= paragraphSequence($hashRef);
} elsif ($hashRef->{contentType} eq "unorderedListSequence") {
$text .= unorderedListSequence($hashRef);
} elsif ($hashRef->{contentType} eq "heading") {
$text .= heading($hashRef);
} elsif ($hashRef->{contentType} eq "preFormatedText") {
$text .= preFormatedText($hashRef);
} elsif ($hashRef->{contentType} eq "sendPurchaseMadeEmail") {
# only present in programs returned to from PayPal after a purchase
sendPurchaseMadeEmail($self,$hashRef);
} # end if
} # end foreach
$self->{CONTENT} = $text;
} # end setContent
sub titledPainting {
# called by: setContent
my $pHashRef = shift;
#{
# contentType => "titledPainting",
# pictureGroup =>"viewsOfDerry",
# pictureWidth =>512,
# pictureHeight =>408,
# pictureUrl =>"viewDiamondLights.jpg",
# pictureAlt =>"Picture of the Diamond and the Guildhall in Derry (Londonderry).",
# pictureTitle =>"View of the Diamond and the Guildhall in Derry with Christmass Illuminations",
# pictureDimensions =>"50 x 40", # in cm , for metres use pictureDimensionsMtrs
# pictureMedium =>"acrylic on canvass",
# pictureDate =>"2004",
#
# }, # end anon hash
my $text = "";
$text .= "<div class='titledPainting'>\n";
$text .= "<div class='thePicture'>\n";
$text .= "<img src='http://yourWebsiteDotCom/gnuPictures/" . $pHashRef->{pictureGroup} ;
$text .= "/" . $pHashRef->{pictureUrl} . "'";
$text .= ' width="' . $pHashRef->{pictureWidth} . '"';
$text .= ' height="' . $pHashRef->{pictureHeight} . '"';
$text .= ' alt="' . $pHashRef->{pictureAlt} . '"';
$text .= " class='contentImage' />\n";
$text .= "</div> <!-- class=thePicture -->\n";
$text .= "<div class='pictureTitle'>\n";
$text .= "<h3>";
my $needComma = 0;
if ($pHashRef->{pictureTitle}) {
$text .= $pHashRef->{pictureTitle};
$needComma = 1;
} # end if
if ($pHashRef->{pictureDate}) {
if ($needComma) {
$text .= ", ";
} # end if
$text .= $pHashRef->{pictureDate};
$needComma = 1;
} # end if
if ($pHashRef->{pictureMedium}) {
if ($needComma) {
$text .= ", ";
} # end if
$text .= $pHashRef->{pictureMedium};
$needComma = 1;
} # end if
if ($pHashRef->{pictureDimensions}) {
if ($needComma) {
$text .= ", ";
} # end if
$text .= $pHashRef->{pictureDimensions} . " cm";
$needComma = 1;
} elsif ($pHashRef->{pictureDimensionsMtrs}) {
if ($needComma) {
$text .= ", ";
} # end if
$text .= $pHashRef->{pictureDimensionsMtrs} . " metres";
$needComma = 1;
} # end if
$text .= "</h3>\n";
$text .= "</div> <!-- end class=pictureTitle -->\n";
$text .= "</div> <!-- class=titledPainting -->\n";
return $text;
} # end titledPainting
sub payPalPainting {
# called by: setContent
my $pHashRef = shift;
# {
# contentType => "payPalPainting",
# pictureGroup =>"irishThemes",
# pictureWidth =>305,
# pictureHeight =>220,
# pictureUrl =>"printGriananFortMount.jpg",
# pictureAlt =>"Picture of a print of Grianan Fort overlooking Lough Swilly, Donegal near Derry or Londonderry.",
# pictureTitle =>"A4 Print: <em>Grianan Fort</em>",
# pictureDimensions =>"29.7 x 21",
# pictureMedium =>"top quality glossy photo paper",
# }, # end anon hash
my $text = "";
$text .= "<div class='payPalPainting'>\n";
$text .= "<div class='thePicture'>\n";
$text .= "<img src='http://yourWebsiteDotCom/gnuPictures/" . $pHashRef->{pictureGroup} ;
$text .= "/" . $pHashRef->{pictureUrl} . "'";
$text .= ' width="' . $pHashRef->{pictureWidth} . '"';
$text .= ' height="' . $pHashRef->{pictureHeight} . '"';
$text .= ' alt="' . $pHashRef->{pictureAlt} . '"';
$text .= " class='payPalImage' />\n";
$text .= "</div> <!-- class=thePicture -->\n";
$text .= "<div class='payPalPictureTitle'>\n";
$text .= "<h2>" . $pHashRef->{pictureTitle} . "</h2>\n";
$text .= "<h2>";
if ($pHashRef->{pictureMedium}) {
$text .= $pHashRef->{pictureMedium};
} # end if
if ($pHashRef->{pictureDimensions}) {
$text .= ", " . $pHashRef->{pictureDimensions} . " cm";
} # end if
$text .= "</h2>\n";
$text .= "</div> <!-- end class=payPalPictureTitle -->\n";
$text .= "</div> <!-- class=payPalPainting -->\n";
return $text;
} # end payPalPainting
sub payPalPrintOneItemButton {
# called by: setContent
my $pHashRef = shift;
# {
# contentType => "payPalPrintOneItemButton",
# testButton =>"true",
# price =>"95.00",
# basketEncodedItem =>"-----PayPal encrypted button string-----",
# }, # end anon hash
my $basketEncodedItem = $pHashRef->{basketEncodedItem};
my $price = $pHashRef->{price};
if ( !$price) {
$price = "20.00";
} # end if
my $text = "";
$text .= "<div class='payPalPrintOneItemButton'>\n";
$text .=<<END_FORM;
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick" />
<h4>\£$price GBP.</h4>
<h3>I like it. I want it!</h3>
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
<h5><a href="http://animatedpaint.co.uk">Dreamscapes Animated Paint</a> is the trading name of juliuspaintings.co.uk</h5>
<input type="hidden" name="encrypted" value="$basketEncodedItem
" />
</form>
END_FORM
$text .= "</div> <!-- class=payPalPrintOneItemButton -->\n";
return $text;
} # end payPalPrintOneItemButton
sub payPalButtonMyText {
my $pHashRef = shift;
# {
# contentType => "payPalButtonMyText",
# testButton =>"true",
# slogan =>"I love them. I"ll take the set!",
# price =>"58.00",
# basketEncodedItem =>"-----PayPal encrypted button string-----",
# }, # end anon hash
my $basketEncodedItem = $pHashRef->{basketEncodedItem};
my $mySlogan = $pHashRef->{slogan};
my $price = $pHashRef->{price};
my $dummy3 = 3;
my $dummy0 = 0;
if ( !$price) {
$price = $dummy3 / $dummy0;
}
my $text = "";
$text .= "<div class='payPalPrintOneItemButton'>\n";
$text .=<<END_FORM;
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick" />
<h4>\£$price GBP.</h4>
<h3>$mySlogan</h3>
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
<h5><a href="http://animatedpaint.co.uk">Dreamscapes Animated Paint</a> is the trading name of juliuspaintings.co.uk</h5>
<input type="hidden" name="encrypted" value="$basketEncodedItem
" />
</form>
END_FORM
$text .= "</div> <!-- class=payPalPrintOneItemButton -->\n";
return $text;
} # end payPalButtonMyText
sub setAbsenceOfPayPalPictureCanBePrinted {
# called by : standardContent
my $self = shift;
my $text = "";
if ($self->{PAYPAL_BUTTON_EXISTS}) { return $text; } # flag is set in setContent=>setPaintingExhibitContent
$text .= "<div class='willProvidePrintIfAsked'>\n";
if ($self->{NUMBER_OF_PICTURES} == 1) {
$text .= "If you would like to buy a print of the picture shown on this page ";
} elsif ($self->{NUMBER_OF_PICTURES} > 1) {
$text .= "If you would like to buy a print of any of the pictures shown on this page ";
} else {
return "";
} # end if
$text .= "then tell me via the comments form below (remember to include your email),\n";
$text .= "and I will provide the means to do this via <a href='http://www.paypal.com'>PayPal</a>.<br />\n";
$text .= "All pictures are printed on high quality glossy photographic paper\n";
$text .= "approximately 29 by 21 cm, 11.4 x 8.2 inches (A4 size).\n";
$text .= "Most prints cost £20.00, postage and packing included.\n";
$text .= "</div> <!-- class=willProvidePrintIfAsked -->\n";
return $text;
} # end setAbsenceOfPayPalPictureCanBePrinted
sub paragraphSequence {
# called by: setContent
my $pHashRef = shift;
# {
# contentType => "paragraphSequence",
# paraSequence => [
# "Paragraph 1.",
# "Paragraph 2.",
# ],
# }, # end anon hash
my $text = "";
$text .= "<div class='paragraphSequence'>\n";
foreach my $para (@{ $pHashRef->{paraSequence} }) {
$text .= "<p>\n";
$text .= $para;
$text .= "\n</p>\n";
} # end foreach
$text .= "</div> <!-- end class=paragraphSequence -->\n";
return $text;
} # end paragraphSequence
sub unorderedListSequence {
my $pHashRef = shift;
# {
# contentType => "unorderedListSequence",
# listSequence => [
# [
# "item 1.",
# ],[
# "item 2",
# ],
#],
#}, # end anon hash
my $text = "";
$text .= "<ul class='unorderedListSequence'>\n";
foreach my $paraAryRef (@{ $pHashRef->{listSequence} }) {
$text .= "<li>\n";
foreach my $para (@{ $paraAryRef }) {
$text .= "<p>\n";
$text .= $para;
$text .= "\n</p>\n";
} # end foreach
$text .= "</li>\n";
} # end foreach
$text .= "</ul> <!-- end class=unorderedListSequence -->\n";
return $text;
} # end unorderedListSequence
sub heading {
# called by: setContent
my $pHashRef = shift;
# {
# contentType => "heading",
# headingType => "h2",
# headingText => "Example heading",
#}, # end anon hash
my $headingType = $pHashRef->{headingType};
my $headingText = $pHashRef->{headingText};
my $text = "";
$text .= "<$headingType>$headingText</$headingType>\n";
return $text;
} # end heading
sub preFormatedText {
# called by: setContent
my $pHashRef = shift;
# {
# contentType => "preFormatedText",
# preTitle => "Figure: Extract from the Seafarer translated from Anglo-Saxon by Ezra Pound",
# preText => [
#"May I for my own self song's truth reckon,
#Journey's jargon, how I in harsh days
#Hardship endured oft.",
#],
#}, # end anon hash
my $text = "";
$text .= "<div class='preFormatedText'>\n" ;
foreach my $para (@{ $pHashRef->{preText} }) {
$text .= "<p>\n";
$text .= $para;
$text .= "\n</p>\n";
} # end foreach
if (defined($pHashRef->{preTitle})) {
$text .= "<h3>" . $pHashRef->{preTitle} . "</h3>";
} # end if
$text .= "</div> <!-- end class=preFormatedText -->\n";
return $text;
} # end preFormatedText
sub setStandardPageComments {
# called from anypage.pl
my $self = shift;
my $commentsObj = $self->{COMMENTS_OBJ};
my $groupName = $self->{INDEX_GROUP};
my $pageFileName = $self->{PAGE_FILE_NAME};
my $textSentlastTime = $commentsObj->text();
#my $commentFieldAndText = "<label for='your_comment_text'>your comments</label>";
my $commentFieldAndText = "<textarea id='your_comment_text' name='text' rows='5' cols='30'>$textSentlastTime</textarea>";
my $sendButtonAndText = "If you include your e-mail I may reply! <input type='submit' value='send' />";
my $commentHeading = "";
if ( $commentsObj->textErrors() ) {
$commentHeading = "<h3 class='commentErrors'>Error:". $commentsObj->textDiagnostic() . "</h3>";
$commentHeading .= "<p class='commentErrors'> please try again.</p>";
} elsif ( $commentsObj->commentReceived() ) {
# i.e. the comment was received ok
$commentHeading = "<h3 class='commentSetOk'>Thank you</h3>";
# I do this to prevent people just sitting there clicking the send button
$commentFieldAndText = "<label for='text'>What you wrote and I now have in my inbox</label>";
$commentFieldAndText .= "<textarea name='text' rows='5' cols='30'>$textSentlastTime</textarea>";
$sendButtonAndText = "<p class='commentComment'>If you included your e-mail I may reply!</p>";
} # end if
my $text = <<FORM;
<a name='commentsForm'> </a>\n
<form name="comments_form" action="http://yourWebsiteDotCom/cgi-bin/gnu/$groupName/$pageFileName#commentsForm" method="post">
<br /><br />
<h3>Send me your comments</h3>
$commentHeading
<p>
$commentFieldAndText
</p>
<p>
$sendButtonAndText
</p>
</form>
FORM
$self->{COMMENTS_FORM} = $text;
} # end setStandardPageComments
sub setMainIndexComments {
# called from anypage.pl
my $self = shift;
my $commentsObj = $self->{COMMENTS_OBJ};
my $groupName = $self->{INDEX_GROUP};
my $pageFileName = $self->{PAGE_FILE_NAME};
my $textSentlastTime = $commentsObj->text();
#my $commentFieldAndText = "<label for='your_comment_text'>your comments</label>";
my $commentFieldAndText = "<textarea id='your_comment_text' name='text' rows='5' cols='30'>$textSentlastTime</textarea>";
my $sendButtonAndText = "If you include your e-mail I may reply!<input type='submit' value='send' />";
my $commentHeading = "";
if ( $commentsObj->textErrors() ) {
$commentHeading = "<h3 class='commentErrors'>Error:". $commentsObj->textDiagnostic() . "</h3>";
$commentHeading .= "<p class='commentErrors'> please try again.</p>";
} elsif ( $commentsObj->commentReceived() ) {
# i.e. the comment was received ok
$commentHeading = "<h3 class='commentSetOk'>Thank you</h3>";
# I do this to prevent people just sitting there clicking the send button
$commentFieldAndText = "<label for='text'>What you wrote and I now have in my inbox</label>";
$commentFieldAndText .= "<textarea name='text' rows='5' cols='30'>$textSentlastTime</textarea>";
$sendButtonAndText = "<p class='commentComment'>If you included your e-mail I may reply!</p>";
} # end if
my $text = <<FORM;
<a name='commentsForm'> </a>\n
<form name="comments_form" action="http://yourWebsiteDotCom/cgi-bin/gnu/mainIndex.pl#commentsForm/$groupName" method="post">
<h3>Send me your comments</h3>
$commentHeading
<p>
$commentFieldAndText
</p>
<p>
$sendButtonAndText
</p>
</form>
FORM
$self->{COMMENTS_FORM} = $text;
} # end setMainIndexComments
sub setSideIndex {
# called from standardContent, mainIndexContent
my $self = shift;
my $indexAryRef = $self->{SIDE_INDEX_OBJ}->getIndex();
my $groupName = $self->{INDEX_GROUP};
my $groupHeading = $self->{SIDE_INDEX_OBJ}->getGroupHeading();
# index structure
# the header e.g. Julius Guzy, paintings and drawings
# set of constant links, e.g. Home, Main Index, recent pictures, work in progress
# followed by a sequence of links to pages
# having the following structure
# {
# indexWidth =>143,
# indexHeight =>100,
# group =>"landscapes",
# pageUrl =>"dunaffHead.pl",
# indexUrl =>"landscapes/dunaffHeadThumb.jpg",
# indexAlt =>"Dunaff Head",
# },
# or
# {
# indexText =>"beautiful bay at Dunaff Head",
# pageUrl =>"dunaffHead.pl",
# },
#
my $text = "";
$text .= "<ul class='constantIndexElements'>\n";
$text .= "<li>".'<a href="http://yourWebsiteDotCom">'."HOME</a></li>\n";
$text .= "<li>".'<a href="'.$self->{MOST_RECENT_SIDE_INDEX}.'">'."RECENT PICTURES</a></li>\n";
$text .= "<li>".'<a href="'.$self->{WORK_IN_PROGRESS}.'">'."WORK IN PROGRESS</a></li>\n";
$text .= "<li>".'<a href="http://yourWebsiteDotCom/cgi-bin/gnu/mainIndex.pl/mainIndex/'.$groupName.'">'."MAIN INDEX</a></li>\n";
$text .= "</ul> <!-- constantIndexElements -->\n";
$text .= "<h3 class='groupHeading'>". $groupHeading ."</h3>\n";
$text .= "<ul class='indexElements'>\n";
foreach my $indexElemHashref ( @{$indexAryRef} ) {
$text .= "<li>";
$text .= "<div class='indexImg'>\n";
if (exists($indexElemHashref->{group})) {
$groupName = $indexElemHashref->{group};
} # end if
my $fileIdentifier = $indexElemHashref->{pageUrl};
my $url = $self->{URL_ROOT} . $groupName . '/' . $fileIdentifier;
$text .= '<a href="'. $url . '">';
if ($indexElemHashref->{indexUrl}) {
$text .= '<img src="http://yourWebsiteDotCom/gnuPictures/'. $groupName ;
$text .= '/'. $indexElemHashref->{indexUrl} . '"';
$text .= ' width="' . $indexElemHashref->{indexWidth} . '"';
$text .= ' height="' . $indexElemHashref->{indexHeight} . '"';
$text .= ' alt="link to ' . $indexElemHashref->{indexAlt} . '" class="idex" />';
} else {
$text .= $indexElemHashref->{indexText};
} # end if
$text .= "</a>\n";
$text .= "</div>\n";
if (exists ($indexElemHashref->{linkText}) ) {
$text .= "<ul class='commentList'>\n";
$text .= "<li>";
$text .= '<a href="'. $url . '">';
$text .= $indexElemHashref->{linkText};
$text .= "</a>\n";
$text .= "\n</li>";
$text .= "\n</ul> <!-- commentList -->\n";
} # end if
if ($indexElemHashref->{comment}) {
$text .= "<ul class='commentList'>\n";
$text .= "<li>". $indexElemHashref->{comment} ."\n</li>";
$text .= "\n</ul> <!-- commentList -->\n";
} # end if
$text .= "</li> <!-- the li of the index entry -->\n";
} # end foreach
$text .= "</ul> <!-- indexElements -->\n";
$self->{LHS_INDEX} = $text;
} # end setSideIndex
sub setWC3PageFooter {
my $self = shift;
my $text = <<END_GENERATE_FOOTER;
<br />
<br />
<hr />
<br />
<div class="w3images">
<div class="footImg1">
<a href="http://juliuspaintings.co.uk/cgi-bin/paint_css/website/websiteCodeStructure.pl"><img src="http://yourWebsiteDotCom/gnuPictures/externalIcons/codeFromJuliuspaintings.png"
alt="Valid CSS!" height="35" width="100" class="w3icon" /></a>
</div>
<div class="footImg2">
<a href="http://jigsaw.w3.org/css-validator/"><img src="http://yourWebsiteDotCom/externalIcons/valid-css.png"
alt="Valid CSS!" height="31" width="88" class="w3icon" /></a>
</div>
<div class="footImg2">
<a href="http://validator.w3.org/check/referer"><img src="http://yourWebsiteDotCom/externalIcons/valid-xhtml10.png"
alt="Valid XHTML 1.0!" height="31" width="88" class="w3icon" /></a>
</div>
</div> <!-- end class w3images -->
END_GENERATE_FOOTER
$self->{PAGE_FOOTER} = $text;
} # end setWC3PageFooter
sub setSlashBodySlashHtml {
# called by: standardContent and by printContent and by mainIndexContent
my $self = shift;
my $text = "</body>\n</html>\n";
$self->{PAGE_END} = $text;
} # end setSlashBodySlashHtml
sub setMainIndexHead {
# called by mainIndexContent
my $self = shift;
# code generated by this routine calls two different css files
my $pageTitle = $self->{PAGE_TITLE};
my $metaKeywords = $self->{META_KEYWORDS};
my $metaDescription = $self->{META_DESCRIPTION};
my $text = <<END_HEADER;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>$pageTitle</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="keywords" content="$metaKeywords" />
<meta name="description" content="$metaDescription" />
<link rel="stylesheet" type="text/css" href="http://yourWebsiteDotCom/gnuCss/gnuMainIndexCombined.css" />
</head>
<body>
END_HEADER
$self->{PAGE_HEAD} = $text;
} # end setMainIndexHead
sub setStandardHeader {
my $self = shift;
my $pageCSS = shift;
my $pageTitle = $self->{PAGE_TITLE};
my $metaKeywords = $self->{META_KEYWORDS};
my $metaDescription = $self->{META_DESCRIPTION};
my $cssUrl = "gnuCss.css";
if ($pageCSS) {
$cssUrl = $pageCSS;
} # end if
my $text = <<END_HEADER;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>$pageTitle</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="keywords" content="$metaKeywords" />
<meta name="description" content="$metaDescription" />
<link rel="stylesheet" type="text/css" href="http://yourWebsiteDotCom/gnuCss/$cssUrl" />
</head>
<body>
END_HEADER
$self->{PAGE_HEAD} = $text;
} # end setStandardHeader
sub setPrintHeader {
my $self = shift;
my $pageCSS = shift;
# code generated by this routine calls two different css files
my $pageTitle = $self->{PAGE_TITLE};
my $cssUrl = "gnuCss.css";
if ($pageCSS) {
$cssUrl = $pageCSS;
} # end if
my $text = <<END_HEADER;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>$pageTitle</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="http://yourWebsiteDotCom/gnuCss/$cssUrl" />
</head>
<body>
END_HEADER
$self->{PAGE_HEAD} = $text;
} # end setPrintHeader
sub fileLastModified {
# called to obtain last modified date for new files
# uses Perl intrinsic routine stat()
my $self = shift;
my $indexGroup = $self->{INDEX_GROUP};
my $pageFileName = $self->{PAGE_FILE_NAME};
my $newFilenameRoot = $self->{FILE_ACCESS_ROOT};
my $filenameToBeDated = $newFilenameRoot . $indexGroup . "/" . $pageFileName;
$self->{FILE_LAST_MODIFIED} = " "; # set it here in case there is an error
my @statEntry = stat($filenameToBeDated) or return sendErrorEmail($self, "Could not stat file $filenameToBeDated: $!");
my $time = $statEntry[9]; # statEntry[9] is mtime see p 801 camel
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($time);
$year += 1900; # normalise
my $month = (qw(January February March April May June July August September October November December))[$mon];
my $weekday = (qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday))[$wday];
# note 1 <= $mday <= 31
my $stndth = (qw(no st nd rd th th th th th th th th th th th th th th th th th st nd rd th th th th th th th st))[$mday];
#my $mday1 = $mday+1;
$hour = sprintf("%02d",$hour);
$min = sprintf("%02d",$min);
my $text = "";
$text .= "<div class='datelastmodified'>\n";
$text .= "<em>Page last modified: $hour:$min $weekday $mday$stndth. $month $year</em>\n";
$text .= "</div> <!-- class='datelastmodified' -->\n";
$self->{FILE_LAST_MODIFIED} = $text;
return $text;
} # end fileLastModified
sub sendCommentEmail {
my $self = shift;
my $commentsObj = shift;
# for details on sending mail see Guelich, Gundavaram and Birznieks, CGI Programming with Perl, O'Reilly, 2000, pp.222-225
my $text = $commentsObj->text();
my $indexGroup = $self->{INDEX_GROUP};
my $pageFileName = $self->{PAGE_FILE_NAME};
my $httpUserAgent = $ENV{HTTP_USER_AGENT};
my $remoteAddress = $ENV{REMOTE_ADDR};
# create the subject string
my $subjectStr = $remoteAddress . " : Comment";
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
my $timeStampStr = "$year:$mon:$hour:$min:$sec";
open MAIL, "| /usr/lib/sendmail -t -i -f'gnuReturnedMailAddr_yourWebsiteDotCom'" or return undef;
print MAIL <<END_OF_MESSAGE;
To: gnuCommentsMailAddr_yourWebsiteDotCom
From: gnuMailAddr_yourWebsiteDotCom
Reply-To: gnuCommentsHandlerMailAddr_yourWebsiteDotCom
Subject: gnu: $subjectStr
Free software: comments Text
$text
visitor Info
TimeStamp : $timeStampStr
indexGroup : $indexGroup
pageFileName : $pageFileName
remoteAddress : $remoteAddress
httpUserAgent : $httpUserAgent
END_OF_MESSAGE
print MAIL "\n";
close MAIL or return undef;
} # end sendCommentEmail
sub sendPurchaseMadeEmail {
# called from sub setContent
my $self = shift;
my $hashRef = shift;
# for details on sending mail see Guelich, Gundavaram and Birznieks, CGI Programming with Perl, O'Reilly, 2000, pp.222-225
my $purchaseMade = $hashRef->{purchaseMade};
my $indexGroup = $self->{INDEX_GROUP};
my $pageFileName = $self->{PAGE_FILE_NAME};
my $httpUserAgent = $ENV{HTTP_USER_AGENT};
my $remoteAddress = $ENV{REMOTE_ADDR};
# create the subject string
my $subjectStr = $purchaseMade;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
my $timeStampStr = "$year:$mon:$hour:$min:$sec";
open MAIL, "| /usr/lib/sendmail -t -i -f'gnuReturnedMailAddr_yourWebsiteDotCom'" or return undef;
print MAIL <<END_OF_MESSAGE;
To: gnuPurchaseMadeMailAddr_yourWebsiteDotCom
From: gnuMailAddr_yourWebsiteDotCom
Reply-To: gnuPurchaseHandlerMailAddr_yourWebsiteDotCom
Subject: gnuPurchase: $subjectStr
Free software: sale made message
$purchaseMade
visitor Info
TimeStamp : $timeStampStr
indexGroup : $indexGroup
pageFileName : $pageFileName
remoteAddress : $remoteAddress
httpUserAgent : $httpUserAgent
END_OF_MESSAGE
print MAIL "\n";
close MAIL or return undef;
} # end sendPurchaseMadeEmail
sub sendErrorEmail {
my $self = shift;
my $error = shift;
# for details on sending mail see Guelich, Gundavaram and Birznieks, CGI Programming with Perl, O'Reilly, 2000, pp.222-225
my $indexGroup = $self->{INDEX_GROUP};
my $pageFileName = $self->{PAGE_FILE_NAME};
my $httpUserAgent = $ENV{HTTP_USER_AGENT};
my $remoteAddress = $ENV{REMOTE_ADDR};
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
my $timeStampStr = "$year:$mon:$hour:$min:$sec";
open MAIL, "| /usr/lib/sendmail -t -i -f'gnuReturnedMailAddr_yourWebsiteDotCom'" or return undef;
print MAIL <<END_OF_MESSAGE;
To: gnuDiagnosticMailAddr_yourWebsiteDotCom
From: gnuErrorMailAddr_yourWebsiteDotCom
Reply-To: gnuErrorHandlerMailAddr_yourWebsiteDotCom
Subject: gnuError: in PageFormatterTemplate
Error occurred in PageFormatterTemplate in free software
$error
TimeStamp : $timeStampStr
indexGroup : $indexGroup
pageFileName : $pageFileName
remoteAddress : $remoteAddress
httpUserAgent : $httpUserAgent
END_OF_MESSAGE
print MAIL "\n";
close MAIL or return " ";
return " ";
} # end sendErrorEmail
1;