mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fixes silverstripe/silverstripe-framework#1910: shortcodes not parsed in RSS feeds
This commit is contained in:
parent
981850890a
commit
306281ed44
@ -58,6 +58,7 @@ class HTMLText extends Text {
|
|||||||
*/
|
*/
|
||||||
public function Summary($maxWords = 50, $flex = 15, $add = '...') {
|
public function Summary($maxWords = 50, $flex = 15, $add = '...') {
|
||||||
$str = false;
|
$str = false;
|
||||||
|
$parsedValue = $this->forTemplate();
|
||||||
|
|
||||||
/* First we need the text of the first paragraph, without tags. Try using SimpleXML first */
|
/* First we need the text of the first paragraph, without tags. Try using SimpleXML first */
|
||||||
if (class_exists('SimpleXMLElement')) {
|
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
|
// 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);
|
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
|
// Nonbreaking spaces get converted into weird characters, so strip them
|
||||||
$value = str_replace(' ', ' ', $this->value);
|
$value = str_replace(' ', ' ', $parsedValue);
|
||||||
try {
|
try {
|
||||||
$res = $doc->loadHTML('<meta content="text/html; charset=utf-8" http-equiv="Content-type"/>' . $value);
|
$res = $doc->loadHTML('<meta content="text/html; charset=utf-8" http-equiv="Content-type"/>' . $value);
|
||||||
}
|
}
|
||||||
@ -86,11 +87,11 @@ class HTMLText extends Text {
|
|||||||
/* See if we can pull a paragraph out*/
|
/* 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
|
// Strip out any images in case there's one at the beginning. Not doing this will return a blank paragraph
|
||||||
$str = preg_replace('{^\s*(<.+?>)*<img[^>]*>}', '', $this->value);
|
$str = preg_replace('{^\s*(<.+?>)*<img[^>]*>}', '', $parsedValue);
|
||||||
if (preg_match('{<p(\s[^<>]*)?>(.*[A-Za-z]+.*)</p>}', $str, $matches)) $str = $matches[2];
|
if (preg_match('{<p(\s[^<>]*)?>(.*[A-Za-z]+.*)</p>}', $str, $matches)) $str = $matches[2];
|
||||||
|
|
||||||
/* If _that_ failed, just use the whole text */
|
/* 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 */
|
/* Now pull out all the html-alike stuff */
|
||||||
/* Take out anything that is obviously a tag */
|
/* Take out anything that is obviously a tag */
|
||||||
@ -141,6 +142,14 @@ class HTMLText extends Text {
|
|||||||
return $this->Summary();
|
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() {
|
public function forTemplate() {
|
||||||
if ($this->processShortcodes) {
|
if ($this->processShortcodes) {
|
||||||
return ShortcodeParser::get_active()->parse($this->value);
|
return ShortcodeParser::get_active()->parse($this->value);
|
||||||
|
@ -62,14 +62,6 @@ class Text extends StringField {
|
|||||||
return strip_tags($this->value);
|
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.
|
* Limit sentences, can be controlled by passing an integer.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user