From 306281ed44dd0e12a6e88d8fa9e43177123ba684 Mon Sep 17 00:00:00 2001 From: James Goodman Date: Mon, 23 Sep 2013 16:20:06 +1200 Subject: [PATCH] Fixes silverstripe/silverstripe-framework#1910: shortcodes not parsed in RSS feeds --- model/fieldtypes/HTMLText.php | 19 ++++++++++++++----- model/fieldtypes/Text.php | 8 -------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/model/fieldtypes/HTMLText.php b/model/fieldtypes/HTMLText.php index 188ec256b..127c0dda3 100644 --- a/model/fieldtypes/HTMLText.php +++ b/model/fieldtypes/HTMLText.php @@ -58,6 +58,7 @@ class HTMLText extends Text { */ public function Summary($maxWords = 50, $flex = 15, $add = '...') { $str = false; + $parsedValue = $this->forTemplate(); /* First we need the text of the first paragraph, without tags. Try using SimpleXML first */ if (class_exists('SimpleXMLElement')) { @@ -66,7 +67,7 @@ class HTMLText extends Text { // Catch warnings thrown by loadHTML and turn them into a failure boolean rather than a SilverStripe error set_error_handler(create_function('$no, $str', 'throw new Exception("HTML Parse Error: ".$str);'), E_ALL); // Nonbreaking spaces get converted into weird characters, so strip them - $value = str_replace(' ', ' ', $this->value); + $value = str_replace(' ', ' ', $parsedValue); try { $res = $doc->loadHTML('' . $value); } @@ -86,11 +87,11 @@ class HTMLText extends Text { /* See if we can pull a paragraph out*/ // Strip out any images in case there's one at the beginning. Not doing this will return a blank paragraph - $str = preg_replace('{^\s*(<.+?>)*]*>}', '', $this->value); + $str = preg_replace('{^\s*(<.+?>)*]*>}', '', $parsedValue); if (preg_match('{]*)?>(.*[A-Za-z]+.*)

}', $str, $matches)) $str = $matches[2]; /* If _that_ failed, just use the whole text */ - if (!$str) $str = $this->value; + if (!$str) $str = $parsedValue; /* Now pull out all the html-alike stuff */ /* Take out anything that is obviously a tag */ @@ -139,8 +140,16 @@ class HTMLText extends Text { /* If we didn't find a sentence ending, use the summary. We re-call rather than using paragraph so that * Summary will limit the result this time */ return $this->Summary(); - } - + } + + /** + * Return the value of the field with relative links converted to absolute urls. + * @return string + */ + public function AbsoluteLinks() { + return HTTP::absoluteURLs($this->forTemplate()); + } + public function forTemplate() { if ($this->processShortcodes) { return ShortcodeParser::get_active()->parse($this->value); diff --git a/model/fieldtypes/Text.php b/model/fieldtypes/Text.php index 63d057381..55bcdc9dd 100644 --- a/model/fieldtypes/Text.php +++ b/model/fieldtypes/Text.php @@ -62,14 +62,6 @@ class Text extends StringField { return strip_tags($this->value); } - /** - * Return the value of the field with relative links converted to absolute urls. - * @return string - */ - public function AbsoluteLinks() { - return HTTP::absoluteURLs($this->value); - } - /** * Limit sentences, can be controlled by passing an integer. *