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

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

View file

@ -197,7 +197,7 @@ sub www_editPage {
-uiLevel=>8
);
$f->readOnly(
-value=>WebGUI::Template::selectTemplate($page{templateId}),
-value=>WebGUI::Template::select($page{templateId}),
-label=>WebGUI::International::get(356),
-uiLevel=>5
);
@ -362,8 +362,8 @@ sub www_editPageSave {
menuTitle=".quote($session{form}{menuTitle}).",
synopsis=".quote($session{form}{synopsis})."
where pageId=$session{form}{pageId}");
WebGUI::SQL->write("update wobject set templatePosition=0 where pageId=$session{form}{pageId}
and templatePosition>".(WebGUI::Template::countPositions($session{form}{templateId})-1));
WebGUI::SQL->write("update wobject set templatePosition=1 where pageId=$session{form}{pageId}
and templatePosition>".WebGUI::Template::countPositions($session{form}{templateId}));
_recursivelyChangeStyle($session{page}{pageId}) if ($session{form}{recurseStyle});
_recursivelyChangePrivileges($session{page}{pageId}) if ($session{form}{recursePrivs});
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})) {
$a = WebGUI::SQL->read("select * from page where templateId=".$session{form}{tid});
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;
WebGUI::SQL->write("delete from template where templateId=".$session{form}{tid});
@ -85,7 +85,7 @@ sub www_editTemplate {
tie %template, 'Tie::CPHash';
if (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) {
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 {
%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::Session;
use WebGUI::SQL;
use WebGUI::Template;
#-------------------------------------------------------------------
sub getStyle {
my ($header, $footer, %style, $styleId, @body);
tie %style, 'Tie::CPHash';
if ($session{form}{makePrintable}) {
$styleId = $session{form}{style} || 3;
%style = WebGUI::SQL->quickHash("select * from style where styleId=$styleId");
@body = split(/\^\-\;/,$style{body});
$header = '<html><!-- WebGUI '.$session{wg}{version}.' -->'."\n";
$header .= '<head><title>'.$session{page}{title}.' - '.$session{setting}{companyName}.'</title>';
$header .= $style{styleSheet}.'</head>'.$body[0];
} else {
%style = WebGUI::SQL->quickHash("select * from style where styleId=$session{page}{styleId}");
@body = split(/\^\-\;/,$style{body});
$header = $session{setting}{docTypeDec}."\n".'<!-- WebGUI '.$WebGUI::VERSION.' -->
<html>
<head>
<title>';
$header .= $session{page}{title}.' - '.$session{setting}{companyName};
$header .= '</title><link REL="icon" HREF="'.$session{config}{extras}.'/favicon.png" TYPE="image/png">'
.$style{styleSheet}
.$session{page}{metaTags};
if ($session{var}{adminOn}) {
# This "triple incantation" panders to the delicate tastes of various browsers for reliable cache suppression.
$header .= '<META HTTP-EQUIV="Pragma" CONTENT="no-cache">';
$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}.'">';
sub get {
my ($header, $footer, %style, $styleId, @body);
tie %style, 'Tie::CPHash';
if ($session{form}{makePrintable}) {
$styleId = $session{form}{style} || 3;
} else {
$styleId = $session{page}{styleId} || 2;
}
%style = WebGUI::SQL->quickHash("select * from style where styleId=$styleId");
@body = split(/\^\-\;/,$style{body});
$header = $session{setting}{docTypeDec}."\n".'<!-- WebGUI '.$WebGUI::VERSION.' --> <html> <head> <title>';
$header .= $session{page}{title}.' - '.$session{setting}{companyName};
$header .= '</title><link REL="icon" HREF="'.$session{config}{extras}.'/favicon.png" TYPE="image/png">'
.$style{styleSheet}.$session{page}{metaTags};
if ($session{var}{adminOn}) {
# This "triple incantation" panders to the delicate tastes of various browsers for reliable cache suppression.
$header .= '<META HTTP-EQUIV="Pragma" CONTENT="no-cache">';
$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];
}
$footer = $body[1].' </html>';
$header = WebGUI::Macro::process($header);
$footer = WebGUI::Macro::process($footer);
return ($header, $footer);
}
$header .= '</head>'.$body[0];
$footer = $body[1].' </html>';
return $header.$_[0].$footer;
}
1;

View file

@ -10,6 +10,7 @@ package WebGUI::Template;
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use HTML::Template;
use strict;
use Tie::IxHash;
use WebGUI::ErrorHandler;
@ -17,24 +18,39 @@ use WebGUI::HTMLForm;
use WebGUI::Session;
use WebGUI::SQL;
#-------------------------------------------------------------------
sub _newPositionFormat {
return "<tmpl_var template.position".($_[0]+1).">";
}
#-------------------------------------------------------------------
sub countPositions {
my ($template, $i);
($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$_[0]);
$i = 0;
while ($template =~ m/\^$i\;/) {
$i = 1;
while ($template =~ m/template\.position$i/) {
$i++;
}
return $i;
return $i-1;
}
#-------------------------------------------------------------------
sub generate {
my ($output, $content, $template);
$template = WebGUI::SQL->quickHashRef("select * from template where templateId=".$_[1]);
$content = $template->{template};
$content =~ s/\^(\d+)\;/${$_[0]}{$1}/g;
return $content;
sub draw {
my $template = get($_[0]);
$template =~ s/\n//g;
$template =~ s/\r//g;
$template =~ s/\'/\\\'/g;
$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);
tie %list, 'Tie::IxHash';
%list = WebGUI::SQL->buildHash("select templateId,name from template order by name");
return %list;
return \%list;
}
#-------------------------------------------------------------------
sub getPositions {
my (%hash, $template, $i);
tie %hash, "Tie::IxHash";
($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$_[0]);
$i = 0;
while ($template =~ m/\^$i\;/) {
for ($i=1; $i<=countPositions($_[0]); $i++) {
$hash{$i} = $i;
$i++;
}
return \%hash;
}
#-------------------------------------------------------------------
sub selectTemplate {
my ($output, $f, %templates, $key);
tie %templates,'Tie::IxHash';
sub process {
my ($t, $html);
$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);
%templates = WebGUI::SQL->buildHash("select templateId,name from template order by name");
$f->select("templateId",\%templates,'',[$_[0]],'','','onChange="changeTemplatePreview(this.form.templateId.value)"');
%templates = WebGUI::SQL->buildHash("select templateId,template from template");
$templates = getList();
$f->select("templateId",$templates,'',[$_[0]],'','','onChange="changeTemplatePreview(this.form.templateId.value)"');
$output = '
<script language="JavaScript">
function checkBrowser(){
@ -110,13 +150,8 @@ sub selectTemplate {
oMessage.writeIt(eval("b"+value));
}
';
foreach $key (keys %templates) {
$templates{$key} =~ s/\n//g;
$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";
foreach $key (keys %{$templates}) {
$output .= " var b".$key." = '".draw($key)."';\n";
}
$output .= '</script>';
$output .= $f->printRowsOnly;

View file

@ -941,7 +941,8 @@ sub www_edit {
-label=>WebGUI::International::get(363),
-value=>[$templatePosition],
-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(
-name=>"startDate",