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.

This commit is contained in:
Colin Kuskie 2010-05-17 13:15:32 -07:00
parent 414e60380f
commit 3ae3684aea
3 changed files with 53 additions and 6 deletions

View file

@ -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

View file

@ -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 =~ /<p>/) {
my $html = $description;
$html =~ tr/\n/ /s;
my @paragraphs = map { "<p>".$_."</p>" } 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};

View file

@ -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(<<EOFEED);
<?xml version="1.0" encoding="UTF-8" ?>
@ -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(<<EOFEED);
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>The WebGUI buglist</title>
<link>/tbb</link>
<copyright /><pubDate>Mon, 12 Oct 2009 11:54:28 -0500</pubDate>
<description />
<item>
<title>Description with wrapped HTML paragraphs</title>
<link>http://www.webgui.org/use/bugs/tracker/11563</link>
<author>serif</author>
<epochDate>1254854387</epochDate>
<guid isPermaLink="true">http://www.webgui.org/use/bugs/tracker/11563</guid>
<pubDate>Mon, 14 May 2010 8:12:00 -0500</pubDate>
<description>
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;No more text is shown of the first paragraph beyond the bold characters of the first line.&lt;/p&gt;
&lt;p&gt;Third paragraph, for completeness.&lt;/p&gt;
</description>
</item>
</channel>
</rss>
EOFEED
$vars = $syndicated_content->getTemplateVariables($feed);
is $vars->{item_loop}->[0]->{descriptionFirstParagraph},
"<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>",
'... 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';
####################################################################
#
# generateFeed, hasTerms