2016-08-19 00:51:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\View\Parsers;
|
|
|
|
|
2023-01-16 03:28:23 +01:00
|
|
|
use SilverStripe\Dev\Deprecation;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @deprecated 4.13.0 Will be removed without equivalent functionality to replace it
|
|
|
|
*/
|
2016-09-09 08:43:05 +02:00
|
|
|
class HTML4Value extends HTMLValue
|
2016-08-19 00:51:35 +02:00
|
|
|
{
|
2023-01-16 03:28:23 +01:00
|
|
|
public function __construct($fragment = null)
|
|
|
|
{
|
|
|
|
Deprecation::withNoReplacement(function () {
|
|
|
|
Deprecation::notice(
|
|
|
|
'4.13.0',
|
|
|
|
'Will be removed without equivalent functionality to replace it',
|
|
|
|
Deprecation::SCOPE_CLASS
|
|
|
|
);
|
|
|
|
});
|
|
|
|
parent::__construct($fragment);
|
|
|
|
}
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
|
|
|
* @param string $content
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function setContent($content)
|
|
|
|
{
|
|
|
|
// Ensure that \r (carriage return) characters don't get replaced with " " entity by DOMDocument
|
|
|
|
// This behaviour is apparently XML spec, but we don't want this because it messes up the HTML
|
2022-04-14 03:12:59 +02:00
|
|
|
$content = str_replace(chr(13), '', $content ?? '');
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
// Reset the document if we're in an invalid state for some reason
|
|
|
|
if (!$this->isValid()) {
|
|
|
|
$this->setDocument(null);
|
|
|
|
}
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
$errorState = libxml_use_internal_errors(true);
|
|
|
|
$result = $this->getDocument()->loadHTML(
|
2018-01-16 19:39:30 +01:00
|
|
|
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>' . "<body>$content</body></html>"
|
2016-11-29 00:31:16 +01:00
|
|
|
);
|
|
|
|
libxml_clear_errors();
|
|
|
|
libxml_use_internal_errors($errorState);
|
|
|
|
return $result;
|
|
|
|
}
|
2016-08-19 00:51:35 +02:00
|
|
|
}
|