diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index 8eb270c28..6407c0679 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -76,7 +76,7 @@ sub contentHandler { } $session->http->setCookie("wgSession",$session->var->{_var}{sessionId}) unless $session->var->{_var}{sessionId} eq $session->http->getCookies->{"wgSession"}; $session->http->getHeader(); - $r->print($output) unless ($session->http->isRedirect()); + $session->output->print($output) unless ($session->http->isRedirect()); WebGUI::Affiliate::grabReferral($session); # process affilliate tracking request } $session->close; @@ -151,7 +151,7 @@ sub setup { my $session = shift; require WebGUI::Operation::WebGUI; $session->http->getHeader; - $session->request->print(WebGUI::Operation::WebGUI::www_setup($session)); + $session->output->print(WebGUI::Operation::WebGUI::www_setup($session)); } @@ -209,10 +209,10 @@ sub uploadsHandler { sub upgrading { my $session = shift; $session->http->getHeader; - $session->request->print($session->http->getHeader()); + $session->output->print($session->http->getHeader()); open(FILE,"<".$session->config->getWebguiRoot."/docs/maintenance.html"); while () { - $session->request->print($_); + $session->output->print($_); } close(FILE); } diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 2a40828c9..a0bfafd00 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -861,6 +861,7 @@ Returns a toolbar with a set of icons that hyperlink to functions that delete, e sub getToolbar { my $self = shift; + return $self->{_toolbar} if (exists $self->{_toolbar}); my $i18n = WebGUI::International->new($self->session, "Asset"); my $toolbar = $self->session->icon->delete('func=delete',$self->get("url"),$i18n->get(43)); my $commit; @@ -1441,6 +1442,19 @@ sub newByUrl { #------------------------------------------------------------------- +=head2 prepareView ( ) + +Executes what is necessary to make the view() method work with content streaming. This includes things like processing template head tags. + +=cut + +sub prepareView { + my $self = shift; + $self->{_toolbar} = $self->getToolbar; +} + +#------------------------------------------------------------------- + =head2 processPropertiesFromFormPost ( ) Updates current Asset with data from Form. diff --git a/lib/WebGUI/Asset/Wobject/Layout.pm b/lib/WebGUI/Asset/Wobject/Layout.pm index 0a2c3c5d6..9b7e40ed9 100644 --- a/lib/WebGUI/Asset/Wobject/Layout.pm +++ b/lib/WebGUI/Asset/Wobject/Layout.pm @@ -134,6 +134,26 @@ sub getEditForm { +#------------------------------------------------------------------- + +sub prepareView { + my $self = shift; + $self->SUPER::prepareView; + if ($self->session->var->isAdminOn) { + # under normal circumstances we don't put HTML stuff in our code, but this will make it much easier + # for end users to work with our templates + $self->session->style->setScript($self->session->config->get("extrasURL")."/draggable.js",{ type=>"text/javascript" }); + $self->session->style->setLink($self->session->config->get("extrasURL")."/draggable.css",{ type=>"text/css", rel=>"stylesheet", media=>"all" }); + $self->session->style->setRawHeadTags(' + + '); + } +} + #------------------------------------------------------------------- sub viewOriginal { my $self = shift; @@ -276,15 +296,6 @@ sub view { if ($vars{showAdmin}) { # under normal circumstances we don't put HTML stuff in our code, but this will make it much easier # for end users to work with our templates - $self->session->style->setScript($self->session->config->get("extrasURL")."/draggable.js",{ type=>"text/javascript" }); - $self->session->style->setLink($self->session->config->get("extrasURL")."/draggable.css",{ type=>"text/css", rel=>"stylesheet", media=>"all" }); - $self->session->style->setRawHeadTags(' - - '); $vars{"dragger.icon"} = $self->session->icon->drag(); $vars{"dragger.init"} = ' @@ -295,12 +306,12 @@ sub view { } my @parts = split("~~~",$self->processTemplate(\%vars,$self->get("templateId"))); foreach my $part (@parts) { - print $part; + $self->session->output->print($part); my $asset = shift @placeHolder; if (defined $asset) { my $t = [Time::HiRes::gettimeofday()] if ($showPerformance); - print $asset->view; - print "Asset:".Time::HiRes::tv_interval($t) if ($showPerformance); + $self->session->output->print($asset->view); + $self->session->output->print("Asset:".Time::HiRes::tv_interval($t)) if ($showPerformance); } } } @@ -317,11 +328,12 @@ sub www_setContentPositions { sub www_view { my $self = shift; $self->session->http->getHeader; + $self->prepareView; my $style = $self->processStyle("~~~"); my ($head, $foot) = split("~~~",$style); - print $head; + $self->session->output->print($head); $self->view; - print $foot; + $self->session->output->print($foot); } 1; diff --git a/lib/WebGUI/AssetExportHtml.pm b/lib/WebGUI/AssetExportHtml.pm index 04cc4fe12..34246ebf7 100644 --- a/lib/WebGUI/AssetExportHtml.pm +++ b/lib/WebGUI/AssetExportHtml.pm @@ -197,11 +197,11 @@ sub www_exportGenerate { return $self->session->privilege->insufficient() unless ($self->session->user->isInGroup(13)); # This routine is called in an IFRAME and prints status output directly to the browser. $|++; # Unbuffered data output - $self->session->request->print($self->session->http->getHeader()); + $self->session->output->print($self->session->http->getHeader()); my $startTime =$self->session->datetime->time(); my $error = $self->checkExportPath(); if ($error) { - $self->session->request->print($error); + $self->session->output->print($error); return; } my $i18n = WebGUI::International->new($self->session, 'Asset'); @@ -212,9 +212,9 @@ sub www_exportGenerate { my $assets = $self->getLineage(["self","descendants"],{returnObjects=>1,endingLineageLength=>$self->getLineageLength+$self->session->form->process("depth")}); foreach my $asset (@{$assets}) { my $url = $asset->get("url"); - $self->session->request->printf( $i18n->get('exporting page'), $url); + $self->session->output->printf( $i18n->get('exporting page'), $url); unless ($asset->canView($userId)) { - $self->session->request->print ($i18n->get('bad user privileges')."\n"); + $self->session->output->print ($i18n->get('bad user privileges')."\n"); next; } my $path; @@ -235,23 +235,23 @@ sub www_exportGenerate { $path = $self->session->config->get("exportPath") . "/" . $path; eval { mkpath($path) }; if($@) { - $self->session->request->printf($i18n->get('could not create path'), $path, $@); + $self->session->output->printf($i18n->get('could not create path'), $path, $@); return; } } $path .= "/".$filename; eval { open(FILE, "> $path") or die "$!" }; if ($@) { - $self->session->request->printf($i18n->get('could not open path'), $path, $@); + $self->session->output->printf($i18n->get('could not open path'), $path, $@); return; } else { print FILE $asset->exportAsHtml({userId=>$userId,extrasUrl=>$extrasURL,uploadsUrl=>$uploadsURL}); close(FILE); } - $self->session->request->print($i18n->get('done')); + $self->session->output->print($i18n->get('done')); } - $self->session->request->printf($i18n->get('export information'), scalar(@{$assets}), ($self->session->datetime->time()-$startTime)); - $self->session->request->print(''.$i18n->get(493).''); + $self->session->output->printf($i18n->get('export information'), scalar(@{$assets}), ($self->session->datetime->time()-$startTime)); + $self->session->output->print(''.$i18n->get(493).''); return; } diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 5a9569ea1..322b24127 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -27,6 +27,7 @@ use WebGUI::Session::Http; use WebGUI::Session::Icon; use WebGUI::Session::Id; use WebGUI::Session::Os; +use WebGUI::Session::Output; use WebGUI::Session::Privilege; use WebGUI::Session::Scratch; use WebGUI::Session::Setting; @@ -63,6 +64,7 @@ B It is important to distinguish the difference between a WebGUI session $session->form $session->http $session->os + $session->output $session->request $session->scratch $session->server @@ -364,6 +366,23 @@ sub open { return $self; } +#------------------------------------------------------------------- + +=head2 output ( ) + +Returns a WebGUI::Session::Output object. + +=cut + +sub output { + my $self = shift; + unless (exists $self->{_output}) { + $self->{_output} = WebGUI::Session::Output->new($self); + } + return $self->{_output}; +} + + #------------------------------------------------------------------- =head2 os ( ) diff --git a/lib/WebGUI/Session/ErrorHandler.pm b/lib/WebGUI/Session/ErrorHandler.pm index 22fdafc36..ac26bc3c0 100644 --- a/lib/WebGUI/Session/ErrorHandler.pm +++ b/lib/WebGUI/Session/ErrorHandler.pm @@ -172,7 +172,7 @@ sub error { my $self = shift; my $message = shift; $self->getLogger->error($message); - print("\n\n".$message.":\n".$self->getStackTrace()); + $self->session->output->print("\n\n".$message.":\n".$self->getStackTrace()); $self->getLogger->debug("Stack trace for ERROR ".$message."\n".$self->getStackTrace()); $self->session->stow->set("debug_error", $self->session->stow->get("debug_error").$message."\n"); } @@ -193,19 +193,19 @@ sub fatal { Apache2::RequestUtil->request->content_type('text/html') if ($self->session->request); $self->getLogger->fatal($message); $self->getLogger->debug("Stack trace for FATAL ".$message."\n".$self->getStackTrace()); - print $self->session->http->getHeader if ($self->session->request); + $self->session->output->print($self->session->http->getHeader) if ($self->session->request); unless ($self->canShowDebug()) { #NOTE: You can't internationalize this because with some types of errors that would cause an infinite loop. - print "

Problem With Request

+ $self->session->output->print("

Problem With Request

We have encountered a problem with your request. Please use your back button and try again. - If this problem persists, please contact us with what you were trying to do and the time and date of the problem."; - print '
'.$self->session->setting("companyName"); - print '
'.$self->session->setting("companyEmail"); - print '
'.$self->session->setting("companyURL"); + If this problem persists, please contact us with what you were trying to do and the time and date of the problem."); + $self->session->output->print('
'.$self->session->setting("companyName")); + $self->session->output->print('
'.$self->session->setting("companyEmail")); + $self->session->output->print('
'.$self->session->setting("companyURL")); } else { - print "

WebGUI Fatal Error

Something unexpected happened that caused this system to fault.

\n"; - print "

".$message."

\n"; - print $self->showDebug(); + $self->session->output->print("

WebGUI Fatal Error

Something unexpected happened that caused this system to fault.

\n"); + $self->session->output->print("

".$message."

\n"); + $self->session->output->print($self->showDebug()); } $self->session->close(); die $message; diff --git a/lib/WebGUI/Session/Output.pm b/lib/WebGUI/Session/Output.pm new file mode 100644 index 000000000..daea5825c --- /dev/null +++ b/lib/WebGUI/Session/Output.pm @@ -0,0 +1,106 @@ +package WebGUI::Session::Output; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2006 Plain Black Corporation. + ------------------------------------------------------------------- + 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 + ------------------------------------------------------------------- + +=cut + +use strict; +use WebGUI::Macro; + +=head1 NAME + +Package WebGUI::Session::Output + +=head1 DESCRIPTION + +This class provides a handler for returning output. Through this we can apply filters (like macros), and simple page caching mechanisms. + +=head1 SYNOPSIS + + $session->output->print($content); + +=head1 METHODS + +These methods are available from this package: + +=cut + + +#------------------------------------------------------------------- + +=head DESTROY ( ) + +Deconstructor. + +=cut + +sub DESTROY { + my $self = shift; + undef $self; +} + + + +#------------------------------------------------------------------- + +=head2 new ( session ) + +Constructor. + +=head3 session + +A reference to the current session. + +=cut + +sub new { + my $class = shift; + my $session = shift; + bless {_session=>$session}, $class; +} + +#------------------------------------------------------------------- + +=head2 print ( content ) + +Outputs content to either the web server or standard out, depending on which is available. + +=head3 content + +The content to output. + +=cut + +sub print { + my $self = shift; + my $content = shift; + WebGUI::Macro::process($self->session, \$content); + print $content; +} + +#------------------------------------------------------------------- + +=head2 session ( ) + +Returns a reference to the current session. + +=cut + +sub session { + my $self = shift; + return $self->{_session}; +} + + + +1; diff --git a/lib/WebGUI/Session/Style.pm b/lib/WebGUI/Session/Style.pm index 687a5b866..dfc36b5c0 100644 --- a/lib/WebGUI/Session/Style.pm +++ b/lib/WebGUI/Session/Style.pm @@ -195,6 +195,7 @@ props["pageURL"] = "'.$self->session->url->page(undef, undef, 1).'"; return props[propName]; } + '; if ($self->session->user->isInGroup(2)) { # This "triple incantation" panders to the delicate tastes of various browsers for reliable cache suppression. @@ -204,7 +205,6 @@ if ($self->session->user->isInGroup(2)) { '; } - $var{'head.tags'} .= "\n\n"; my $style = WebGUI::Asset::Template->new($self->session,$templateId); my $output; if (defined $style) { @@ -212,10 +212,9 @@ if ($self->session->user->isInGroup(2)) { } else { $output = "WebGUI was unable to instantiate your style template.".$var{'body.content'}; } - WebGUI::Macro::process($self->session,\$output); - my $macroHeadTags = $self->generateAdditionalHeadTags(); - WebGUI::Macro::process($self->session,\$macroHeadTags); - $output =~ s/\<\!-- macro head tags --\>/$macroHeadTags/; + WebGUI::Macro::process(\$output); + my $macroHeadTags = $self->generateAdditionalHeadTags(); + $output =~ s/\<\!--morehead--\>/$macroHeadTags/; if ($self->session->errorHandler->canShowDebug()) { $output .= $self->session->errorHandler->showDebug(); }