From 3ae3684aea1860dcc33d96baca84ebb6e6dc6a59 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 17 May 2010 13:15:32 -0700 Subject: [PATCH] Better handling for paragraphs in the SC. This code needs to be refactored out and generalized into a method that anything can use. Fixes bug #11563. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/SyndicatedContent.pm | 17 ++++++-- t/Asset/Wobject/SyndicatedContent.t | 41 ++++++++++++++++++- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 7e00e7963..204542fab 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -18,6 +18,7 @@ - added: a new inbox setting which supresses friend rejection notices - fixed #11552: Visitors (and others) can bypass group-by-IP restrictions - fixed #11572: visitors can enter editProfile + - fixed #11563: Syndicated Content - descriptionFirstParagraph cuts off 7.9.4 - We're shipping underscore.js now for its suite of extremely handy utility diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm index d9ed64724..adca46f13 100644 --- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm +++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm @@ -316,10 +316,19 @@ sub getTemplateVariables { $item{descriptionFirst25words} =~ s/(((\S+)\s+){25}).*/$1/s; $item{descriptionFirst10words} = $item{descriptionFirst25words}; $item{descriptionFirst10words} =~ s/(((\S+)\s+){10}).*/$1/s; - $item{descriptionFirst2paragraphs} = $item{description}; - $item{descriptionFirst2paragraphs} =~ s/^((.*?\n){2}).*/$1/s; - $item{descriptionFirstParagraph} = $item{descriptionFirst2paragraphs}; - $item{descriptionFirstParagraph} =~ s/^(.*?\n).*/$1/s; + if ($description =~ /

/) { + my $html = $description; + $html =~ tr/\n/ /s; + my @paragraphs = map { "

".$_."

" } WebGUI::HTML::splitTag($html,3); + $item{descriptionFirstParagraph} = $paragraphs[0]; + $item{descriptionFirst2paragraphs} = join '', @paragraphs[0..1]; + } + else { + $item{descriptionFirst2paragraphs} = $item{description}; + $item{descriptionFirst2paragraphs} =~ s/^((.*?\n){2}).*/$1/s; + $item{descriptionFirstParagraph} = $item{descriptionFirst2paragraphs}; + $item{descriptionFirstParagraph} =~ s/^(.*?\n).*/$1/s; + } $item{descriptionFirst4sentences} = $item{description}; $item{descriptionFirst4sentences} =~ s/^((.*?\.){4}).*/$1/s; $item{descriptionFirst3sentences} = $item{descriptionFirst4sentences}; diff --git a/t/Asset/Wobject/SyndicatedContent.t b/t/Asset/Wobject/SyndicatedContent.t index c4eafdb40..ac29eff1a 100644 --- a/t/Asset/Wobject/SyndicatedContent.t +++ b/t/Asset/Wobject/SyndicatedContent.t @@ -20,7 +20,7 @@ use Data::Dumper; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 25; # increment this value for each test you create +use Test::More tests => 27; # increment this value for each test you create use Test::Deep; use WebGUI::Asset::Wobject::SyndicatedContent; use XML::FeedPP; @@ -114,7 +114,7 @@ ok($processed_template, "A response was received from processTemplate."); # #################################################################### -##Construct a feed with no description, so the resulting template variables can +##Construct a feed with no description so the resulting template variables can ##be checked for an undef description my $feed = XML::FeedPP->new(< @@ -141,6 +141,43 @@ EOFEED my $vars = $syndicated_content->getTemplateVariables($feed); ok( defined $vars->{item_loop}->[0]->{description}, 'getTemplateVariables: description is not undefined'); +##Construct a feed with a wrapped description, to check for paragraph handling. +$feed = XML::FeedPP->new(< + + +The WebGUI buglist +/tbb +Mon, 12 Oct 2009 11:54:28 -0500 + + +Description with wrapped HTML paragraphs +http://www.webgui.org/use/bugs/tracker/11563 +serif +1254854387 +http://www.webgui.org/use/bugs/tracker/11563 +Mon, 14 May 2010 8:12:00 -0500 + +<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> +<p>Third paragraph, for completeness.</p> + + + + +EOFEED + +$vars = $syndicated_content->getTemplateVariables($feed); +is $vars->{item_loop}->[0]->{descriptionFirstParagraph}, +"

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.

", +'... first paragraph, when HTML is used'; +is $vars->{item_loop}->[0]->{descriptionFirst2paragraphs}, +"

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.

No more text is shown of the first paragraph beyond the bold characters of the first line.

", +'... first paragraph, when HTML is used'; + #################################################################### # # generateFeed, hasTerms