Added the new templating mechanism to styles and templates.

This commit is contained in:
JT Smith 2002-10-07 05:58:07 +00:00
parent 8c9040e396
commit 834f4abb03
8 changed files with 122 additions and 88 deletions

View file

@ -74,7 +74,7 @@ alter table Product change productTemplateId Product_templateId int not null def
alter table Product_benefit change productBenefitId Product_benefitId int not null; alter table Product_benefit change productBenefitId Product_benefitId int not null;
alter table Product_feature change productFeatureId Product_featureId int not null; alter table Product_feature change productFeatureId Product_featureId int not null;
alter table Product_specification change productSpecificationId Product_specificationId int not null; alter table Product_specification change productSpecificationId Product_specificationId int not null;
update wobject set templatePosition=templatePosition+1;

View file

@ -28,8 +28,9 @@ use WebGUI::Utility;
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub page { sub page {
my ($debug, %contentHash, $w, $cmd, $pageEdit, $wobject, $wobjectOutput, $extra, $originalWobject, $proxyWobjectId, my ($debug, %contentHash, $w, $cmd, $pageEdit, $wobject, $wobjectOutput, $extra, $originalWobject, $proxyWobjectId,
$sth, $httpHeader, $header, $footer, $content, $operationOutput, $adminBar, %hash, $canEdit); $sth, $httpHeader, $content, $operationOutput, $adminBar, $template, %hash, $canEdit);
WebGUI::Session::open($_[0],$_[1]); WebGUI::Session::open($_[0],$_[1]);
$template = 1;
if (exists $session{form}{op}) { if (exists $session{form}{op}) {
if ($session{form}{op} =~ /^[A-Za-z]+$/) { if ($session{form}{op} =~ /^[A-Za-z]+$/) {
$cmd = "WebGUI::Operation::www_".$session{form}{op}; $cmd = "WebGUI::Operation::www_".$session{form}{op};
@ -95,11 +96,9 @@ sub page {
WebGUI::Session::close(); WebGUI::Session::close();
return $httpHeader.$operationOutput.$wobjectOutput; return $httpHeader.$operationOutput.$wobjectOutput;
} elsif ($operationOutput ne "") { } elsif ($operationOutput ne "") {
$contentHash{0} = $operationOutput; $contentHash{"template.position".1} = $operationOutput;
$content = WebGUI::Template::generate(\%contentHash,1);
} elsif ($wobjectOutput ne "") { } elsif ($wobjectOutput ne "") {
$contentHash{0} = $wobjectOutput; $contentHash{"template.position".1} = $wobjectOutput;
$content = WebGUI::Template::generate(\%contentHash,1);
} elsif ($session{page}{redirectURL}) { } elsif ($session{page}{redirectURL}) {
$session{header}{redirect} = WebGUI::Session::httpRedirect($session{page}{redirectURL}) $session{header}{redirect} = WebGUI::Session::httpRedirect($session{page}{redirectURL})
} else { } else {
@ -120,7 +119,7 @@ sub page {
$sth = WebGUI::SQL->read("select * from wobject where pageId=$session{page}{pageId} order by sequenceNumber, wobjectId"); $sth = WebGUI::SQL->read("select * from wobject where pageId=$session{page}{pageId} order by sequenceNumber, wobjectId");
while ($wobject = $sth->hashRef) { while ($wobject = $sth->hashRef) {
if ($session{var}{adminOn} && $canEdit) { if ($session{var}{adminOn} && $canEdit) {
$contentHash{${$wobject}{templatePosition}} .= "\n<hr>" $contentHash{"template.position".${$wobject}{templatePosition}} .= "\n<hr>"
.deleteIcon('func=delete&wid='.${$wobject}{wobjectId}) .deleteIcon('func=delete&wid='.${$wobject}{wobjectId})
.editIcon('func=edit&wid='.${$wobject}{wobjectId}) .editIcon('func=edit&wid='.${$wobject}{wobjectId})
.moveUpIcon('func=moveUp&wid='.${$wobject}{wobjectId}) .moveUpIcon('func=moveUp&wid='.${$wobject}{wobjectId})
@ -151,18 +150,17 @@ sub page {
$w = eval{$cmd->new($wobject)}; $w = eval{$cmd->new($wobject)};
WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root cause: ".$@) if($@); WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root cause: ".$@) if($@);
if ($w->inDateRange) { if ($w->inDateRange) {
$contentHash{${$wobject}{templatePosition}} .= '<div class="wobject'.${$wobject}{namespace}.'" id="wobjectId'.${$wobject}{wobjectId}.'">'; $contentHash{"template.position".${$wobject}{templatePosition}} .= '<div class="wobject'.${$wobject}{namespace}.'" id="wobjectId'.${$wobject}{wobjectId}.'">';
$contentHash{${$wobject}{templatePosition}} .= '<a name="'.${$wobject}{wobjectId}.'"></a>'; $contentHash{"template.position".${$wobject}{templatePosition}} .= '<a name="'.${$wobject}{wobjectId}.'"></a>';
$contentHash{${$wobject}{templatePosition}} .= eval{$w->www_view}; $contentHash{"template.position".${$wobject}{templatePosition}} .= eval{$w->www_view};
WebGUI::ErrorHandler::fatalError("Wobject runtime error: ${$wobject}{namespace}. Root cause: ".$@) if($@); WebGUI::ErrorHandler::fatalError("Wobject runtime error: ${$wobject}{namespace}. Root cause: ".$@) if($@);
$contentHash{${$wobject}{templatePosition}} .= "</div>\n\n"; $contentHash{"template.position".${$wobject}{templatePosition}} .= "</div>\n\n";
} }
} }
$sth->finish; $sth->finish;
$content = WebGUI::Template::generate(\%contentHash,$session{page}{templateId}); $template = $session{page}{templateId};
} else { } else {
$contentHash{0} = WebGUI::Privilege::noAccess(); $contentHash{"template.position".1} = WebGUI::Privilege::noAccess();
$content = WebGUI::Template::generate(\%contentHash,1);
} }
} }
if ($session{setting}{showDebug} || ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3))) { if ($session{setting}{showDebug} || ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3))) {
@ -191,9 +189,17 @@ sub page {
return $httpHeader; return $httpHeader;
} else { } else {
$httpHeader = WebGUI::Session::httpHeader(); $httpHeader = WebGUI::Session::httpHeader();
($header, $footer) = WebGUI::Style::getStyle(); $content = WebGUI::Template::process(
WebGUI::Macro::process(
WebGUI::Style::get(
$pageEdit
.WebGUI::Template::get($template)
)
),
\%contentHash
);
WebGUI::Session::close(); WebGUI::Session::close();
return $httpHeader.$adminBar.$header.$pageEdit.$content.$footer.$debug; return $httpHeader.$adminBar.$content.$debug;
} }
} }

View file

@ -122,5 +122,6 @@ sub filter {
1; 1;

View file

@ -197,7 +197,7 @@ sub www_editPage {
-uiLevel=>8 -uiLevel=>8
); );
$f->readOnly( $f->readOnly(
-value=>WebGUI::Template::selectTemplate($page{templateId}), -value=>WebGUI::Template::select($page{templateId}),
-label=>WebGUI::International::get(356), -label=>WebGUI::International::get(356),
-uiLevel=>5 -uiLevel=>5
); );
@ -362,8 +362,8 @@ sub www_editPageSave {
menuTitle=".quote($session{form}{menuTitle}).", menuTitle=".quote($session{form}{menuTitle}).",
synopsis=".quote($session{form}{synopsis})." synopsis=".quote($session{form}{synopsis})."
where pageId=$session{form}{pageId}"); where pageId=$session{form}{pageId}");
WebGUI::SQL->write("update wobject set templatePosition=0 where pageId=$session{form}{pageId} WebGUI::SQL->write("update wobject set templatePosition=1 where pageId=$session{form}{pageId}
and templatePosition>".(WebGUI::Template::countPositions($session{form}{templateId})-1)); and templatePosition>".WebGUI::Template::countPositions($session{form}{templateId}));
_recursivelyChangeStyle($session{page}{pageId}) if ($session{form}{recurseStyle}); _recursivelyChangeStyle($session{page}{pageId}) if ($session{form}{recurseStyle});
_recursivelyChangePrivileges($session{page}{pageId}) if ($session{form}{recursePrivs}); _recursivelyChangePrivileges($session{page}{pageId}) if ($session{form}{recursePrivs});
WebGUI::Session::refreshPageInfo($session{page}{pageId}) if ($session{form}{pageId} == $session{page}{pageId}); WebGUI::Session::refreshPageInfo($session{page}{pageId}) if ($session{form}{pageId} == $session{page}{pageId});

View file

@ -68,7 +68,7 @@ sub www_deleteTemplateConfirm {
} elsif (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) { } elsif (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) {
$a = WebGUI::SQL->read("select * from page where templateId=".$session{form}{tid}); $a = WebGUI::SQL->read("select * from page where templateId=".$session{form}{tid});
while (($pageId) = $a->array) { while (($pageId) = $a->array) {
WebGUI::SQL->write("update wobject set templatePosition=0 where pageId=$pageId"); WebGUI::SQL->write("update wobject set templatePosition=1 where pageId=$pageId");
} }
$a->finish; $a->finish;
WebGUI::SQL->write("delete from template where templateId=".$session{form}{tid}); WebGUI::SQL->write("delete from template where templateId=".$session{form}{tid});
@ -85,7 +85,7 @@ sub www_editTemplate {
tie %template, 'Tie::CPHash'; tie %template, 'Tie::CPHash';
if (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) { if (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) {
if ($session{form}{tid} eq "new") { if ($session{form}{tid} eq "new") {
$template{template} = "<table>\n <tr>\n <td>\n\n^0;\n\n </td>\n </tr>\n</table>\n"; $template{template} = "<table>\n <tr>\n <td>\n\n<tmpl_var template.position1>\n\n </td>\n </tr>\n</table>\n";
} else { } else {
%template = WebGUI::SQL->quickHash("select * from template where templateId=$session{form}{tid}"); %template = WebGUI::SQL->quickHash("select * from template where templateId=$session{form}{tid}");
} }

View file

@ -15,51 +15,42 @@ use Tie::CPHash;
use WebGUI::Macro; use WebGUI::Macro;
use WebGUI::Session; use WebGUI::Session;
use WebGUI::SQL; use WebGUI::SQL;
use WebGUI::Template;
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub getStyle { sub get {
my ($header, $footer, %style, $styleId, @body); my ($header, $footer, %style, $styleId, @body);
tie %style, 'Tie::CPHash'; tie %style, 'Tie::CPHash';
if ($session{form}{makePrintable}) { if ($session{form}{makePrintable}) {
$styleId = $session{form}{style} || 3; $styleId = $session{form}{style} || 3;
%style = WebGUI::SQL->quickHash("select * from style where styleId=$styleId"); } else {
@body = split(/\^\-\;/,$style{body}); $styleId = $session{page}{styleId} || 2;
$header = '<html><!-- WebGUI '.$session{wg}{version}.' -->'."\n"; }
$header .= '<head><title>'.$session{page}{title}.' - '.$session{setting}{companyName}.'</title>'; %style = WebGUI::SQL->quickHash("select * from style where styleId=$styleId");
$header .= $style{styleSheet}.'</head>'.$body[0]; @body = split(/\^\-\;/,$style{body});
} else { $header = $session{setting}{docTypeDec}."\n".'<!-- WebGUI '.$WebGUI::VERSION.' --> <html> <head> <title>';
%style = WebGUI::SQL->quickHash("select * from style where styleId=$session{page}{styleId}"); $header .= $session{page}{title}.' - '.$session{setting}{companyName};
@body = split(/\^\-\;/,$style{body}); $header .= '</title><link REL="icon" HREF="'.$session{config}{extras}.'/favicon.png" TYPE="image/png">'
$header = $session{setting}{docTypeDec}."\n".'<!-- WebGUI '.$WebGUI::VERSION.' --> .$style{styleSheet}.$session{page}{metaTags};
<html> if ($session{var}{adminOn}) {
<head> # This "triple incantation" panders to the delicate tastes of various browsers for reliable cache suppression.
<title>'; $header .= '<META HTTP-EQUIV="Pragma" CONTENT="no-cache">';
$header .= $session{page}{title}.' - '.$session{setting}{companyName}; $header .= '<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate, max_age=0">';
$header .= '</title><link REL="icon" HREF="'.$session{config}{extras}.'/favicon.png" TYPE="image/png">' $header .= '<META HTTP-EQUIV="Expires" CONTENT="0">';
.$style{styleSheet} }
.$session{page}{metaTags}; if ($session{page}{defaultMetaTags}) {
if ($session{var}{adminOn}) { $header .= '<meta http-equiv="Keywords" name="Keywords" content="'.$session{page}{title}
# This "triple incantation" panders to the delicate tastes of various browsers for reliable cache suppression. .', '.$session{setting}{companyName}.'">';
$header .= '<META HTTP-EQUIV="Pragma" CONTENT="no-cache">'; $header .= '<meta http-equiv="Description" name="Description" content="'.$session{page}{synopsis}.'">';
$header .= '<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate, max_age=0">';
$header .= '<META HTTP-EQUIV="Expires" CONTENT="0">';
}
if ($session{page}{defaultMetaTags}) {
$header .= '<meta http-equiv="Keywords" name="Keywords" content="'.
$session{page}{title}.', '.$session{setting}{companyName}.'">';
$header .= '<meta http-equiv="Description" name="Description" content="'.
$session{page}{synopsis}.'">';
} }
$header .= '</head>'.$body[0]; $header .= '</head>'.$body[0];
} $footer = $body[1].' </html>';
$footer = $body[1].' </html>'; return $header.$_[0].$footer;
$header = WebGUI::Macro::process($header);
$footer = WebGUI::Macro::process($footer);
return ($header, $footer);
} }
1; 1;

View file

@ -10,6 +10,7 @@ package WebGUI::Template;
# http://www.plainblack.com info@plainblack.com # http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------- #-------------------------------------------------------------------
use HTML::Template;
use strict; use strict;
use Tie::IxHash; use Tie::IxHash;
use WebGUI::ErrorHandler; use WebGUI::ErrorHandler;
@ -17,24 +18,39 @@ use WebGUI::HTMLForm;
use WebGUI::Session; use WebGUI::Session;
use WebGUI::SQL; use WebGUI::SQL;
#-------------------------------------------------------------------
sub _newPositionFormat {
return "<tmpl_var template.position".($_[0]+1).">";
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub countPositions { sub countPositions {
my ($template, $i); my ($template, $i);
($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$_[0]); ($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$_[0]);
$i = 0; $i = 1;
while ($template =~ m/\^$i\;/) { while ($template =~ m/template\.position$i/) {
$i++; $i++;
} }
return $i; return $i-1;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub generate { sub draw {
my ($output, $content, $template); my $template = get($_[0]);
$template = WebGUI::SQL->quickHashRef("select * from template where templateId=".$_[1]); $template =~ s/\n//g;
$content = $template->{template}; $template =~ s/\r//g;
$content =~ s/\^(\d+)\;/${$_[0]}{$1}/g; $template =~ s/\'/\\\'/g;
return $content; $template =~ s/\<table.*?\>/\<table cellspacing=0 cellpadding=3 width=100 height=80 border=1\>/ig;
$template =~ s/\<tmpl_var\s+template\.position(\d+)\>/$1/ig;
return $template;
}
#-------------------------------------------------------------------
sub get {
my ($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$_[0]);
$template =~ s/\^(\d+)\;/_newPositionFormat($1)/eg; #compatibility with old-style templates
return $template;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -42,30 +58,54 @@ sub getList {
my (%list); my (%list);
tie %list, 'Tie::IxHash'; tie %list, 'Tie::IxHash';
%list = WebGUI::SQL->buildHash("select templateId,name from template order by name"); %list = WebGUI::SQL->buildHash("select templateId,name from template order by name");
return %list; return \%list;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub getPositions { sub getPositions {
my (%hash, $template, $i); my (%hash, $template, $i);
tie %hash, "Tie::IxHash"; tie %hash, "Tie::IxHash";
($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$_[0]); for ($i=1; $i<=countPositions($_[0]); $i++) {
$i = 0;
while ($template =~ m/\^$i\;/) {
$hash{$i} = $i; $hash{$i} = $i;
$i++;
} }
return \%hash; return \%hash;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub selectTemplate { sub process {
my ($output, $f, %templates, $key); my ($t, $html);
tie %templates,'Tie::IxHash'; $html = $_[0];
$t = HTML::Template->new(
scalarref=>\$html,
loop_context_vars=>1,
die_on_bad_params=>0,
strict=>0
);
while (my ($section, $hash) = each %session) {
while (my ($key, $value) = each %$hash) {
if (ref $value eq 'ARRAY') {
next;
#$value = '['.join(', ',@$value).']';
} elsif (ref $value eq 'HASH') {
next;
#$value = '{'.join(', ',map {"$_ => $value->{$_}"} keys %$value).'}';
}
unless (lc($key) eq "password" || lc($key) eq "identifier") {
$t->param($section.".".$key=>$value);
}
}
}
$t->param(%{$_[1]});
$t->param("webgui.version"=>$WebGUI::VERSION);
return $t->output;
}
#-------------------------------------------------------------------
sub select {
my ($templates, $output, $f, $key);
$f = WebGUI::HTMLForm->new(1); $f = WebGUI::HTMLForm->new(1);
%templates = WebGUI::SQL->buildHash("select templateId,name from template order by name"); $templates = getList();
$f->select("templateId",\%templates,'',[$_[0]],'','','onChange="changeTemplatePreview(this.form.templateId.value)"'); $f->select("templateId",$templates,'',[$_[0]],'','','onChange="changeTemplatePreview(this.form.templateId.value)"');
%templates = WebGUI::SQL->buildHash("select templateId,template from template");
$output = ' $output = '
<script language="JavaScript"> <script language="JavaScript">
function checkBrowser(){ function checkBrowser(){
@ -110,13 +150,8 @@ sub selectTemplate {
oMessage.writeIt(eval("b"+value)); oMessage.writeIt(eval("b"+value));
} }
'; ';
foreach $key (keys %templates) { foreach $key (keys %{$templates}) {
$templates{$key} =~ s/\n//g; $output .= " var b".$key." = '".draw($key)."';\n";
$templates{$key} =~ s/\r//g;
$templates{$key} =~ s/\'/\\\'/g;
$templates{$key} =~ s/\<table.*?\>/\<table cellspacing=0 cellpadding=3 width=100 height=80 border=1\>/ig;
$templates{$key} =~ s/\^(\d+)\;/$1/g;
$output .= " var b".$key." = '".$templates{$key}."';\n";
} }
$output .= '</script>'; $output .= '</script>';
$output .= $f->printRowsOnly; $output .= $f->printRowsOnly;

View file

@ -941,7 +941,8 @@ sub www_edit {
-label=>WebGUI::International::get(363), -label=>WebGUI::International::get(363),
-value=>[$templatePosition], -value=>[$templatePosition],
-uiLevel=>5, -uiLevel=>5,
-options=>WebGUI::Template::getPositions($session{page}{templateId}) -options=>WebGUI::Template::getPositions($session{page}{templateId}),
-subtext=>WebGUI::Template::draw($session{page}{templateId})
); );
$f->date( $f->date(
-name=>"startDate", -name=>"startDate",