From 2b3b3fd4585bbdfdcc10f7fcc5276db03a22106f Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 26 Nov 2008 21:24:44 +0000 Subject: [PATCH] Remove the headblock property from the Template Asset, and merge it into extra head tags. Style templates are not allowed to have extra head tags. --- docs/changelog/7.x.x.txt | 2 +- docs/gotcha.txt | 7 ++- docs/upgrades/upgrade_7.6.4-7.6.5.pl | 33 ++++++++++++- lib/WebGUI/Asset.pm | 56 ++++++++++++++++------- lib/WebGUI/Asset/Template.pm | 40 ++++++++++------ lib/WebGUI/Asset/Wobject.pm | 4 +- lib/WebGUI/i18n/English/Asset_Template.pm | 12 ----- 7 files changed, 108 insertions(+), 46 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ad391953e..307791612 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -12,6 +12,7 @@ - fixed #4159: more menu doesn't appear for current asset on crumb trail - fixed #9157: another typ-o in i18n - fixed #9112: Thingy View Thing screen doesn't preserve newlines + - fixed #9155: purpose of "headblock" duplicates "extra head tags" 7.6.4 - Survey now will show progress and time limit. @@ -79,7 +80,6 @@ - fixed #9140: Date format error when adding tasks to PM - fixed #8800: Errors in POD of Asset-related mix-in modules (Bernd Kalbfuß-Zimmermann) - fixed #9143: Yes No user profile fields problem when default == 1 - - fixed #9155: purpose of "headblock" duplicates "extra head tags" 7.5.34 - fixed: Regression with ProfileField->formField. Added tests to prevent future regression diff --git a/docs/gotcha.txt b/docs/gotcha.txt index c50a07686..f972ee028 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -10,8 +10,13 @@ save you many hours of grief. 7.6.5 -------------------------------------------------------------------- * The deprecated use of Graphics::Magick has been eliminated. WebGUI uses - Image::Magick exclusively for all image processing functions once again. + Image::Magick exclusively for all image processing functions once again. + * The Head Block of Templates has been merged into the Extra Head + Tags field. Extra Head Tags are now added for all templates and + assets included on a page, except for Style templates, which do + not have Extra Head Tags. Existing Extra Head Tags for Style + templates have been removed. 7.6.4 -------------------------------------------------------------------- diff --git a/docs/upgrades/upgrade_7.6.4-7.6.5.pl b/docs/upgrades/upgrade_7.6.4-7.6.5.pl index 02a4c77cf..b1ad6b7c3 100644 --- a/docs/upgrades/upgrade_7.6.4-7.6.5.pl +++ b/docs/upgrades/upgrade_7.6.4-7.6.5.pl @@ -20,6 +20,7 @@ use Getopt::Long; use WebGUI::Session; use WebGUI::Storage; use WebGUI::Asset; +use WebGUI::Asset; my $toVersion = "7.6.5"; # make this match what version you're going to @@ -27,12 +28,42 @@ my $quiet; # this line required my $session = start(); # this line required -fixAccountMisspellings( $session ); +fixAccountMisspellings( $session ); +removeTemplateHeadBlock( $session ); # upgrade functions go here finish($session); # this line required +#---------------------------------------------------------------------------- +# Describe what our function does +sub removeTemplateHeadBlock { + my $session = shift; + print "\tMerging Template head blocks into the Extra Head Tags field... " unless $quiet; + my $sth = $session->db->prepare('select assetId, revisionDate, headBlock from template'); + $sth->execute(); + TMPL: while (my $templateData = $sth->hashRef) { + my $template = WebGUI::Asset->new($session, + $templateData->{assetId}, 'WebGUI::Asset::Template', + $templateData->{revisionDate}, + ); + next TMPL unless defined $template; + if ($template->get('namespace') eq 'style') { + $template->update({ + extraHeadTags => '', + }); + } + else { + $template->update({ + extraHeadTags => $template->getExtraHeadTags . $templateData->{headBlock}, + }); + } + } + $session->db->write('ALTER TABLE template DROP COLUMN headBlock'); + # and here's our code + print "DONE!\n" unless $quiet; +} + #---------------------------------------------------------------------------- # Describe what our function does #sub exampleFunction { diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 62fdd3f6d..61cd1a62d 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -371,7 +371,7 @@ sub definition { uiLevel=>3, fieldType=>'text', defaultValue=>'', - filter=>'fixUrl' + filter=>'fixUrl', }, isHidden=>{ tab=>"display", @@ -387,7 +387,7 @@ sub definition { hoverHelp=>$i18n->get('940 description'), uiLevel=>9, fieldType=>'yesNo', - defaultValue=>0 + defaultValue=>0, }, encryptPage=>{ fieldType => ($session->config->get("sslEnabled") ? 'yesNo' : 'hidden'), @@ -404,7 +404,7 @@ sub definition { uiLevel=>6, fieldType=>'user', filter=>'fixId', - defaultValue=>'3' + defaultValue=>'3', }, groupIdView=>{ tab=>"security", @@ -413,7 +413,7 @@ sub definition { uiLevel=>6, fieldType=>'group', filter=>'fixId', - defaultValue=>'7' + defaultValue=>'7', }, groupIdEdit=>{ tab=>"security", @@ -423,7 +423,7 @@ sub definition { uiLevel=>6, fieldType=>'group', filter=>'fixId', - defaultValue=>'4' + defaultValue=>'4', }, synopsis=>{ tab=>"meta", @@ -431,15 +431,16 @@ sub definition { hoverHelp=>$i18n->get('412 description'), uiLevel=>3, fieldType=>'textarea', - defaultValue=>undef + defaultValue=>undef, }, extraHeadTags=>{ tab=>"meta", label=>$i18n->get("extra head tags"), hoverHelp=>$i18n->get('extra head tags description'), uiLevel=>5, - fieldType=>'textarea', - defaultValue=>undef + fieldType=>'codearea', + defaultValue=>undef, + customDrawMethod => 'drawExtraHeadTags', }, isPackage=>{ label=>$i18n->get("make package"), @@ -447,7 +448,7 @@ sub definition { hoverHelp=>$i18n->get('make package description'), uiLevel=>7, fieldType=>'yesNo', - defaultValue=>0 + defaultValue=>0, }, isPrototype=>{ tab=>"meta", @@ -455,7 +456,7 @@ sub definition { hoverHelp=>$i18n->get('make prototype description'), uiLevel=>9, fieldType=>'yesNo', - defaultValue=>0 + defaultValue=>0, }, isExportable=>{ tab=>'meta', @@ -476,7 +477,7 @@ sub definition { status=>{ noFormPost=>1, fieldType=>'hidden', - defaultValue=>'pending' + defaultValue=>'pending', }, lastModified=>{ noFormPost=>1, @@ -486,7 +487,7 @@ sub definition { assetSize=>{ noFormPost=>1, fieldType=>'hidden', - defaultValue=>0 + defaultValue=>0, }, ); push(@{$definition}, { @@ -502,6 +503,25 @@ sub definition { } +#------------------------------------------------------------------- + +=head2 drawExtraHeadTags ( ) + +Draw the Extra Head Tags. Done with a customDrawMethod because the Template +will override this. + +=cut + +sub drawExtraHeadTags { + my ($self, $params) = @_; + return WebGUI::Form::codearea($self->session, { + name => $params->{name}, + value => $self->get($params->{name}), + defaultValue => undef, + }); +} + + #------------------------------------------------------------------- =head2 DESTROY ( ) @@ -1958,7 +1978,7 @@ OUTPUT =head2 prepareView ( ) -Executes what is necessary to make the view() method work with content chunking. This includes things like processing template head tags. +Executes what is necessary to make the view() method work with content chunking. =cut @@ -1970,12 +1990,11 @@ sub prepareView { my $style = $self->session->style; my @keywords = @{WebGUI::Keyword->new($self->session)->getKeywordsForAsset({asset=>$self, asArrayRef=>1})}; if (scalar @keywords) { - $style->setMeta( { + $style->setMeta({ name => 'keywords', content => join(',', @keywords), - }); + }); } - $style->setRawHeadTags($self->getExtraHeadTags); } #------------------------------------------------------------------- @@ -2114,7 +2133,9 @@ sub processTemplate { =head2 processStyle ( html ) -Returns some HTML wrappered in a style. Should be overridden by subclasses, because this one actually doesn't do anything other than return the html back to you. +Returns some HTML wrappered in a style. Should be overridden by subclasses, because +this one actually doesn't do anything other than return the html back to you and +adds the Asset's extraHeadTags into the raw head tags. =head3 html @@ -2124,6 +2145,7 @@ The content to wrap up. sub processStyle { my ($self, $output) = @_; + $self->session->style->setRawHeadTags($self->getExtraHeadTags); return $output; } diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 2bb72dd68..23594a104 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -90,10 +90,6 @@ sub definition { fieldType => 'selectList', defaultValue => [$session->config->get("defaultTemplateParser")], }, - headBlock => { - fieldType => "codearea", - defaultValue => undef, - }, namespace => { fieldType => 'combo', defaultValue => undef, @@ -103,6 +99,25 @@ sub definition { return $class->SUPER::definition($session,$definition); } +#------------------------------------------------------------------- + +=head2 drawExtraHeadTags ( ) + +Override the master drawExtraHeadTags to prevent Style template from having +Extra Head Tags. + +=cut + +sub drawExtraHeadTags { + my ($self, $params) = @_; + if ($self->get('namespace') eq 'style') { + my $i18n = WebGUI::International->new($self->session); + return $i18n->get(881); + } + return $self->SUPER::drawExtraHeadTags($params); +} + + #------------------------------------------------------------------- =head2 duplicate @@ -125,15 +140,20 @@ sub processPropertiesFromFormPost { my $self = shift; $self->SUPER::processPropertiesFromFormPost; # TODO: Perhaps add a way to check template syntax before it blows stuff up? + my %data; + my $needsUpdate = 0; if ($self->getValue("parser") ne $self->session->form->process("parser","className") && ($self->session->form->process("parser","className") ne "")) { - my %data; if (isIn($self->session->form->process("parser","className"),@{$self->session->config->get("templateParsers")})) { %data = ( parser => $self->session->form->process("parser","className") ); } else { %data = ( parser => $self->session->config->get("defaultTemplateParser") ); } - $self->update(\%data); } + if ($self->session->form->process("namespace") eq 'style') { + $needsUpdate = 1; + $data{extraHeadTags} = ''; + } + $self->update(\%data) if $needsUpdate; } #------------------------------------------------------------------- @@ -185,12 +205,6 @@ sub getEditForm { -syntax => "html", -value=>$self->getValue("template") ); - $tabform->getTab("properties")->codearea( - -name=>"headBlock", - -label=>$i18n->get('head block'), - -hoverHelp=>$i18n->get('head block description'), - -value=>$self->getValue("headBlock") - ); if($self->session->config->get("templateParsers")){ my @temparray = @{$self->session->config->get("templateParsers")}; tie my %parsers, 'Tie::IxHash'; @@ -323,7 +337,7 @@ sub prepare { my $templateHeadersSent = $self->session->stow->get("templateHeadersSent") || []; my @sent = @{$templateHeadersSent}; unless (isIn($self->getId, @sent)) { # don't send head block if we've already sent it for this template - $self->session->style->setRawHeadTags($self->getParser($self->session, $self->get('parser'))->process($self->get('headBlock'), $vars)); + $self->session->style->setRawHeadTags($self->getParser($self->session, $self->get('parser'))->process($self->getExtraHeadTags, $vars)); } push(@sent, $self->getId); $self->session->stow->set("templateHeadersSent", \@sent); diff --git a/lib/WebGUI/Asset/Wobject.pm b/lib/WebGUI/Asset/Wobject.pm index 0570f8aa4..56fb93a64 100644 --- a/lib/WebGUI/Asset/Wobject.pm +++ b/lib/WebGUI/Asset/Wobject.pm @@ -370,7 +370,8 @@ sub processPropertiesFromFormPost { =head2 processStyle ( output ) -Returns output parsed under the current style. +Returns output parsed under the current style. Sets the Asset's extra head tags +into the raw head tags, too. =head3 output @@ -381,6 +382,7 @@ An HTML blob to be parsed into the current style. sub processStyle { my $self = shift; my $output = shift; + $self->session->style->setRawHeadTags($self->getExtraHeadTags); return $self->session->style->process($output,$self->get("styleTemplateId")); } diff --git a/lib/WebGUI/i18n/English/Asset_Template.pm b/lib/WebGUI/i18n/English/Asset_Template.pm index 620c8a5b5..dca29af5c 100644 --- a/lib/WebGUI/i18n/English/Asset_Template.pm +++ b/lib/WebGUI/i18n/English/Asset_Template.pm @@ -2,18 +2,6 @@ package WebGUI::i18n::English::Asset_Template; use strict; our $I18N = { - 'head block' => { - message => q|Head Block|, - context => q|label for the get edit form where users should put things that go in the html head block|, - lastUpdated => 0, - }, - - 'head block description' => { - message => q|Put meta tags, script tags, link tables, style sheets, and anything else here that you want to appear in the head block of the HTML document.|, - context => q|hover help for the head block field|, - lastUpdated => 0, - }, - 'style wizard' => { message => q|Style Wizard|, context => q|Label for link to engage the style wizard.|,