several small improvements to lots of stuff

This commit is contained in:
JT Smith 2006-04-07 17:15:53 +00:00
parent d272e7de58
commit 7cf2c22a95
12 changed files with 122 additions and 64 deletions

View file

@ -138,6 +138,36 @@ sub canView {
}
#-------------------------------------------------------------------
=head2 checkView ( )
Returns error messages if a user can't view due to publishing problems, otherwise it sets the cookie and returns undef. This is sort of a hack until we find something better.
=cut
sub checkView {
my $self = shift;
unless ($self->canView) {
if ($self->get("state") eq "published") { # no privileges, make em log in
return $self->session->privilege->noAccess();
} elsif ($self->session->var->get("adminOn") && $self->get("state") =~ /^trash/) { # show em trash
$self->session->http->setRedirect($self->getUrl("func=manageTrash"));
return undef;
} elsif ($self->session->var->get("adminOn") && $self->get("state") =~ /^clipboard/) { # show em clipboard
$self->session->http->setRedirect($self->getUrl("func=manageClipboard"));
return undef;
} else { # tell em it doesn't exist anymore
$self->session->http->setStatus("410");
return WebGUI::Asset->getNotFound($self->session)->www_view;
}
}
$self->logView();
# must find a way to do this next line better
$self->session->http->setCookie("wgSession",$self->session->var->{_var}{sessionId}) unless $self->session->var->{_var}{sessionId} eq $self->session->http->getCookies->{"wgSession"};
return undef;
}
#-------------------------------------------------------------------
=head2 definition ( [ definition ] )

View file

@ -1033,22 +1033,8 @@ Renders self->view based upon current style, subject to timeouts. Returns Privil
sub www_view {
my $self = shift;
return $self->session->privilege->noAccess() unless $self->canView;
unless ($self->canView) {
if ($self->get("state") eq "published") { # no privileges, make em log in
return $self->session->privilege->noAccess();
} elsif ($self->session->var->get("adminOn") && $self->get("state") =~ /^trash/) { # show em trash
$self->session->http->setRedirect($self->getUrl("func=manageTrash"));
return undef;
} elsif ($self->session->var->get("adminOn") && $self->get("state") =~ /^clipboard/) { # show em clipboard
$self->session->http->setRedirect($self->getUrl("func=manageClipboard"));
return undef;
} else { # tell em it doesn't exist anymore
$self->session->http->setStatus("410");
return WebGUI::Asset->getNotFound($self->session)->www_view;
}
}
# must find a way to do this next line better
$self->session->http->setCookie("wgSession",$self->session->var->{_var}{sessionId}) unless $self->session->var->{_var}{sessionId} eq $self->session->http->getCookies->{"wgSession"};
my $check = $self->checkView;
return $check if (defined $check);
$self->session->http->getHeader;
$self->prepareView;
my $style = $self->getParent->processStyle("~~~");

View file

@ -266,7 +266,11 @@ This method sets the tags from the head block parameter of the template into the
sub prepare {
my $self = shift;
$self->{_prepared} = 1;
$self->session->style->setRawHeadTags($self->get("headBlock"));
if ($self->session->style->sent) {
$self->session->output->print($self->get("headBlock"));
} else {
$self->session->style->setRawHeadTags($self->get("headBlock"));
}
}

View file

@ -552,23 +552,8 @@ Renders self->view based upon current style, subject to timeouts. Returns Privil
sub www_view {
my $self = shift;
unless ($self->canView) {
if ($self->get("state") eq "published") { # no privileges, make em log in
return $self->session->privilege->noAccess();
} elsif ($self->session->var->get("adminOn") && $self->get("state") =~ /^trash/) { # show em trash
$self->session->http->setRedirect($self->getUrl("func=manageTrash"));
return undef;
} elsif ($self->session->var->get("adminOn") && $self->get("state") =~ /^clipboard/) { # show em clipboard
$self->session->http->setRedirect($self->getUrl("func=manageClipboard"));
return undef;
} else { # tell em it doesn't exist anymore
$self->session->http->setStatus("410");
return WebGUI::Asset->getNotFound($self->session)->www_view;
}
}
$self->logView();
# must find a way to do this next line better
$self->session->http->setCookie("wgSession",$self->session->var->{_var}{sessionId}) unless $self->session->var->{_var}{sessionId} eq $self->session->http->getCookies->{"wgSession"};
my $check = $self->checkView;
return $check if (defined $check);
$self->session->http->getHeader;
$self->prepareView;
my $style = $self->processStyle("~~~");

View file

@ -265,31 +265,23 @@ sub www_setContentPositions {
#-------------------------------------------------------------------
sub www_view {
my $self = shift;
# slashdot / burst protection
# slashdot / burst protection hack
if ($self->session->var->get("userId") eq "1" && $self->session->form->param("func") eq "" && $self->session->form->param("op") eq "") {
unless ($self->canView) {
if ($self->get("state") eq "published") { # no privileges, make em log in
return $self->session->privilege->noAccess();
} elsif ($self->session->var->get("adminOn") && $self->get("state") =~ /^trash/) { # show em trash
$self->session->http->setRedirect($self->getUrl("func=manageTrash"));
return undef;
} elsif ($self->session->var->get("adminOn") && $self->get("state") =~ /^clipboard/) { # show em clipboard
$self->session->http->setRedirect($self->getUrl("func=manageClipboard"));
return undef;
} else { # tell em it doesn't exist anymore
$self->session->http->setStatus("410");
return WebGUI::Asset->getNotFound($self->session)->www_view;
}
}
$self->logView();
# must find a way to do this next line better
$self->session->http->setCookie("wgSession",$self->session->var->{_var}{sessionId}) unless $self->session->var->{_var}{sessionId} eq $self->session->http->getCookies->{"wgSession"};
my $check = $self->checkView;
return $check if (defined $check);
my $cache = WebGUI::Cache->new($self->session, "view_".$self->getId);
my $out = $cache->get if defined $cache;
unless ($out) {
$self->prepareView;
$self->session->stow->set("cacheFixOverride", 1);
$out = $self->processStyle($self->view);
$cache->set($out, 60);
$self->session->stow->delete("cacheFixOverride");
}
while ($out =~ /(\[AD\:(\w+)\])/gs) {
my $ad = $1;
my $macro = "^AdSpace(".$2.");";
$out =~ s/\Q$ad/$macro/ges;
}
return $out;
}

View file

@ -33,6 +33,9 @@ The unique name of an Ad Space.
sub process {
my $session = shift;
my $name = shift;
if ($session->stow->get("cacheFixOverride")) {
return "[AD:".$name."]";
}
my $adSpace = WebGUI::AdSpace->newByName($session, $name);
return undef unless defined $adSpace;
return $adSpace->displayImpression;

View file

@ -264,11 +264,17 @@ Edit or add an ad space form.
sub www_editAdSpace {
my $session = shift;
my $adSpace = shift;
return $session->privilege->insufficient unless ($session->user->isInGroup("pbgroup000000000000017"));
my $id = $session->form->param("adSpaceId") || "new";
my $id;
if (defined $adSpace) {
$id = $adSpace->getId;
} else {
$id = $session->form->param("adSpaceId") || "new";
$adSpace = WebGUI::AdSpace->new($session, $id);
}
my $ac = WebGUI::AdminConsole->new($session,"adSpace");
my $i18n = WebGUI::International->new($session,"AdSpace");
my $adSpace = WebGUI::AdSpace->new($session, $id);
$ac->addSubmenuItem($session->url->page("op=editAd;adSpaceId=".$id), $i18n->get("add an ad")) if defined $adSpace;
$ac->addSubmenuItem($session->url->page("op=manageAdSpaces"), $i18n->get("manage ad spaces"));
my $f = WebGUI::HTMLForm->new($session);
@ -349,7 +355,8 @@ sub www_editAdSpaceSave {
height=>$session->form->process("height", "integer"),
);
if ($session->form->param("adSpaceId") eq "new") {
WebGUI::AdSpace->create($session, \%properties);
my $adSpace = WebGUI::AdSpace->create($session, \%properties);
return www_editAdSpace($session, $adSpace);
} else {
my $adSpace = WebGUI::AdSpace->new($session, $session->form->param("adSpaceId"));
$adSpace->set(\%properties);

View file

@ -50,6 +50,20 @@ sub DESTROY {
}
#-------------------------------------------------------------------
=head2 goodNightAndGoodLuck ( )
This should be called at the end of all possible output HTML output. It handles printing out debug and other maintenance tasks.
=cut
sub goodNightAndGoodLuck {
my $self = shift;
if ($self->session->errorHandler->canShowDebug()) {
print $self->session->errorHandler->showDebug();
}
}
#-------------------------------------------------------------------

View file

@ -166,6 +166,7 @@ The unique identifier for the template to retrieve.
sub process {
my $self = shift;
$self->sent(1);
my %var;
$var{'body.content'} = shift;
my $templateId = shift;
@ -234,6 +235,28 @@ sub session {
#-------------------------------------------------------------------
=head2 sent ( boolean )
Returns a boolean indicating whether the style has already been sent. This is important when trying to set things to the HTML head block.
=head3 boolean
Set the value.
=cut
sub sent {
my $self = shift;
my $boolean = shift;
if (defined $boolean) {
$self->session->stow->set("styleHeadSent",$boolean);
return $boolean;
}
return $self->session->stow->get("styleHeadSent");
}
#-------------------------------------------------------------------
=head2 setLink ( url, params )
Sets a <link> tag into the <head> of this rendered page for this page view. This is typically used for dynamically adding references to CSS and RSS documents.