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);
|
$inputfield = $this->getInputfield($page, $field);
|
||||||
$postName = $name;
|
$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
|
// 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
|
// so we determine if it's necessary to decode them here
|
||||||
if($inputfield instanceof InputfieldTextarea) {
|
if($inputfield instanceof InputfieldTextarea) {
|
||||||
if(wireInstanceOf($inputfield, 'InputfieldCKEditor')) {
|
if(wireInstanceOf($inputfield, 'InputfieldCKEditor')) {
|
||||||
$decode = false;
|
// ok
|
||||||
} else if(wireInstanceOf($inputfield, 'InputfieldTinyMCE')) {
|
} else if(wireInstanceOf($inputfield, 'InputfieldTinyMCE')) {
|
||||||
$postName = "Inputfield_$name";
|
$postName = "Inputfield_$name";
|
||||||
$decode = false;
|
|
||||||
} else if($field->get('contentType') >= FieldtypeTextarea::contentTypeHTML) {
|
} else if($field->get('contentType') >= FieldtypeTextarea::contentTypeHTML) {
|
||||||
$decode = false;
|
// ok
|
||||||
} else {
|
} 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) {
|
} else if($inputfield instanceof InputfieldText) {
|
||||||
$decode = true;
|
$decodeAndStrip = true;
|
||||||
} else {
|
|
||||||
$decode = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($decode) {
|
if($decodeAndStrip) {
|
||||||
$value = $sanitizer->unentities($value);
|
$value = $sanitizer->unentities($value);
|
||||||
|
$value = strip_tags($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$input->post->$postName = $value;
|
$input->post->$postName = $value;
|
||||||
@@ -1294,6 +1298,7 @@ class PageFrontEdit extends WireData implements Module {
|
|||||||
if(is_object($unformatted)) $unformatted = (string) $unformatted;
|
if(is_object($unformatted)) $unformatted = (string) $unformatted;
|
||||||
|
|
||||||
$purifyHTML = true;
|
$purifyHTML = true;
|
||||||
|
$addBreaks = false;
|
||||||
|
|
||||||
if($field && $field->type instanceof FieldtypeTextarea) {
|
if($field && $field->type instanceof FieldtypeTextarea) {
|
||||||
$contentType = (int) $field->get('contentType');
|
$contentType = (int) $field->get('contentType');
|
||||||
@@ -1301,7 +1306,11 @@ class PageFrontEdit extends WireData implements Module {
|
|||||||
if($cls === 'InputfieldCKEditor' || $cls === 'InputfieldTinyMCE' || $contentType == 1 || $contentType == 2) {
|
if($cls === 'InputfieldCKEditor' || $cls === 'InputfieldTinyMCE' || $contentType == 1 || $contentType == 2) {
|
||||||
// HTML is expected and allowed
|
// HTML is expected and allowed
|
||||||
$purifyHTML = false;
|
$purifyHTML = false;
|
||||||
}
|
} else if($cls === 'InputfieldTextarea') {
|
||||||
|
$textformatters = $field->get('textformatters');
|
||||||
|
if(in_array('TextformatterNewlineBR', $textformatters)) $addBreaks = true;
|
||||||
|
if(in_array('TextformatterMarkdownExtra', $textformatters)) $addBreaks = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_string($unformatted) && $purifyHTML && (strpos($unformatted, '<') !== false || strpos($unformatted, '&') !== false)) {
|
if(is_string($unformatted) && $purifyHTML && (strpos($unformatted, '<') !== false || strpos($unformatted, '&') !== false)) {
|
||||||
@@ -1310,6 +1319,8 @@ class PageFrontEdit extends WireData implements Module {
|
|||||||
$unformatted = $this->wire()->sanitizer->purify(trim($unformatted));
|
$unformatted = $this->wire()->sanitizer->purify(trim($unformatted));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($addBreaks) $unformatted = nl2br($unformatted);
|
||||||
|
|
||||||
return $unformatted;
|
return $unformatted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user