From 7cf2c22a95b3e25fc20ec48477590ab852cecf6b Mon Sep 17 00:00:00 2001 From: JT Smith Date: Fri, 7 Apr 2006 17:15:53 +0000 Subject: [PATCH] several small improvements to lots of stuff --- docs/install.txt | 17 +++++++++++---- docs/upgrades/upgrade_6.8.8-6.99.0.pl | 7 ++++++- lib/WebGUI.pm | 8 +++---- lib/WebGUI/Asset.pm | 30 +++++++++++++++++++++++++++ lib/WebGUI/Asset/Post/Thread.pm | 18 ++-------------- lib/WebGUI/Asset/Template.pm | 6 +++++- lib/WebGUI/Asset/Wobject.pm | 19 ++--------------- lib/WebGUI/Asset/Wobject/Layout.pm | 28 +++++++++---------------- lib/WebGUI/Macro/AdSpace.pm | 3 +++ lib/WebGUI/Operation/AdSpace.pm | 13 +++++++++--- lib/WebGUI/Session/Output.pm | 14 +++++++++++++ lib/WebGUI/Session/Style.pm | 23 ++++++++++++++++++++ 12 files changed, 122 insertions(+), 64 deletions(-) diff --git a/docs/install.txt b/docs/install.txt index 2bf39ed23..0e3a5d33b 100644 --- a/docs/install.txt +++ b/docs/install.txt @@ -36,7 +36,9 @@ PerlRequire /data/WebGUI/sbin/preload.perl 5. Extract WebGUI into your webroot. -6. Run the following Database commands. (You should modify the +6. Start MySQL. + +7. Run the following Database commands. (You should modify the commands to match your database, username, and password.) mysql -e "create database WebGUI" @@ -44,9 +46,9 @@ PerlRequire /data/WebGUI/sbin/preload.perl mysql -e "flush privileges" mysql -uwebgui -ppassword WebGUI < docs/create.sql -7. Edit "etc/WebGUI.conf" to match your DB settings and log directory. +8. Edit "etc/WebGUI.conf" to match your DB settings and log directory. -8. Run the following command from your WebGUI/sbin directory to install +9. Run the following command from your WebGUI/sbin directory to install the required perl modules and determine whether you've configured your system correctly. @@ -54,6 +56,13 @@ PerlRequire /data/WebGUI/sbin/preload.perl If it returns all "OK" then you're done. -9. Browse to your site. You'll be guided through a few quick questions +10. Start Apache. + +11. Start Spectre. + + cd /data/WebGUI/sbin + perl spectre.pl --daemon + +12. Browse to your site. You'll be guided through a few quick questions to setup an admin account. diff --git a/docs/upgrades/upgrade_6.8.8-6.99.0.pl b/docs/upgrades/upgrade_6.8.8-6.99.0.pl index 1a3f27bf9..db1f4bc45 100644 --- a/docs/upgrades/upgrade_6.8.8-6.99.0.pl +++ b/docs/upgrades/upgrade_6.8.8-6.99.0.pl @@ -89,7 +89,6 @@ sub addAdManager { title varchar(255) not null, type varchar(15) not null default 'text', storageId varchar(22) binary, - filename varchar(255), adText varchar(255), url text, richMedia text, @@ -105,6 +104,12 @@ sub addAdManager { renderedAd text )"); $session->db->write("alter table advertisement add index adSpaceId_isActive (adSpaceId, isActive)"); + my $macros = $session->config->get("macros"); + $macros->{AdSpace} = "AdSpace"; + $session->config->set("macros",$macros); + my $group = WebGUI::Group->new($session, "new", "pbgroup000000000000017"); + $group->name("Ad Manager"); + $group->description("These users will be able to manage advertisements."); } #------------------------------------------------- diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index 3da2c011f..82bcc14ec 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -105,7 +105,10 @@ sub contentHandler { } $session->http->setCookie("wgSession",$session->var->{_var}{sessionId}) unless $session->var->{_var}{sessionId} eq $session->http->getCookies->{"wgSession"}; $session->http->getHeader(); - $session->output->print($output) unless ($session->http->isRedirect()); + unless ($session->http->isRedirect()) { + $session->output->print($output); + $session->output->goodNightAndGoodLuck(); + } WebGUI::Affiliate::grabReferral($session); # process affilliate tracking request } $session->close; @@ -195,9 +198,6 @@ sub page { if ($output eq "chunked") { $output = undef; } - if ($session->errorHandler->canShowDebug()) { - $output .= $session->errorHandler->showDebug(); - } return $output; } diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index e803c210c..818d8859b 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -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 ] ) diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index c67559e55..b3c8046f3 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -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("~~~"); diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 608c5041b..4eae69028 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -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")); + } } diff --git a/lib/WebGUI/Asset/Wobject.pm b/lib/WebGUI/Asset/Wobject.pm index 912ba1ae9..4d4f0838a 100644 --- a/lib/WebGUI/Asset/Wobject.pm +++ b/lib/WebGUI/Asset/Wobject.pm @@ -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("~~~"); diff --git a/lib/WebGUI/Asset/Wobject/Layout.pm b/lib/WebGUI/Asset/Wobject/Layout.pm index bb87d6ee3..16bcd1c2c 100644 --- a/lib/WebGUI/Asset/Wobject/Layout.pm +++ b/lib/WebGUI/Asset/Wobject/Layout.pm @@ -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; } diff --git a/lib/WebGUI/Macro/AdSpace.pm b/lib/WebGUI/Macro/AdSpace.pm index bebff0a8b..73b3b407e 100644 --- a/lib/WebGUI/Macro/AdSpace.pm +++ b/lib/WebGUI/Macro/AdSpace.pm @@ -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; diff --git a/lib/WebGUI/Operation/AdSpace.pm b/lib/WebGUI/Operation/AdSpace.pm index 15901c918..dc8448f63 100644 --- a/lib/WebGUI/Operation/AdSpace.pm +++ b/lib/WebGUI/Operation/AdSpace.pm @@ -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); diff --git a/lib/WebGUI/Session/Output.pm b/lib/WebGUI/Session/Output.pm index 5e6fef071..2e67ce3c3 100644 --- a/lib/WebGUI/Session/Output.pm +++ b/lib/WebGUI/Session/Output.pm @@ -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(); + } +} #------------------------------------------------------------------- diff --git a/lib/WebGUI/Session/Style.pm b/lib/WebGUI/Session/Style.pm index bcc43137a..ed81191bd 100644 --- a/lib/WebGUI/Session/Style.pm +++ b/lib/WebGUI/Session/Style.pm @@ -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 tag into the of this rendered page for this page view. This is typically used for dynamically adding references to CSS and RSS documents.