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\Exception\NoSuchCacheException
;
22 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
;
23 use TYPO3\CMS\Core\Core\Environment
;
24 use TYPO3\CMS\Core\Localization\LocalizationFactory
;
25 use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry
;
26 use TYPO3\CMS\Core\Service\MarkerBasedTemplateService
;
27 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility
;
28 use TYPO3\CMS\Core\Utility\GeneralUtility
;
29 use TYPO3\CMS\Core\Utility\PathUtility
;
30 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
;
33 * TYPO3 pageRender class
34 * This class render the HTML of a webpage, usable for BE and FE
36 class PageRenderer
implements \TYPO3\CMS\Core\SingletonInterface
38 // Constants for the part to be rendered
39 const PART_COMPLETE
= 0;
40 const PART_HEADER
= 1;
41 const PART_FOOTER
= 2;
43 const REQUIREJS_SCOPE_CONFIG
= 'config';
44 const REQUIREJS_SCOPE_RESOLVE
= 'resolve';
49 protected $compressJavascript = false;
54 protected $compressCss = false;
59 protected $removeLineBreaksFromTemplate = false;
64 protected $concatenateJavascript = false;
69 protected $concatenateCss = false;
74 protected $moveJsFromHeaderToFooter = false;
77 * @var \TYPO3\CMS\Core\Localization\Locales
83 * Two character string or 'default'
90 * List of language dependencies for actual language. This is used for local variants of a language
91 * that depend on their "main" language, like Brazilian Portuguese or Canadian French.
95 protected $languageDependencies = [];
98 * @var \TYPO3\CMS\Core\Resource\ResourceCompressor
100 protected $compressor;
102 // Arrays containing associative array for the included files
106 protected $jsFiles = [];
111 protected $jsFooterFiles = [];
116 protected $jsLibs = [];
121 protected $jsFooterLibs = [];
126 protected $cssFiles = [];
131 protected $cssLibs = [];
134 * The title of the page
141 * Charset for the rendering
160 protected $renderXhtml = true;
162 // Static header blocks
166 protected $xmlPrologAndDocType = '';
171 protected $metaTags = [];
174 * META Tags added via the API
178 protected $metaTagsByAPI = [];
183 protected $inlineComments = [];
188 protected $headerData = [];
193 protected $footerData = [];
198 protected $titleTag = '<title>|</title>';
203 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
208 protected $htmlTag = '<html>';
213 protected $headTag = '<head>';
218 protected $baseUrlTag = '<base href="|" />';
223 protected $iconMimeType = '';
228 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />';
230 // Static inline code blocks
234 protected $jsInline = [];
239 protected $jsFooterInline = [];
244 protected $cssInline = [];
249 protected $bodyContent;
254 protected $templateFile;
256 // Paths to contributed libraries
259 * default path to the requireJS library, relative to the typo3/ directory
262 protected $requireJsPath = 'EXT:core/Resources/Public/JavaScript/Contrib/';
264 // Internal flags for JS-libraries
266 * if set, the requireJS library is included
269 protected $addRequireJs = false;
272 * Inline configuration for requireJS (internal)
275 protected $requireJsConfig = [];
278 * Module names of internal requireJS 'paths'
281 protected $internalRequireJsPathModuleNames = [];
284 * Inline configuration for requireJS (public)
287 protected $publicRequireJsConfig = [];
292 protected $inlineLanguageLabels = [];
297 protected $inlineLanguageLabelFiles = [];
302 protected $inlineSettings = [];
307 protected $inlineJavascriptWrap = [];
312 protected $inlineCssWrap = [];
315 * Saves error messages generated during compression
319 protected $compressError = '';
322 * Is empty string for HTML and ' /' for XHTML rendering
326 protected $endingSlash = '';
329 * @var MetaTagManagerRegistry
331 protected $metaTagRegistry;
334 * @var FrontendInterface
336 protected static $cache = null;
339 * @param string $templateFile Declare the used template file. Omit this parameter will use default template
341 public function __construct($templateFile = '')
344 $this->locales
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Localization\Locales
::class);
345 if ($templateFile !== '') {
346 $this->templateFile
= $templateFile;
348 $this->inlineJavascriptWrap
= [
349 '<script type="text/javascript">' . LF
. '/*<![CDATA[*/' . LF
,
350 '/*]]>*/' . LF
. '</script>' . LF
352 $this->inlineCssWrap
= [
353 '<style type="text/css">' . LF
. '/*<![CDATA[*/' . LF
. '<!-- ' . LF
,
354 '-->' . LF
. '/*]]>*/' . LF
. '</style>' . LF
357 $this->metaTagRegistry
= GeneralUtility
::makeInstance(MetaTagManagerRegistry
::class);
358 $this->setMetaTag('name', 'generator', 'TYPO3 CMS');
362 * @param FrontendInterface $cache
364 public static function setCache(FrontendInterface
$cache)
366 static::$cache = $cache;
370 * Reset all vars to initial values
372 protected function reset()
374 $this->templateFile
= 'EXT:core/Resources/Private/Templates/PageRenderer.html';
376 $this->jsFooterFiles
= [];
377 $this->jsInline
= [];
378 $this->jsFooterInline
= [];
380 $this->cssFiles
= [];
381 $this->cssInline
= [];
382 $this->metaTags
= [];
383 $this->metaTagsByAPI
= [];
384 $this->inlineComments
= [];
385 $this->headerData
= [];
386 $this->footerData
= [];
389 /*****************************************************/
394 /*****************************************************/
398 * @param string $title title of webpage
400 public function setTitle($title)
402 $this->title
= $title;
406 * Enables/disables rendering of XHTML code
408 * @param bool $enable Enable XHTML
410 public function setRenderXhtml($enable)
412 $this->renderXhtml
= $enable;
416 * Sets xml prolog and docType
418 * @param string $xmlPrologAndDocType Complete tags for xml prolog and docType
420 public function setXmlPrologAndDocType($xmlPrologAndDocType)
422 $this->xmlPrologAndDocType
= $xmlPrologAndDocType;
428 * @param string $charSet Used charset
430 public function setCharSet($charSet)
432 $this->charSet
= $charSet;
438 * @param string $lang Used language
440 public function setLanguage($lang)
443 $this->languageDependencies
= [];
445 // Language is found. Configure it:
446 if (in_array($this->lang
, $this->locales
->getLocales())) {
447 $this->languageDependencies
[] = $this->lang
;
448 foreach ($this->locales
->getLocaleDependencies($this->lang
) as $language) {
449 $this->languageDependencies
[] = $language;
455 * Set the meta charset tag
457 * @param string $metaCharsetTag
459 public function setMetaCharsetTag($metaCharsetTag)
461 $this->metaCharsetTag
= $metaCharsetTag;
467 * @param string $htmlTag Html tag
469 public function setHtmlTag($htmlTag)
471 $this->htmlTag
= $htmlTag;
477 * @param string $headTag HTML head tag
479 public function setHeadTag($headTag)
481 $this->headTag
= $headTag;
487 * @param string $favIcon
489 public function setFavIcon($favIcon)
491 $this->favIcon
= $favIcon;
495 * Sets icon mime type
497 * @param string $iconMimeType
499 public function setIconMimeType($iconMimeType)
501 $this->iconMimeType
= $iconMimeType;
507 * @param string $baseUrl HTML base URL
509 public function setBaseUrl($baseUrl)
511 $this->baseUrl
= $baseUrl;
517 * @param string $file
519 public function setTemplateFile($file)
521 $this->templateFile
= $file;
525 * Sets Content for Body
527 * @param string $content
529 public function setBodyContent($content)
531 $this->bodyContent
= $content;
535 * Sets path to requireJS library (relative to typo3 directory)
537 * @param string $path Path to requireJS library
539 public function setRequireJsPath($path)
541 $this->requireJsPath
= $path;
545 * @param string $scope
548 public function getRequireJsConfig(string $scope = null): array
550 // return basic RequireJS configuration without shim, paths and packages
551 if ($scope === static::REQUIREJS_SCOPE_CONFIG
) {
552 return array_replace_recursive(
553 $this->publicRequireJsConfig
,
554 $this->filterArrayKeys(
555 $this->requireJsConfig
,
556 ['shim', 'paths', 'packages'],
561 // return RequireJS configuration for resolving only shim, paths and packages
562 if ($scope === static::REQUIREJS_SCOPE_RESOLVE
) {
563 return $this->filterArrayKeys(
564 $this->requireJsConfig
,
565 ['shim', 'paths', 'packages'],
572 /*****************************************************/
574 /* Public Enablers / Disablers */
577 /*****************************************************/
579 * Enables MoveJsFromHeaderToFooter
581 public function enableMoveJsFromHeaderToFooter()
583 $this->moveJsFromHeaderToFooter
= true;
587 * Disables MoveJsFromHeaderToFooter
589 public function disableMoveJsFromHeaderToFooter()
591 $this->moveJsFromHeaderToFooter
= false;
595 * Enables compression of javascript
597 public function enableCompressJavascript()
599 $this->compressJavascript
= true;
603 * Disables compression of javascript
605 public function disableCompressJavascript()
607 $this->compressJavascript
= false;
611 * Enables compression of css
613 public function enableCompressCss()
615 $this->compressCss
= true;
619 * Disables compression of css
621 public function disableCompressCss()
623 $this->compressCss
= false;
627 * Enables concatenation of js files
629 public function enableConcatenateJavascript()
631 $this->concatenateJavascript
= true;
635 * Disables concatenation of js files
637 public function disableConcatenateJavascript()
639 $this->concatenateJavascript
= false;
643 * Enables concatenation of css files
645 public function enableConcatenateCss()
647 $this->concatenateCss
= true;
651 * Disables concatenation of css files
653 public function disableConcatenateCss()
655 $this->concatenateCss
= false;
659 * Sets removal of all line breaks in template
661 public function enableRemoveLineBreaksFromTemplate()
663 $this->removeLineBreaksFromTemplate
= true;
667 * Unsets removal of all line breaks in template
669 public function disableRemoveLineBreaksFromTemplate()
671 $this->removeLineBreaksFromTemplate
= false;
676 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
678 public function enableDebugMode()
680 $this->compressJavascript
= false;
681 $this->compressCss
= false;
682 $this->concatenateCss
= false;
683 $this->concatenateJavascript
= false;
684 $this->removeLineBreaksFromTemplate
= false;
687 /*****************************************************/
692 /*****************************************************/
696 * @return string $title Title of webpage
698 public function getTitle()
706 * @return string $charSet
708 public function getCharSet()
710 return $this->charSet
;
716 * @return string $lang
718 public function getLanguage()
724 * Returns rendering mode XHTML or HTML
726 * @return bool TRUE if XHTML, FALSE if HTML
728 public function getRenderXhtml()
730 return $this->renderXhtml
;
736 * @return string $htmlTag Html tag
738 public function getHtmlTag()
740 return $this->htmlTag
;
748 public function getMetaCharsetTag()
750 return $this->metaCharsetTag
;
756 * @return string $tag Head tag
758 public function getHeadTag()
760 return $this->headTag
;
766 * @return string $favIcon
768 public function getFavIcon()
770 return $this->favIcon
;
774 * Gets icon mime type
776 * @return string $iconMimeType
778 public function getIconMimeType()
780 return $this->iconMimeType
;
786 * @return string $url
788 public function getBaseUrl()
790 return $this->baseUrl
;
798 public function getTemplateFile()
800 return $this->templateFile
;
804 * Gets MoveJsFromHeaderToFooter
808 public function getMoveJsFromHeaderToFooter()
810 return $this->moveJsFromHeaderToFooter
;
814 * Gets compress of javascript
818 public function getCompressJavascript()
820 return $this->compressJavascript
;
824 * Gets compress of css
828 public function getCompressCss()
830 return $this->compressCss
;
834 * Gets concatenate of js files
838 public function getConcatenateJavascript()
840 return $this->concatenateJavascript
;
844 * Gets concatenate of css files
848 public function getConcatenateCss()
850 return $this->concatenateCss
;
854 * Gets remove of empty lines from template
858 public function getRemoveLineBreaksFromTemplate()
860 return $this->removeLineBreaksFromTemplate
;
864 * Gets content for body
868 public function getBodyContent()
870 return $this->bodyContent
;
874 * Gets the inline language labels.
876 * @return array The inline language labels
878 public function getInlineLanguageLabels()
880 return $this->inlineLanguageLabels
;
884 * Gets the inline language files
888 public function getInlineLanguageLabelFiles()
890 return $this->inlineLanguageLabelFiles
;
893 /*****************************************************/
895 /* Public Functions to add Data */
898 /*****************************************************/
901 * Sets a given meta tag
903 * @param string $type The type of the meta tag. Allowed values are property, name or http-equiv
904 * @param string $name The name of the property to add
905 * @param string $content The content of the meta tag
906 * @param array $subProperties Subproperties of the meta tag (like e.g. og:image:width)
907 * @param bool $replace Replace earlier set meta tag
908 * @throws \InvalidArgumentException
910 public function setMetaTag(string $type, string $name, string $content, array $subProperties = [], $replace = true)
912 // Lowercase all the things
913 $type = strtolower($type);
914 $name = strtolower($name);
915 if (!in_array($type, ['property', 'name', 'http-equiv'], true)) {
916 throw new \
InvalidArgumentException(
917 '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 $cache = GeneralUtility
::makeInstance(CacheManager
::class)->getCache('pages');
1679 } catch (NoSuchCacheException
$e) {
1683 foreach ($metaTagManagers as $manager => $managerObject) {
1684 $cacheIdentifier = $this->getTypoScriptFrontendController()->newHash
. '-metatag-' . $manager;
1686 $existingCacheEntry = false;
1687 if ($cache instanceof FrontendInterface
&& $properties = $cache->get($cacheIdentifier)) {
1688 $existingCacheEntry = true;
1690 $properties = $managerObject->renderAllProperties();
1693 if (!empty($properties)) {
1694 $metaTags[] = $properties;
1696 if ($cache instanceof FrontendInterface
&& !$existingCacheEntry && ($this->getTypoScriptFrontendController()->page
['uid'] ??
false)) {
1700 ['pageId_' . $this->getTypoScriptFrontendController()->page
['uid']],
1701 $this->getTypoScriptFrontendController()->get_cache_timeout()
1710 * Render the page but not the JavaScript and CSS Files
1712 * @param string $substituteHash The hash that is used for the placehoder markers
1714 * @return string Content of rendered section
1716 public function renderPageWithUncachedObjects($substituteHash)
1718 $this->prepareRendering();
1719 $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
1720 $template = $this->getTemplateForPart(self
::PART_COMPLETE
);
1721 $templateService = GeneralUtility
::makeInstance(MarkerBasedTemplateService
::class);
1722 return trim($templateService->substituteMarkerArray($template, $markerArray, '###|###'));
1726 * Renders the JavaScript and CSS files that have been added during processing
1727 * of uncached content objects (USER_INT, COA_INT)
1729 * @param string $cachedPageContent
1730 * @param string $substituteHash The hash that is used for the placehoder markers
1734 public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash)
1736 $this->prepareRendering();
1737 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1738 $title = $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '';
1740 '<!-- ###TITLE' . $substituteHash . '### -->' => $title,
1741 '<!-- ###CSS_LIBS' . $substituteHash . '### -->' => $cssLibs,
1742 '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
1743 '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
1744 '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
1745 '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
1746 '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
1747 '<!-- ###META' . $substituteHash . '### -->' => implode(LF
, array_merge($this->metaTags
, $this->renderMetaTagsFromAPI())),
1748 '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF
, $this->headerData
),
1749 '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF
, $this->footerData
),
1750 '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
1751 '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
1752 '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline
1754 foreach ($markerArray as $placeHolder => $content) {
1755 $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
1758 return $cachedPageContent;
1762 * Remove ending slashes from static header block
1763 * if the page is being rendered as html (not xhtml)
1764 * and define property $this->endingSlash for further use
1766 protected function prepareRendering()
1768 if ($this->getRenderXhtml()) {
1769 $this->endingSlash
= ' /';
1771 $this->metaCharsetTag
= str_replace(' />', '>', $this->metaCharsetTag
);
1772 $this->baseUrlTag
= str_replace(' />', '>', $this->baseUrlTag
);
1773 $this->shortcutTag
= str_replace(' />', '>', $this->shortcutTag
);
1774 $this->endingSlash
= '';
1779 * Renders all JavaScript and CSS
1781 * @return array<string>
1783 protected function renderJavaScriptAndCss()
1785 $this->executePreRenderHook();
1786 $mainJsLibs = $this->renderMainJavaScriptLibraries();
1787 if ($this->concatenateJavascript ||
$this->concatenateCss
) {
1788 // Do the file concatenation
1789 $this->doConcatenate();
1791 if ($this->compressCss ||
$this->compressJavascript
) {
1792 // Do the file compression
1793 $this->doCompress();
1795 $this->executeRenderPostTransformHook();
1796 $cssLibs = $this->renderCssLibraries();
1797 $cssFiles = $this->renderCssFiles();
1798 $cssInline = $this->renderCssInline();
1799 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
1800 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
1801 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
1802 $jsLibs = $mainJsLibs . $jsLibs;
1803 if ($this->moveJsFromHeaderToFooter
) {
1804 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
1806 $jsFooterFiles = $jsFiles . LF
. $jsFooterFiles;
1808 $jsFooterInline = $jsInline . LF
. $jsFooterInline;
1811 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1812 return [$jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs];
1816 * Fills the marker array with the given strings and trims each value
1818 * @param string $jsLibs
1819 * @param string $jsFiles
1820 * @param string $jsFooterFiles
1821 * @param string $cssLibs
1822 * @param string $cssFiles
1823 * @param string $jsInline
1824 * @param string $cssInline
1825 * @param string $jsFooterInline
1826 * @param string $jsFooterLibs
1827 * @param string $metaTags
1828 * @return array Marker array
1830 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags)
1833 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1834 'HTMLTAG' => $this->htmlTag
,
1835 'HEADTAG' => $this->headTag
,
1836 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1837 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
1838 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1839 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1840 'CSS_LIBS' => $cssLibs,
1841 'CSS_INCLUDE' => $cssFiles,
1842 'CSS_INLINE' => $cssInline,
1843 'JS_INLINE' => $jsInline,
1844 'JS_INCLUDE' => $jsFiles,
1845 'JS_LIBS' => $jsLibs,
1846 'TITLE' => $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '',
1847 'META' => $metaTags,
1848 'HEADERDATA' => $this->headerData ?
implode(LF
, $this->headerData
) : '',
1849 'FOOTERDATA' => $this->footerData ?
implode(LF
, $this->footerData
) : '',
1850 'JS_LIBS_FOOTER' => $jsFooterLibs,
1851 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1852 'JS_INLINE_FOOTER' => $jsFooterInline,
1853 'BODY' => $this->bodyContent
1855 $markerArray = array_map('trim', $markerArray);
1856 return $markerArray;
1860 * Fills the marker array with the given strings and trims each value
1862 * @param string $substituteHash The hash that is used for the placehoder markers
1863 * @return array Marker array
1865 protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash)
1868 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1869 'HTMLTAG' => $this->htmlTag
,
1870 'HEADTAG' => $this->headTag
,
1871 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1872 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
1873 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1874 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1875 'META' => '<!-- ###META' . $substituteHash . '### -->',
1876 'BODY' => $this->bodyContent
,
1877 'TITLE' => '<!-- ###TITLE' . $substituteHash . '### -->',
1878 'CSS_LIBS' => '<!-- ###CSS_LIBS' . $substituteHash . '### -->',
1879 'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
1880 'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
1881 'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
1882 'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
1883 'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
1884 'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
1885 'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
1886 'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
1887 'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
1888 'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->'
1890 $markerArray = array_map('trim', $markerArray);
1891 return $markerArray;
1895 * Reads the template file and returns the requested part as string
1900 protected function getTemplateForPart($part)
1902 $templateFile = GeneralUtility
::getFileAbsFileName($this->templateFile
);
1903 if (is_file($templateFile)) {
1904 $template = file_get_contents($templateFile);
1905 if ($this->removeLineBreaksFromTemplate
) {
1906 $template = strtr($template, [LF
=> '', CR
=> '']);
1908 if ($part !== self
::PART_COMPLETE
) {
1909 $templatePart = explode('###BODY###', $template);
1910 $template = $templatePart[$part - 1];
1919 * Helper function for render the main JavaScript libraries,
1920 * currently: RequireJS
1922 * @return string Content with JavaScript libraries
1924 protected function renderMainJavaScriptLibraries()
1928 // Include RequireJS
1929 if ($this->addRequireJs
) {
1930 $out .= $this->getRequireJsLoader();
1933 $this->loadJavaScriptLanguageStrings();
1934 if (TYPO3_MODE
=== 'BE') {
1935 $noBackendUserLoggedIn = empty($GLOBALS['BE_USER']->user
['uid']);
1936 $this->addAjaxUrlsToInlineSettings($noBackendUserLoggedIn);
1938 $inlineSettings = '';
1939 $languageLabels = $this->parseLanguageLabelsForJavaScript();
1940 if (!empty($languageLabels)) {
1941 $inlineSettings .= 'TYPO3.lang = ' . json_encode($languageLabels) . ';';
1943 $inlineSettings .= $this->inlineSettings ?
'TYPO3.settings = ' . json_encode($this->inlineSettings
) . ';' : '';
1945 if ($inlineSettings !== '') {
1946 // make sure the global TYPO3 is available
1947 $inlineSettings = 'var TYPO3 = TYPO3 || {};' . CRLF
. $inlineSettings;
1948 $out .= $this->inlineJavascriptWrap
[0] . $inlineSettings . $this->inlineJavascriptWrap
[1];
1955 * Converts the language labels for usage in JavaScript
1959 protected function parseLanguageLabelsForJavaScript(): array
1961 if (empty($this->inlineLanguageLabels
)) {
1966 foreach ($this->inlineLanguageLabels
as $key => $translationUnit) {
1967 if (is_array($translationUnit)) {
1968 $translationUnit = current($translationUnit);
1969 $labels[$key] = $translationUnit['target'] ??
$translationUnit['source'];
1971 $labels[$key] = $translationUnit;
1979 * Load the language strings into JavaScript
1981 protected function loadJavaScriptLanguageStrings()
1983 if (!empty($this->inlineLanguageLabelFiles
)) {
1984 foreach ($this->inlineLanguageLabelFiles
as $languageLabelFile) {
1985 $this->includeLanguageFileForInline($languageLabelFile['fileRef'], $languageLabelFile['selectionPrefix'], $languageLabelFile['stripFromSelectionName']);
1988 $this->inlineLanguageLabelFiles
= [];
1989 // Convert settings back to UTF-8 since json_encode() only works with UTF-8:
1990 if ($this->getCharSet() && $this->getCharSet() !== 'utf-8' && is_array($this->inlineSettings
)) {
1991 $this->convertCharsetRecursivelyToUtf8($this->inlineSettings
, $this->getCharSet());
1996 * Small helper function to convert charsets for arrays into utf-8
1998 * @param mixed $data given by reference (string/array usually)
1999 * @param string $fromCharset convert FROM this charset
2001 protected function convertCharsetRecursivelyToUtf8(&$data, string $fromCharset)
2003 foreach ($data as $key => $value) {
2004 if (is_array($data[$key])) {
2005 $this->convertCharsetRecursivelyToUtf8($data[$key], $fromCharset);
2006 } elseif (is_string($data[$key])) {
2007 $data[$key] = mb_convert_encoding($data[$key], 'utf-8', $fromCharset);
2013 * Make URLs to all backend ajax handlers available as inline setting.
2015 * @param bool $publicRoutesOnly
2017 protected function addAjaxUrlsToInlineSettings(bool $publicRoutesOnly = false)
2020 // Add the ajax-based routes
2021 /** @var UriBuilder $uriBuilder */
2022 $uriBuilder = GeneralUtility
::makeInstance(UriBuilder
::class);
2023 /** @var Router $router */
2024 $router = GeneralUtility
::makeInstance(Router
::class);
2025 $routes = $router->getRoutes();
2026 foreach ($routes as $routeIdentifier => $route) {
2027 if ($publicRoutesOnly && $route->getOption('access') !== 'public') {
2030 if ($route->getOption('ajax')) {
2031 $uri = (string)$uriBuilder->buildUriFromRoute($routeIdentifier);
2032 // use the shortened value in order to use this in JavaScript
2033 $routeIdentifier = str_replace('ajax_', '', $routeIdentifier);
2034 $ajaxUrls[$routeIdentifier] = $uri;
2038 $this->inlineSettings
['ajaxUrls'] = $ajaxUrls;
2042 * Render CSS library files
2046 protected function renderCssLibraries()
2049 if (!empty($this->cssLibs
)) {
2050 foreach ($this->cssLibs
as $file => $properties) {
2051 $tag = $this->createCssTag($properties, $file);
2052 if ($properties['forceOnTop']) {
2053 $cssFiles = $tag . $cssFiles;
2067 protected function renderCssFiles()
2070 if (!empty($this->cssFiles
)) {
2071 foreach ($this->cssFiles
as $file => $properties) {
2072 $tag = $this->createCssTag($properties, $file);
2073 if ($properties['forceOnTop']) {
2074 $cssFiles = $tag . $cssFiles;
2084 * Create link (inline=0) or style (inline=1) tag
2086 * @param array $properties
2087 * @param string $file
2090 private function createCssTag(array $properties, string $file): string
2092 if ($properties['inline'] && @is_file
($file)) {
2093 $tag = $this->createInlineCssTagFromFile($file, $properties);
2095 $href = $this->getStreamlinedFileName($file);
2096 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2097 . '" type="text/css" href="' . htmlspecialchars($href)
2098 . '" media="' . htmlspecialchars($properties['media']) . '"'
2099 . ($properties['title'] ?
' title="' . htmlspecialchars($properties['title']) . '"' : '')
2100 . $this->endingSlash
. '>';
2102 if ($properties['allWrap']) {
2103 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2104 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2116 protected function renderCssInline()
2119 if (!empty($this->cssInline
)) {
2120 foreach ($this->cssInline
as $name => $properties) {
2121 $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2122 if ($properties['forceOnTop']) {
2123 $cssInline = $cssCode . $cssInline;
2125 $cssInline .= $cssCode;
2128 $cssInline = $this->inlineCssWrap
[0] . $cssInline . $this->inlineCssWrap
[1];
2134 * Render JavaScipt libraries
2136 * @return array<string> jsLibs and jsFooterLibs strings
2138 protected function renderAdditionalJavaScriptLibraries()
2142 if (!empty($this->jsLibs
)) {
2143 foreach ($this->jsLibs
as $properties) {
2144 $properties['file'] = $this->getStreamlinedFileName($properties['file']);
2145 $async = $properties['async'] ?
' async="async"' : '';
2146 $defer = $properties['defer'] ?
' defer="defer"' : '';
2147 $integrity = $properties['integrity'] ?
' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2148 $crossorigin = $properties['crossorigin'] ?
' crossorigin="' . htmlspecialchars($properties['crossorigin']) . '"' : '';
2149 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $defer . $integrity . $crossorigin . '></script>';
2150 if ($properties['allWrap']) {
2151 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2152 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2155 if ($properties['forceOnTop']) {
2156 if ($properties['section'] === self
::PART_HEADER
) {
2157 $jsLibs = $tag . $jsLibs;
2159 $jsFooterLibs = $tag . $jsFooterLibs;
2162 if ($properties['section'] === self
::PART_HEADER
) {
2165 $jsFooterLibs .= $tag;
2170 if ($this->moveJsFromHeaderToFooter
) {
2171 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
2174 return [$jsLibs, $jsFooterLibs];
2178 * Render JavaScript files
2180 * @return array<string> jsFiles and jsFooterFiles strings
2182 protected function renderJavaScriptFiles()
2185 $jsFooterFiles = '';
2186 if (!empty($this->jsFiles
)) {
2187 foreach ($this->jsFiles
as $file => $properties) {
2188 $file = $this->getStreamlinedFileName($file);
2189 $async = $properties['async'] ?
' async="async"' : '';
2190 $defer = $properties['defer'] ?
' defer="defer"' : '';
2191 $integrity = $properties['integrity'] ?
' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2192 $crossorigin = $properties['crossorigin'] ?
' crossorigin="' . htmlspecialchars($properties['crossorigin']) . '"' : '';
2193 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $defer . $integrity . $crossorigin . '></script>';
2194 if ($properties['allWrap']) {
2195 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2196 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2199 if ($properties['forceOnTop']) {
2200 if ($properties['section'] === self
::PART_HEADER
) {
2201 $jsFiles = $tag . $jsFiles;
2203 $jsFooterFiles = $tag . $jsFooterFiles;
2206 if ($properties['section'] === self
::PART_HEADER
) {
2209 $jsFooterFiles .= $tag;
2214 if ($this->moveJsFromHeaderToFooter
) {
2215 $jsFooterFiles = $jsFiles . $jsFooterFiles;
2218 return [$jsFiles, $jsFooterFiles];
2222 * Render inline JavaScript
2224 * @return array<string> jsInline and jsFooterInline string
2226 protected function renderInlineJavaScript()
2229 $jsFooterInline = '';
2230 if (!empty($this->jsInline
)) {
2231 foreach ($this->jsInline
as $name => $properties) {
2232 $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2233 if ($properties['forceOnTop']) {
2234 if ($properties['section'] === self
::PART_HEADER
) {
2235 $jsInline = $jsCode . $jsInline;
2237 $jsFooterInline = $jsCode . $jsFooterInline;
2240 if ($properties['section'] === self
::PART_HEADER
) {
2241 $jsInline .= $jsCode;
2243 $jsFooterInline .= $jsCode;
2249 $jsInline = $this->inlineJavascriptWrap
[0] . $jsInline . $this->inlineJavascriptWrap
[1];
2251 if ($jsFooterInline) {
2252 $jsFooterInline = $this->inlineJavascriptWrap
[0] . $jsFooterInline . $this->inlineJavascriptWrap
[1];
2254 if ($this->moveJsFromHeaderToFooter
) {
2255 $jsFooterInline = $jsInline . $jsFooterInline;
2258 return [$jsInline, $jsFooterInline];
2262 * Include language file for inline usage
2264 * @param string $fileRef
2265 * @param string $selectionPrefix
2266 * @param string $stripFromSelectionName
2267 * @throws \RuntimeException
2269 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '')
2271 if (!isset($this->lang
) ||
!isset($this->charSet
)) {
2272 throw new \
RuntimeException('Language and character encoding are not set.', 1284906026);
2274 $labelsFromFile = [];
2275 $allLabels = $this->readLLfile($fileRef);
2276 if ($allLabels !== false) {
2277 // Merge language specific translations:
2278 if ($this->lang
!== 'default' && isset($allLabels[$this->lang
])) {
2279 $labels = array_merge($allLabels['default'], $allLabels[$this->lang
]);
2281 $labels = $allLabels['default'];
2283 // Iterate through all locallang labels:
2284 foreach ($labels as $label => $value) {
2285 // If $selectionPrefix is set, only respect labels that start with $selectionPrefix
2286 if ($selectionPrefix === '' ||
strpos($label, $selectionPrefix) === 0) {
2287 // Remove substring $stripFromSelectionName from label
2288 $label = str_replace($stripFromSelectionName, '', $label);
2289 $labelsFromFile[$label] = $value;
2292 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $labelsFromFile);
2297 * Reads a locallang file.
2299 * @param string $fileRef Reference to a relative filename to include.
2300 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2302 protected function readLLfile($fileRef)
2304 /** @var LocalizationFactory $languageFactory */
2305 $languageFactory = GeneralUtility
::makeInstance(LocalizationFactory
::class);
2307 if ($this->lang
!== 'default') {
2308 $languages = array_reverse($this->languageDependencies
);
2309 // At least we need to have English
2310 if (empty($languages)) {
2311 $languages[] = 'default';
2314 $languages = ['default'];
2317 $localLanguage = [];
2318 foreach ($languages as $language) {
2319 $tempLL = $languageFactory->getParsedData($fileRef, $language);
2321 $localLanguage['default'] = $tempLL['default'];
2322 if (!isset($localLanguage[$this->lang
])) {
2323 $localLanguage[$this->lang
] = $localLanguage['default'];
2325 if ($this->lang
!== 'default' && isset($tempLL[$language])) {
2326 // Merge current language labels onto labels from previous language
2327 // This way we have a labels with fall back applied
2328 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($localLanguage[$this->lang
], $tempLL[$language], true, false);
2332 return $localLanguage;
2335 /*****************************************************/
2339 /*****************************************************/
2341 * Concatenate files into one file
2342 * registered handler
2344 protected function doConcatenate()
2346 $this->doConcatenateCss();
2347 $this->doConcatenateJavaScript();
2351 * Concatenate JavaScript files according to the configuration.
2353 protected function doConcatenateJavaScript()
2355 if ($this->concatenateJavascript
) {
2356 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsConcatenateHandler'])) {
2357 // use external concatenation routine
2359 'jsLibs' => &$this->jsLibs
,
2360 'jsFiles' => &$this->jsFiles
,
2361 'jsFooterFiles' => &$this->jsFooterFiles
,
2362 'headerData' => &$this->headerData
,
2363 'footerData' => &$this->footerData
2365 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsConcatenateHandler'], $params, $this);
2367 $this->jsLibs
= $this->getCompressor()->concatenateJsFiles($this->jsLibs
);
2368 $this->jsFiles
= $this->getCompressor()->concatenateJsFiles($this->jsFiles
);
2369 $this->jsFooterFiles
= $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles
);
2375 * Concatenate CSS files according to configuration.
2377 protected function doConcatenateCss()
2379 if ($this->concatenateCss
) {
2380 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssConcatenateHandler'])) {
2381 // use external concatenation routine
2383 'cssFiles' => &$this->cssFiles
,
2384 'cssLibs' => &$this->cssLibs
,
2385 'headerData' => &$this->headerData
,
2386 'footerData' => &$this->footerData
2388 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssConcatenateHandler'], $params, $this);
2391 if (TYPO3_MODE
=== 'BE') {
2392 $cssOptions = ['baseDirectories' => GeneralUtility
::makeInstance(DocumentTemplate
::class)->getSkinStylesheetDirectories()];
2394 $this->cssLibs
= $this->getCompressor()->concatenateCssFiles($this->cssLibs
, $cssOptions);
2395 $this->cssFiles
= $this->getCompressor()->concatenateCssFiles($this->cssFiles
, $cssOptions);
2401 * Compresses inline code
2403 protected function doCompress()
2405 $this->doCompressJavaScript();
2406 $this->doCompressCss();
2410 * Compresses CSS according to configuration.
2412 protected function doCompressCss()
2414 if ($this->compressCss
) {
2415 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'])) {
2416 // Use external compression routine
2418 'cssInline' => &$this->cssInline
,
2419 'cssFiles' => &$this->cssFiles
,
2420 'cssLibs' => &$this->cssLibs
,
2421 'headerData' => &$this->headerData
,
2422 'footerData' => &$this->footerData
2424 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'], $params, $this);
2426 $this->cssLibs
= $this->getCompressor()->compressCssFiles($this->cssLibs
);
2427 $this->cssFiles
= $this->getCompressor()->compressCssFiles($this->cssFiles
);
2433 * Compresses JavaScript according to configuration.
2435 protected function doCompressJavaScript()
2437 if ($this->compressJavascript
) {
2438 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'])) {
2439 // Use external compression routine
2441 'jsInline' => &$this->jsInline
,
2442 'jsFooterInline' => &$this->jsFooterInline
,
2443 'jsLibs' => &$this->jsLibs
,
2444 'jsFiles' => &$this->jsFiles
,
2445 'jsFooterFiles' => &$this->jsFooterFiles
,
2446 'headerData' => &$this->headerData
,
2447 'footerData' => &$this->footerData
2449 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'], $params, $this);
2451 // Traverse the arrays, compress files
2452 if (!empty($this->jsInline
)) {
2453 foreach ($this->jsInline
as $name => $properties) {
2454 if ($properties['compress']) {
2456 $this->jsInline
[$name]['code'] = GeneralUtility
::minifyJavaScript($properties['code'], $error);
2458 $this->compressError
.= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF
;
2463 $this->jsLibs
= $this->getCompressor()->compressJsFiles($this->jsLibs
);
2464 $this->jsFiles
= $this->getCompressor()->compressJsFiles($this->jsFiles
);
2465 $this->jsFooterFiles
= $this->getCompressor()->compressJsFiles($this->jsFooterFiles
);
2471 * Returns instance of \TYPO3\CMS\Core\Resource\ResourceCompressor
2473 * @return \TYPO3\CMS\Core\Resource\ResourceCompressor
2475 protected function getCompressor()
2477 if ($this->compressor
=== null) {
2478 $this->compressor
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\
Resource\ResourceCompressor
::class);
2480 return $this->compressor
;
2484 * Processes a Javascript file dependent on the current context
2486 * Adds the version number for Frontend, compresses the file for Backend
2488 * @param string $filename Filename
2489 * @return string New filename
2491 protected function processJsFile($filename)
2493 $filename = $this->getStreamlinedFileName($filename, false);
2494 if ($this->compressJavascript
) {
2495 $filename = $this->getCompressor()->compressJsFile($filename);
2496 } elseif (TYPO3_MODE
=== 'FE') {
2497 $filename = GeneralUtility
::createVersionNumberedFilename($filename);
2499 return $this->getAbsoluteWebPath($filename);
2503 * This function acts as a wrapper to allow relative and paths starting with EXT: to be dealt with
2504 * in this very case to always return the absolute web path to be included directly before output.
2506 * This is mainly added so the EXT: syntax can be resolved for PageRenderer in one central place,
2507 * and hopefully removed in the future by one standard API call.
2509 * @param string $file the filename to process
2510 * @param bool $prepareForOutput whether the file should be prepared as version numbered file and prefixed as absolute webpath
2514 protected function getStreamlinedFileName($file, $prepareForOutput = true)
2516 if (strpos($file, 'EXT:') === 0) {
2517 $file = GeneralUtility
::getFileAbsFileName($file);
2518 // as the path is now absolute, make it "relative" to the current script to stay compatible
2519 $file = PathUtility
::getRelativePathTo($file);
2520 $file = rtrim($file, '/');
2522 $file = GeneralUtility
::resolveBackPath($file);
2524 if ($prepareForOutput) {
2525 $file = GeneralUtility
::createVersionNumberedFilename($file);
2526 $file = $this->getAbsoluteWebPath($file);
2532 * Gets absolute web path of filename for backend disposal.
2533 * Resolving the absolute path in the frontend with conflict with
2534 * applying config.absRefPrefix in frontend rendering process.
2536 * @param string $file
2538 * @see TypoScriptFrontendController::setAbsRefPrefix()
2540 protected function getAbsoluteWebPath(string $file): string
2542 if (TYPO3_MODE
=== 'FE') {
2545 return PathUtility
::getAbsoluteWebPath($file);
2549 * Returns global frontend controller
2551 * @return TypoScriptFrontendController
2553 protected function getTypoScriptFrontendController()
2555 return $GLOBALS['TSFE'];
2558 /*****************************************************/
2562 /*****************************************************/
2564 * Execute PreRenderHook for possible manipulation
2566 protected function executePreRenderHook()
2568 $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] ??
false;
2573 'jsLibs' => &$this->jsLibs
,
2574 'jsFooterLibs' => &$this->jsFooterLibs
,
2575 'jsFiles' => &$this->jsFiles
,
2576 'jsFooterFiles' => &$this->jsFooterFiles
,
2577 'cssLibs' => &$this->cssLibs
,
2578 'cssFiles' => &$this->cssFiles
,
2579 'headerData' => &$this->headerData
,
2580 'footerData' => &$this->footerData
,
2581 'jsInline' => &$this->jsInline
,
2582 'jsFooterInline' => &$this->jsFooterInline
,
2583 'cssInline' => &$this->cssInline
2585 foreach ($hooks as $hook) {
2586 GeneralUtility
::callUserFunction($hook, $params, $this);
2591 * PostTransform for possible manipulation of concatenated and compressed files
2593 protected function executeRenderPostTransformHook()
2595 $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] ??
false;
2600 'jsLibs' => &$this->jsLibs
,
2601 'jsFooterLibs' => &$this->jsFooterLibs
,
2602 'jsFiles' => &$this->jsFiles
,
2603 'jsFooterFiles' => &$this->jsFooterFiles
,
2604 'cssLibs' => &$this->cssLibs
,
2605 'cssFiles' => &$this->cssFiles
,
2606 'headerData' => &$this->headerData
,
2607 'footerData' => &$this->footerData
,
2608 'jsInline' => &$this->jsInline
,
2609 'jsFooterInline' => &$this->jsFooterInline
,
2610 'cssInline' => &$this->cssInline
2612 foreach ($hooks as $hook) {
2613 GeneralUtility
::callUserFunction($hook, $params, $this);
2618 * Execute postRenderHook for possible manipulation
2620 * @param string $jsLibs
2621 * @param string $jsFiles
2622 * @param string $jsFooterFiles
2623 * @param string $cssLibs
2624 * @param string $cssFiles
2625 * @param string $jsInline
2626 * @param string $cssInline
2627 * @param string $jsFooterInline
2628 * @param string $jsFooterLibs
2630 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssLibs, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs)
2632 $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] ??
false;
2637 'jsLibs' => &$jsLibs,
2638 'jsFiles' => &$jsFiles,
2639 'jsFooterFiles' => &$jsFooterFiles,
2640 'cssLibs' => &$cssLibs,
2641 'cssFiles' => &$cssFiles,
2642 'headerData' => &$this->headerData
,
2643 'footerData' => &$this->footerData
,
2644 'jsInline' => &$jsInline,
2645 'cssInline' => &$cssInline,
2646 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType
,
2647 'htmlTag' => &$this->htmlTag
,
2648 'headTag' => &$this->headTag
,
2649 'charSet' => &$this->charSet
,
2650 'metaCharsetTag' => &$this->metaCharsetTag
,
2651 'shortcutTag' => &$this->shortcutTag
,
2652 'inlineComments' => &$this->inlineComments
,
2653 'baseUrl' => &$this->baseUrl
,
2654 'baseUrlTag' => &$this->baseUrlTag
,
2655 'favIcon' => &$this->favIcon
,
2656 'iconMimeType' => &$this->iconMimeType
,
2657 'titleTag' => &$this->titleTag
,
2658 'title' => &$this->title
,
2659 'metaTags' => &$this->metaTags
,
2660 'jsFooterInline' => &$jsFooterInline,
2661 'jsFooterLibs' => &$jsFooterLibs,
2662 'bodyContent' => &$this->bodyContent
2664 foreach ($hooks as $hook) {
2665 GeneralUtility
::callUserFunction($hook, $params, $this);
2670 * Creates an CSS inline tag
2672 * @param string $file the filename to process
2673 * @param array $properties
2676 protected function createInlineCssTagFromFile(string $file, array $properties): string
2678 $cssInline = file_get_contents($file);
2680 return '<style type="text/css"'
2681 . ' media="' . htmlspecialchars($properties['media']) . '"'
2682 . ($properties['title'] ?
' title="' . htmlspecialchars($properties['title']) . '"' : '')
2684 . '/*<![CDATA[*/' . LF
. '<!-- ' . LF
2686 . '-->' . LF
. '/*]]>*/' . LF
. '</style>' . LF
;