2 namespace TYPO3\CMS\Core\Page
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Routing\Router
;
18 use TYPO3\CMS\Backend\Routing\UriBuilder
;
19 use TYPO3\CMS\Backend\Template\DocumentTemplate
;
20 use TYPO3\CMS\Core\Cache\CacheManager
;
21 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
;
22 use TYPO3\CMS\Core\Core\Environment
;
23 use TYPO3\CMS\Core\Localization\LocalizationFactory
;
24 use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry
;
25 use TYPO3\CMS\Core\Service\MarkerBasedTemplateService
;
26 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility
;
27 use TYPO3\CMS\Core\Utility\GeneralUtility
;
28 use TYPO3\CMS\Core\Utility\PathUtility
;
29 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
;
32 * TYPO3 pageRender class
33 * This class render the HTML of a webpage, usable for BE and FE
35 class PageRenderer
implements \TYPO3\CMS\Core\SingletonInterface
37 // Constants for the part to be rendered
38 const PART_COMPLETE
= 0;
39 const PART_HEADER
= 1;
40 const PART_FOOTER
= 2;
42 const REQUIREJS_SCOPE_CONFIG
= 'config';
43 const REQUIREJS_SCOPE_RESOLVE
= 'resolve';
48 protected $compressJavascript = false;
53 protected $compressCss = false;
58 protected $removeLineBreaksFromTemplate = false;
63 protected $concatenateJavascript = false;
68 protected $concatenateCss = false;
73 protected $moveJsFromHeaderToFooter = false;
76 * @var \TYPO3\CMS\Core\Localization\Locales
82 * Two character string or 'default'
89 * List of language dependencies for actual language. This is used for local variants of a language
90 * that depend on their "main" language, like Brazilian Portuguese or Canadian French.
94 protected $languageDependencies = [];
97 * @var \TYPO3\CMS\Core\Resource\ResourceCompressor
99 protected $compressor;
101 // Arrays containing associative array for the included files
105 protected $jsFiles = [];
110 protected $jsFooterFiles = [];
115 protected $jsLibs = [];
120 protected $jsFooterLibs = [];
125 protected $cssFiles = [];
130 protected $cssLibs = [];
133 * The title of the page
140 * Charset for the rendering
159 protected $renderXhtml = true;
161 // Static header blocks
165 protected $xmlPrologAndDocType = '';
170 protected $metaTags = [];
175 protected $inlineComments = [];
180 protected $headerData = [];
185 protected $footerData = [];
190 protected $titleTag = '<title>|</title>';
195 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
200 protected $htmlTag = '<html>';
205 protected $headTag = '<head>';
210 protected $baseUrlTag = '<base href="|" />';
215 protected $iconMimeType = '';
220 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />';
222 // Static inline code blocks
226 protected $jsInline = [];
231 protected $jsFooterInline = [];
236 protected $cssInline = [];
241 protected $bodyContent;
246 protected $templateFile;
248 // Paths to contributed libraries
251 * default path to the requireJS library, relative to the typo3/ directory
254 protected $requireJsPath = 'EXT:core/Resources/Public/JavaScript/Contrib/';
256 // Internal flags for JS-libraries
258 * if set, the requireJS library is included
261 protected $addRequireJs = false;
264 * Inline configuration for requireJS (internal)
267 protected $requireJsConfig = [];
270 * Module names of internal requireJS 'paths'
273 protected $internalRequireJsPathModuleNames = [];
276 * Inline configuration for requireJS (public)
279 protected $publicRequireJsConfig = [];
284 protected $inlineLanguageLabels = [];
289 protected $inlineLanguageLabelFiles = [];
294 protected $inlineSettings = [];
299 protected $inlineJavascriptWrap = [];
304 protected $inlineCssWrap = [];
307 * Saves error messages generated during compression
311 protected $compressError = '';
314 * Is empty string for HTML and ' /' for XHTML rendering
318 protected $endingSlash = '';
321 * @var MetaTagManagerRegistry
323 protected $metaTagRegistry;
326 * @var FrontendInterface
328 protected static $cache = null;
331 * @param string $templateFile Declare the used template file. Omit this parameter will use default template
333 public function __construct($templateFile = '')
336 $this->locales
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Localization\Locales
::class);
337 if ($templateFile !== '') {
338 $this->templateFile
= $templateFile;
340 $this->inlineJavascriptWrap
= [
341 '<script type="text/javascript">' . LF
. '/*<![CDATA[*/' . LF
,
342 '/*]]>*/' . LF
. '</script>' . LF
344 $this->inlineCssWrap
= [
345 '<style type="text/css">' . LF
. '/*<![CDATA[*/' . LF
. '<!-- ' . LF
,
346 '-->' . LF
. '/*]]>*/' . LF
. '</style>' . LF
349 $this->metaTagRegistry
= GeneralUtility
::makeInstance(MetaTagManagerRegistry
::class);
350 $this->setMetaTag('name', 'generator', 'TYPO3 CMS');
354 * Set restored meta tag managers as singletons
355 * so that uncached plugins can use them to add or remove meta tags
357 public function __wakeup()
359 GeneralUtility
::setSingletonInstance(get_class($this->metaTagRegistry
), $this->metaTagRegistry
);
363 * @param FrontendInterface $cache
365 public static function setCache(FrontendInterface
$cache)
367 static::$cache = $cache;
371 * Reset all vars to initial values
373 protected function reset()
375 $this->templateFile
= 'EXT:core/Resources/Private/Templates/PageRenderer.html';
377 $this->jsFooterFiles
= [];
378 $this->jsInline
= [];
379 $this->jsFooterInline
= [];
381 $this->cssFiles
= [];
382 $this->cssInline
= [];
383 $this->metaTags
= [];
384 $this->metaTagsByAPI
= [];
385 $this->inlineComments
= [];
386 $this->headerData
= [];
387 $this->footerData
= [];
390 /*****************************************************/
395 /*****************************************************/
399 * @param string $title title of webpage
401 public function setTitle($title)
403 $this->title
= $title;
407 * Enables/disables rendering of XHTML code
409 * @param bool $enable Enable XHTML
411 public function setRenderXhtml($enable)
413 $this->renderXhtml
= $enable;
417 * Sets xml prolog and docType
419 * @param string $xmlPrologAndDocType Complete tags for xml prolog and docType
421 public function setXmlPrologAndDocType($xmlPrologAndDocType)
423 $this->xmlPrologAndDocType
= $xmlPrologAndDocType;
429 * @param string $charSet Used charset
431 public function setCharSet($charSet)
433 $this->charSet
= $charSet;
439 * @param string $lang Used language
441 public function setLanguage($lang)
444 $this->languageDependencies
= [];
446 // Language is found. Configure it:
447 if (in_array($this->lang
, $this->locales
->getLocales())) {
448 $this->languageDependencies
[] = $this->lang
;
449 foreach ($this->locales
->getLocaleDependencies($this->lang
) as $language) {
450 $this->languageDependencies
[] = $language;
456 * Set the meta charset tag
458 * @param string $metaCharsetTag
460 public function setMetaCharsetTag($metaCharsetTag)
462 $this->metaCharsetTag
= $metaCharsetTag;
468 * @param string $htmlTag Html tag
470 public function setHtmlTag($htmlTag)
472 $this->htmlTag
= $htmlTag;
478 * @param string $headTag HTML head tag
480 public function setHeadTag($headTag)
482 $this->headTag
= $headTag;
488 * @param string $favIcon
490 public function setFavIcon($favIcon)
492 $this->favIcon
= $favIcon;
496 * Sets icon mime type
498 * @param string $iconMimeType
500 public function setIconMimeType($iconMimeType)
502 $this->iconMimeType
= $iconMimeType;
508 * @param string $baseUrl HTML base URL
510 public function setBaseUrl($baseUrl)
512 $this->baseUrl
= $baseUrl;
518 * @param string $file
520 public function setTemplateFile($file)
522 $this->templateFile
= $file;
526 * Sets Content for Body
528 * @param string $content
530 public function setBodyContent($content)
532 $this->bodyContent
= $content;
536 * Sets path to requireJS library (relative to typo3 directory)
538 * @param string $path Path to requireJS library
540 public function setRequireJsPath($path)
542 $this->requireJsPath
= $path;
546 * @param string $scope
549 public function getRequireJsConfig(string $scope = null): array
551 // return basic RequireJS configuration without shim, paths and packages
552 if ($scope === static::REQUIREJS_SCOPE_CONFIG
) {
553 return array_replace_recursive(
554 $this->publicRequireJsConfig
,
555 $this->filterArrayKeys(
556 $this->requireJsConfig
,
557 ['shim', 'paths', 'packages'],
562 // return RequireJS configuration for resolving only shim, paths and packages
563 if ($scope === static::REQUIREJS_SCOPE_RESOLVE
) {
564 return $this->filterArrayKeys(
565 $this->requireJsConfig
,
566 ['shim', 'paths', 'packages'],
573 /*****************************************************/
575 /* Public Enablers / Disablers */
578 /*****************************************************/
580 * Enables MoveJsFromHeaderToFooter
582 public function enableMoveJsFromHeaderToFooter()
584 $this->moveJsFromHeaderToFooter
= true;
588 * Disables MoveJsFromHeaderToFooter
590 public function disableMoveJsFromHeaderToFooter()
592 $this->moveJsFromHeaderToFooter
= false;
596 * Enables compression of javascript
598 public function enableCompressJavascript()
600 $this->compressJavascript
= true;
604 * Disables compression of javascript
606 public function disableCompressJavascript()
608 $this->compressJavascript
= false;
612 * Enables compression of css
614 public function enableCompressCss()
616 $this->compressCss
= true;
620 * Disables compression of css
622 public function disableCompressCss()
624 $this->compressCss
= false;
628 * Enables concatenation of js files
630 public function enableConcatenateJavascript()
632 $this->concatenateJavascript
= true;
636 * Disables concatenation of js files
638 public function disableConcatenateJavascript()
640 $this->concatenateJavascript
= false;
644 * Enables concatenation of css files
646 public function enableConcatenateCss()
648 $this->concatenateCss
= true;
652 * Disables concatenation of css files
654 public function disableConcatenateCss()
656 $this->concatenateCss
= false;
660 * Sets removal of all line breaks in template
662 public function enableRemoveLineBreaksFromTemplate()
664 $this->removeLineBreaksFromTemplate
= true;
668 * Unsets removal of all line breaks in template
670 public function disableRemoveLineBreaksFromTemplate()
672 $this->removeLineBreaksFromTemplate
= false;
677 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
679 public function enableDebugMode()
681 $this->compressJavascript
= false;
682 $this->compressCss
= false;
683 $this->concatenateCss
= false;
684 $this->concatenateJavascript
= false;
685 $this->removeLineBreaksFromTemplate
= false;
688 /*****************************************************/
693 /*****************************************************/
697 * @return string $title Title of webpage
699 public function getTitle()
707 * @return string $charSet
709 public function getCharSet()
711 return $this->charSet
;
717 * @return string $lang
719 public function getLanguage()
725 * Returns rendering mode XHTML or HTML
727 * @return bool TRUE if XHTML, FALSE if HTML
729 public function getRenderXhtml()
731 return $this->renderXhtml
;
737 * @return string $htmlTag Html tag
739 public function getHtmlTag()
741 return $this->htmlTag
;
749 public function getMetaCharsetTag()
751 return $this->metaCharsetTag
;
757 * @return string $tag Head tag
759 public function getHeadTag()
761 return $this->headTag
;
767 * @return string $favIcon
769 public function getFavIcon()
771 return $this->favIcon
;
775 * Gets icon mime type
777 * @return string $iconMimeType
779 public function getIconMimeType()
781 return $this->iconMimeType
;
787 * @return string $url
789 public function getBaseUrl()
791 return $this->baseUrl
;
799 public function getTemplateFile()
801 return $this->templateFile
;
805 * Gets MoveJsFromHeaderToFooter
809 public function getMoveJsFromHeaderToFooter()
811 return $this->moveJsFromHeaderToFooter
;
815 * Gets compress of javascript
819 public function getCompressJavascript()
821 return $this->compressJavascript
;
825 * Gets compress of css
829 public function getCompressCss()
831 return $this->compressCss
;
835 * Gets concatenate of js files
839 public function getConcatenateJavascript()
841 return $this->concatenateJavascript
;
845 * Gets concatenate of css files
849 public function getConcatenateCss()
851 return $this->concatenateCss
;
855 * Gets remove of empty lines from template
859 public function getRemoveLineBreaksFromTemplate()
861 return $this->removeLineBreaksFromTemplate
;
865 * Gets content for body
869 public function getBodyContent()
871 return $this->bodyContent
;
875 * Gets the inline language labels.
877 * @return array The inline language labels
879 public function getInlineLanguageLabels()
881 return $this->inlineLanguageLabels
;
885 * Gets the inline language files
889 public function getInlineLanguageLabelFiles()
891 return $this->inlineLanguageLabelFiles
;
894 /*****************************************************/
896 /* Public Functions to add Data */
899 /*****************************************************/
902 * Sets a given meta tag
904 * @param string $type The type of the meta tag. Allowed values are property, name or http-equiv
905 * @param string $name The name of the property to add
906 * @param string $content The content of the meta tag
907 * @param array $subProperties Subproperties of the meta tag (like e.g. og:image:width)
908 * @param bool $replace Replace earlier set meta tag
909 * @throws \InvalidArgumentException
911 public function setMetaTag(string $type, string $name, string $content, array $subProperties = [], $replace = true)
913 // Lowercase all the things
914 $type = strtolower($type);
915 $name = strtolower($name);
916 if (!in_array($type, ['property', 'name', 'http-equiv'], true)) {
917 throw new \
InvalidArgumentException(
918 'When setting a meta tag the only types allowed are property, name or http-equiv. "' . $type . '" given.',
922 $manager = $this->metaTagRegistry
->getManagerForProperty($name);
923 $manager->addProperty($name, $content, $subProperties, $replace, $type);
927 * Returns the requested meta tag
929 * @param string $type
930 * @param string $name
934 public function getMetaTag(string $type, string $name): array
936 // Lowercase all the things
937 $type = strtolower($type);
938 $name = strtolower($name);
940 $manager = $this->metaTagRegistry
->getManagerForProperty($name);
941 $propertyContent = $manager->getProperty($name, $type);
943 if (!empty($propertyContent[0])) {
947 'content' => $propertyContent[0]['content']
954 * Unset the requested meta tag
956 * @param string $type
957 * @param string $name
959 public function removeMetaTag(string $type, string $name)
961 // Lowercase all the things
962 $type = strtolower($type);
963 $name = strtolower($name);
965 $manager = $this->metaTagRegistry
->getManagerForProperty($name);
966 $manager->removeProperty($name, $type);
970 * Adds inline HTML comment
972 * @param string $comment
974 public function addInlineComment($comment)
976 if (!in_array($comment, $this->inlineComments
)) {
977 $this->inlineComments
[] = $comment;
984 * @param string $data Free header data for HTML header
986 public function addHeaderData($data)
988 if (!in_array($data, $this->headerData
)) {
989 $this->headerData
[] = $data;
996 * @param string $data Free header data for HTML header
998 public function addFooterData($data)
1000 if (!in_array($data, $this->footerData
)) {
1001 $this->footerData
[] = $data;
1006 * Adds JS Library. JS Library block is rendered on top of the JS files.
1008 * @param string $name Arbitrary identifier
1009 * @param string $file File name
1010 * @param string $type Content Type
1011 * @param bool $compress Flag if library should be compressed
1012 * @param bool $forceOnTop Flag if added library should be inserted at begin of this block
1013 * @param string $allWrap
1014 * @param bool $excludeFromConcatenation
1015 * @param string $splitChar The char used to split the allWrap value, default is "|"
1016 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1017 * @param string $integrity Subresource Integrity (SRI)
1018 * @param bool $defer Flag if property 'defer="defer"' should be added to JavaScript tags
1019 * @param string $crossorigin CORS settings attribute
1021 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = false, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '', $defer = false, $crossorigin = '')
1024 $type = 'text/javascript';
1026 if (!in_array(strtolower($name), $this->jsLibs
)) {
1027 $this->jsLibs
[strtolower($name)] = [
1030 'section' => self
::PART_HEADER
,
1031 'compress' => $compress,
1032 'forceOnTop' => $forceOnTop,
1033 'allWrap' => $allWrap,
1034 'excludeFromConcatenation' => $excludeFromConcatenation,
1035 'splitChar' => $splitChar,
1037 'integrity' => $integrity,
1039 'crossorigin' => $crossorigin,
1045 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
1047 * @param string $name Arbitrary identifier
1048 * @param string $file File name
1049 * @param string $type Content Type
1050 * @param bool $compress Flag if library should be compressed
1051 * @param bool $forceOnTop Flag if added library should be inserted at begin of this block
1052 * @param string $allWrap
1053 * @param bool $excludeFromConcatenation
1054 * @param string $splitChar The char used to split the allWrap value, default is "|"
1055 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1056 * @param string $integrity Subresource Integrity (SRI)
1057 * @param bool $defer Flag if property 'defer="defer"' should be added to JavaScript tags
1058 * @param string $crossorigin CORS settings attribute
1060 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = false, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '', $defer = false, $crossorigin = '')
1063 $type = 'text/javascript';
1065 $name .= '_jsFooterLibrary';
1066 if (!in_array(strtolower($name), $this->jsLibs
)) {
1067 $this->jsLibs
[strtolower($name)] = [
1070 'section' => self
::PART_FOOTER
,
1071 'compress' => $compress,
1072 'forceOnTop' => $forceOnTop,
1073 'allWrap' => $allWrap,
1074 'excludeFromConcatenation' => $excludeFromConcatenation,
1075 'splitChar' => $splitChar,
1077 'integrity' => $integrity,
1079 'crossorigin' => $crossorigin,
1087 * @param string $file File name
1088 * @param string $type Content Type
1089 * @param bool $compress
1090 * @param bool $forceOnTop
1091 * @param string $allWrap
1092 * @param bool $excludeFromConcatenation
1093 * @param string $splitChar The char used to split the allWrap value, default is "|"
1094 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1095 * @param string $integrity Subresource Integrity (SRI)
1096 * @param bool $defer Flag if property 'defer="defer"' should be added to JavaScript tags
1097 * @param string $crossorigin CORS settings attribute
1099 public function addJsFile($file, $type = 'text/javascript', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '', $defer = false, $crossorigin = '')
1102 $type = 'text/javascript';
1104 if (!isset($this->jsFiles
[$file])) {
1105 $this->jsFiles
[$file] = [
1108 'section' => self
::PART_HEADER
,
1109 'compress' => $compress,
1110 'forceOnTop' => $forceOnTop,
1111 'allWrap' => $allWrap,
1112 'excludeFromConcatenation' => $excludeFromConcatenation,
1113 'splitChar' => $splitChar,
1115 'integrity' => $integrity,
1117 'crossorigin' => $crossorigin,
1123 * Adds JS file to footer
1125 * @param string $file File name
1126 * @param string $type Content Type
1127 * @param bool $compress
1128 * @param bool $forceOnTop
1129 * @param string $allWrap
1130 * @param bool $excludeFromConcatenation
1131 * @param string $splitChar The char used to split the allWrap value, default is "|"
1132 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1133 * @param string $integrity Subresource Integrity (SRI)
1134 * @param bool $defer Flag if property 'defer="defer"' should be added to JavaScript tags
1135 * @param string $crossorigin CORS settings attribute
1137 public function addJsFooterFile($file, $type = 'text/javascript', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '', $defer = false, $crossorigin = '')
1140 $type = 'text/javascript';
1142 if (!isset($this->jsFiles
[$file])) {
1143 $this->jsFiles
[$file] = [
1146 'section' => self
::PART_FOOTER
,
1147 'compress' => $compress,
1148 'forceOnTop' => $forceOnTop,
1149 'allWrap' => $allWrap,
1150 'excludeFromConcatenation' => $excludeFromConcatenation,
1151 'splitChar' => $splitChar,
1153 'integrity' => $integrity,
1155 'crossorigin' => $crossorigin,
1161 * Adds JS inline code
1163 * @param string $name
1164 * @param string $block
1165 * @param bool $compress
1166 * @param bool $forceOnTop
1168 public function addJsInlineCode($name, $block, $compress = true, $forceOnTop = false)
1170 if (!isset($this->jsInline
[$name]) && !empty($block)) {
1171 $this->jsInline
[$name] = [
1172 'code' => $block . LF
,
1173 'section' => self
::PART_HEADER
,
1174 'compress' => $compress,
1175 'forceOnTop' => $forceOnTop
1181 * Adds JS inline code to footer
1183 * @param string $name
1184 * @param string $block
1185 * @param bool $compress
1186 * @param bool $forceOnTop
1188 public function addJsFooterInlineCode($name, $block, $compress = true, $forceOnTop = false)
1190 if (!isset($this->jsInline
[$name]) && !empty($block)) {
1191 $this->jsInline
[$name] = [
1192 'code' => $block . LF
,
1193 'section' => self
::PART_FOOTER
,
1194 'compress' => $compress,
1195 'forceOnTop' => $forceOnTop
1203 * @param string $file
1204 * @param string $rel
1205 * @param string $media
1206 * @param string $title
1207 * @param bool $compress
1208 * @param bool $forceOnTop
1209 * @param string $allWrap
1210 * @param bool $excludeFromConcatenation
1211 * @param string $splitChar The char used to split the allWrap value, default is "|"
1212 * @param bool $inline
1214 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $inline = false)
1216 if (!isset($this->cssFiles
[$file])) {
1217 $this->cssFiles
[$file] = [
1222 'compress' => $compress,
1223 'forceOnTop' => $forceOnTop,
1224 'allWrap' => $allWrap,
1225 'excludeFromConcatenation' => $excludeFromConcatenation,
1226 'splitChar' => $splitChar,
1235 * @param string $file
1236 * @param string $rel
1237 * @param string $media
1238 * @param string $title
1239 * @param bool $compress
1240 * @param bool $forceOnTop
1241 * @param string $allWrap
1242 * @param bool $excludeFromConcatenation
1243 * @param string $splitChar The char used to split the allWrap value, default is "|"
1244 * @param bool $inline
1246 public function addCssLibrary($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $inline = false)
1248 if (!isset($this->cssLibs
[$file])) {
1249 $this->cssLibs
[$file] = [
1254 'compress' => $compress,
1255 'forceOnTop' => $forceOnTop,
1256 'allWrap' => $allWrap,
1257 'excludeFromConcatenation' => $excludeFromConcatenation,
1258 'splitChar' => $splitChar,
1265 * Adds CSS inline code
1267 * @param string $name
1268 * @param string $block
1269 * @param bool $compress
1270 * @param bool $forceOnTop
1272 public function addCssInlineBlock($name, $block, $compress = false, $forceOnTop = false)
1274 if (!isset($this->cssInline
[$name]) && !empty($block)) {
1275 $this->cssInline
[$name] = [
1277 'compress' => $compress,
1278 'forceOnTop' => $forceOnTop
1284 * Call function if you need the requireJS library
1285 * this automatically adds the JavaScript path of all loaded extensions in the requireJS path option
1286 * so it resolves names like TYPO3/CMS/MyExtension/MyJsFile to EXT:MyExtension/Resources/Public/JavaScript/MyJsFile.js
1287 * when using requireJS
1289 public function loadRequireJs()
1291 $this->addRequireJs
= true;
1292 if (!empty($this->requireJsConfig
) && !empty($this->publicRequireJsConfig
)) {
1296 $loadedExtensions = ExtensionManagementUtility
::getLoadedExtensionListArray();
1297 $isDevelopment = GeneralUtility
::getApplicationContext()->isDevelopment();
1298 $cacheIdentifier = 'requireJS_' . md5(implode(',', $loadedExtensions) . ($isDevelopment ?
':dev' : '') . GeneralUtility
::getIndpEnv('TYPO3_REQUEST_SCRIPT'));
1299 /** @var FrontendInterface $cache */
1300 $cache = static::$cache ?? GeneralUtility
::makeInstance(CacheManager
::class)->getCache('assets');
1301 $requireJsConfig = $cache->get($cacheIdentifier);
1303 // if we did not get a configuration from the cache, compute and store it in the cache
1304 if (!isset($requireJsConfig['internal']) ||
!isset($requireJsConfig['public'])) {
1305 $requireJsConfig = $this->computeRequireJsConfig($isDevelopment, $loadedExtensions);
1306 $cache->set($cacheIdentifier, $requireJsConfig);
1309 $this->requireJsConfig
= $requireJsConfig['internal'];
1310 $this->publicRequireJsConfig
= $requireJsConfig['public'];
1311 $this->internalRequireJsPathModuleNames
= $requireJsConfig['internalNames'];
1315 * Computes the RequireJS configuration, mainly consisting of the paths to the core and all extension JavaScript
1316 * resource folders plus some additional generic configuration.
1318 * @param bool $isDevelopment
1319 * @param array $loadedExtensions
1320 * @return array The RequireJS configuration
1322 protected function computeRequireJsConfig($isDevelopment, array $loadedExtensions)
1324 // load all paths to map to package names / namespaces
1325 $requireJsConfig = [
1328 'internalNames' => [],
1331 // In order to avoid browser caching of JS files, adding a GET parameter to the files loaded via requireJS
1332 if ($isDevelopment) {
1333 $requireJsConfig['public']['urlArgs'] = 'bust=' . $GLOBALS['EXEC_TIME'];
1335 $requireJsConfig['public']['urlArgs'] = 'bust=' . GeneralUtility
::hmac(TYPO3_version
. Environment
::getProjectPath());
1337 $corePath = ExtensionManagementUtility
::extPath('core', 'Resources/Public/JavaScript/Contrib/');
1338 $corePath = PathUtility
::getAbsoluteWebPath($corePath);
1339 // first, load all paths for the namespaces, and configure contrib libs.
1340 $requireJsConfig['public']['paths'] = [
1341 'jquery' => $corePath . '/jquery/jquery',
1342 'jquery-ui' => $corePath . 'jquery-ui',
1343 'datatables' => $corePath . 'jquery.dataTables',
1344 'nprogress' => $corePath . 'nprogress',
1345 'moment' => $corePath . 'moment',
1346 'cropper' => $corePath . 'cropper.min',
1347 'imagesloaded' => $corePath . 'imagesloaded.pkgd.min',
1348 'bootstrap' => $corePath . 'bootstrap/bootstrap',
1349 'twbs/bootstrap-datetimepicker' => $corePath . 'bootstrap-datetimepicker',
1350 'autosize' => $corePath . 'autosize',
1351 'taboverride' => $corePath . 'taboverride.min',
1352 'twbs/bootstrap-slider' => $corePath . 'bootstrap-slider.min',
1353 'jquery/autocomplete' => $corePath . 'jquery.autocomplete',
1354 'd3' => $corePath . 'd3/d3',
1355 'Sortable' => $corePath . 'Sortable.min',
1357 $requireJsConfig['public']['waitSeconds'] = 30;
1358 $requireJsConfig['public']['typo3BaseUrl'] = false;
1359 $publicPackageNames = ['core', 'frontend', 'backend'];
1360 foreach ($loadedExtensions as $packageName) {
1361 $jsPath = 'EXT:' . $packageName . '/Resources/Public/JavaScript/';
1362 $absoluteJsPath = GeneralUtility
::getFileAbsFileName($jsPath);
1363 $fullJsPath = PathUtility
::getAbsoluteWebPath($absoluteJsPath);
1364 $fullJsPath = rtrim($fullJsPath, '/');
1365 if (!empty($fullJsPath) && file_exists($absoluteJsPath)) {
1366 $type = in_array($packageName, $publicPackageNames, true) ?
'public' : 'internal';
1367 $requireJsConfig[$type]['paths']['TYPO3/CMS/' . GeneralUtility
::underscoredToUpperCamelCase($packageName)] = $fullJsPath;
1370 // sanitize module names in internal 'paths'
1371 $internalPathModuleNames = array_keys($requireJsConfig['internal']['paths'] ??
[]);
1372 $sanitizedInternalPathModuleNames = array_map(
1373 function ($moduleName) {
1374 // trim spaces and slashes & add ending slash
1375 return trim($moduleName, ' /') . '/';
1377 $internalPathModuleNames
1379 $requireJsConfig['internalNames'] = array_combine(
1380 $sanitizedInternalPathModuleNames,
1381 $internalPathModuleNames
1384 // check if additional AMD modules need to be loaded if a single AMD module is initialized
1385 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules'] ??
false)) {
1386 $this->addInlineSettingArray(
1387 'RequireJS.PostInitializationModules',
1388 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules']
1392 return $requireJsConfig;
1396 * Add additional configuration to require js.
1398 * Configuration will be merged recursive with overrule.
1400 * To add another path mapping deliver the following configuration:
1402 * 'EXTERN/mybootstrapjs' => 'sysext/.../twbs/bootstrap.min',
1405 * @param array $configuration The configuration that will be merged with existing one.
1407 public function addRequireJsConfiguration(array $configuration)
1409 if (TYPO3_MODE
=== 'BE') {
1410 // Load RequireJS in backend context at first. Doing this in FE could break the output
1411 $this->loadRequireJs();
1413 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($this->requireJsConfig
, $configuration);
1417 * Generates RequireJS loader HTML markup.
1420 * @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
1422 protected function getRequireJsLoader(): string
1425 $backendRequest = TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_BE
;
1426 $backendUserLoggedIn = !empty($GLOBALS['BE_USER']->user
['uid']);
1428 // no backend request - basically frontend
1429 if (!$backendRequest) {
1430 $requireJsConfig = $this->getRequireJsConfig(static::REQUIREJS_SCOPE_CONFIG
);
1431 $requireJsConfig['typo3BaseUrl'] = GeneralUtility
::getIndpEnv('TYPO3_SITE_PATH') . '?eID=requirejs';
1432 // backend request, but no backend user logged in
1433 } elseif (!$backendUserLoggedIn) {
1434 $uriBuilder = GeneralUtility
::makeInstance(UriBuilder
::class);
1435 $requireJsConfig = $this->getRequireJsConfig(static::REQUIREJS_SCOPE_CONFIG
);
1436 $requireJsConfig['typo3BaseUrl'] = (string)$uriBuilder->buildUriFromRoute('ajax_core_requirejs');
1437 // backend request, having backend user logged in
1439 $requireJsConfig = array_replace_recursive(
1440 $this->publicRequireJsConfig
,
1441 $this->requireJsConfig
1445 // add (probably filtered) RequireJS configuration
1446 $html .= GeneralUtility
::wrapJS('var require = ' . json_encode($requireJsConfig)) . LF
;
1447 // directly after that, include the require.js file
1448 $html .= '<script src="'
1449 . $this->processJsFile($this->requireJsPath
. 'require.js')
1450 . '" type="text/javascript"></script>' . LF
;
1452 if (!empty($requireJsConfig['typo3BaseUrl'])) {
1453 $html .= '<script src="'
1454 . $this->processJsFile(
1455 'EXT:core/Resources/Public/JavaScript/requirejs-loader.js'
1457 . '" type="text/javascript"></script>' . LF
;
1464 * @param array $array
1465 * @param string[] $keys
1469 protected function filterArrayKeys(array $array, array $keys, bool $keep = true): array
1471 return array_filter(
1473 function (string $key) use ($keys, $keep) {
1474 return in_array($key, $keys, true) === $keep;
1476 ARRAY_FILTER_USE_KEY
1481 * includes an AMD-compatible JS file by resolving the ModuleName, and then requires the file via a requireJS request,
1482 * additionally allowing to execute JavaScript code afterwards
1484 * this function only works for AMD-ready JS modules, used like "define('TYPO3/CMS/Backend/FormEngine..."
1487 * TYPO3/CMS/Backend/FormEngine =>
1488 * "TYPO3": Vendor Name
1489 * "CMS": Product Name
1490 * "Backend": Extension Name
1491 * "FormEngine": FileName in the Resources/Public/JavaScript folder
1493 * @param string $mainModuleName Must be in the form of "TYPO3/CMS/PackageName/ModuleName" e.g. "TYPO3/CMS/Backend/FormEngine"
1494 * @param string $callBackFunction loaded right after the requireJS loading, must be wrapped in function() {}
1496 public function loadRequireJsModule($mainModuleName, $callBackFunction = null)
1498 $inlineCodeKey = $mainModuleName;
1499 // make sure requireJS is initialized
1500 $this->loadRequireJs();
1501 // move internal module path definition to public module definition
1502 // (since loading a module ends up disclosing the existence anyway)
1503 $baseModuleName = $this->findRequireJsBaseModuleName($mainModuleName);
1504 if ($baseModuleName !== null && isset($this->requireJsConfig
['paths'][$baseModuleName])) {
1505 $this->publicRequireJsConfig
['paths'][$baseModuleName] = $this->requireJsConfig
['paths'][$baseModuleName];
1506 unset($this->requireJsConfig
['paths'][$baseModuleName]);
1508 // execute the main module, and load a possible callback function
1509 $javaScriptCode = 'require(["' . $mainModuleName . '"]';
1510 if ($callBackFunction !== null) {
1511 $inlineCodeKey .= sha1($callBackFunction);
1512 $javaScriptCode .= ', ' . $callBackFunction;
1514 $javaScriptCode .= ');';
1515 $this->addJsInlineCode('RequireJS-Module-' . $inlineCodeKey, $javaScriptCode);
1519 * Determines requireJS base module name (if defined).
1521 * @param string $moduleName
1522 * @return string|null
1524 protected function findRequireJsBaseModuleName(string $moduleName)
1526 // trim spaces and slashes & add ending slash
1527 $sanitizedModuleName = trim($moduleName, ' /') . '/';
1528 foreach ($this->internalRequireJsPathModuleNames
as $sanitizedBaseModuleName => $baseModuleName) {
1529 if (strpos($sanitizedModuleName, $sanitizedBaseModuleName) === 0) {
1530 return $baseModuleName;
1537 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1538 * The label can be used in scripts with TYPO3.lang.<key>
1540 * @param string $key
1541 * @param string $value
1543 public function addInlineLanguageLabel($key, $value)
1545 $this->inlineLanguageLabels
[$key] = $value;
1549 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1550 * The label can be used in scripts with TYPO3.lang.<key>
1551 * Array will be merged with existing array.
1553 * @param array $array
1555 public function addInlineLanguageLabelArray(array $array)
1557 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $array);
1561 * Gets labels to be used in JavaScript fetched from a locallang file.
1563 * @param string $fileRef Input is a file-reference (see GeneralUtility::getFileAbsFileName). That file is expected to be a 'locallang.xlf' file containing a valid XML TYPO3 language structure.
1564 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1565 * @param string $stripFromSelectionName String to be removed from the label names in the output. (default: '')
1567 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '')
1569 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1570 if ($fileRef && !isset($this->inlineLanguageLabelFiles
[$index])) {
1571 $this->inlineLanguageLabelFiles
[$index] = [
1572 'fileRef' => $fileRef,
1573 'selectionPrefix' => $selectionPrefix,
1574 'stripFromSelectionName' => $stripFromSelectionName
1580 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1581 * The label can be used in scripts with TYPO3.setting.<key>
1583 * @param string $namespace
1584 * @param string $key
1585 * @param mixed $value
1587 public function addInlineSetting($namespace, $key, $value)
1590 if (strpos($namespace, '.')) {
1591 $parts = explode('.', $namespace);
1592 $a = &$this->inlineSettings
;
1593 foreach ($parts as $part) {
1598 $this->inlineSettings
[$namespace][$key] = $value;
1601 $this->inlineSettings
[$key] = $value;
1606 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1607 * The label can be used in scripts with TYPO3.setting.<key>
1608 * Array will be merged with existing array.
1610 * @param string $namespace
1611 * @param array $array
1613 public function addInlineSettingArray($namespace, array $array)
1616 if (strpos($namespace, '.')) {
1617 $parts = explode('.', $namespace);
1618 $a = &$this->inlineSettings
;
1619 foreach ($parts as $part) {
1622 $a = array_merge((array)$a, $array);
1624 $this->inlineSettings
[$namespace] = array_merge((array)$this->inlineSettings
[$namespace], $array);
1627 $this->inlineSettings
= array_merge($this->inlineSettings
, $array);
1632 * Adds content to body content
1634 * @param string $content
1636 public function addBodyContent($content)
1638 $this->bodyContent
.= $content;
1641 /*****************************************************/
1643 /* Render Functions */
1645 /*****************************************************/
1647 * Render the section (Header or Footer)
1649 * @param int $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1650 * @return string Content of rendered section
1652 public function render($part = self
::PART_COMPLETE
)
1654 $this->prepareRendering();
1655 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1656 $metaTags = implode(LF
, array_merge($this->metaTags
, $this->renderMetaTagsFromAPI()));
1657 $markerArray = $this->getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags);
1658 $template = $this->getTemplateForPart($part);
1660 // The page renderer needs a full reset, even when only rendering one part of the page
1661 // This means that you can only register footer files *after* the header has been already rendered.
1662 // In case you render the footer part first, header files can only be added *after* the footer has been rendered
1664 $templateService = GeneralUtility
::makeInstance(MarkerBasedTemplateService
::class);
1665 return trim($templateService->substituteMarkerArray($template, $markerArray, '###|###'));
1669 * Renders metaTags based on tags added via the API
1673 protected function renderMetaTagsFromAPI()
1676 $metaTagManagers = $this->metaTagRegistry
->getAllManagers();
1678 foreach ($metaTagManagers as $manager => $managerObject) {
1679 $properties = $managerObject->renderAllProperties();
1680 if (!empty($properties)) {
1681 $metaTags[] = $properties;
1688 * Render the page but not the JavaScript and CSS Files
1690 * @param string $substituteHash The hash that is used for the placehoder markers
1692 * @return string Content of rendered section
1694 public function renderPageWithUncachedObjects($substituteHash)
1696 $this->prepareRendering();
1697 $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
1698 $template = $this->getTemplateForPart(self
::PART_COMPLETE
);
1699 $templateService = GeneralUtility
::makeInstance(MarkerBasedTemplateService
::class);
1700 return trim($templateService->substituteMarkerArray($template, $markerArray, '###|###'));
1704 * Renders the JavaScript and CSS files that have been added during processing
1705 * of uncached content objects (USER_INT, COA_INT)
1707 * @param string $cachedPageContent
1708 * @param string $substituteHash The hash that is used for the placehoder markers
1712 public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash)
1714 $this->prepareRendering();
1715 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1716 $title = $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '';
1718 '<!-- ###TITLE' . $substituteHash . '### -->' => $title,
1719 '<!-- ###CSS_LIBS' . $substituteHash . '### -->' => $cssLibs,
1720 '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
1721 '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
1722 '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
1723 '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
1724 '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
1725 '<!-- ###META' . $substituteHash . '### -->' => implode(LF
, array_merge($this->metaTags
, $this->renderMetaTagsFromAPI())),
1726 '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF
, $this->headerData
),
1727 '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF
, $this->footerData
),
1728 '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
1729 '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
1730 '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline
1732 foreach ($markerArray as $placeHolder => $content) {
1733 $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
1736 return $cachedPageContent;
1740 * Remove ending slashes from static header block
1741 * if the page is being rendered as html (not xhtml)
1742 * and define property $this->endingSlash for further use
1744 protected function prepareRendering()
1746 if ($this->getRenderXhtml()) {
1747 $this->endingSlash
= ' /';
1749 $this->metaCharsetTag
= str_replace(' />', '>', $this->metaCharsetTag
);
1750 $this->baseUrlTag
= str_replace(' />', '>', $this->baseUrlTag
);
1751 $this->shortcutTag
= str_replace(' />', '>', $this->shortcutTag
);
1752 $this->endingSlash
= '';
1757 * Renders all JavaScript and CSS
1759 * @return array<string>
1761 protected function renderJavaScriptAndCss()
1763 $this->executePreRenderHook();
1764 $mainJsLibs = $this->renderMainJavaScriptLibraries();
1765 if ($this->concatenateJavascript ||
$this->concatenateCss
) {
1766 // Do the file concatenation
1767 $this->doConcatenate();
1769 if ($this->compressCss ||
$this->compressJavascript
) {
1770 // Do the file compression
1771 $this->doCompress();
1773 $this->executeRenderPostTransformHook();
1774 $cssLibs = $this->renderCssLibraries();
1775 $cssFiles = $this->renderCssFiles();
1776 $cssInline = $this->renderCssInline();
1777 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
1778 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
1779 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
1780 $jsLibs = $mainJsLibs . $jsLibs;
1781 if ($this->moveJsFromHeaderToFooter
) {
1782 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
1784 $jsFooterFiles = $jsFiles . LF
. $jsFooterFiles;
1786 $jsFooterInline = $jsInline . LF
. $jsFooterInline;
1789 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1790 return [$jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs];
1794 * Fills the marker array with the given strings and trims each value
1796 * @param string $jsLibs
1797 * @param string $jsFiles
1798 * @param string $jsFooterFiles
1799 * @param string $cssLibs
1800 * @param string $cssFiles
1801 * @param string $jsInline
1802 * @param string $cssInline
1803 * @param string $jsFooterInline
1804 * @param string $jsFooterLibs
1805 * @param string $metaTags
1806 * @return array Marker array
1808 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags)
1811 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1812 'HTMLTAG' => $this->htmlTag
,
1813 'HEADTAG' => $this->headTag
,
1814 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1815 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
1816 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1817 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1818 'CSS_LIBS' => $cssLibs,
1819 'CSS_INCLUDE' => $cssFiles,
1820 'CSS_INLINE' => $cssInline,
1821 'JS_INLINE' => $jsInline,
1822 'JS_INCLUDE' => $jsFiles,
1823 'JS_LIBS' => $jsLibs,
1824 'TITLE' => $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '',
1825 'META' => $metaTags,
1826 'HEADERDATA' => $this->headerData ?
implode(LF
, $this->headerData
) : '',
1827 'FOOTERDATA' => $this->footerData ?
implode(LF
, $this->footerData
) : '',
1828 'JS_LIBS_FOOTER' => $jsFooterLibs,
1829 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1830 'JS_INLINE_FOOTER' => $jsFooterInline,
1831 'BODY' => $this->bodyContent
1833 $markerArray = array_map('trim', $markerArray);
1834 return $markerArray;
1838 * Fills the marker array with the given strings and trims each value
1840 * @param string $substituteHash The hash that is used for the placehoder markers
1841 * @return array Marker array
1843 protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash)
1846 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1847 'HTMLTAG' => $this->htmlTag
,
1848 'HEADTAG' => $this->headTag
,
1849 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1850 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
1851 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1852 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1853 'META' => '<!-- ###META' . $substituteHash . '### -->',
1854 'BODY' => $this->bodyContent
,
1855 'TITLE' => '<!-- ###TITLE' . $substituteHash . '### -->',
1856 'CSS_LIBS' => '<!-- ###CSS_LIBS' . $substituteHash . '### -->',
1857 'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
1858 'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
1859 'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
1860 'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
1861 'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
1862 'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
1863 'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
1864 'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
1865 'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
1866 'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->'
1868 $markerArray = array_map('trim', $markerArray);
1869 return $markerArray;
1873 * Reads the template file and returns the requested part as string
1878 protected function getTemplateForPart($part)
1880 $templateFile = GeneralUtility
::getFileAbsFileName($this->templateFile
);
1881 if (is_file($templateFile)) {
1882 $template = file_get_contents($templateFile);
1883 if ($this->removeLineBreaksFromTemplate
) {
1884 $template = strtr($template, [LF
=> '', CR
=> '']);
1886 if ($part !== self
::PART_COMPLETE
) {
1887 $templatePart = explode('###BODY###', $template);
1888 $template = $templatePart[$part - 1];
1897 * Helper function for render the main JavaScript libraries,
1898 * currently: RequireJS
1900 * @return string Content with JavaScript libraries
1902 protected function renderMainJavaScriptLibraries()
1906 // Include RequireJS
1907 if ($this->addRequireJs
) {
1908 $out .= $this->getRequireJsLoader();
1911 $this->loadJavaScriptLanguageStrings();
1912 if (TYPO3_MODE
=== 'BE') {
1913 $noBackendUserLoggedIn = empty($GLOBALS['BE_USER']->user
['uid']);
1914 $this->addAjaxUrlsToInlineSettings($noBackendUserLoggedIn);
1916 $inlineSettings = '';
1917 $languageLabels = $this->parseLanguageLabelsForJavaScript();
1918 if (!empty($languageLabels)) {
1919 $inlineSettings .= 'TYPO3.lang = ' . json_encode($languageLabels) . ';';
1921 $inlineSettings .= $this->inlineSettings ?
'TYPO3.settings = ' . json_encode($this->inlineSettings
) . ';' : '';
1923 if ($inlineSettings !== '') {
1924 // make sure the global TYPO3 is available
1925 $inlineSettings = 'var TYPO3 = TYPO3 || {};' . CRLF
. $inlineSettings;
1926 $out .= $this->inlineJavascriptWrap
[0] . $inlineSettings . $this->inlineJavascriptWrap
[1];
1933 * Converts the language labels for usage in JavaScript
1937 protected function parseLanguageLabelsForJavaScript(): array
1939 if (empty($this->inlineLanguageLabels
)) {
1944 foreach ($this->inlineLanguageLabels
as $key => $translationUnit) {
1945 if (is_array($translationUnit)) {
1946 $translationUnit = current($translationUnit);
1947 $labels[$key] = $translationUnit['target'] ??
$translationUnit['source'];
1949 $labels[$key] = $translationUnit;
1957 * Load the language strings into JavaScript
1959 protected function loadJavaScriptLanguageStrings()
1961 if (!empty($this->inlineLanguageLabelFiles
)) {
1962 foreach ($this->inlineLanguageLabelFiles
as $languageLabelFile) {
1963 $this->includeLanguageFileForInline($languageLabelFile['fileRef'], $languageLabelFile['selectionPrefix'], $languageLabelFile['stripFromSelectionName']);
1966 $this->inlineLanguageLabelFiles
= [];
1967 // Convert settings back to UTF-8 since json_encode() only works with UTF-8:
1968 if ($this->getCharSet() && $this->getCharSet() !== 'utf-8' && is_array($this->inlineSettings
)) {
1969 $this->convertCharsetRecursivelyToUtf8($this->inlineSettings
, $this->getCharSet());
1974 * Small helper function to convert charsets for arrays into utf-8
1976 * @param mixed $data given by reference (string/array usually)
1977 * @param string $fromCharset convert FROM this charset
1979 protected function convertCharsetRecursivelyToUtf8(&$data, string $fromCharset)
1981 foreach ($data as $key => $value) {
1982 if (is_array($data[$key])) {
1983 $this->convertCharsetRecursivelyToUtf8($data[$key], $fromCharset);
1984 } elseif (is_string($data[$key])) {
1985 $data[$key] = mb_convert_encoding($data[$key], 'utf-8', $fromCharset);
1991 * Make URLs to all backend ajax handlers available as inline setting.
1993 * @param bool $publicRoutesOnly
1995 protected function addAjaxUrlsToInlineSettings(bool $publicRoutesOnly = false)
1998 // Add the ajax-based routes
1999 /** @var UriBuilder $uriBuilder */
2000 $uriBuilder = GeneralUtility
::makeInstance(UriBuilder
::class);
2001 /** @var Router $router */
2002 $router = GeneralUtility
::makeInstance(Router
::class);
2003 $routes = $router->getRoutes();
2004 foreach ($routes as $routeIdentifier => $route) {
2005 if ($publicRoutesOnly && $route->getOption('access') !== 'public') {
2008 if ($route->getOption('ajax')) {
2009 $uri = (string)$uriBuilder->buildUriFromRoute($routeIdentifier);
2010 // use the shortened value in order to use this in JavaScript
2011 $routeIdentifier = str_replace('ajax_', '', $routeIdentifier);
2012 $ajaxUrls[$routeIdentifier] = $uri;
2016 $this->inlineSettings
['ajaxUrls'] = $ajaxUrls;
2020 * Render CSS library files
2024 protected function renderCssLibraries()
2027 if (!empty($this->cssLibs
)) {
2028 foreach ($this->cssLibs
as $file => $properties) {
2029 $tag = $this->createCssTag($properties, $file);
2030 if ($properties['forceOnTop']) {
2031 $cssFiles = $tag . $cssFiles;
2045 protected function renderCssFiles()
2048 if (!empty($this->cssFiles
)) {
2049 foreach ($this->cssFiles
as $file => $properties) {
2050 $tag = $this->createCssTag($properties, $file);
2051 if ($properties['forceOnTop']) {
2052 $cssFiles = $tag . $cssFiles;
2062 * Create link (inline=0) or style (inline=1) tag
2064 * @param array $properties
2065 * @param string $file
2068 private function createCssTag(array $properties, string $file): string
2070 if ($properties['inline'] && @is_file
($file)) {
2071 $tag = $this->createInlineCssTagFromFile($file, $properties);
2073 $href = $this->getStreamlinedFileName($file);
2074 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2075 . '" type="text/css" href="' . htmlspecialchars($href)
2076 . '" media="' . htmlspecialchars($properties['media']) . '"'
2077 . ($properties['title'] ?
' title="' . htmlspecialchars($properties['title']) . '"' : '')
2078 . $this->endingSlash
. '>';
2080 if ($properties['allWrap']) {
2081 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2082 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2094 protected function renderCssInline()
2097 if (!empty($this->cssInline
)) {
2098 foreach ($this->cssInline
as $name => $properties) {
2099 $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2100 if ($properties['forceOnTop']) {
2101 $cssInline = $cssCode . $cssInline;
2103 $cssInline .= $cssCode;
2106 $cssInline = $this->inlineCssWrap
[0] . $cssInline . $this->inlineCssWrap
[1];
2112 * Render JavaScipt libraries
2114 * @return array<string> jsLibs and jsFooterLibs strings
2116 protected function renderAdditionalJavaScriptLibraries()
2120 if (!empty($this->jsLibs
)) {
2121 foreach ($this->jsLibs
as $properties) {
2122 $properties['file'] = $this->getStreamlinedFileName($properties['file']);
2123 $async = $properties['async'] ?
' async="async"' : '';
2124 $defer = $properties['defer'] ?
' defer="defer"' : '';
2125 $integrity = $properties['integrity'] ?
' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2126 $crossorigin = $properties['crossorigin'] ?
' crossorigin="' . htmlspecialchars($properties['crossorigin']) . '"' : '';
2127 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $defer . $integrity . $crossorigin . '></script>';
2128 if ($properties['allWrap']) {
2129 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2130 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2133 if ($properties['forceOnTop']) {
2134 if ($properties['section'] === self
::PART_HEADER
) {
2135 $jsLibs = $tag . $jsLibs;
2137 $jsFooterLibs = $tag . $jsFooterLibs;
2140 if ($properties['section'] === self
::PART_HEADER
) {
2143 $jsFooterLibs .= $tag;
2148 if ($this->moveJsFromHeaderToFooter
) {
2149 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
2152 return [$jsLibs, $jsFooterLibs];
2156 * Render JavaScript files
2158 * @return array<string> jsFiles and jsFooterFiles strings
2160 protected function renderJavaScriptFiles()
2163 $jsFooterFiles = '';
2164 if (!empty($this->jsFiles
)) {
2165 foreach ($this->jsFiles
as $file => $properties) {
2166 $file = $this->getStreamlinedFileName($file);
2167 $async = $properties['async'] ?
' async="async"' : '';
2168 $defer = $properties['defer'] ?
' defer="defer"' : '';
2169 $integrity = $properties['integrity'] ?
' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2170 $crossorigin = $properties['crossorigin'] ?
' crossorigin="' . htmlspecialchars($properties['crossorigin']) . '"' : '';
2171 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $defer . $integrity . $crossorigin . '></script>';
2172 if ($properties['allWrap']) {
2173 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2174 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2177 if ($properties['forceOnTop']) {
2178 if ($properties['section'] === self
::PART_HEADER
) {
2179 $jsFiles = $tag . $jsFiles;
2181 $jsFooterFiles = $tag . $jsFooterFiles;
2184 if ($properties['section'] === self
::PART_HEADER
) {
2187 $jsFooterFiles .= $tag;
2192 if ($this->moveJsFromHeaderToFooter
) {
2193 $jsFooterFiles = $jsFiles . $jsFooterFiles;
2196 return [$jsFiles, $jsFooterFiles];
2200 * Render inline JavaScript
2202 * @return array<string> jsInline and jsFooterInline string
2204 protected function renderInlineJavaScript()
2207 $jsFooterInline = '';
2208 if (!empty($this->jsInline
)) {
2209 foreach ($this->jsInline
as $name => $properties) {
2210 $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2211 if ($properties['forceOnTop']) {
2212 if ($properties['section'] === self
::PART_HEADER
) {
2213 $jsInline = $jsCode . $jsInline;
2215 $jsFooterInline = $jsCode . $jsFooterInline;
2218 if ($properties['section'] === self
::PART_HEADER
) {
2219 $jsInline .= $jsCode;
2221 $jsFooterInline .= $jsCode;
2227 $jsInline = $this->inlineJavascriptWrap
[0] . $jsInline . $this->inlineJavascriptWrap
[1];
2229 if ($jsFooterInline) {
2230 $jsFooterInline = $this->inlineJavascriptWrap
[0] . $jsFooterInline . $this->inlineJavascriptWrap
[1];
2232 if ($this->moveJsFromHeaderToFooter
) {
2233 $jsFooterInline = $jsInline . $jsFooterInline;
2236 return [$jsInline, $jsFooterInline];
2240 * Include language file for inline usage
2242 * @param string $fileRef
2243 * @param string $selectionPrefix
2244 * @param string $stripFromSelectionName
2245 * @throws \RuntimeException
2247 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '')
2249 if (!isset($this->lang
) ||
!isset($this->charSet
)) {
2250 throw new \
RuntimeException('Language and character encoding are not set.', 1284906026);
2252 $labelsFromFile = [];
2253 $allLabels = $this->readLLfile($fileRef);
2254 if ($allLabels !== false) {
2255 // Merge language specific translations:
2256 if ($this->lang
!== 'default' && isset($allLabels[$this->lang
])) {
2257 $labels = array_merge($allLabels['default'], $allLabels[$this->lang
]);
2259 $labels = $allLabels['default'];
2261 // Iterate through all locallang labels:
2262 foreach ($labels as $label => $value) {
2263 // If $selectionPrefix is set, only respect labels that start with $selectionPrefix
2264 if ($selectionPrefix === '' ||
strpos($label, $selectionPrefix) === 0) {
2265 // Remove substring $stripFromSelectionName from label
2266 $label = str_replace($stripFromSelectionName, '', $label);
2267 $labelsFromFile[$label] = $value;
2270 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $labelsFromFile);
2275 * Reads a locallang file.
2277 * @param string $fileRef Reference to a relative filename to include.
2278 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2280 protected function readLLfile($fileRef)
2282 /** @var LocalizationFactory $languageFactory */
2283 $languageFactory = GeneralUtility
::makeInstance(LocalizationFactory
::class);
2285 if ($this->lang
!== 'default') {
2286 $languages = array_reverse($this->languageDependencies
);
2287 // At least we need to have English
2288 if (empty($languages)) {
2289 $languages[] = 'default';
2292 $languages = ['default'];
2295 $localLanguage = [];
2296 foreach ($languages as $language) {
2297 $tempLL = $languageFactory->getParsedData($fileRef, $language);
2299 $localLanguage['default'] = $tempLL['default'];
2300 if (!isset($localLanguage[$this->lang
])) {
2301 $localLanguage[$this->lang
] = $localLanguage['default'];
2303 if ($this->lang
!== 'default' && isset($tempLL[$language])) {
2304 // Merge current language labels onto labels from previous language
2305 // This way we have a labels with fall back applied
2306 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($localLanguage[$this->lang
], $tempLL[$language], true, false);
2310 return $localLanguage;
2313 /*****************************************************/
2317 /*****************************************************/
2319 * Concatenate files into one file
2320 * registered handler
2322 protected function doConcatenate()
2324 $this->doConcatenateCss();
2325 $this->doConcatenateJavaScript();
2329 * Concatenate JavaScript files according to the configuration.
2331 protected function doConcatenateJavaScript()
2333 if ($this->concatenateJavascript
) {
2334 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsConcatenateHandler'])) {
2335 // use external concatenation routine
2337 'jsLibs' => &$this->jsLibs
,
2338 'jsFiles' => &$this->jsFiles
,
2339 'jsFooterFiles' => &$this->jsFooterFiles
,
2340 'headerData' => &$this->headerData
,
2341 'footerData' => &$this->footerData
2343 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsConcatenateHandler'], $params, $this);
2345 $this->jsLibs
= $this->getCompressor()->concatenateJsFiles($this->jsLibs
);
2346 $this->jsFiles
= $this->getCompressor()->concatenateJsFiles($this->jsFiles
);
2347 $this->jsFooterFiles
= $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles
);
2353 * Concatenate CSS files according to configuration.
2355 protected function doConcatenateCss()
2357 if ($this->concatenateCss
) {
2358 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssConcatenateHandler'])) {
2359 // use external concatenation routine
2361 'cssFiles' => &$this->cssFiles
,
2362 'cssLibs' => &$this->cssLibs
,
2363 'headerData' => &$this->headerData
,
2364 'footerData' => &$this->footerData
2366 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssConcatenateHandler'], $params, $this);
2369 if (TYPO3_MODE
=== 'BE') {
2370 $cssOptions = ['baseDirectories' => GeneralUtility
::makeInstance(DocumentTemplate
::class)->getSkinStylesheetDirectories()];
2372 $this->cssLibs
= $this->getCompressor()->concatenateCssFiles($this->cssLibs
, $cssOptions);
2373 $this->cssFiles
= $this->getCompressor()->concatenateCssFiles($this->cssFiles
, $cssOptions);
2379 * Compresses inline code
2381 protected function doCompress()
2383 $this->doCompressJavaScript();
2384 $this->doCompressCss();
2388 * Compresses CSS according to configuration.
2390 protected function doCompressCss()
2392 if ($this->compressCss
) {
2393 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'])) {
2394 // Use external compression routine
2396 'cssInline' => &$this->cssInline
,
2397 'cssFiles' => &$this->cssFiles
,
2398 'cssLibs' => &$this->cssLibs
,
2399 'headerData' => &$this->headerData
,
2400 'footerData' => &$this->footerData
2402 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'], $params, $this);
2404 $this->cssLibs
= $this->getCompressor()->compressCssFiles($this->cssLibs
);
2405 $this->cssFiles
= $this->getCompressor()->compressCssFiles($this->cssFiles
);
2411 * Compresses JavaScript according to configuration.
2413 protected function doCompressJavaScript()
2415 if ($this->compressJavascript
) {
2416 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'])) {
2417 // Use external compression routine
2419 'jsInline' => &$this->jsInline
,
2420 'jsFooterInline' => &$this->jsFooterInline
,
2421 'jsLibs' => &$this->jsLibs
,
2422 'jsFiles' => &$this->jsFiles
,
2423 'jsFooterFiles' => &$this->jsFooterFiles
,
2424 'headerData' => &$this->headerData
,
2425 'footerData' => &$this->footerData
2427 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'], $params, $this);
2429 // Traverse the arrays, compress files
2430 if (!empty($this->jsInline
)) {
2431 foreach ($this->jsInline
as $name => $properties) {
2432 if ($properties['compress']) {
2434 $this->jsInline
[$name]['code'] = GeneralUtility
::minifyJavaScript($properties['code'], $error);
2436 $this->compressError
.= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF
;
2441 $this->jsLibs
= $this->getCompressor()->compressJsFiles($this->jsLibs
);
2442 $this->jsFiles
= $this->getCompressor()->compressJsFiles($this->jsFiles
);
2443 $this->jsFooterFiles
= $this->getCompressor()->compressJsFiles($this->jsFooterFiles
);
2449 * Returns instance of \TYPO3\CMS\Core\Resource\ResourceCompressor
2451 * @return \TYPO3\CMS\Core\Resource\ResourceCompressor
2453 protected function getCompressor()
2455 if ($this->compressor
=== null) {
2456 $this->compressor
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\
Resource\ResourceCompressor
::class);
2458 return $this->compressor
;
2462 * Processes a Javascript file dependent on the current context
2464 * Adds the version number for Frontend, compresses the file for Backend
2466 * @param string $filename Filename
2467 * @return string New filename
2469 protected function processJsFile($filename)
2471 $filename = $this->getStreamlinedFileName($filename, false);
2472 if ($this->compressJavascript
) {
2473 $filename = $this->getCompressor()->compressJsFile($filename);
2474 } elseif (TYPO3_MODE
=== 'FE') {
2475 $filename = GeneralUtility
::createVersionNumberedFilename($filename);
2477 return $this->getAbsoluteWebPath($filename);
2481 * This function acts as a wrapper to allow relative and paths starting with EXT: to be dealt with
2482 * in this very case to always return the absolute web path to be included directly before output.
2484 * This is mainly added so the EXT: syntax can be resolved for PageRenderer in one central place,
2485 * and hopefully removed in the future by one standard API call.
2487 * @param string $file the filename to process
2488 * @param bool $prepareForOutput whether the file should be prepared as version numbered file and prefixed as absolute webpath
2492 protected function getStreamlinedFileName($file, $prepareForOutput = true)
2494 if (strpos($file, 'EXT:') === 0) {
2495 $file = GeneralUtility
::getFileAbsFileName($file);
2496 // as the path is now absolute, make it "relative" to the current script to stay compatible
2497 $file = PathUtility
::getRelativePathTo($file);
2498 $file = rtrim($file, '/');
2500 $file = GeneralUtility
::resolveBackPath($file);
2502 if ($prepareForOutput) {
2503 $file = GeneralUtility
::createVersionNumberedFilename($file);
2504 $file = $this->getAbsoluteWebPath($file);
2510 * Gets absolute web path of filename for backend disposal.
2511 * Resolving the absolute path in the frontend with conflict with
2512 * applying config.absRefPrefix in frontend rendering process.
2514 * @param string $file
2516 * @see TypoScriptFrontendController::setAbsRefPrefix()
2518 protected function getAbsoluteWebPath(string $file): string
2520 if (TYPO3_MODE
=== 'FE') {
2523 return PathUtility
::getAbsoluteWebPath($file);
2527 * Returns global frontend controller
2529 * @return TypoScriptFrontendController
2531 protected function getTypoScriptFrontendController()
2533 return $GLOBALS['TSFE'];
2536 /*****************************************************/
2540 /*****************************************************/
2542 * Execute PreRenderHook for possible manipulation
2544 protected function executePreRenderHook()
2546 $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] ??
false;
2551 'jsLibs' => &$this->jsLibs
,
2552 'jsFooterLibs' => &$this->jsFooterLibs
,
2553 'jsFiles' => &$this->jsFiles
,
2554 'jsFooterFiles' => &$this->jsFooterFiles
,
2555 'cssLibs' => &$this->cssLibs
,
2556 'cssFiles' => &$this->cssFiles
,
2557 'headerData' => &$this->headerData
,
2558 'footerData' => &$this->footerData
,
2559 'jsInline' => &$this->jsInline
,
2560 'jsFooterInline' => &$this->jsFooterInline
,
2561 'cssInline' => &$this->cssInline
2563 foreach ($hooks as $hook) {
2564 GeneralUtility
::callUserFunction($hook, $params, $this);
2569 * PostTransform for possible manipulation of concatenated and compressed files
2571 protected function executeRenderPostTransformHook()
2573 $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] ??
false;
2578 'jsLibs' => &$this->jsLibs
,
2579 'jsFooterLibs' => &$this->jsFooterLibs
,
2580 'jsFiles' => &$this->jsFiles
,
2581 'jsFooterFiles' => &$this->jsFooterFiles
,
2582 'cssLibs' => &$this->cssLibs
,
2583 'cssFiles' => &$this->cssFiles
,
2584 'headerData' => &$this->headerData
,
2585 'footerData' => &$this->footerData
,
2586 'jsInline' => &$this->jsInline
,
2587 'jsFooterInline' => &$this->jsFooterInline
,
2588 'cssInline' => &$this->cssInline
2590 foreach ($hooks as $hook) {
2591 GeneralUtility
::callUserFunction($hook, $params, $this);
2596 * Execute postRenderHook for possible manipulation
2598 * @param string $jsLibs
2599 * @param string $jsFiles
2600 * @param string $jsFooterFiles
2601 * @param string $cssLibs
2602 * @param string $cssFiles
2603 * @param string $jsInline
2604 * @param string $cssInline
2605 * @param string $jsFooterInline
2606 * @param string $jsFooterLibs
2608 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssLibs, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs)
2610 $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] ??
false;
2615 'jsLibs' => &$jsLibs,
2616 'jsFiles' => &$jsFiles,
2617 'jsFooterFiles' => &$jsFooterFiles,
2618 'cssLibs' => &$cssLibs,
2619 'cssFiles' => &$cssFiles,
2620 'headerData' => &$this->headerData
,
2621 'footerData' => &$this->footerData
,
2622 'jsInline' => &$jsInline,
2623 'cssInline' => &$cssInline,
2624 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType
,
2625 'htmlTag' => &$this->htmlTag
,
2626 'headTag' => &$this->headTag
,
2627 'charSet' => &$this->charSet
,
2628 'metaCharsetTag' => &$this->metaCharsetTag
,
2629 'shortcutTag' => &$this->shortcutTag
,
2630 'inlineComments' => &$this->inlineComments
,
2631 'baseUrl' => &$this->baseUrl
,
2632 'baseUrlTag' => &$this->baseUrlTag
,
2633 'favIcon' => &$this->favIcon
,
2634 'iconMimeType' => &$this->iconMimeType
,
2635 'titleTag' => &$this->titleTag
,
2636 'title' => &$this->title
,
2637 'metaTags' => &$this->metaTags
,
2638 'jsFooterInline' => &$jsFooterInline,
2639 'jsFooterLibs' => &$jsFooterLibs,
2640 'bodyContent' => &$this->bodyContent
2642 foreach ($hooks as $hook) {
2643 GeneralUtility
::callUserFunction($hook, $params, $this);
2648 * Creates an CSS inline tag
2650 * @param string $file the filename to process
2651 * @param array $properties
2654 protected function createInlineCssTagFromFile(string $file, array $properties): string
2656 $cssInline = file_get_contents($file);
2658 return '<style type="text/css"'
2659 . ' media="' . htmlspecialchars($properties['media']) . '"'
2660 . ($properties['title'] ?
' title="' . htmlspecialchars($properties['title']) . '"' : '')
2662 . '/*<![CDATA[*/' . LF
. '<!-- ' . LF
2664 . '-->' . LF
. '/*]]>*/' . LF
. '</style>' . LF
;