rearranged some of the basic page processing functionality to make implementing urls as resources easier
This commit is contained in:
parent
4f697b6aa6
commit
d0f637ad3e
3 changed files with 111 additions and 101 deletions
|
|
@ -258,4 +258,11 @@ alter table page change id id char(22);
|
|||
delete from incrementer where incrementerId in ("messageLogId","profileCategoryId","templateId","navigationId","passiveProfileLogId","metaData_fieldId","userId","collateralId","pageId","databaseLinkId", "DataForm_entryId", "DataForm_fieldId", "DataForm_tabId", "EventsCalendar_eventId", "EventsCalendar_recurringId", "FileManager_fileId", "forumId", "forumPostId", "forumThreadId", "groupId", "languageId", "Product_benefitId", "Product_featureId", "Product_specificationId", "replacementId", "Survey_answerId", "Survey_id", "Survey_questionId", "Survey_responseId", "USS_id", "USS_submissionId", "wobjectId");
|
||||
alter table forum change postsPerPage threadsPerPage int(11) default 30;
|
||||
alter table forum add postsPerPage int(11) default 10 after threadsPerPage;
|
||||
update page set title='Nameless Root',menuTitle='Nameless Root',urlizedTitle='nameless_root', redirectUrl='/' where pageId=0;
|
||||
create table urls (
|
||||
urlId char(22) not null primary key,
|
||||
url varchar(255) not null unique key,
|
||||
subroutine varchar(255) not null,
|
||||
params text
|
||||
);
|
||||
|
||||
|
|
|
|||
142
lib/WebGUI.pm
142
lib/WebGUI.pm
|
|
@ -61,66 +61,6 @@ sub _processAction {
|
|||
$session{form} = \%form;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _processFunctions {
|
||||
my ($wobject, $output, $proxyWobjectId, $cmd, $w);
|
||||
if (exists $session{form}{func} && exists $session{form}{wid}) {
|
||||
if ($session{form}{func} =~ /^[A-Za-z]+$/) {
|
||||
if ($session{form}{wid} eq "new") {
|
||||
$wobject = {wobjectId=>"new",namespace=>$session{form}{namespace},pageId=>$session{page}{pageId}};
|
||||
} else {
|
||||
$wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobjectId=".quote($session{form}{wid}),WebGUI::SQL->getSlave);
|
||||
if (${$wobject}{namespace} eq "") {
|
||||
WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or "
|
||||
."corrupt, but was requested "
|
||||
."by $session{user}{username} [$session{user}{userId}].");
|
||||
$wobject = ();
|
||||
}
|
||||
}
|
||||
if ($wobject) {
|
||||
if (${$wobject}{pageId} != $session{page}{pageId}) {
|
||||
($proxyWobjectId) = WebGUI::SQL->quickArray("select wobject.wobjectId from
|
||||
wobject,WobjectProxy
|
||||
where wobject.wobjectId=WobjectProxy.wobjectId
|
||||
and wobject.pageId=".quote($session{page}{pageId})."
|
||||
and WobjectProxy.proxiedWobjectId=".quote(${$wobject}{wobjectId}),WebGUI::SQL->getSlave);
|
||||
${$wobject}{_WobjectProxy} = $proxyWobjectId;
|
||||
}
|
||||
unless (${$wobject}{pageId} == $session{page}{pageId}
|
||||
|| ${$wobject}{pageId} == 2
|
||||
|| ${$wobject}{pageId} == 3
|
||||
|| ${$wobject}{_WobjectProxy} ne "") {
|
||||
$output .= WebGUI::International::get(417);
|
||||
WebGUI::ErrorHandler::security("access wobject [".$session{form}{wid}."] on page '"
|
||||
.$session{page}{title}."' [".$session{page}{pageId}."].");
|
||||
} else {
|
||||
if (WebGUI::Page::canView()) {
|
||||
$cmd = "WebGUI::Wobject::".${$wobject}{namespace};
|
||||
my $load = "use ".$cmd; # gotta load the wobject before you can use it
|
||||
eval($load);
|
||||
WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@);
|
||||
$w = eval{$cmd->new($wobject)};
|
||||
WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root Cause: ".$@) if($@);
|
||||
if ($session{form}{func} =~ /^[A-Za-z]+$/) {
|
||||
$cmd = "www_".$session{form}{func};
|
||||
$output = eval{$w->$cmd};
|
||||
WebGUI::ErrorHandler::fatalError("Wobject runtime error: ${$wobject}{namespace} / $session{form}{func}. Root cause: ".$@) if($@);
|
||||
} else {
|
||||
WebGUI::ErrorHandler::security("execute an invalid function: ".$session{form}{func});
|
||||
}
|
||||
} else {
|
||||
$output = WebGUI::Privilege::noAccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WebGUI::ErrorHandler::security("execute an invalid function on wobject "
|
||||
.$session{form}{wid}.": ".$session{form}{func});
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _processOperations {
|
||||
|
|
@ -139,54 +79,54 @@ sub _processOperations {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub page {
|
||||
my $useExistingSession = $_[2];
|
||||
WebGUI::Session::open($_[0],$_[1]) unless ($useExistingSession);
|
||||
my $useCache = ($session{form}{op} eq "" && $session{form}{wid} eq "" && $session{form}{makePrintable} eq ""
|
||||
&& (($session{page}{cacheTimeout} > 10 && $session{user}{userId} !=1) || ($session{page}{cacheTimeoutVisitor} > 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});
|
||||
$output = $cache->get;
|
||||
}
|
||||
my $operationOutput = _processOperations();
|
||||
WebGUI::Affiliate::grabReferral();
|
||||
my $wobjectOutput = _processFunctions();
|
||||
if ($operationOutput eq "" && $wobjectOutput eq "" && $session{form}{action2} ne "") {
|
||||
_processAction($session{form}{action2});
|
||||
$operationOutput = _processOperations();
|
||||
$wobjectOutput = _processFunctions();
|
||||
}
|
||||
if ($output ne "") {
|
||||
# using cache
|
||||
WebGUI::PassiveProfiling::addPage(); # add wobjects on page to passive profile log
|
||||
} elsif (WebGUI::HTTP::getMimeType() ne "text/html") {
|
||||
$output = $operationOutput.$wobjectOutput;
|
||||
} elsif ($operationOutput ne "") {
|
||||
$output = _generatePage($operationOutput);
|
||||
} elsif ($wobjectOutput ne "") {
|
||||
$output = _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($output, $ttl) if ($useCache);
|
||||
}
|
||||
my $httpHeader = WebGUI::HTTP::getHeader();
|
||||
my $webguiRoot = shift;
|
||||
my $configFile = shift;
|
||||
my $useExistingSession = shift; # used for static page generation functions where you may generate more than one page at a time.
|
||||
WebGUI::Session::open($webguiRoot,$configFile) unless ($useExistingSession);
|
||||
|
||||
# JT: don't forget to do something with action 2
|
||||
|
||||
my $output = _processOperations();
|
||||
if ($output ne "") {
|
||||
$output = _generatePage($output);
|
||||
} else {
|
||||
my $useCache = (
|
||||
$session{form}{op} eq "" &&
|
||||
$session{form}{func} eq "" &&
|
||||
(
|
||||
( $session{page}{cacheTimeout} > 10 && $session{user}{userId} !=1) ||
|
||||
( $session{page}{cacheTimeoutVisitor} > 10 && $session{user}{userId} == 1)
|
||||
) &&
|
||||
not $session{var}{adminOn}
|
||||
);
|
||||
my $cache;
|
||||
if ($useCache) {
|
||||
$cache = WebGUI::Cache->new("page_".$session{page}{pageId}."_".$session{user}{userId});
|
||||
$output = $cache->get;
|
||||
}
|
||||
unless ($output) {
|
||||
$output = WebGUI::Page::generate();
|
||||
if (WebGUI::HTTP::getMimeType() eq "text/html") {
|
||||
$output = _generatePage($output);
|
||||
}
|
||||
my $ttl;
|
||||
if ($session{user}{userId} == 1) {
|
||||
$ttl = $session{page}{cacheTimeoutVisitor};
|
||||
} else {
|
||||
$ttl = $session{page}{cacheTimeout};
|
||||
}
|
||||
$cache->set($output, $ttl) if ($useCache);
|
||||
}
|
||||
WebGUI::PassiveProfiling::addPage(); # add wobjects on page to passive profile log
|
||||
}
|
||||
WebGUI::Affiliate::grabReferral(); # process affilliate tracking request
|
||||
my $httpHeader = WebGUI::HTTP::getHeader();
|
||||
# This allows an operation or wobject to write directly to the browser.
|
||||
if ($session{page}{empty}) {
|
||||
$httpHeader = $output = undef;
|
||||
}
|
||||
|
||||
WebGUI::Session::close() unless ($useExistingSession);
|
||||
|
||||
return $httpHeader.$output;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -125,6 +125,67 @@ These functions are available from this package:
|
|||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _processWobjectFunctions {
|
||||
my ($wobject, $output, $proxyWobjectId, $cmd, $w);
|
||||
if (exists $session{form}{func} && exists $session{form}{wid}) {
|
||||
if ($session{form}{func} =~ /^[A-Za-z]+$/) {
|
||||
if ($session{form}{wid} eq "new") {
|
||||
$wobject = {wobjectId=>"new",namespace=>$session{form}{namespace},pageId=>$session{page}{pageId}};
|
||||
} else {
|
||||
$wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobjectId=".quote($session{form}{wid}),WebGUI::SQL->getSlave);
|
||||
if (${$wobject}{namespace} eq "") {
|
||||
WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or "
|
||||
."corrupt, but was requested "
|
||||
."by $session{user}{username} [$session{user}{userId}].");
|
||||
$wobject = ();
|
||||
}
|
||||
}
|
||||
if ($wobject) {
|
||||
if (${$wobject}{pageId} != $session{page}{pageId}) {
|
||||
($proxyWobjectId) = WebGUI::SQL->quickArray("select wobject.wobjectId from
|
||||
wobject,WobjectProxy
|
||||
where wobject.wobjectId=WobjectProxy.wobjectId
|
||||
and wobject.pageId=".quote($session{page}{pageId})."
|
||||
and WobjectProxy.proxiedWobjectId=".quote(${$wobject}{wobjectId}),WebGUI::SQL->getSlave);
|
||||
${$wobject}{_WobjectProxy} = $proxyWobjectId;
|
||||
}
|
||||
unless (${$wobject}{pageId} == $session{page}{pageId}
|
||||
|| ${$wobject}{pageId} == 2
|
||||
|| ${$wobject}{pageId} == 3
|
||||
|| ${$wobject}{_WobjectProxy} ne "") {
|
||||
$output .= WebGUI::International::get(417);
|
||||
WebGUI::ErrorHandler::security("access wobject [".$session{form}{wid}."] on page '"
|
||||
.$session{page}{title}."' [".$session{page}{pageId}."].");
|
||||
} else {
|
||||
if (WebGUI::Page::canView()) {
|
||||
$cmd = "WebGUI::Wobject::".${$wobject}{namespace};
|
||||
my $load = "use ".$cmd; # gotta load the wobject before you can use it
|
||||
eval($load);
|
||||
WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@);
|
||||
$w = eval{$cmd->new($wobject)};
|
||||
WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root Cause: ".$@) if($@);
|
||||
if ($session{form}{func} =~ /^[A-Za-z]+$/) {
|
||||
$cmd = "www_".$session{form}{func};
|
||||
$output = eval{$w->$cmd};
|
||||
WebGUI::ErrorHandler::fatalError("Wobject runtime error: ${$wobject}{namespace} / $session{form}{func}. Root cause: ".$@) if($@);
|
||||
} else {
|
||||
WebGUI::ErrorHandler::security("execute an invalid function: ".$session{form}{func});
|
||||
}
|
||||
} else {
|
||||
$output = WebGUI::Privilege::noAccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WebGUI::ErrorHandler::security("execute an invalid function on wobject "
|
||||
.$session{form}{wid}.": ".$session{form}{func});
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 add
|
||||
|
|
@ -485,6 +546,8 @@ Generates the content of the page.
|
|||
|
||||
sub generate {
|
||||
return WebGUI::Privilege::noAccess() unless (canView());
|
||||
my $output = _processWobjectFunctions();
|
||||
return $output if ($output);
|
||||
my %var;
|
||||
if ($session{page}{defaultMetaTags}) {
|
||||
WebGUI::Style::setMeta({'http-equiv'=>"Keywords", name=>"Keywords", content=>join(",",$session{page}{title},$session{page}{menuTitle})});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue