style and page template migrations complete

This commit is contained in:
JT Smith 2003-11-28 19:24:40 +00:00
parent de758d8dfe
commit 5d0faf0e3f
12 changed files with 354 additions and 409 deletions

View file

@ -7,6 +7,15 @@ upgrading from one version to the next, or even between multiple
versions. Be sure to heed the warnings contained herein as they will versions. Be sure to heed the warnings contained herein as they will
save you many hours of grief. save you many hours of grief.
6.0.0
--------------------------------------------------------------------
* You MUST clear your filesystem cache or WebGUI will crash. It is
typically in /tmp/FileCache. A command like the following
run as the super user will do the job nicely:
rm -Rf /tmp/FileCache
5.5.0 5.5.0
-------------------------------------------------------------------- --------------------------------------------------------------------
* If you have any custom Message Board templates they will be * If you have any custom Message Board templates they will be

3
docs/temp.sql Normal file
View file

@ -0,0 +1,3 @@
# add this stuff to previousVersion.sql just before 6.0 release
delete from style where styleId < 0;

View file

@ -0,0 +1,126 @@
#!/usr/bin/perl
use lib "../../lib";
use Getopt::Long;
use Parse::PlainConfig;
use strict;
use WebGUI::Session;
use WebGUI::SQL;
my $configFile;
my $quiet;
GetOptions(
'configFile=s'=>\$configFile,
'quiet'=>\$quiet
);
WebGUI::Session::open("../..",$configFile);
#--------------------------------------------
print "\tMigrating styles.\n" unless ($quiet);
my $sth = WebGUI::SQL->read("select * from style");
while (my $style = $sth->hashRef) {
my ($header,$footer) = split(/\^\-\;/,$style->{body});
my ($newStyleId) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='style'");
if ($style->{styleId} > 0 && $style->{styleId} < 25) {
$newStyleId = $style->{styleId};
} elsif ($newStyleId > 999) {
$newStyleId++;
} else {
$newStyleId = 1000;
}
my $newStyle = $session{setting}{docTypeDec}.'
<html>
<head>
<title><tmpl_var session.page.title> - <tmpl_var session.setting.companyName></title>
<tmpl_var head.tags>
'.$style->{styleSheet}.'
</head>
'.$header.'
<tmpl_var body.content>
'.$footer.'
</html>
';
WebGUI::SQL->write("insert into template (templateId, name, template, namespace) values (".$newStyleId.",
".quote($style->{name}).", ".quote($newStyle).", 'style')");
WebGUI::SQL->write("update page set styleId=".$newStyleId." where styleId=".$style->{styleId});
WebGUI::SQL->write("update themeComponent set id=".$newStyleId.", type='template' where id=".$style->{styleId}." and type='style'");
}
$sth->finish;
WebGUI::SQL->write("delete from incrementer where incrementerId='styleId'");
WebGUI::SQL->write("delete from settings where name='docTypeDec'");
WebGUI::SQL->write("drop table style");
#--------------------------------------------
print "\tMigrating page templates.\n" unless ($quiet);
my $sth = WebGUI::SQL->read("select * from template where namespace='Page'");
while (my $template = $sth->hashRef) {
#eliminate the need for compatibility with old-style page templates
$template->{template} =~ s/\^(\d+)\;/_positionFormat5x($1)/eg;
$template->{template} = '
<tmpl_if session.var.adminOn>
<style>
div.wobject:hover {
border: 1px outset #cccccc;
}
</style>
</tmpl_if>
<tmpl_if session.var.adminOn> <tmpl_if page.canEdit>
<tmpl_var page.toolbar>
</tmpl_if> </tmpl_if>
'.$template->{template};
$template->{template} =~ s/\<tmpl_var page\.position(\d+)\>/_positionFormat6x($1)/eg;
WebGUI::SQL->write("update template set namespace='page', template=".quote($template->{template})
." where templateId=".$template->{templateId}." and namespace='Page'");
}
$sth->finish;
#--------------------------------------------
#print "\tUpdating config file.\n" unless ($quiet);
#my $pathToConfig = '../../etc/'.$configFile;
#my $conf = Parse::PlainConfig->new('DELIM' => '=', 'FILE' => $pathToConfig);
#my $wobjects = $conf->get("wobjects");
#$conf->set("wobjects"=>$wobjects);
#$conf->write;
#--------------------------------------------
print "\tRemoving unneeded files.\n" unless ($quiet);
unlink("../../lib/WebGUI/Operation/Style.pm");
#unlink("../../lib/WebGUI/Wobject/LinkList.pm");
#unlink("../../lib/WebGUI/Wobject/FAQ.pm");
WebGUI::Session::close();
#-------------------------------------------------------------------
sub _positionFormat5x {
return "<tmpl_var page.position".($_[0]+1).">";
}
#-------------------------------------------------------------------
sub _positionFormat6x {
my $newPositionCode = '
<tmpl_loop position'.$_[0].'_loop>
<tmpl_if wobject.canView>
<div class="wobject"> <div class="wobject<tmpl_var wobject.namespace>" id="wobjectId<tmpl_var wobject.id>">
<tmpl_if session.var.adminOn> <tmpl_if wobject.canEdit>
<tmpl_var wobject.toolbar>
</tmpl_if> </tmpl_if>
<tmpl_if wobject.isInDateRange>
<a name="<tmpl_var wobject.id>"></a>
<tmpl_var wobject.content>
</tmpl_if wobject.isInDateRange>
</div> </div>
</tmpl_if>
</tmpl_loop>
';
return $newPositionCode;
}

View file

@ -1,2 +1,14 @@
insert into webguiVersion values ('6.0.0','upgrade',unix_timestamp()); insert into webguiVersion values ('6.0.0','upgrade',unix_timestamp());
delete from international where internationalId=158 and namespace='WebGUI';
delete from international where internationalId=803 and namespace='WebGUI';
delete from international where internationalId=804 and namespace='WebGUI';
delete from international where internationalId=805 and namespace='WebGUI';
delete from international where internationalId=814 and namespace='WebGUI';
delete from international where internationalId=156 and namespace='WebGUI';
delete from international where internationalId=155 and namespace='WebGUI';
delete from international where internationalId=380 and namespace='WebGUI';
delete from international where internationalId=151 and namespace='WebGUI';
delete from international where internationalId=501 and namespace='WebGUI';
delete from international where internationalId=154 and namespace='WebGUI';
delete from international where internationalId=157 and namespace='WebGUI';
delete from style where name='Reserved';

View file

@ -16,7 +16,6 @@ use Tie::CPHash;
use WebGUI::Affiliate; use WebGUI::Affiliate;
use WebGUI::Cache; use WebGUI::Cache;
use WebGUI::ErrorHandler; use WebGUI::ErrorHandler;
use WebGUI::Icon;
use WebGUI::International; use WebGUI::International;
use WebGUI::Macro; use WebGUI::Macro;
use WebGUI::Operation; use WebGUI::Operation;
@ -25,110 +24,28 @@ use WebGUI::Session;
use WebGUI::SQL; use WebGUI::SQL;
use WebGUI::Style; use WebGUI::Style;
use WebGUI::Page; use WebGUI::Page;
use WebGUI::Template;
use WebGUI::URL; use WebGUI::URL;
use WebGUI::Utility;
#-------------------------------------------------------------------
sub _generateDebug {
if ($session{setting}{showDebug} || ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3))) {
return WebGUI::ErrorHandler::showDebug();
}
return "";
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub _generatePage { sub _generatePage {
my ($canEdit, $pageEdit, $sth, $wobject, %contentHash, $originalWobject, $sql, $extra, %hash, $cmd, $w, $template,$canEditWobject); my $content = shift;
if (WebGUI::Privilege::canViewPage()) { if ($session{form}{op} eq "" && $session{setting}{trackPageStatistics} && $session{form}{wid} ne "new") {
if ($session{var}{adminOn}) { WebGUI::SQL->write("insert into pageStatistics (dateStamp, userId, username, ipAddress, userAgent, referer,
$canEdit = WebGUI::Privilege::canEditPage(); pageId, pageTitle, wobjectId, wobjectFunction) values (".time().",".$session{user}{userId}
if ($canEdit) { .",".quote($session{user}{username}).",
$pageEdit = "\n<br>" ".quote($session{env}{REMOTE_ADDR}).", ".quote($session{env}{HTTP_USER_AGENT}).",
.pageIcon() ".quote($session{env}{HTTP_REFERER}).", ".$session{page}{pageId}.",
.deleteIcon('op=deletePage') ".quote($session{page}{title}).", ".quote($session{form}{wid}).", ".quote($session{form}{func}).")");
.editIcon('op=editPage') }
.moveUpIcon('op=movePageUp') my $output = WebGUI::Macro::process(WebGUI::Style::process($content));
.moveDownIcon('op=movePageDown') if ($session{setting}{showDebug} || ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3))) {
.cutIcon('op=cutPage') $output .= WebGUI::ErrorHandler::showDebug();
."\n";
}
}
$sth = WebGUI::SQL->read("select * from wobject where pageId=$session{page}{pageId}
order by sequenceNumber, wobjectId");
while ($wobject = $sth->hashRef) {
$canEditWobject = WebGUI::Privilege::canEditWobject($wobject->{wobjectId});
if ($session{var}{adminOn} && $canEditWobject) {
$contentHash{"page.position".${$wobject}{templatePosition}} .= "\n<hr>"
.wobjectIcon()
.deleteIcon('func=delete&wid='.${$wobject}{wobjectId})
.editIcon('func=edit&wid='.${$wobject}{wobjectId})
.moveUpIcon('func=moveUp&wid='.${$wobject}{wobjectId})
.moveDownIcon('func=moveDown&wid='.${$wobject}{wobjectId})
.moveTopIcon('func=moveTop&wid='.${$wobject}{wobjectId})
.moveBottomIcon('func=moveBottom&wid='.${$wobject}{wobjectId})
.cutIcon('func=cut&wid='.${$wobject}{wobjectId})
.copyIcon('func=copy&wid='.${$wobject}{wobjectId});
if (${$wobject}{namespace} ne "WobjectProxy" && isIn("WobjectProxy",@{$session{config}{wobjects}})) {
$contentHash{"page.position".${$wobject}{templatePosition}} .=
shortcutIcon('func=createShortcut&wid='.${$wobject}{wobjectId})
}
$contentHash{"page.position".${$wobject}{templatePosition}} .= '<br>';
}
if(!WebGUI::Privilege::canViewWobject($wobject->{wobjectId})){ next; }
if (${$wobject}{namespace} eq "WobjectProxy") {
$originalWobject = $wobject;
my ($wobjectProxy) = WebGUI::SQL->quickHashRef("select * from WobjectProxy where wobjectId=".${$wobject}{wobjectId});
$wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobject.wobjectId=".$wobjectProxy->{proxiedWobjectId});
if (${$wobject}{namespace} eq "") {
$wobject = $originalWobject;
} else {
${$wobject}{startDate} = ${$originalWobject}{startDate};
${$wobject}{endDate} = ${$originalWobject}{endDate};
${$wobject}{templatePosition} = ${$originalWobject}{templatePosition};
${$wobject}{_WobjectProxy} = ${$originalWobject}{wobjectId};
if ($wobjectProxy->{overrideTitle}) {
${$wobject}{title} = ${$originalWobject}{title};
}
if ($wobjectProxy->{overrideDisplayTitle}) {
${$wobject}{displayTitle} = ${$originalWobject}{displayTitle};
}
if ($wobjectProxy->{overrideDescription}) {
${$wobject}{description} = ${$originalWobject}{description};
}
if ($wobjectProxy->{overrideTemplate}) {
${$wobject}{templateId} = $wobjectProxy->{proxiedTemplateId};
}
}
}
$extra = WebGUI::SQL->quickHashRef("select * from ".$wobject->{namespace}."
where wobjectId=".$wobject->{wobjectId});
tie %hash, 'Tie::CPHash';
%hash = (%{$wobject},%{$extra});
$wobject = \%hash;
$cmd = "WebGUI::Wobject::".${$wobject}{namespace};
$w = eval{$cmd->new($wobject)};
WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root cause: ".$@) if($@);
if ($w->inDateRange) {
$contentHash{"page.position".${$wobject}{templatePosition}} .= '<div class="wobject"><div class="wobject'
.${$wobject}{namespace}.'" id="wobjectId'.${$wobject}{wobjectId}.'">';
$contentHash{"page.position".${$wobject}{templatePosition}} .= '<a name="'
.${$wobject}{wobjectId}.'"></a>';
$contentHash{"page.position".${$wobject}{templatePosition}} .= eval{$w->www_view};
WebGUI::ErrorHandler::fatalError("Wobject runtime error: ${$wobject}{namespace}. Root cause: ".$@) if($@);
$contentHash{"page.position".${$wobject}{templatePosition}} .= "</div></div>\n\n";
}
}
$sth->finish;
$template = $session{page}{templateId};
} else {
$contentHash{"page.position1"} = WebGUI::Privilege::noAccess();
} }
return (\%contentHash,$template,$pageEdit); return $output;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub _processAction { sub _processAction {
my ($urlString, %form, $pair, @pairs, @param); my ($urlString, %form, $pair, @pairs, @param);
@ -223,64 +140,48 @@ sub _processOperations {
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub page { sub page {
my ($cache, $debug, $positions, $wobjectOutput, $pageEdit, $httpHeader, $content, $operationOutput, $template);
WebGUI::Session::open($_[0],$_[1]); WebGUI::Session::open($_[0],$_[1]);
my $useCache = ($session{form}{op} eq "" && $session{form}{wid} eq "" && $session{form}{makePrintable} eq "" my $useCache = ($session{form}{op} eq "" && $session{form}{wid} eq "" && $session{form}{makePrintable} eq ""
&& (($session{page}{cacheTimeout} > 10 && $session{user}{userId} !=1) || ($session{page}{cacheTimeout} > 10 && $session{user}{userId} == 1)) && (($session{page}{cacheTimeout} > 10 && $session{user}{userId} !=1) || ($session{page}{cacheTimeout} > 10 && $session{user}{userId} == 1))
&& not $session{var}{adminOn}); && not $session{var}{adminOn});
my ($output, $cache);
if ($useCache) { if ($useCache) {
$cache = WebGUI::Cache->new("page_".$session{page}{pageId}."_".$session{user}{userId}); $cache = WebGUI::Cache->new("page_".$session{page}{pageId}."_".$session{user}{userId});
$content = $cache->get; $output = $cache->get;
} }
$operationOutput = _processOperations(); my $operationOutput = _processOperations();
WebGUI::Affiliate::grabReferral(); WebGUI::Affiliate::grabReferral();
$wobjectOutput = _processFunctions(); my $wobjectOutput = _processFunctions();
if ($operationOutput eq "" && $wobjectOutput eq "" && $session{form}{action2} ne "") { if ($operationOutput eq "" && $wobjectOutput eq "" && $session{form}{action2} ne "") {
_processAction($session{form}{action2}); _processAction($session{form}{action2});
$operationOutput = _processOperations(); $operationOutput = _processOperations();
$wobjectOutput = _processFunctions(); $wobjectOutput = _processFunctions();
} }
if ($operationOutput eq "" && $session{setting}{trackPageStatistics} && $session{form}{wid} ne "new" && $session{header}{mimetype} eq "text/html") { if ($output ne "") {
WebGUI::SQL->write("insert into pageStatistics (dateStamp, userId, username, ipAddress, userAgent, referer, $output = WebGUI::Session::httpHeader().$output;
pageId, pageTitle, wobjectId, wobjectFunction) values (".time().",".$session{user}{userId} } elsif ($session{header}{mimetype} ne "text/html") {
.",".quote($session{user}{username}).", $output = WebGUI::Session::httpHeader().$operationOutput.$wobjectOutput;
".quote($session{env}{REMOTE_ADDR}).", ".quote($session{env}{HTTP_USER_AGENT}).",
".quote($session{env}{HTTP_REFERER}).", ".$session{page}{pageId}.",
".quote($session{page}{title}).", ".quote($session{form}{wid}).", ".quote($session{form}{func}).")");
}
if ($session{header}{mimetype} ne "text/html") {
$httpHeader = WebGUI::Session::httpHeader();
WebGUI::Session::close();
return $httpHeader.$operationOutput.$wobjectOutput;
} elsif ($operationOutput ne "") { } elsif ($operationOutput ne "") {
$positions->{"page.position1"} = $operationOutput; $output = WebGUI::Session::httpHeader()._generatePage($operationOutput);
} elsif ($session{page}{redirectURL} && !$session{var}{adminOn}) { } elsif ($session{page}{redirectURL} && !$session{var}{adminOn}) {
$httpHeader = WebGUI::Session::httpRedirect(WebGUI::Macro::process($session{page}{redirectURL})); $output = WebGUI::Session::httpRedirect(WebGUI::Macro::process($session{page}{redirectURL}));
WebGUI::Session::close();
return $httpHeader;
} elsif ($session{header}{redirect} ne "") { } elsif ($session{header}{redirect} ne "") {
$httpHeader = $session{header}{redirect}; $output = $session{header}{redirect};
WebGUI::Session::close();
return $httpHeader;
} elsif ($wobjectOutput ne "") { } elsif ($wobjectOutput ne "") {
$positions->{"page.position1"} = $wobjectOutput; $output = WebGUI::Session::httpHeader()._generatePage($wobjectOutput);
} elsif (!($useCache && defined $content)) { } else {
($positions, $template, $pageEdit) = _generatePage(); $output = _generatePage(WebGUI::Page::generate());
}
$httpHeader = WebGUI::Session::httpHeader();
unless ($useCache && defined $content) {
$content = WebGUI::Macro::process(WebGUI::Template::process(WebGUI::Style::get($pageEdit.WebGUI::Page::getTemplate($template)), $positions));
my $ttl; my $ttl;
if ($session{user}{userId} == 1) { if ($session{user}{userId} == 1) {
$ttl = $session{page}{cacheTimeoutVisitor}; $ttl = $session{page}{cacheTimeoutVisitor};
} else { } else {
$ttl = $session{page}{cacheTimeout}; $ttl = $session{page}{cacheTimeout};
} }
$cache->set($content, $ttl) if ($useCache); $cache->set($output, $ttl) if ($useCache);
$output = WebGUI::Session::httpHeader().$output;
} }
$debug = _generateDebug();
WebGUI::Session::close(); WebGUI::Session::close();
return $httpHeader.$content.$debug; return $output;
} }

View file

@ -28,7 +28,6 @@ use WebGUI::Operation::Scratch;
use WebGUI::Operation::Search; use WebGUI::Operation::Search;
use WebGUI::Operation::Settings; use WebGUI::Operation::Settings;
use WebGUI::Operation::Statistics; use WebGUI::Operation::Statistics;
use WebGUI::Operation::Style;
use WebGUI::Operation::Template; use WebGUI::Operation::Template;
use WebGUI::Operation::Theme; use WebGUI::Operation::Theme;
use WebGUI::Operation::Trash; use WebGUI::Operation::Trash;

View file

@ -24,16 +24,12 @@ our @EXPORT = qw(&www_deployPackage &www_selectPackageToDeploy);
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub _duplicateWobjects { sub _duplicateWobjects {
my ($sth, $wobject, $cmd, %hash, $extra, $w, %properties); my (%properties);
tie %properties, 'Tie::CPHash'; tie %properties, 'Tie::CPHash';
$sth = WebGUI::SQL->read("select * from wobject where pageId=$_[0] order by sequenceNumber"); my $sth = WebGUI::SQL->read("select * from wobject where pageId=$_[0] order by sequenceNumber");
while ($wobject = $sth->hashRef) { while (my $wobject = $sth->hashRef) {
$extra = WebGUI::SQL->quickHashRef("select * from ${$wobject}{namespace} where wobjectId=${$wobject}{wobjectId}"); my $cmd = "WebGUI::Wobject::".${$wobject}{namespace};
tie %hash, 'Tie::CPHash'; my $w = $cmd->new($wobject);
%hash = (%{$wobject},%{$extra});
$wobject = \%hash;
$cmd = "WebGUI::Wobject::".${$wobject}{namespace};
$w = $cmd->new($wobject);
$w->duplicate($_[1]); $w->duplicate($_[1]);
} }
$sth->finish; $sth->finish;

View file

@ -365,19 +365,18 @@ sub www_editPage {
-unitsValue=>$data[1], -unitsValue=>$data[1],
-uiLevel=>8 -uiLevel=>8
); );
%hash = WebGUI::SQL->buildHash("select styleId,name from style where name<>'Reserved' order by name");
if (WebGUI::Privilege::isInGroup(5)) { if (WebGUI::Privilege::isInGroup(5)) {
$subtext = ' &nbsp; <a href="'.WebGUI::URL::page('op=listStyles') $subtext = ' &nbsp; <a href="'.WebGUI::URL::page('op=listStyles')
.'">'.WebGUI::International::get(6).'</a>'; .'">'.WebGUI::International::get(6).'</a>';
} else { } else {
$subtext = ""; $subtext = "";
} }
$f->getTab("layout")->select( $f->getTab("layout")->template(
-name=>"styleId", -name=>"styleId",
-options=>\%hash,
-label=>WebGUI::International::get(105), -label=>WebGUI::International::get(105),
-value=>[$page{styleId}], -value=>$page{styleId},
-subtext=>$subtext, -subtext=>$subtext,
-namespace=>'style',
-uiLevel=>5 -uiLevel=>5
); );
if ($childCount) { if ($childCount) {

View file

@ -1,202 +0,0 @@
package WebGUI::Operation::Style;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2003 Plain Black LLC.
#-------------------------------------------------------------------
# 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 Exporter;
use strict;
use Tie::CPHash;
use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::International;
use WebGUI::Operation::Shared;
use WebGUI::Paginator;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Utility;
our @ISA = qw(Exporter);
our @EXPORT = qw(&www_copyStyle &www_deleteStyle &www_deleteStyleConfirm &www_editStyle &www_editStyleSave &www_listStyles);
#-------------------------------------------------------------------
sub _submenu {
my (%menu);
tie %menu, 'Tie::IxHash';
$menu{WebGUI::URL::page('op=editStyle&sid=new')} = WebGUI::International::get(158);
if (($session{form}{op} eq "editStyle" && $session{form}{sid} ne "new") || $session{form}{op} eq "deleteStyleConfirm") {
$menu{WebGUI::URL::page('op=editStyle&sid='.$session{form}{sid})} = WebGUI::International::get(803);
$menu{WebGUI::URL::page('op=copyStyle&sid='.$session{form}{sid})} = WebGUI::International::get(804);
$menu{WebGUI::URL::page('op=deleteStyle&sid='.$session{form}{sid})} = WebGUI::International::get(805);
$menu{WebGUI::URL::page('op=listStyles')} = WebGUI::International::get(814);
}
return menuWrapper($_[0],\%menu);
}
#-------------------------------------------------------------------
sub www_copyStyle {
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(5));
my (%style);
tie %style, 'Tie::CPHash';
%style = WebGUI::SQL->quickHash("select * from style where styleId=$session{form}{sid}");
WebGUI::SQL->write("insert into style (styleId,name,body,styleSheet) values (".getNextId("styleId").",
".quote('Copy of '.$style{name}).", ".quote($style{body}).", ".quote($style{styleSheet}).")");
return www_listStyles();
}
#-------------------------------------------------------------------
sub www_deleteStyle {
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(5));
return WebGUI::Privilege::vitalComponent() if ($session{form}{sid} < 1000 && $session{form}{sid} > 0);
my ($output);
$output .= helpIcon(4);
$output .= '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(155).'<p>';
$output .= '<div align="center"><a href="'.
WebGUI::URL::page('op=deleteStyleConfirm&sid='.$session{form}{sid})
.'">'.WebGUI::International::get(44).'</a>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.WebGUI::URL::page('op=listStyles').
'">'.WebGUI::International::get(45).'</a></div>';
return _submenu($output);
}
#-------------------------------------------------------------------
sub www_deleteStyleConfirm {
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(5));
return WebGUI::Privilege::vitalComponent() if ($session{form}{sid} < 1000 && $session{form}{sid} > 0);
WebGUI::SQL->write("delete from style where styleId=".$session{form}{sid});
WebGUI::SQL->write("update page set styleId=2 where styleId=".$session{form}{sid});
return www_listStyles();
}
#-------------------------------------------------------------------
sub www_editStyle {
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(5));
my ($output, %style, $f);
tie %style, 'Tie::CPHash';
if ($session{form}{sid} eq "new") {
$style{body} = "^AdminBar;\n\n<body>\n\n^-;\n\n</body>";
$style{styleSheet} = '
<style>
.content{
font-family: helvetica, arial;
font-size: 10pt;
}
.adminBar {
background-color: #dddddd;
font-family: helvetica, arial;
}
.tableMenu {
background-color: #dddddd;
font-size: 8pt;
font-family: Helvetica, Arial;
}
.tableMenu a {
text-decoration: none;
}
.tableHeader {
background-color: #dddddd;
font-size: 10pt;
font-family: Helvetica, Arial;
}
.tableData {
font-size: 10pt;
font-family: Helvetica, Arial;
}
.pollColor {
background-color: #cccccc;
border: thin solid #aaaaaa;
}
.pagination {
font-family: helvetica, arial;
font-size: 8pt;
text-align: center;
}
.tab {
border: 1px solid black;
background-color: #eeeeee;
}
.tabBody {
border: 1px solid black;
border-top: 1px solid black;
border-left: 1px solid black;
background-color: #dddddd;
}
div.tabs {
line-height: 15px;
font-size: 14px;
}
.tabHover {
background-color: #cccccc;
}
.tabActive {
background-color: #dddddd;
}
</style>
';
} else {
%style = WebGUI::SQL->quickHash("select * from style where styleId=$session{form}{sid}");
}
$output .= helpIcon(16);
$output .= '<h1>'.WebGUI::International::get(156).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("op","editStyleSave");
$f->hidden("sid",$session{form}{sid});
$f->readOnly($session{form}{sid},WebGUI::International::get(380));
$f->text("name",WebGUI::International::get(151),$style{name});
$f->textarea("body",WebGUI::International::get(501),$style{body},'','','',(5+$session{setting}{textAreaRows}));
$f->textarea("styleSheet",WebGUI::International::get(154),$style{styleSheet},'','','',(5+$session{setting}{textAreaRows}));
$f->submit;
$output .= $f->print;
return _submenu($output);
}
#-------------------------------------------------------------------
sub www_editStyleSave {
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(5));
if ($session{form}{sid} eq "new") {
$session{form}{sid} = getNextId("styleId");
WebGUI::SQL->write("insert into style (styleId) values ($session{form}{sid})");
}
$session{form}{body} = "^AdminBar;\n\n<body>\n\n^-;\n\n</body>" if ($session{form}{body} eq "");
WebGUI::SQL->write("update style set name=".quote($session{form}{name}).", body=".quote($session{form}{body}).",
styleSheet=".quote($session{form}{styleSheet})." where styleId=".$session{form}{sid});
return www_listStyles();
}
#-------------------------------------------------------------------
sub www_listStyles {
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(5));
my ($output, $sth, @data, @row, $i, $p);
$output = helpIcon(9);
$output .= '<h1>'.WebGUI::International::get(157).'</h1>';
$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])
.editIcon('op=editStyle&sid='.$data[0])
.copyIcon('op=copyStyle&sid='.$data[0])
.'</td>';
$row[$i] .= '<td valign="top" class="tableData">'.$data[1].'</td></tr>';
$i++;
}
$sth->finish;
$p = WebGUI::Paginator->new(WebGUI::URL::page('op=listStyles'),\@row);
$output .= '<table border=1 cellpadding=5 cellspacing=0 align="center">';
$output .= $p->getPage($session{form}{pn});
$output .= '</table>';
$output .= $p->getBarTraditional($session{form}{pn});
return _submenu($output);
}
1;

View file

@ -20,10 +20,12 @@ use strict;
use Tie::IxHash; use Tie::IxHash;
use WebGUI::ErrorHandler; use WebGUI::ErrorHandler;
use WebGUI::HTMLForm; use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::Persistent::Tree;
use WebGUI::Session; use WebGUI::Session;
use WebGUI::SQL; use WebGUI::SQL;
use WebGUI::Template; use WebGUI::Template;
use WebGUI::Persistent::Tree; use WebGUI::Utility;
our @ISA = qw(WebGUI::Persistent::Tree); our @ISA = qw(WebGUI::Persistent::Tree);
@ -40,8 +42,9 @@ This package provides utility functions for WebGUI's page system.
use WebGUI::Page; use WebGUI::Page;
$integer = WebGUI::Page::countTemplatePositions($templateId); $integer = WebGUI::Page::countTemplatePositions($templateId);
$html = WebGUI::Page::drawTemplate($templateId); $html = WebGUI::Page::drawTemplate($templateId);
$html = WebGUI::Page::generate();
$hashRef = WebGUI::Page::getTemplateList(); $hashRef = WebGUI::Page::getTemplateList();
$template = WebGUI::Page::getTemplate($templateId); $template = WebGUI::Page::getTemplate();
$hashRef = WebGUI::Page::getTemplatePositions($templateId); $hashRef = WebGUI::Page::getTemplatePositions($templateId);
$url = WebGUI::Page::makeUnique($url,$pageId); $url = WebGUI::Page::makeUnique($url,$pageId);
@ -53,12 +56,6 @@ These functions are available from this package:
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub _newPositionFormat {
return "<tmpl_var page.position".($_[0]+1).">";
}
#-------------------------------------------------------------------
sub classSettings { sub classSettings {
return { return {
properties => { properties => {
@ -112,7 +109,7 @@ sub countTemplatePositions {
my ($template, $i); my ($template, $i);
$template = getTemplate($_[0]); $template = getTemplate($_[0]);
$i = 1; $i = 1;
while ($template =~ m/page\.position$i/) { while ($template =~ m/position$i\_loop/) {
$i++; $i++;
} }
return $i-1; return $i-1;
@ -164,10 +161,87 @@ sub drawTemplate {
$template = WebGUI::Macro::negate($template); $template = WebGUI::Macro::negate($template);
$template =~ s/\<script.*?\>.*?\<\/script\>//gi; $template =~ s/\<script.*?\>.*?\<\/script\>//gi;
$template =~ s/\<table.*?\>/\<table cellspacing=0 cellpadding=3 width=100 height=80 border=1\>/ig; $template =~ s/\<table.*?\>/\<table cellspacing=0 cellpadding=3 width=100 height=80 border=1\>/ig;
$template =~ s/\<tmpl_var\s+page\.position(\d+)\>/$1/ig; $template =~ s/\<tmpl_loop\s+position(\d+)\_loop\>.*?\<\/tmpl\_loop\>/$1/ig;
return $template; return $template;
} }
#-------------------------------------------------------------------
=head2 generate ( )
Generates the content of the page.
=cut
sub generate {
return WebGUI::Privilege::noAccess() unless (WebGUI::Privilege::canViewPage());
my %var;
$var{'page.canEdit'} = WebGUI::Privilege::canEditPage();
$var{'page.toolbar'} = pageIcon()
.deleteIcon('op=deletePage')
.editIcon('op=editPage')
.moveUpIcon('op=movePageUp')
.moveDownIcon('op=movePageDown')
.cutIcon('op=cutPage');
my $sth = WebGUI::SQL->read("select * from wobject where pageId=".$session{page}{pageId}." order by sequenceNumber, wobjectId");
while (my $wobject = $sth->hashRef) {
my $wobjectToolbar = wobjectIcon()
.deleteIcon('func=delete&wid='.${$wobject}{wobjectId})
.editIcon('func=edit&wid='.${$wobject}{wobjectId})
.moveUpIcon('func=moveUp&wid='.${$wobject}{wobjectId})
.moveDownIcon('func=moveDown&wid='.${$wobject}{wobjectId})
.moveTopIcon('func=moveTop&wid='.${$wobject}{wobjectId})
.moveBottomIcon('func=moveBottom&wid='.${$wobject}{wobjectId})
.cutIcon('func=cut&wid='.${$wobject}{wobjectId})
.copyIcon('func=copy&wid='.${$wobject}{wobjectId});
if (${$wobject}{namespace} ne "WobjectProxy" && isIn("WobjectProxy",@{$session{config}{wobjects}})) {
$wobjectToolbar .= shortcutIcon('func=createShortcut&wid='.${$wobject}{wobjectId});
}
if (${$wobject}{namespace} eq "WobjectProxy") {
my $originalWobject = $wobject;
my ($wobjectProxy) = WebGUI::SQL->quickHashRef("select * from WobjectProxy where wobjectId=".${$wobject}{wobjectId});
$wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobject.wobjectId=".$wobjectProxy->{proxiedWobjectId});
if (${$wobject}{namespace} eq "") {
$wobject = $originalWobject;
} else {
${$wobject}{startDate} = ${$originalWobject}{startDate};
${$wobject}{endDate} = ${$originalWobject}{endDate};
${$wobject}{templatePosition} = ${$originalWobject}{templatePosition};
${$wobject}{_WobjectProxy} = ${$originalWobject}{wobjectId};
if ($wobjectProxy->{overrideTitle}) {
${$wobject}{title} = ${$originalWobject}{title};
}
if ($wobjectProxy->{overrideDisplayTitle}) {
${$wobject}{displayTitle} = ${$originalWobject}{displayTitle};
}
if ($wobjectProxy->{overrideDescription}) {
${$wobject}{description} = ${$originalWobject}{description};
}
if ($wobjectProxy->{overrideTemplate}) {
${$wobject}{templateId} = $wobjectProxy->{proxiedTemplateId};
}
}
}
my $cmd = "WebGUI::Wobject::".${$wobject}{namespace};
my $w = eval{$cmd->new($wobject)};
WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root cause: ".$@) if($@);
push(@{$var{'position'.$wobject->{templatePosition}.'_loop'}},{
'wobject.canView'=>WebGUI::Privilege::canViewWobject($wobject->{wobjectId}),
'wobject.canEdit'=>WebGUI::Privilege::canEditWobject($wobject->{wobjectId}),
'wobject.toolbar'=>$wobjectToolbar,
'wobject.namespace'=>$wobject->{namespace},
'wobject.id'=>$wobject->{wobjectId},
'wobject.isInDateRange'=>$w->inDateRange,
'wobject.content'=>eval{$w->www_view}
});
WebGUI::ErrorHandler::fatalError("Wobject runtime error: ${$wobject}{namespace}. Root cause: ".$@) if($@);
}
$sth->finish;
return WebGUI::Template::process(getTemplate(),\%var);
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getTemplateList =head2 getTemplateList
@ -177,12 +251,12 @@ Returns a hash reference containing template ids and template titles for all the
=cut =cut
sub getTemplateList { sub getTemplateList {
return WebGUI::Template::getList("Page"); return WebGUI::Template::getList("page");
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getTemplate ( templateId ) =head2 getTemplate ( [ templateId ] )
Returns an HTML template. Returns an HTML template.
@ -190,16 +264,15 @@ Returns an HTML template.
=item templateId =item templateId
The id of the page template you wish to retrieve. The id of the page template you wish to retrieve. Defaults to the current page's template id.
=back =back
=cut =cut
sub getTemplate { sub getTemplate {
my $template = WebGUI::Template::get($_[0],"Page"); my $templateId = $_[0] || $session{page}{templateId};
$template =~ s/\^(\d+)\;/_newPositionFormat($1)/eg; #compatibility with old-style templates return WebGUI::Template::get($templateId,"page");
return $template;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -33,9 +33,10 @@ This package contains utility methods for WebGUI's style system.
=head1 SYNOPSIS =head1 SYNOPSIS
use WebGUI::Style; use WebGUI::Style;
$style = WebGUI::Style::get(); $template = WebGUI::Style::getTemplate();
$html = WebGUI::Style::process($content);
=head1 METHODS =head1 SUBROUTINES
These subroutines are available from this package: These subroutines are available from this package:
@ -44,56 +45,80 @@ These subroutines are available from this package:
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 get ( ) =head2 getTemplate ( [ templateId ] )
Returns a style based upon the current WebGUI session information. Retrieves the template for this style.
=over
=item templateId
The unique identifier for the template to retrieve. Defaults to the style template tied to the current page.
=back
=cut =cut
sub get { sub getTemplate {
my ($header, $footer, %style, $styleId, @body); my $templateId = shift || $session{page}{styleId};
tie %style, 'Tie::CPHash'; return WebGUI::Template::get($templateId,"style");
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});
my $type = lc($session{setting}{siteicon});
$type =~ s/.*\.(.*?)$/$1/;
$header = $session{setting}{docTypeDec}.'
<!-- WebGUI '.$WebGUI::VERSION.' -->
<html> <head>
<title>'.$session{page}{title}.' - '.$session{setting}{companyName}.'</title>
';
$header .= $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}.'" />';
if ($session{page}{synopsis}) {
$header .= '<meta http-equiv="Description" name="Description" content="'.$session{page}{synopsis}.'" />';
}
}
$header .= '
<meta http-equiv="Content-Type"
content="text/html; charset='.($session{header}{charset}||$session{language}{characterSet}||"ISO-8859-1").'" />
<link rel="icon" href="'.$session{setting}{siteicon}.'" type="image/'.$type.'" />
<link rel="SHORTCUT ICON" href="'.$session{setting}{favicon}.'" />
</head>
';
$header .= $body[0];
$footer = $body[1].' </html>';
return $header.$_[0].$footer;
} }
#-------------------------------------------------------------------
=head2 process ( content [ , templateId ] )
Returns a parsed style with content based upon the current WebGUI session information.
=over
=item content
The content to be parsed into the style. Usually generated by WebGUI::Page::generate().
=item templateId
The unique identifier for the template to retrieve. Defaults to the style template tied to the current page.
=back
=cut
sub process {
my %var;
$var{'body.content'} = shift;
my $templateId = shift;
my $type = lc($session{setting}{siteicon});
$type =~ s/.*\.(.*?)$/$1/;
$var{'head.tags'} = '
<meta name="generator" content="WebGUI '.$WebGUI::VERSION.'" />
<meta http-equiv="Content-Type" content="text/html; charset='.($session{header}{charset}||$session{language}{characterSet}||"ISO-8859-1").'" />
<link rel="icon" href="'.$session{setting}{siteicon}.'" type="image/'.$type.'" />
<link rel="SHORTCUT ICON" href="'.$session{setting}{favicon}.'" />
';
$var{'head.tags'} .= $session{page}{metaTags};
if ($session{var}{adminOn}) {
# This "triple incantation" panders to the delicate tastes of various browsers for reliable cache suppression.
$var{'head.tags'} .= '
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate, max_age=0" />
<meta http-equiv="Expires" content="0" />
';
}
if ($session{page}{defaultMetaTags}) {
$var{'head.tags'} .= '
<meta http-equiv="Keywords" name="Keywords" content="'.$session{page}{title}.', '.$session{setting}{companyName}.'" />
';
if ($session{page}{synopsis}) {
$var{'head.tags'} .= '
<meta http-equiv="Description" name="Description" content="'.$session{page}{synopsis}.'" />
';
}
}
return WebGUI::Template::process(getTemplate($templateId),\%var);
}
1; 1;

View file

@ -663,8 +663,12 @@ sub new {
fieldType=>"hidden" fieldType=>"hidden"
} }
}; };
my %fullProperties;
my $extra = WebGUI::SQL->quickHashRef("select * from ".$properties->{namespace}." where wobjectId='".$properties->{wobjectId}."'");
tie %fullProperties, 'Tie::CPHash';
%fullProperties = (%{$properties},%{$extra});
bless({ bless({
_property=>$properties, _property=>\%fullProperties,
_useTemplate=>$useTemplate, _useTemplate=>$useTemplate,
_useDiscussion=>$useDiscussion, _useDiscussion=>$useDiscussion,
_wobjectProperties=>$wobjectProperties, _wobjectProperties=>$wobjectProperties,