Added new templating mechanism.

This commit is contained in:
JT Smith 2002-05-26 21:20:39 +00:00
parent 299995af14
commit 9cda39ef82
13 changed files with 108 additions and 464 deletions

View file

@ -23,7 +23,6 @@ use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Style;
use WebGUI::Template;
use WebGUI::Template::Default;
use WebGUI::URL;
use WebGUI::Utility;
@ -88,6 +87,12 @@ sub _displayAdminBar {
%hash
);
}
if (WebGUI::Privilege::isInGroup(8,$session{user}{userId})) {
%hash = (
WebGUI::URL::page('op=listTemplates')=>WebGUI::International::get(508),
%hash
);
}
%hash = (
WebGUI::URL::page('op=viewHelpIndex')=>WebGUI::International::get(13),
%hash
@ -126,9 +131,6 @@ sub page {
my ($debug, %contentHash, $w, $cmd, $pageEdit, $wobject, $wobjectOutput, $extra,
$sth, $httpHeader, $header, $footer, $content, $operationOutput, $adminBar, %hash);
WebGUI::Session::open($_[0],$_[1]);
# For some reason we have to pre-cache the templates when running under mod_perl
# so that's what we're doing with this next command.
WebGUI::Template::loadTemplates();
if ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3)) {
$debug = '<table bgcolor="#ffffff" style="color: #000000; font-size: 10pt; font-family: helvetica;">';
while (my ($section, $hash) = each %session) {
@ -170,11 +172,11 @@ sub page {
# $wobjectOutput = WebGUI::International::get(381); # bad error
}
if ($operationOutput ne "") {
$contentHash{A} = $operationOutput;
$content = WebGUI::Template::Default::generate(\%contentHash);
$contentHash{0} = $operationOutput;
$content = WebGUI::Template::generate(\%contentHash,1);
} elsif ($wobjectOutput ne "") {
$contentHash{A} = $wobjectOutput;
$content = WebGUI::Template::Default::generate(\%contentHash);
$contentHash{0} = $wobjectOutput;
$content = WebGUI::Template::generate(\%contentHash,1);
} else {
if (WebGUI::Privilege::canViewPage()) {
if ($session{var}{adminOn}) {
@ -213,13 +215,10 @@ sub page {
}
}
$sth->finish;
$cmd = "use WebGUI::Template::".$session{page}{template};
eval($cmd);
$cmd = "WebGUI::Template::".$session{page}{template}."::generate";
$content = &$cmd(\%contentHash);
$content = WebGUI::Template::generate(\%contentHash,$session{page}{templateId});
} else {
$contentHash{A} = WebGUI::Privilege::noAccess();
$content = WebGUI::Template::Default::generate(\%contentHash);
$contentHash{0} = WebGUI::Privilege::noAccess();
$content = WebGUI::Template::generate(\%contentHash,1);
}
}
if ($session{var}{adminOn}) {

View file

@ -24,6 +24,7 @@ use WebGUI::Operation::Search;
use WebGUI::Operation::Settings;
use WebGUI::Operation::Statistics;
use WebGUI::Operation::Style;
use WebGUI::Operation::Template;
use WebGUI::Operation::Trash;
use WebGUI::Operation::User;

View file

@ -139,7 +139,7 @@ sub www_editPage {
$f = WebGUI::HTMLForm->new;
if ($session{form}{npp} ne "") {
%page = WebGUI::SQL->quickHash("select * from page where pageId=$session{form}{npp}");
$page{templatePosition} = 'A';
$page{templateId} = 1;
$page{pageId} = "new";
$page{title} = $page{menuTitle} = $page{urlizedTitle} = $page{synopsis} = '';
$page{parentId} = $session{form}{npp};
@ -158,10 +158,9 @@ sub www_editPage {
$f->text("title",WebGUI::International::get(99),$page{title});
$f->text("menuTitle",WebGUI::International::get(411),$page{menuTitle});
$f->text("urlizedTitle",WebGUI::International::get(104),$page{urlizedTitle});
%hash = sortHash(WebGUI::Template::getList());
$f->select("template",\%hash,WebGUI::International::get(356),[$page{templatePosition}],'','',
'onChange="updateTemplateImage(template.value)"',
'<script language="JavaScript"> function updateTemplateImage(template) { document.template.src = "'.$session{setting}{lib}.'/templates/"+template+".gif"; } </script><br><img src="'.$session{setting}{lib}.'/templates/'.$session{page}{template}.'.gif" name="template">');
#%hash = WebGUI::Template::getList();
#$f->select("templateId",\%hash,WebGUI::International::get(356),[$page{templateId}]);
$f->readOnly(WebGUI::Template::selectTemplate($page{templateId}),WebGUI::International::get(356));
$f->textarea("synopsis",WebGUI::International::get(412),$page{synopsis});
$f->textarea("metatags",WebGUI::International::get(100),$page{metaTags});
$f->yesNo("defaultMetaTags",WebGUI::International::get(307),$page{defaultMetaTags});
@ -226,7 +225,7 @@ sub www_editPageSave {
metaTags=".quote($session{form}{metaTags}).",
urlizedTitle='$session{form}{urlizedTitle}',
defaultMetaTags='$session{form}{defaultMetaTags}',
template='$session{form}{template}',
templateId='$session{form}{templateId}',
menuTitle=".quote($session{form}{menuTitle}).",
synopsis=".quote($session{form}{synopsis})."
where pageId=$session{form}{pageId}");

View file

@ -123,8 +123,8 @@ sub www_listStyles {
$output = helpIcon(9);
$output .= '<h1>'.WebGUI::International::get(157).'</h1>';
$output .= '<div align="center"><a href="'.WebGUI::URL::page('op=editStyle&sid=new').
'">'.WebGUI::International::get(158).'</a></div>';
$sth = WebGUI::SQL->read("select styleId,name from style where name<>'Reserved' order by name");
'">'.WebGUI::International::get(158).'</a><p/></div>';
$sth = WebGUI::SQL->read("select styleId,name from style order by name");
while (@data = $sth->array) {
$row[$i] = '<tr><td valign="top" class="tableData">'
.deleteIcon('op=deleteStyle&sid='.$data[0])

View file

@ -1,15 +1,5 @@
package WebGUI::Template;
#####################################################################
#####################################################################
# NOTICE: Use of this subsystem is depricated and is not recommended.
#####################################################################
#####################################################################
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
@ -20,73 +10,108 @@ package WebGUI::Template;
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict qw(vars subs);
use strict;
use Tie::IxHash;
use WebGUI::ErrorHandler;
use WebGUI::HTMLForm;
use WebGUI::Session;
use WebGUI::SQL;
#-------------------------------------------------------------------
sub loadTemplates {
my ($templateDir, @files, $file, $use, @template, $i);
if ($^O =~ /Win/i) {
$templateDir = "\\lib\\WebGUI\\Template";
} else {
$templateDir = "/lib/WebGUI/Template";
}
opendir (DIR,$session{config}{webguiRoot}.$templateDir) or WebGUI::ErrorHandler::fatalError("Can't open template directory!");
@files = readdir(DIR);
foreach $file (@files) {
if ($file =~ /(.*?)\.pm$/) {
$template[$i] = $1;
$use = "require WebGUI::Template::".$template[$i];
eval($use);
if ($@) {
WebGUI::ErrorHandler::fatalError("Template load failed: ".$@);
}
$i++;
}
}
closedir(DIR);
return @template;
}
#-------------------------------------------------------------------
sub calculatePositions {
my (%positions, $string);
$string = "A";
$positions{A} = "A";
while ($string ne $_[0]) {
$string = ++$string;
$positions{$string} = $string;
}
return %positions;
sub generate {
my ($output, $content, %template);
%template = WebGUI::SQL->quickHash("select * from template where templateId=".$_[1]);
$content = $template{template};
$content =~ s/\^(\d+)\;/${$_[0]}{$1}/g;
return $content;
}
#-------------------------------------------------------------------
sub getList {
my (@templates, $cmd, $template, $namespace, %list);
@templates = loadTemplates();
foreach $template (@templates) {
#$cmd = "WebGUI::Template::".$template."::namespace";
#$namespace = $$cmd;
$cmd = "WebGUI::Template::".$template."::name";
$list{$template} = &$cmd();
}
my (%list);
tie %list, 'Tie::IxHash';
%list = WebGUI::SQL->buildHash("select templateId,name from template order by name");
return %list;
}
#-------------------------------------------------------------------
sub getPositions {
my ($cmd, %hash);
my ($cmd, %hash, $template, $i);
tie %hash, "Tie::IxHash";
$cmd = "use WebGUI::Template::".$_[0];
eval($cmd);
$cmd = "WebGUI::Template::".$_[0]."::getPositions";
%hash = &$cmd;
return %hash;
($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$_[0]);
$i = 0;
while ($template =~ m/\^$i\;/) {
$hash{$i} = $i;
$i++;
}
return \%hash;
}
#-------------------------------------------------------------------
sub selectTemplate {
my ($output, $f, %templates, $key);
tie %templates,'Tie::IxHash';
$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");
$output = '
<script language="JavaScript">
function checkBrowser(){
this.ver=navigator.appVersion;
this.dom=document.getElementById?1:0;
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
this.ns4=(document.layers && !this.dom)?1:0;
this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5 || this.dom);
return this;
}
bw=new checkBrowser();
function makeChangeTextObj(obj){
this.css=bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
this.writeref=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj].document:0;
this.writeIt=b_writeIt;
}
function b_writeIt(text){
var obj;
if(bw.ns4) {
if (document.loading) document.loading.visibility = "hidden";
this.writeref.write(text + "&nbsp;&nbsp;&nbsp;");
this.writeref.close();
} else {
if (bw.ie4) {
if (document.all.loading) obj = document.all.loading;
}
if (obj) obj.style.visibility = "hidden";
this.writeref.innerHTML=text;
}
}
function init(){
if(bw.bw){
oMessage=new makeChangeTextObj("templatePreview");
oMessage.css.visibility="visible";
changeTemplatePreview('.$_[0].');
}
}
onload=init
function changeTemplatePreview(value) {
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\ border\=1>/ig;
$templates{$key} =~ s/\^(\d+)\;/$1/g;
$output .= " var b".$key." = '".$templates{$key}."';\n";
}
$output .= '</script>';
$output .= $f->printRowsOnly;
$output .= '<div id="templatePreview"></div>';
return $output;
}
1;

View file

@ -1,51 +0,0 @@
package WebGUI::Template::Default;
#####################################################################
#####################################################################
# NOTICE: Use of this subsystem is depricated and is not recommended.
#####################################################################
#####################################################################
our $namespace = "Default";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::International;
use WebGUI::Template;
#-------------------------------------------------------------------
sub generate {
my ($output, $content);
$content = $_[0];
$output = '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
$output .= '<tr><td valign="top" class="content">';
$output .= ${$content}{A};
$output .= '</td></tr></table>';
return $output;
}
#-------------------------------------------------------------------
sub name {
return WebGUI::International::get(355);
}
#-------------------------------------------------------------------
sub getPositions {
return WebGUI::Template::calculatePositions('A');
}
1;

View file

@ -1,53 +0,0 @@
package WebGUI::Template::LeftColumn;
#####################################################################
#####################################################################
# NOTICE: Use of this subsystem is depricated and is not recommended.
#####################################################################
#####################################################################
our $namespace = "LeftColumn";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::International;
#-------------------------------------------------------------------
sub generate {
my ($output, $content);
$content = $_[0];
$output = '<table cellpadding="3" cellspacing="0" border="0" width="100%">';
$output .= '<tr><td valign="top" class="content" width="34%">';
$output .= ${$content}{A};
$output .= '</td><td valign="top" class="content" width="66%">';
$output .= ${$content}{B};
$output .= '</td></tr></table>';
return $output;
}
#-------------------------------------------------------------------
sub name {
return WebGUI::International::get(358);
}
#-------------------------------------------------------------------
sub getPositions {
return WebGUI::Template::calculatePositions('B');
}
1;

View file

@ -1,53 +0,0 @@
package WebGUI::Template::News;
#####################################################################
#####################################################################
# NOTICE: Use of this subsystem is depricated and is not recommended.
#####################################################################
#####################################################################
our $namespace = "News";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::International;
#-------------------------------------------------------------------
sub generate {
my ($output, $content);
$content = $_[0];
$output = '<table cellpadding="3" cellspacing="0" border="0" width="100%"><tr>';
$output .= '<td valign="top" class="content" colspan="2" width="100%">'.${$content}{A}.'</td></tr><tr>';
$output .= '<td valign="top" class="content" width="50%">'.${$content}{B}.'</td>';
$output .= '<td valign="top" class="content" width="50%">'.${$content}{C}.'</td>';
$output .= '</tr><tr><td valign="top" class="content" colspan="2" width="100%">'.${$content}{D}.'</td></tr>';
$output .= '</table>';
return $output;
}
#-------------------------------------------------------------------
sub name {
return WebGUI::International::get(357);
}
#-------------------------------------------------------------------
sub getPositions {
return WebGUI::Template::calculatePositions('D');
}
1;

View file

@ -1,55 +0,0 @@
package WebGUI::Template::OneOverThree;
#####################################################################
#####################################################################
# NOTICE: Use of this subsystem is depricated and is not recommended.
#####################################################################
#####################################################################
our $namespace = "OneOverThree";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::International;
#-------------------------------------------------------------------
sub generate {
my ($output, $content);
$content = $_[0];
$output = '<table cellpadding="3" cellspacing="0" border="0" width="100%">';
$output .= '<tr><td valign="top" class="content" colspan="3">';
$output .= ${$content}{A};
$output .= '</td></tr><tr>';
$output .= '<td valign="top" class="content" width="33%">'.${$content}{B}.'</td>';
$output .= '<td valign="top" class="content" width="34%">'.${$content}{C}.'</td>';
$output .= '<td valign="top" class="content" width="33%">'.${$content}{D}.'</td>';
$output .= '</tr></table>';
return $output;
}
#-------------------------------------------------------------------
sub name {
return WebGUI::International::get(360);
}
#-------------------------------------------------------------------
sub getPositions {
return WebGUI::Template::calculatePositions('D');
}
1;

View file

@ -1,54 +0,0 @@
package WebGUI::Template::RightColumn;
#####################################################################
#####################################################################
# NOTICE: Use of this subsystem is depricated and is not recommended.
#####################################################################
#####################################################################
our $namespace = "RightColumn";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::International;
#-------------------------------------------------------------------
sub generate {
my ($output, $content);
$content = $_[0];
$output = '<table cellpadding="3" cellspacing="0" border="0" width="100%">';
$output .= '<tr><td valign="top" class="content" width="66%">';
$output .= ${$content}{A};
$output .= '</td><td valign="top" class="content" width="34%">';
$output .= ${$content}{B};
$output .= '</td></tr></table>';
return $output;
}
#-------------------------------------------------------------------
sub name {
return WebGUI::International::get(359);
}
#-------------------------------------------------------------------
sub getPositions {
return WebGUI::Template::calculatePositions('B');
}
1;

View file

@ -1,53 +0,0 @@
package WebGUI::Template::SideBySide;
#####################################################################
#####################################################################
# NOTICE: Use of this subsystem is depricated and is not recommended.
#####################################################################
#####################################################################
our $namespace = "SideBySide";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::International;
#-------------------------------------------------------------------
sub generate {
my ($output, $content);
$content = $_[0];
$output = '<table cellpadding="3" cellspacing="0" border="0" width="100%">';
$output .= '<tr><td valign="top" class="content" width="50%">';
$output .= ${$content}{A};
$output .= '</td><td valign="top" class="content" width="50%">';
$output .= ${$content}{B};
$output .= '</td></tr></table>';
return $output;
}
#-------------------------------------------------------------------
sub name {
return WebGUI::International::get(362);
}
#-------------------------------------------------------------------
sub getPositions {
return WebGUI::Template::calculatePositions('B');
}
1;

View file

@ -1,53 +0,0 @@
package WebGUI::Template::ThreeOverOne;
#####################################################################
#####################################################################
# NOTICE: Use of this subsystem is depricated and is not recommended.
#####################################################################
#####################################################################
our $namespace = "ThreeOverOne";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::International;
#-------------------------------------------------------------------
sub generate {
my ($output, $content);
$content = $_[0];
$output = '<table cellpadding="3" cellspacing="0" border="0" width="100%"><tr>';
$output .= '<td valign="top" class="content" width="33%">'.${$content}{A}.'</td>';
$output .= '<td valign="top" class="content" width="34%">'.${$content}{B}.'</td>';
$output .= '<td valign="top" class="content" width="33%">'.${$content}{C}.'</td>';
$output .= '</tr><tr><td valign="top" class="content" colspan="3">'.${$content}{D}.'</td></tr>';
$output .= '</table>';
return $output;
}
#-------------------------------------------------------------------
sub name {
return WebGUI::International::get(361);
}
#-------------------------------------------------------------------
sub getPositions {
return WebGUI::Template::calculatePositions('D');
}
1;

View file

@ -71,14 +71,6 @@ sub _getNextSequenceNumber {
return ($sequenceNumber+1);
}
#-------------------------------------------------------------------
sub _getPositions {
my (%hash);
tie %hash, "Tie::IxHash";
%hash = WebGUI::Template::getPositions($session{page}{template});
return \%hash;
}
#-------------------------------------------------------------------
=head2 description ( )
@ -402,7 +394,7 @@ sub www_edit {
$displayTitle = $_[0]->get("displayTitle");
}
$title = $_[0]->get("title") || $_[0]->get("namespace");
$templatePosition = $_[0]->get("templatePosition") || 'A';
$templatePosition = $_[0]->get("templatePosition") || '0';
$endDate = $_[0]->get("endDate") || (time()+315360000);
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
@ -413,7 +405,7 @@ sub www_edit {
$f->text("title",WebGUI::International::get(99),$title);
$f->yesNo("displayTitle",WebGUI::International::get(174),$displayTitle);
$f->yesNo("processMacros",WebGUI::International::get(175),$_[0]->get("processMacros"));
$f->select("templatePosition",_getPositions(),WebGUI::International::get(363),[$templatePosition]);
$f->select("templatePosition",WebGUI::Template::getPositions($session{page}{templateId}),WebGUI::International::get(363),[$templatePosition]);
$f->date("startDate",WebGUI::International::get(497),$_[0]->get("startDate"));
$f->date("endDate",WebGUI::International::get(498),$endDate);
$f->HTMLArea("description",WebGUI::International::get(85),$_[0]->get("description"));