Remove HTML from SC sentences and words template variables, and any initial whitespace. Fixes bug #11589.

This commit is contained in:
Colin Kuskie 2010-05-25 12:41:22 -07:00
parent 9cfcf84c2f
commit ab0204dfd9
4 changed files with 42 additions and 32 deletions

View file

@ -9,6 +9,7 @@
- fixed #11582: Registering with a .mobi email address
- fixed #11580: Date not populated for Story Archive RSS feed
- fixed #11587: Thingy, no fields and undefined statement handles
- fixed #11589: Syndicated Content: Return raw text for sentence and word template variables
7.9.5
- Asset->www_copy now has a progress bar

View file

@ -305,17 +305,19 @@ sub getTemplateVariables {
$item{guid} = WebGUI::HTML::filter(scalar $object->guid, 'javascript');
$item{link} = WebGUI::HTML::filter(scalar $object->link, 'javascript');
my $description = WebGUI::HTML::filter(scalar($object->description), 'javascript');
my $raw_description = WebGUI::HTML::filter($description, 'all');
$raw_description =~ s/^\s+//s;
$item{description} = defined $description ? $description : '';
$item{descriptionFirst100words} = $item{description};
$item{descriptionFirst100words} =~ s/(((\S+)\s+){100}).*/$1/s;
$item{descriptionFirst100words} = $raw_description;
$item{descriptionFirst100words} =~ s/(((\S+)\s+){1,100}).*/$1/ms;
$item{descriptionFirst75words} = $item{descriptionFirst100words};
$item{descriptionFirst75words} =~ s/(((\S+)\s+){75}).*/$1/s;
$item{descriptionFirst75words} =~ s/(((\S+)\s+){1,75}).*/$1/ms;
$item{descriptionFirst50words} = $item{descriptionFirst75words};
$item{descriptionFirst50words} =~ s/(((\S+)\s+){50}).*/$1/s;
$item{descriptionFirst50words} =~ s/(((\S+)\s+){1,50}).*/$1/ms;
$item{descriptionFirst25words} = $item{descriptionFirst50words};
$item{descriptionFirst25words} =~ s/(((\S+)\s+){25}).*/$1/s;
$item{descriptionFirst25words} =~ s/(((\S+)\s+){1,25}).*/$1/ms;
$item{descriptionFirst10words} = $item{descriptionFirst25words};
$item{descriptionFirst10words} =~ s/(((\S+)\s+){10}).*/$1/s;
$item{descriptionFirst10words} =~ s/(((\S+)\s+){1,10}).*/$1/ms;
if ($description =~ /<p>/) {
my $html = $description;
$html =~ tr/\n/ /s;
@ -329,12 +331,12 @@ sub getTemplateVariables {
$item{descriptionFirstParagraph} = $item{descriptionFirst2paragraphs};
$item{descriptionFirstParagraph} =~ s/^(.*?\n).*/$1/s;
}
$item{descriptionFirst4sentences} = $item{description};
$item{descriptionFirst4sentences} =~ s/^((.*?\.){4}).*/$1/s;
$item{descriptionFirst4sentences} = $raw_description;
$item{descriptionFirst4sentences} =~ s/^((.*?\.){1,4}).*/$1/s;
$item{descriptionFirst3sentences} = $item{descriptionFirst4sentences};
$item{descriptionFirst3sentences} =~ s/^((.*?\.){3}).*/$1/s;
$item{descriptionFirst3sentences} =~ s/^((.*?\.){1,3}).*/$1/s;
$item{descriptionFirst2sentences} = $item{descriptionFirst3sentences};
$item{descriptionFirst2sentences} =~ s/^((.*?\.){2}).*/$1/s;
$item{descriptionFirst2sentences} =~ s/^((.*?\.){1,2}).*/$1/s;
$item{descriptionFirstSentence} = $item{descriptionFirst2sentences};
$item{descriptionFirstSentence} =~ s/^(.*?\.).*/$1/s;
push @{$var{item_loop}}, \%item;

View file

@ -280,48 +280,48 @@ Feed Order: Items will be in the order they appeared in the feed}
},
'descriptionFirst100words' => {
message => q{The first 100 words of the description.},
lastUpdated => 0,
message => q{The first 100 words of the description, with all HTML removed.},
lastUpdated => 1274815483,
},
'descriptionFirst75words' => {
message => q{The first 75 words of the description.},
lastUpdated => 0,
message => q{The first 75 words of the description, with all HTML removed.},
lastUpdated => 1274815485,
},
'descriptionFirst50words' => {
message => q{The first 50 words of the description.},
lastUpdated => 0,
message => q{The first 50 words of the description, with all HTML removed.},
lastUpdated => 1274815486,
},
'descriptionFirst25words' => {
message => q{The first 25 words of the description.},
lastUpdated => 0,
message => q{The first 25 words of the description, with all HTML removed.},
lastUpdated => 1274815488,
},
'descriptionFirst10words' => {
message => q{The first 10 words of the description.},
lastUpdated => 0,
message => q{The first 10 words of the description, with all HTML removed.},
lastUpdated => 1274815490,
},
'descriptionFirst2paragraphs' => {
message => q{The first 2 paragraphs of the description.},
message => q{The first 2 paragraphs of the description, with all HTML removed.},
lastUpdated => 0,
},
'descriptionFirstParagraph' => {
message => q{The first paragraph of the description.},
message => q{The first paragraph of the description, with all HTML removed.},
lastUpdated => 0,
},
'descriptionFirst4sentences' => {
message => q{The first 4 sentences of the description.},
lastUpdated => 0,
message => q{The first 4 sentences of the description, with all HTML removed.},
lastUpdated => 1274816277,
},
'descriptionFirst3sentences' => {
message => q{The first 3 sentences of the description.},
lastUpdated => 0,
message => q{The first 3 sentences of the description, with all HTML removed.},
lastUpdated => 1274816276,
},
'descriptionFirst2sentences' => {
message => q{The first 2 sentences of the description.},
lastUpdated => 0,
message => q{The first 2 sentences of the description, with all HTML removed.},
lastUpdated => 1274816274,
},
'descriptionFirstSentence' => {
message => q{The first sentence of the description.},
lastUpdated => 0,
message => q{The first sentence of the description, with all HTML removed.},
lastUpdated => 1274816273,
},
};

View file

@ -20,7 +20,7 @@ use Data::Dumper;
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 27; # increment this value for each test you create
use Test::More tests => 29; # increment this value for each test you create
use Test::Deep;
use WebGUI::Asset::Wobject::SyndicatedContent;
use XML::FeedPP;
@ -176,7 +176,14 @@ is $vars->{item_loop}->[0]->{descriptionFirstParagraph},
'... first paragraph, when HTML is used';
is $vars->{item_loop}->[0]->{descriptionFirst2paragraphs},
"<p>In the attached feed, there is a hidden return line character from the Rich Text editor in the first sentence of the description. When using a Syndicated Content for the feed, the variable descriptionFirstParagraph variable cuts off at this return line character, creating invalid markup.</p><p>No more text is shown of the first paragraph beyond the bold characters of the first line.</p>",
'... first paragraph, when HTML is used';
'... first two paragraphs, when HTML is used';
is $vars->{item_loop}->[0]->{descriptionFirst10words},
"In the attached feed, there is a hidden return line ",
'... first 10 words, with HTML stripped';
is $vars->{item_loop}->[0]->{descriptionFirstSentence},
"In the attached feed, there is a hidden return line character from the
Rich Text editor in the first sentence of the description.",
'... first sentence, with HTML stripped';
####################################################################
#