mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 01:34:31 +02:00
Update PageFrontEdit to behave better with InputfieldTextarea fields that do not support HTML.
This commit is contained in:
@@ -1170,27 +1170,31 @@ class PageFrontEdit extends WireData implements Module {
|
||||
$inputfield = $this->getInputfield($page, $field);
|
||||
$postName = $name;
|
||||
|
||||
// decode entities and strip tags?
|
||||
$decodeAndStrip = false;
|
||||
|
||||
// jQuery HTML function entity encodes things like & to & even if they don't appear in the source
|
||||
// so we determine if it's necessary to decode them here
|
||||
if($inputfield instanceof InputfieldTextarea) {
|
||||
if(wireInstanceOf($inputfield, 'InputfieldCKEditor')) {
|
||||
$decode = false;
|
||||
// ok
|
||||
} else if(wireInstanceOf($inputfield, 'InputfieldTinyMCE')) {
|
||||
$postName = "Inputfield_$name";
|
||||
$decode = false;
|
||||
} else if($field->get('contentType') >= FieldtypeTextarea::contentTypeHTML) {
|
||||
$decode = false;
|
||||
// ok
|
||||
} else {
|
||||
$decode = true;
|
||||
// convert browser added div and break tags to newlines
|
||||
$value = str_replace(array('<div><br></div>', '<br>', '<br />'), "\n", $value);
|
||||
$value = str_replace(array('<div>', '</div>'), array("\n", ""), $value);
|
||||
$decodeAndStrip = true;
|
||||
}
|
||||
} else if($inputfield instanceof InputfieldText) {
|
||||
$decode = true;
|
||||
} else {
|
||||
$decode = false;
|
||||
$decodeAndStrip = true;
|
||||
}
|
||||
|
||||
if($decode) {
|
||||
if($decodeAndStrip) {
|
||||
$value = $sanitizer->unentities($value);
|
||||
$value = strip_tags($value);
|
||||
}
|
||||
|
||||
$input->post->$postName = $value;
|
||||
@@ -1294,6 +1298,7 @@ class PageFrontEdit extends WireData implements Module {
|
||||
if(is_object($unformatted)) $unformatted = (string) $unformatted;
|
||||
|
||||
$purifyHTML = true;
|
||||
$addBreaks = false;
|
||||
|
||||
if($field && $field->type instanceof FieldtypeTextarea) {
|
||||
$contentType = (int) $field->get('contentType');
|
||||
@@ -1301,6 +1306,10 @@ class PageFrontEdit extends WireData implements Module {
|
||||
if($cls === 'InputfieldCKEditor' || $cls === 'InputfieldTinyMCE' || $contentType == 1 || $contentType == 2) {
|
||||
// HTML is expected and allowed
|
||||
$purifyHTML = false;
|
||||
} else if($cls === 'InputfieldTextarea') {
|
||||
$textformatters = $field->get('textformatters');
|
||||
if(in_array('TextformatterNewlineBR', $textformatters)) $addBreaks = true;
|
||||
if(in_array('TextformatterMarkdownExtra', $textformatters)) $addBreaks = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1310,6 +1319,8 @@ class PageFrontEdit extends WireData implements Module {
|
||||
$unformatted = $this->wire()->sanitizer->purify(trim($unformatted));
|
||||
}
|
||||
|
||||
if($addBreaks) $unformatted = nl2br($unformatted);
|
||||
|
||||
return $unformatted;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user