31 public function render($conf = []): string
33 $renderMode = isset($conf[
'renderMode.'])
34 ? $this->cObj->stdWrap($conf[
'renderMode'], $conf[
'renderMode.'])
35 : $conf[
'renderMode'];
37 if ($renderMode ===
'inline') {
52 list($width, $height, $isDefaultWidth, $isDefaultHeight) = $this->
getDimensions($conf);
55 if (file_exists($src)) {
56 $svgContent = file_get_contents($src);
57 $svgContent = preg_replace(
'/<script[\s\S]*?>[\s\S]*?<\/script>/i',
'', $svgContent);
59 $previousValueOfEntityLoader = libxml_disable_entity_loader();
60 $svgElement = simplexml_load_string($svgContent);
61 libxml_disable_entity_loader($previousValueOfEntityLoader);
63 $domXml = dom_import_simplexml($svgElement);
64 if (!$isDefaultWidth) {
65 $domXml->setAttribute(
'width', $width);
67 if (!$isDefaultHeight) {
68 $domXml->setAttribute(
'height', $height);
71 $content = $domXml->ownerDocument->saveXML($domXml->ownerDocument->documentElement);
73 $value = isset($conf[
'value.']) ? $this->cObj->stdWrap($conf[
'value'], $conf[
'value.']) : $conf[
'value'];
76 $content[] =
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' . (int)$width .
'" height="' . (
int)$height .
'">';
78 $content[] =
'</svg>';
79 $content = implode(LF, $content);
82 if (isset($conf[
'stdWrap.'])) {
83 $content = $this->cObj->stdWrap($content, $conf[
'stdWrap.']);
101 $value = isset($conf[
'value.']) ? $this->cObj->stdWrap($conf[
'value'], $conf[
'value.']) : $conf[
'value'];
102 $noscript = isset($conf[
'noscript.']) ? $this->cObj->stdWrap($conf[
'noscript'], $conf[
'noscript.']) : $conf[
'noscript'];
105 if (!empty($conf[
'noscript.']) || !empty($conf[
'noscript'])) {
106 trigger_error(
'SVG cObject: The option "noscript" will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
108 if (!empty($conf[
'value.']) || !empty($conf[
'value'])) {
109 trigger_error(
'SVG cObject: The option "value" without setting renderMode=inline will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
114 $content[] =
'<!--[if IE]>';
115 $content[] =
' <object src="' . htmlspecialchars($src) .
'" classid="image/svg+xml" width="' . (int)$width .
'" height="' . (
int)$height .
'">';
116 $content[] =
'<![endif]-->';
117 $content[] =
'<!--[if !IE]>-->';
118 $content[] =
' <object data="' . htmlspecialchars($src) .
'" type="image/svg+xml" width="' . (int)$width .
'" height="' . (
int)$height .
'">';
119 $content[] =
'<!--<![endif]-->';
120 $content[] = $noscript;
121 $content[] =
'</object>';
124 $content[] =
'<script type="image/svg+xml">';
125 $content[] =
' <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' . (int)$width .
'" height="' . (
int)$height .
'">';
127 $content[] =
' </svg>';
128 $content[] =
'</script>';
129 $content[] =
'<noscript>';
130 $content[] = $noscript;
131 $content[] =
'</noscript>';
133 $content = implode(LF, $content);
134 if (isset($conf[
'stdWrap.'])) {
135 $content = $this->cObj->stdWrap($content, $conf[
'stdWrap.']);
147 $src = isset($conf[
'src.']) ? $this->cObj->stdWrap($conf[
'src'], $conf[
'src.']) : $conf[
'src'];
148 return GeneralUtility::getFileAbsFileName($src);
158 $isDefaultWidth =
false;
159 $isDefaultHeight =
false;
160 $width = isset($conf[
'width.']) ? $this->cObj->stdWrap($conf[
'width'], $conf[
'width.']) : $conf[
'width'];
161 $height = isset($conf[
'height.']) ? $this->cObj->stdWrap($conf[
'height'], $conf[
'height.']) : $conf[
'height'];
164 $isDefaultWidth =
true;
167 if (empty($height)) {
168 $isDefaultHeight =
true;
172 return [$width, $height, $isDefaultWidth, $isDefaultHeight];