diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 34e4bdae6..5008ce3ea 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -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 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 -------------------------------------------------------------------- * If you have any custom Message Board templates they will be diff --git a/docs/temp.sql b/docs/temp.sql new file mode 100644 index 000000000..8c28f0b77 --- /dev/null +++ b/docs/temp.sql @@ -0,0 +1,3 @@ +# add this stuff to previousVersion.sql just before 6.0 release + +delete from style where styleId < 0; diff --git a/docs/upgrades/upgrade_5.5.3-6.0.0.pl b/docs/upgrades/upgrade_5.5.3-6.0.0.pl new file mode 100644 index 000000000..144ccf736 --- /dev/null +++ b/docs/upgrades/upgrade_5.5.3-6.0.0.pl @@ -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}.' + + + <tmpl_var session.page.title> - <tmpl_var session.setting.companyName> + + '.$style->{styleSheet}.' + + '.$header.' + + '.$footer.' + + '; + 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} = ' + + + + + + + '.$template->{template}; + $template->{template} =~ s/\/_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 ""; +} + +#------------------------------------------------------------------- +sub _positionFormat6x { + my $newPositionCode = ' + + +
+ + + + + + + +
+
+
+ '; + return $newPositionCode; +} + + diff --git a/docs/upgrades/upgrade_5.5.3-6.0.0.sql b/docs/upgrades/upgrade_5.5.3-6.0.0.sql index de054314e..5654ead1a 100644 --- a/docs/upgrades/upgrade_5.5.3-6.0.0.sql +++ b/docs/upgrades/upgrade_5.5.3-6.0.0.sql @@ -1,2 +1,14 @@ 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'; diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index 8393b0436..61ef58b82 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -16,7 +16,6 @@ use Tie::CPHash; use WebGUI::Affiliate; use WebGUI::Cache; use WebGUI::ErrorHandler; -use WebGUI::Icon; use WebGUI::International; use WebGUI::Macro; use WebGUI::Operation; @@ -25,110 +24,28 @@ use WebGUI::Session; use WebGUI::SQL; use WebGUI::Style; use WebGUI::Page; -use WebGUI::Template; 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 { - my ($canEdit, $pageEdit, $sth, $wobject, %contentHash, $originalWobject, $sql, $extra, %hash, $cmd, $w, $template,$canEditWobject); - if (WebGUI::Privilege::canViewPage()) { - if ($session{var}{adminOn}) { - $canEdit = WebGUI::Privilege::canEditPage(); - if ($canEdit) { - $pageEdit = "\n
" - .pageIcon() - .deleteIcon('op=deletePage') - .editIcon('op=editPage') - .moveUpIcon('op=movePageUp') - .moveDownIcon('op=movePageDown') - .cutIcon('op=cutPage') - ."\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
" - .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}} .= '
'; - } - - 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}} .= '
'; - $contentHash{"page.position".${$wobject}{templatePosition}} .= ''; - $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}} .= "
\n\n"; - } - } - $sth->finish; - $template = $session{page}{templateId}; - } else { - $contentHash{"page.position1"} = WebGUI::Privilege::noAccess(); + my $content = shift; + if ($session{form}{op} eq "" && $session{setting}{trackPageStatistics} && $session{form}{wid} ne "new") { + WebGUI::SQL->write("insert into pageStatistics (dateStamp, userId, username, ipAddress, userAgent, referer, + pageId, pageTitle, wobjectId, wobjectFunction) values (".time().",".$session{user}{userId} + .",".quote($session{user}{username}).", + ".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}).")"); + } + my $output = WebGUI::Macro::process(WebGUI::Style::process($content)); + if ($session{setting}{showDebug} || ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3))) { + $output .= WebGUI::ErrorHandler::showDebug(); } - return (\%contentHash,$template,$pageEdit); + return $output; } + #------------------------------------------------------------------- sub _processAction { my ($urlString, %form, $pair, @pairs, @param); @@ -223,64 +140,48 @@ sub _processOperations { #------------------------------------------------------------------- sub page { - my ($cache, $debug, $positions, $wobjectOutput, $pageEdit, $httpHeader, $content, $operationOutput, $template); WebGUI::Session::open($_[0],$_[1]); 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)) && not $session{var}{adminOn}); + my ($output, $cache); if ($useCache) { $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(); - $wobjectOutput = _processFunctions(); + my $wobjectOutput = _processFunctions(); if ($operationOutput eq "" && $wobjectOutput eq "" && $session{form}{action2} ne "") { _processAction($session{form}{action2}); $operationOutput = _processOperations(); $wobjectOutput = _processFunctions(); } - if ($operationOutput eq "" && $session{setting}{trackPageStatistics} && $session{form}{wid} ne "new" && $session{header}{mimetype} eq "text/html") { - WebGUI::SQL->write("insert into pageStatistics (dateStamp, userId, username, ipAddress, userAgent, referer, - pageId, pageTitle, wobjectId, wobjectFunction) values (".time().",".$session{user}{userId} - .",".quote($session{user}{username}).", - ".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; + if ($output ne "") { + $output = WebGUI::Session::httpHeader().$output; + } elsif ($session{header}{mimetype} ne "text/html") { + $output = WebGUI::Session::httpHeader().$operationOutput.$wobjectOutput; } elsif ($operationOutput ne "") { - $positions->{"page.position1"} = $operationOutput; + $output = WebGUI::Session::httpHeader()._generatePage($operationOutput); } elsif ($session{page}{redirectURL} && !$session{var}{adminOn}) { - $httpHeader = WebGUI::Session::httpRedirect(WebGUI::Macro::process($session{page}{redirectURL})); - WebGUI::Session::close(); - return $httpHeader; + $output = WebGUI::Session::httpRedirect(WebGUI::Macro::process($session{page}{redirectURL})); } elsif ($session{header}{redirect} ne "") { - $httpHeader = $session{header}{redirect}; - WebGUI::Session::close(); - return $httpHeader; + $output = $session{header}{redirect}; } elsif ($wobjectOutput ne "") { - $positions->{"page.position1"} = $wobjectOutput; - } elsif (!($useCache && defined $content)) { - ($positions, $template, $pageEdit) = _generatePage(); - } - $httpHeader = WebGUI::Session::httpHeader(); - unless ($useCache && defined $content) { - $content = WebGUI::Macro::process(WebGUI::Template::process(WebGUI::Style::get($pageEdit.WebGUI::Page::getTemplate($template)), $positions)); + $output = WebGUI::Session::httpHeader()._generatePage($wobjectOutput); + } else { + $output = _generatePage(WebGUI::Page::generate()); my $ttl; if ($session{user}{userId} == 1) { $ttl = $session{page}{cacheTimeoutVisitor}; } else { $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(); - return $httpHeader.$content.$debug; + return $output; } diff --git a/lib/WebGUI/Operation.pm b/lib/WebGUI/Operation.pm index d990c9b3a..17591d32f 100644 --- a/lib/WebGUI/Operation.pm +++ b/lib/WebGUI/Operation.pm @@ -28,7 +28,6 @@ use WebGUI::Operation::Scratch; use WebGUI::Operation::Search; use WebGUI::Operation::Settings; use WebGUI::Operation::Statistics; -use WebGUI::Operation::Style; use WebGUI::Operation::Template; use WebGUI::Operation::Theme; use WebGUI::Operation::Trash; diff --git a/lib/WebGUI/Operation/Package.pm b/lib/WebGUI/Operation/Package.pm index 9ef91ef6b..62a920f1e 100644 --- a/lib/WebGUI/Operation/Package.pm +++ b/lib/WebGUI/Operation/Package.pm @@ -24,16 +24,12 @@ our @EXPORT = qw(&www_deployPackage &www_selectPackageToDeploy); #------------------------------------------------------------------- sub _duplicateWobjects { - my ($sth, $wobject, $cmd, %hash, $extra, $w, %properties); + my (%properties); tie %properties, 'Tie::CPHash'; - $sth = WebGUI::SQL->read("select * from wobject where pageId=$_[0] order by sequenceNumber"); - while ($wobject = $sth->hashRef) { - $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 = $cmd->new($wobject); + my $sth = WebGUI::SQL->read("select * from wobject where pageId=$_[0] order by sequenceNumber"); + while (my $wobject = $sth->hashRef) { + my $cmd = "WebGUI::Wobject::".${$wobject}{namespace}; + my $w = $cmd->new($wobject); $w->duplicate($_[1]); } $sth->finish; diff --git a/lib/WebGUI/Operation/Page.pm b/lib/WebGUI/Operation/Page.pm index c13d2104c..0f902dc2f 100644 --- a/lib/WebGUI/Operation/Page.pm +++ b/lib/WebGUI/Operation/Page.pm @@ -365,19 +365,18 @@ sub www_editPage { -unitsValue=>$data[1], -uiLevel=>8 ); - %hash = WebGUI::SQL->buildHash("select styleId,name from style where name<>'Reserved' order by name"); if (WebGUI::Privilege::isInGroup(5)) { $subtext = '   '.WebGUI::International::get(6).''; } else { $subtext = ""; } - $f->getTab("layout")->select( + $f->getTab("layout")->template( -name=>"styleId", - -options=>\%hash, -label=>WebGUI::International::get(105), - -value=>[$page{styleId}], + -value=>$page{styleId}, -subtext=>$subtext, + -namespace=>'style', -uiLevel=>5 ); if ($childCount) { diff --git a/lib/WebGUI/Operation/Style.pm b/lib/WebGUI/Operation/Style.pm deleted file mode 100644 index 80d7e72cc..000000000 --- a/lib/WebGUI/Operation/Style.pm +++ /dev/null @@ -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 .= '

'.WebGUI::International::get(42).'

'; - $output .= WebGUI::International::get(155).'

'; - $output .= '

'.WebGUI::International::get(44).''; - $output .= '    '.WebGUI::International::get(45).'
'; - 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\n\n^-;\n\n"; - $style{styleSheet} = ' - - '; - } else { - %style = WebGUI::SQL->quickHash("select * from style where styleId=$session{form}{sid}"); - } - $output .= helpIcon(16); - $output .= '

'.WebGUI::International::get(156).'

'; - $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\n\n^-;\n\n" 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 .= '

'.WebGUI::International::get(157).'

'; - $sth = WebGUI::SQL->read("select styleId,name from style order by name"); - while (@data = $sth->array) { - $row[$i] = '' - .deleteIcon('op=deleteStyle&sid='.$data[0]) - .editIcon('op=editStyle&sid='.$data[0]) - .copyIcon('op=copyStyle&sid='.$data[0]) - .''; - $row[$i] .= ''.$data[1].''; - $i++; - } - $sth->finish; - $p = WebGUI::Paginator->new(WebGUI::URL::page('op=listStyles'),\@row); - $output .= ''; - $output .= $p->getPage($session{form}{pn}); - $output .= '
'; - $output .= $p->getBarTraditional($session{form}{pn}); - return _submenu($output); -} - - - -1; diff --git a/lib/WebGUI/Page.pm b/lib/WebGUI/Page.pm index 2877e221e..11f86e41e 100644 --- a/lib/WebGUI/Page.pm +++ b/lib/WebGUI/Page.pm @@ -20,10 +20,12 @@ use strict; use Tie::IxHash; use WebGUI::ErrorHandler; use WebGUI::HTMLForm; +use WebGUI::Icon; +use WebGUI::Persistent::Tree; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Template; -use WebGUI::Persistent::Tree; +use WebGUI::Utility; our @ISA = qw(WebGUI::Persistent::Tree); @@ -40,8 +42,9 @@ This package provides utility functions for WebGUI's page system. use WebGUI::Page; $integer = WebGUI::Page::countTemplatePositions($templateId); $html = WebGUI::Page::drawTemplate($templateId); + $html = WebGUI::Page::generate(); $hashRef = WebGUI::Page::getTemplateList(); - $template = WebGUI::Page::getTemplate($templateId); + $template = WebGUI::Page::getTemplate(); $hashRef = WebGUI::Page::getTemplatePositions($templateId); $url = WebGUI::Page::makeUnique($url,$pageId); @@ -53,12 +56,6 @@ These functions are available from this package: #------------------------------------------------------------------- -sub _newPositionFormat { - return ""; -} - -#------------------------------------------------------------------- - sub classSettings { return { properties => { @@ -112,7 +109,7 @@ sub countTemplatePositions { my ($template, $i); $template = getTemplate($_[0]); $i = 1; - while ($template =~ m/page\.position$i/) { + while ($template =~ m/position$i\_loop/) { $i++; } return $i-1; @@ -164,10 +161,87 @@ sub drawTemplate { $template = WebGUI::Macro::negate($template); $template =~ s/\.*?\<\/script\>//gi; $template =~ s/\/\/ig; - $template =~ s/\/$1/ig; + $template =~ s/\.*?\<\/tmpl\_loop\>/$1/ig; 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 @@ -177,12 +251,12 @@ Returns a hash reference containing template ids and template titles for all the =cut sub getTemplateList { - return WebGUI::Template::getList("Page"); + return WebGUI::Template::getList("page"); } #------------------------------------------------------------------- -=head2 getTemplate ( templateId ) +=head2 getTemplate ( [ templateId ] ) Returns an HTML template. @@ -190,16 +264,15 @@ Returns an HTML template. =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 =cut sub getTemplate { - my $template = WebGUI::Template::get($_[0],"Page"); - $template =~ s/\^(\d+)\;/_newPositionFormat($1)/eg; #compatibility with old-style templates - return $template; + my $templateId = $_[0] || $session{page}{templateId}; + return WebGUI::Template::get($templateId,"page"); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Style.pm b/lib/WebGUI/Style.pm index cb20c8f75..54b246644 100644 --- a/lib/WebGUI/Style.pm +++ b/lib/WebGUI/Style.pm @@ -33,9 +33,10 @@ This package contains utility methods for WebGUI's style system. =head1 SYNOPSIS 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: @@ -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 -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}); - my $type = lc($session{setting}{siteicon}); - $type =~ s/.*\.(.*?)$/$1/; - $header = $session{setting}{docTypeDec}.' - - - '.$session{page}{title}.' - '.$session{setting}{companyName}.' - '; - $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 .= ''; - $header .= ''; - $header .= ''; - } - if ($session{page}{defaultMetaTags}) { - $header .= ''; - if ($session{page}{synopsis}) { - $header .= ''; - } - } - $header .= ' - - - - - '; - $header .= $body[0]; - $footer = $body[1].' '; - return $header.$_[0].$footer; +sub getTemplate { + my $templateId = shift || $session{page}{styleId}; + return WebGUI::Template::get($templateId,"style"); } +#------------------------------------------------------------------- + +=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'} = ' + + + + + '; + $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'} .= ' + + + + '; + } + if ($session{page}{defaultMetaTags}) { + $var{'head.tags'} .= ' + + '; + if ($session{page}{synopsis}) { + $var{'head.tags'} .= ' + + '; + } + } + return WebGUI::Template::process(getTemplate($templateId),\%var); +} + 1; diff --git a/lib/WebGUI/Wobject.pm b/lib/WebGUI/Wobject.pm index cb6a5a683..7f6f27fb3 100644 --- a/lib/WebGUI/Wobject.pm +++ b/lib/WebGUI/Wobject.pm @@ -663,8 +663,12 @@ sub new { 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({ - _property=>$properties, + _property=>\%fullProperties, _useTemplate=>$useTemplate, _useDiscussion=>$useDiscussion, _wobjectProperties=>$wobjectProperties,