From d744551c31e25d75a12d1bcd264e8b1e6773daaf Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sat, 26 Apr 2008 19:46:13 +0000 Subject: [PATCH] - rfe: Not being limited to single-worded Tags - Exposed keywords API to all assets through edit screen. Now keywords are searchable and add metatags for all assets. --- docs/changelog/7.x.x.txt | 3 +++ lib/WebGUI/Asset.pm | 21 ++++++++++++++-- lib/WebGUI/Keyword.pm | 43 ++++++++++++++++++++++++++++++-- lib/WebGUI/i18n/English/Asset.pm | 6 +++++ 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 59ea33c26..00a498987 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,7 @@ 7.5.11 + - rfe: Not being limited to single-worded Tags + - Exposed keywords API to all assets through edit screen. Now keywords are + searchable and add metatags for all assets. - fix: template variable isUncommitted is not documented in the help - Cleaned the pollution from the forms system. - fix: Event is no longer editable by anyone who can add events diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 22a123d1b..7629c8ef3 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -944,7 +944,16 @@ sub getEditForm { } } - if ($self->session->setting->get("metaDataEnabled")) { + # display keywords field + $tabform->getTab('meta')->text( + name => 'keywords', + value => $self->get('keywords'), + label => $i18n->get('keywords'), + hoverHelp => $i18n->get('keywords help'), + ); + + # metadata / content profiling + if ($self->session->setting->get("metaDataEnabled")) { my $meta = $self->getMetaDataFields(); foreach my $field (keys %$meta) { my $fieldType = $meta->{$field}{fieldType} || "text"; @@ -1944,7 +1953,15 @@ Executes what is necessary to make the view() method work with content chunking. sub prepareView { my $self = shift; $self->{_toolbar} = $self->getToolbar; - $self->session->style->setRawHeadTags($self->getExtraHeadTags); + my $style = $self->session->style; + my @keywords = $self->get('keywords'); + if (scalar @keywords) { + $style->setMeta( { + name => 'keywords', + content => join(',', @keywords), + }); + } + $style->setRawHeadTags($self->getExtraHeadTags); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Keyword.pm b/lib/WebGUI/Keyword.pm index 72f93dcbb..d5e0ba112 100644 --- a/lib/WebGUI/Keyword.pm +++ b/lib/WebGUI/Keyword.pm @@ -157,7 +157,7 @@ sub getKeywordsForAsset { return \@keywords; } else { - return join(" ", @keywords); + return wantarray ? @keywords : join(" ", map({ m/\s/ ? '"' . $_ . '"' : $_ } @keywords)); } } @@ -266,7 +266,7 @@ sub setKeywordsForAsset { $keywords = $options->{keywords}; } else { - @{$keywords} = split(" ", $options->{keywords}); + $keywords = string2list($options->{keywords}); } $self->deleteKeywordsForAsset($options->{asset}); @@ -284,6 +284,45 @@ sub setKeywordsForAsset { } } +#------------------------------------------------------------------------------ + +=head2 string2list ( string ) + +Returns an array reference of phrases. + +=head3 string + +A scalar containing space separated phrases. + +=cut + +sub string2list { + my $text = shift; + return if (ref $text); + my @words = (); + my $word = ''; + my $errorFlag = 0; + while ( defined $text and length $text and not $errorFlag) { + if ($text =~ s/\A(?: ([^\"\s\\]+) | \\(.) )//mx) { + $word .= $1; + } + elsif ($text =~ s/\A"((?:[^\"\\]|\\.)*)"//mx) { + $word .= $1; + } + elsif ($text =~ s/\A\s+//m){ + push(@words, $word); + $word = ''; + } + elsif ($text =~ s/\A"//) { + $errorFlag = 1; + } + else { + $errorFlag = 1; + } + } + push(@words, $word); + return \@words; +} 1; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 6ba3a29de..5e1921c68 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -14,6 +14,12 @@ our $I18N = { context => q|A label for the property that relates assets to keywords.| }, + 'keywords help' => { + message => q|Add some keywords here for this asset. They'll automatically be added to the search index, and as the keywords metatag.|, + lastUpdated => 0, + context => q|help for the keywords property| + }, + 'add the missing page' => { message => q|Add the missing page.|, lastUpdated => 0,