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\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Localization\LocalizationFactory
;
19 use TYPO3\CMS\Core\Utility\GeneralUtility
;
22 * TYPO3 pageRender class (new in TYPO3 4.3.0)
23 * This class render the HTML of a webpage, usable for BE and FE
25 class PageRenderer
implements \TYPO3\CMS\Core\SingletonInterface
{
27 // Constants for the part to be rendered
28 const PART_COMPLETE
= 0;
29 const PART_HEADER
= 1;
30 const PART_FOOTER
= 2;
31 // jQuery Core version that is shipped with TYPO3
32 const JQUERY_VERSION_LATEST
= '1.11.3';
33 // jQuery namespace options
34 const JQUERY_NAMESPACE_NONE
= 'none';
35 const JQUERY_NAMESPACE_DEFAULT
= 'jQuery';
36 const JQUERY_NAMESPACE_DEFAULT_NOCONFLICT
= 'defaultNoConflict';
41 protected $compressJavascript = FALSE;
46 protected $compressCss = FALSE;
51 protected $removeLineBreaksFromTemplate = FALSE;
56 protected $concatenateFiles = FALSE;
61 protected $concatenateJavascript = FALSE;
66 protected $concatenateCss = FALSE;
71 protected $moveJsFromHeaderToFooter = FALSE;
74 * @var \TYPO3\CMS\Core\Charset\CharsetConverter
79 * @var \TYPO3\CMS\Core\Localization\Locales
85 * Two character string or 'default'
92 * List of language dependencies for actual language. This is used for local variants of a language
93 * that depend on their "main" language, like Brazilian Portuguese or Canadian French.
97 protected $languageDependencies = array();
100 * @var \TYPO3\CMS\Core\Resource\ResourceCompressor
102 protected $compressor;
104 // Arrays containing associative array for the included files
108 protected $jsFiles = array();
113 protected $jsFooterFiles = array();
118 protected $jsLibs = array();
123 protected $jsFooterLibs = array();
128 protected $cssFiles = array();
133 protected $cssLibs = array();
136 * The title of the page
143 * Charset for the rendering
162 protected $renderXhtml = TRUE;
164 // Static header blocks
168 protected $xmlPrologAndDocType = '';
173 protected $metaTags = array();
178 protected $inlineComments = array();
183 protected $headerData = array();
188 protected $footerData = array();
193 protected $titleTag = '<title>|</title>';
198 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
203 protected $htmlTag = '<html>';
208 protected $headTag = '<head>';
213 protected $baseUrlTag = '<base href="|" />';
218 protected $iconMimeType = '';
223 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />';
225 // Static inline code blocks
229 protected $jsInline = array();
234 protected $jsFooterInline = array();
239 protected $extOnReadyCode = array();
244 protected $cssInline = array();
249 protected $bodyContent;
254 protected $templateFile;
259 protected $jsLibraryNames = array('extjs');
261 // Paths to contibuted libraries
264 * default path to the requireJS library, relative to the typo3/ directory
267 protected $requireJsPath = 'sysext/core/Resources/Public/JavaScript/Contrib/';
272 protected $extJsPath = 'sysext/core/Resources/Public/JavaScript/Contrib/extjs/';
275 * The local directory where one can find jQuery versions and plugins
279 protected $jQueryPath = 'sysext/core/Resources/Public/JavaScript/Contrib/jquery/';
281 // Internal flags for JS-libraries
283 * This array holds all jQuery versions that should be included in the
285 * Each version is described by "source", "version" and "namespace"
287 * The namespace of every particular version is the key
288 * of that array, because only one version per namespace can exist.
290 * The type "source" describes where the jQuery core should be included from
291 * currently, TYPO3 supports "local" (make use of jQuery path), "google",
292 * "jquery", "msn" and "cloudflare".
294 * Currently there are downsides to "local" which supports only the latest/shipped
295 * jQuery core out of the box.
299 protected $jQueryVersions = array();
302 * Array of jQuery version numbers shipped with the core
306 protected $availableLocalJqueryVersions = array(
307 self
::JQUERY_VERSION_LATEST
311 * Array of jQuery CDNs with placeholders
315 protected $jQueryCdnUrls = array(
316 'google' => 'https://ajax.googleapis.com/ajax/libs/jquery/%1$s/jquery%2$s.js',
317 'msn' => 'https://ajax.aspnetcdn.com/ajax/jQuery/jquery-%1$s%2$s.js',
318 'jquery' => 'https://code.jquery.com/jquery-%1$s%2$s.js',
319 'cloudflare' => 'https://cdnjs.cloudflare.com/ajax/libs/jquery/%1$s/jquery%2$s.js'
323 * if set, the requireJS library is included
326 protected $addRequireJs = FALSE;
329 * inline configuration for requireJS
332 protected $requireJsConfig = array();
337 protected $addExtJS = FALSE;
342 protected $extDirectCodeAdded = FALSE;
347 protected $enableExtJsDebug = FALSE;
352 protected $enableJqueryDebug = FALSE;
357 protected $extJStheme = TRUE;
362 protected $extJScss = TRUE;
367 protected $inlineLanguageLabels = array();
372 protected $inlineLanguageLabelFiles = array();
377 protected $inlineSettings = array();
382 protected $inlineJavascriptWrap = array();
385 * Saves error messages generated during compression
389 protected $compressError = '';
392 * Is empty string for HTML and ' /' for XHTML rendering
396 protected $endingSlash = '';
406 * @param string $templateFile Declare the used template file. Omit this parameter will use default template
407 * @param string $backPath Relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
409 public function __construct($templateFile = '', $backPath = NULL) {
411 $this->csConvObj
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter
::class);
412 $this->locales
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Localization\Locales
::class);
413 if ($templateFile !== '') {
414 $this->templateFile
= $templateFile;
416 $this->backPath
= isset($backPath) ?
$backPath : $GLOBALS['BACK_PATH'];
417 $this->inlineJavascriptWrap
= array(
418 '<script type="text/javascript">' . LF
. '/*<![CDATA[*/' . LF
,
419 '/*]]>*/' . LF
. '</script>' . LF
421 $this->inlineCssWrap
= array(
422 '<style type="text/css">' . LF
. '/*<![CDATA[*/' . LF
. '<!-- ' . LF
,
423 '-->' . LF
. '/*]]>*/' . LF
. '</style>' . LF
428 * Reset all vars to initial values
432 protected function reset() {
433 $this->templateFile
= 'EXT:core/Resources/Private/Templates/PageRenderer.html';
434 $this->jsFiles
= array();
435 $this->jsFooterFiles
= array();
436 $this->jsInline
= array();
437 $this->jsFooterInline
= array();
438 $this->jsLibs
= array();
439 $this->cssFiles
= array();
440 $this->cssInline
= array();
441 $this->metaTags
= array();
442 $this->inlineComments
= array();
443 $this->headerData
= array();
444 $this->footerData
= array();
445 $this->extOnReadyCode
= array();
446 $this->jQueryVersions
= array();
449 /*****************************************************/
454 /*****************************************************/
458 * @param string $title title of webpage
461 public function setTitle($title) {
462 $this->title
= $title;
466 * Enables/disables rendering of XHTML code
468 * @param bool $enable Enable XHTML
471 public function setRenderXhtml($enable) {
472 $this->renderXhtml
= $enable;
476 * Sets xml prolog and docType
478 * @param string $xmlPrologAndDocType Complete tags for xml prolog and docType
481 public function setXmlPrologAndDocType($xmlPrologAndDocType) {
482 $this->xmlPrologAndDocType
= $xmlPrologAndDocType;
488 * @param string $charSet Used charset
491 public function setCharSet($charSet) {
492 $this->charSet
= $charSet;
498 * @param string $lang Used language
501 public function setLanguage($lang) {
503 $this->languageDependencies
= array();
505 // Language is found. Configure it:
506 if (in_array($this->lang
, $this->locales
->getLocales())) {
507 $this->languageDependencies
[] = $this->lang
;
508 foreach ($this->locales
->getLocaleDependencies($this->lang
) as $language) {
509 $this->languageDependencies
[] = $language;
515 * Set the meta charset tag
517 * @param string $metaCharsetTag
520 public function setMetaCharsetTag($metaCharsetTag) {
521 $this->metaCharsetTag
= $metaCharsetTag;
527 * @param string $htmlTag Html tag
530 public function setHtmlTag($htmlTag) {
531 $this->htmlTag
= $htmlTag;
537 * @param string $headTag HTML head tag
540 public function setHeadTag($headTag) {
541 $this->headTag
= $headTag;
547 * @param string $favIcon
550 public function setFavIcon($favIcon) {
551 $this->favIcon
= $favIcon;
555 * Sets icon mime type
557 * @param string $iconMimeType
560 public function setIconMimeType($iconMimeType) {
561 $this->iconMimeType
= $iconMimeType;
567 * @param string $baseUrl HTML base URL
570 public function setBaseUrl($baseUrl) {
571 $this->baseUrl
= $baseUrl;
577 * @param string $file
580 public function setTemplateFile($file) {
581 $this->templateFile
= $file;
587 * @param string $backPath
590 public function setBackPath($backPath) {
591 $this->backPath
= $backPath;
595 * Sets Content for Body
597 * @param string $content
600 public function setBodyContent($content) {
601 $this->bodyContent
= $content;
605 * Sets path to requireJS library (relative to typo3 directory)
607 * @param string $path Path to requireJS library
610 public function setRequireJsPath($path) {
611 $this->requireJsPath
= $path;
615 * Sets Path for ExtJs library (relative to typo3 directory)
617 * @param string $path
620 public function setExtJsPath($path) {
621 $this->extJsPath
= $path;
624 /*****************************************************/
626 /* Public Enablers / Disablers */
629 /*****************************************************/
631 * Enables MoveJsFromHeaderToFooter
635 public function enableMoveJsFromHeaderToFooter() {
636 $this->moveJsFromHeaderToFooter
= TRUE;
640 * Disables MoveJsFromHeaderToFooter
644 public function disableMoveJsFromHeaderToFooter() {
645 $this->moveJsFromHeaderToFooter
= FALSE;
649 * Enables compression of javascript
653 public function enableCompressJavascript() {
654 $this->compressJavascript
= TRUE;
658 * Disables compression of javascript
662 public function disableCompressJavascript() {
663 $this->compressJavascript
= FALSE;
667 * Enables compression of css
671 public function enableCompressCss() {
672 $this->compressCss
= TRUE;
676 * Disables compression of css
680 public function disableCompressCss() {
681 $this->compressCss
= FALSE;
685 * Enables concatenation of js and css files
689 public function enableConcatenateFiles() {
690 $this->concatenateFiles
= TRUE;
694 * Disables concatenation of js and css files
698 public function disableConcatenateFiles() {
699 $this->concatenateFiles
= FALSE;
703 * Enables concatenation of js files
707 public function enableConcatenateJavascript() {
708 $this->concatenateJavascript
= TRUE;
712 * Disables concatenation of js files
716 public function disableConcatenateJavascript() {
717 $this->concatenateJavascript
= FALSE;
721 * Enables concatenation of css files
725 public function enableConcatenateCss() {
726 $this->concatenateCss
= TRUE;
730 * Disables concatenation of css files
734 public function disableConcatenateCss() {
735 $this->concatenateCss
= FALSE;
739 * Sets removal of all line breaks in template
743 public function enableRemoveLineBreaksFromTemplate() {
744 $this->removeLineBreaksFromTemplate
= TRUE;
748 * Unsets removal of all line breaks in template
752 public function disableRemoveLineBreaksFromTemplate() {
753 $this->removeLineBreaksFromTemplate
= FALSE;
758 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
762 public function enableDebugMode() {
763 $this->compressJavascript
= FALSE;
764 $this->compressCss
= FALSE;
765 $this->concatenateFiles
= FALSE;
766 $this->removeLineBreaksFromTemplate
= FALSE;
767 $this->enableExtJsDebug
= TRUE;
768 $this->enableJqueryDebug
= TRUE;
771 /*****************************************************/
776 /*****************************************************/
780 * @return string $title Title of webpage
782 public function getTitle() {
789 * @return string $charSet
791 public function getCharSet() {
792 return $this->charSet
;
798 * @return string $lang
800 public function getLanguage() {
805 * Returns rendering mode XHTML or HTML
807 * @return bool TRUE if XHTML, FALSE if HTML
809 public function getRenderXhtml() {
810 return $this->renderXhtml
;
816 * @return string $htmlTag Html tag
818 public function getHtmlTag() {
819 return $this->htmlTag
;
827 public function getMetaCharsetTag() {
828 return $this->metaCharsetTag
;
834 * @return string $tag Head tag
836 public function getHeadTag() {
837 return $this->headTag
;
843 * @return string $favIcon
845 public function getFavIcon() {
846 return $this->favIcon
;
850 * Gets icon mime type
852 * @return string $iconMimeType
854 public function getIconMimeType() {
855 return $this->iconMimeType
;
861 * @return string $url
863 public function getBaseUrl() {
864 return $this->baseUrl
;
872 public function getTemplateFile() {
873 return $this->templateFile
;
877 * Gets MoveJsFromHeaderToFooter
881 public function getMoveJsFromHeaderToFooter() {
882 return $this->moveJsFromHeaderToFooter
;
886 * Gets compress of javascript
890 public function getCompressJavascript() {
891 return $this->compressJavascript
;
895 * Gets compress of css
899 public function getCompressCss() {
900 return $this->compressCss
;
904 * Gets concatenate of js and css files
908 public function getConcatenateFiles() {
909 return $this->concatenateFiles
;
913 * Gets concatenate of js files
917 public function getConcatenateJavascript() {
918 return $this->concatenateJavascript
;
922 * Gets concatenate of css files
926 public function getConcatenateCss() {
927 return $this->concatenateCss
;
931 * Gets remove of empty lines from template
935 public function getRemoveLineBreaksFromTemplate() {
936 return $this->removeLineBreaksFromTemplate
;
940 * Gets content for body
944 public function getBodyContent() {
945 return $this->bodyContent
;
949 * Gets Path for ExtJs library (relative to typo3 directory)
953 public function getExtJsPath() {
954 return $this->extJsPath
;
958 * Gets the inline language labels.
960 * @return array The inline language labels
962 public function getInlineLanguageLabels() {
963 return $this->inlineLanguageLabels
;
967 * Gets the inline language files
971 public function getInlineLanguageLabelFiles() {
972 return $this->inlineLanguageLabelFiles
;
975 /*****************************************************/
977 /* Public Functions to add Data */
980 /*****************************************************/
984 * @param string $meta Meta data (complete metatag)
987 public function addMetaTag($meta) {
988 if (!in_array($meta, $this->metaTags
)) {
989 $this->metaTags
[] = $meta;
994 * Adds inline HTML comment
996 * @param string $comment
999 public function addInlineComment($comment) {
1000 if (!in_array($comment, $this->inlineComments
)) {
1001 $this->inlineComments
[] = $comment;
1008 * @param string $data Free header data for HTML header
1011 public function addHeaderData($data) {
1012 if (!in_array($data, $this->headerData
)) {
1013 $this->headerData
[] = $data;
1020 * @param string $data Free header data for HTML header
1023 public function addFooterData($data) {
1024 if (!in_array($data, $this->footerData
)) {
1025 $this->footerData
[] = $data;
1030 * Adds JS Library. JS Library block is rendered on top of the JS files.
1032 * @param string $name Arbitrary identifier
1033 * @param string $file File name
1034 * @param string $type Content Type
1035 * @param bool $compress Flag if library should be compressed
1036 * @param bool $forceOnTop Flag if added library should be inserted at begin of this block
1037 * @param string $allWrap
1038 * @param bool $excludeFromConcatenation
1039 * @param string $splitChar The char used to split the allWrap value, default is "|"
1040 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1041 * @param string $integrity Subresource Integrity (SRI)
1044 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE, $integrity = '') {
1046 $type = 'text/javascript';
1048 if (!in_array(strtolower($name), $this->jsLibs
)) {
1049 $this->jsLibs
[strtolower($name)] = array(
1052 'section' => self
::PART_HEADER
,
1053 'compress' => $compress,
1054 'forceOnTop' => $forceOnTop,
1055 'allWrap' => $allWrap,
1056 'excludeFromConcatenation' => $excludeFromConcatenation,
1057 'splitChar' => $splitChar,
1059 'integrity' => $integrity,
1065 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
1067 * @param string $name Arbitrary identifier
1068 * @param string $file File name
1069 * @param string $type Content Type
1070 * @param bool $compress Flag if library should be compressed
1071 * @param bool $forceOnTop Flag if added library should be inserted at begin of this block
1072 * @param string $allWrap
1073 * @param bool $excludeFromConcatenation
1074 * @param string $splitChar The char used to split the allWrap value, default is "|"
1075 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1076 * @param string $integrity Subresource Integrity (SRI)
1079 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE, $integrity = '') {
1081 $type = 'text/javascript';
1083 if (!in_array(strtolower($name), $this->jsLibs
)) {
1084 $this->jsLibs
[strtolower($name)] = array(
1087 'section' => self
::PART_FOOTER
,
1088 'compress' => $compress,
1089 'forceOnTop' => $forceOnTop,
1090 'allWrap' => $allWrap,
1091 'excludeFromConcatenation' => $excludeFromConcatenation,
1092 'splitChar' => $splitChar,
1094 'integrity' => $integrity,
1102 * @param string $file File name
1103 * @param string $type Content Type
1104 * @param bool $compress
1105 * @param bool $forceOnTop
1106 * @param string $allWrap
1107 * @param bool $excludeFromConcatenation
1108 * @param string $splitChar The char used to split the allWrap value, default is "|"
1109 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1110 * @param string $integrity Subresource Integrity (SRI)
1113 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE, $integrity = '') {
1115 $type = 'text/javascript';
1117 if (!isset($this->jsFiles
[$file])) {
1118 $this->jsFiles
[$file] = array(
1121 'section' => self
::PART_HEADER
,
1122 'compress' => $compress,
1123 'forceOnTop' => $forceOnTop,
1124 'allWrap' => $allWrap,
1125 'excludeFromConcatenation' => $excludeFromConcatenation,
1126 'splitChar' => $splitChar,
1128 'integrity' => $integrity,
1134 * Adds JS file to footer
1136 * @param string $file File name
1137 * @param string $type Content Type
1138 * @param bool $compress
1139 * @param bool $forceOnTop
1140 * @param string $allWrap
1141 * @param bool $excludeFromConcatenation
1142 * @param string $splitChar The char used to split the allWrap value, default is "|"
1143 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1144 * @param string $integrity Subresource Integrity (SRI)
1147 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE, $integrity = '') {
1149 $type = 'text/javascript';
1151 if (!isset($this->jsFiles
[$file])) {
1152 $this->jsFiles
[$file] = array(
1155 'section' => self
::PART_FOOTER
,
1156 'compress' => $compress,
1157 'forceOnTop' => $forceOnTop,
1158 'allWrap' => $allWrap,
1159 'excludeFromConcatenation' => $excludeFromConcatenation,
1160 'splitChar' => $splitChar,
1162 'integrity' => $integrity,
1168 * Adds JS inline code
1170 * @param string $name
1171 * @param string $block
1172 * @param bool $compress
1173 * @param bool $forceOnTop
1176 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1177 if (!isset($this->jsInline
[$name]) && !empty($block)) {
1178 $this->jsInline
[$name] = array(
1179 'code' => $block . LF
,
1180 'section' => self
::PART_HEADER
,
1181 'compress' => $compress,
1182 'forceOnTop' => $forceOnTop
1188 * Adds JS inline code to footer
1190 * @param string $name
1191 * @param string $block
1192 * @param bool $compress
1193 * @param bool $forceOnTop
1196 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1197 if (!isset($this->jsInline
[$name]) && !empty($block)) {
1198 $this->jsInline
[$name] = array(
1199 'code' => $block . LF
,
1200 'section' => self
::PART_FOOTER
,
1201 'compress' => $compress,
1202 'forceOnTop' => $forceOnTop
1208 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
1210 * @param string $block Javascript code
1211 * @param bool $forceOnTop Position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
1214 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
1215 if (!in_array($block, $this->extOnReadyCode
)) {
1217 array_unshift($this->extOnReadyCode
, $block);
1219 $this->extOnReadyCode
[] = $block;
1225 * Adds the ExtDirect code
1227 * @param array $filterNamespaces Limit the output to defined namespaces. If empty, all namespaces are generated
1230 public function addExtDirectCode(array $filterNamespaces = array()) {
1231 if ($this->extDirectCodeAdded
) {
1234 $this->extDirectCodeAdded
= TRUE;
1235 if (empty($filterNamespaces)) {
1236 $filterNamespaces = array('TYPO3');
1238 // @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1239 // add compatibility mapping for the old flashmessage API
1240 $this->addJsFile(GeneralUtility
::resolveBackPath($this->backPath
.
1241 'sysext/backend/Resources/Public/JavaScript/flashmessage_compatibility.js'));
1243 // Add language labels for ExtDirect
1244 if (TYPO3_MODE
=== 'FE') {
1245 $this->addInlineLanguageLabelArray(array(
1246 'extDirect_timeoutHeader' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutHeader'),
1247 'extDirect_timeoutMessage' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutMessage')
1250 $this->addInlineLanguageLabelArray(array(
1251 'extDirect_timeoutHeader' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutHeader'),
1252 'extDirect_timeoutMessage' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutMessage')
1256 $token = ($api = '');
1257 if (TYPO3_MODE
=== 'BE') {
1258 $formprotection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory
::get();
1259 $token = $formprotection->generateToken('extDirect');
1261 // Debugger Console strings
1262 $this->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/debugger.xlf');
1264 /** @var $extDirect \TYPO3\CMS\Core\ExtDirect\ExtDirectApi */
1265 $extDirect = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\ExtDirect\ExtDirectApi
::class);
1266 $api = $extDirect->getApiPhp($filterNamespaces);
1268 $this->addJsInlineCode('TYPO3ExtDirectAPI', $api, FALSE);
1270 // Note: we need to iterate thru the object, because the addProvider method
1271 // does this only with multiple arguments
1272 $this->addExtOnReadyCode('
1274 TYPO3.ExtDirectToken = "' . $token . '";
1275 for (var api in Ext.app.ExtDirectAPI) {
1276 var provider = Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
1277 provider.on("beforecall", function(provider, transaction, meta) {
1278 if (transaction.data) {
1279 transaction.data[transaction.data.length] = TYPO3.ExtDirectToken;
1281 transaction.data = [TYPO3.ExtDirectToken];
1285 provider.on("call", function(provider, transaction, meta) {
1286 if (transaction.isForm) {
1287 transaction.params.securityToken = TYPO3.ExtDirectToken;
1293 var extDirectDebug = function(message, header, group) {
1294 var TYPO3ViewportInstance = null;
1296 if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
1297 TYPO3ViewportInstance = top.TYPO3.Backend;
1298 } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
1299 TYPO3ViewportInstance = TYPO3.Backend;
1302 if (TYPO3ViewportInstance !== null) {
1303 TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
1304 } else if (typeof console === "object") {
1305 console.log(message);
1307 document.write(message);
1311 Ext.Direct.on("exception", function(event) {
1312 if (event.code === Ext.Direct.exceptions.TRANSPORT && !event.where) {
1313 top.TYPO3.Notification.error(
1314 TYPO3.l10n.localize("extDirect_timeoutHeader"),
1315 TYPO3.l10n.localize("extDirect_timeoutMessage")
1319 if (event.code === "parse") {
1321 "<p>" + event.xhr.responseText + "<\\/p>",
1323 "ExtDirect - Exception"
1325 } else if (event.code === "router") {
1326 top.TYPO3.Notification.error(
1330 } else if (event.where) {
1331 backtrace = "<p style=\\"margin-top: 20px;\\">" +
1332 "<strong>Backtrace:<\\/strong><br \\/>" +
1333 event.where.replace(/#/g, "<br \\/>#") +
1336 "<p>" + event.message + "<\\/p>" + backtrace,
1338 "ExtDirect - Exception"
1346 Ext.Direct.on("event", function(event, provider) {
1347 if (typeof event.debug !== "undefined" && event.debug !== "") {
1348 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
1357 * @param string $file
1358 * @param string $rel
1359 * @param string $media
1360 * @param string $title
1361 * @param bool $compress
1362 * @param bool $forceOnTop
1363 * @param string $allWrap
1364 * @param bool $excludeFromConcatenation
1365 * @param string $splitChar The char used to split the allWrap value, default is "|"
1368 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|') {
1369 if (!isset($this->cssFiles
[$file])) {
1370 $this->cssFiles
[$file] = array(
1375 'compress' => $compress,
1376 'forceOnTop' => $forceOnTop,
1377 'allWrap' => $allWrap,
1378 'excludeFromConcatenation' => $excludeFromConcatenation,
1379 'splitChar' => $splitChar
1387 * @param string $file
1388 * @param string $rel
1389 * @param string $media
1390 * @param string $title
1391 * @param bool $compress
1392 * @param bool $forceOnTop
1393 * @param string $allWrap
1394 * @param bool $excludeFromConcatenation
1395 * @param string $splitChar The char used to split the allWrap value, default is "|"
1398 public function addCssLibrary($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|') {
1399 if (!isset($this->cssLibs
[$file])) {
1400 $this->cssLibs
[$file] = array(
1405 'compress' => $compress,
1406 'forceOnTop' => $forceOnTop,
1407 'allWrap' => $allWrap,
1408 'excludeFromConcatenation' => $excludeFromConcatenation,
1409 'splitChar' => $splitChar
1415 * Adds CSS inline code
1417 * @param string $name
1418 * @param string $block
1419 * @param bool $compress
1420 * @param bool $forceOnTop
1423 public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
1424 if (!isset($this->cssInline
[$name]) && !empty($block)) {
1425 $this->cssInline
[$name] = array(
1427 'compress' => $compress,
1428 'forceOnTop' => $forceOnTop
1434 * Call this function if you need to include the jQuery library
1436 * @param null|string $version The jQuery version that should be included, either "latest" or any available version
1437 * @param null|string $source The location of the jQuery source, can be "local", "google", "msn", "jquery" or just an URL to your jQuery lib
1438 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored.
1440 * @throws \UnexpectedValueException
1442 public function loadJquery($version = NULL, $source = NULL, $namespace = self
::JQUERY_NAMESPACE_DEFAULT
) {
1443 // Set it to the version that is shipped with the TYPO3 core
1444 if ($version === NULL ||
$version === 'latest') {
1445 $version = self
::JQUERY_VERSION_LATEST
;
1447 // Check if the source is set, otherwise set it to "default"
1448 if ($source === NULL) {
1451 if ($source === 'local' && !in_array($version, $this->availableLocalJqueryVersions
)) {
1452 throw new \
UnexpectedValueException('The requested jQuery version is not available in the local filesystem.', 1341505305);
1454 if (!preg_match('/^[a-zA-Z0-9]+$/', $namespace)) {
1455 throw new \
UnexpectedValueException('The requested namespace contains non alphanumeric characters.', 1341571604);
1457 $this->jQueryVersions
[$namespace] = array(
1458 'version' => $version,
1464 * Call function if you need the requireJS library
1465 * this automatically adds the JavaScript path of all loaded extensions in the requireJS path option
1466 * so it resolves names like TYPO3/CMS/MyExtension/MyJsFile to EXT:MyExtension/Resources/Public/JavaScript/MyJsFile.js
1467 * when using requireJS
1471 public function loadRequireJs() {
1473 // load all paths to map to package names / namespaces
1474 if (empty($this->requireJsConfig
)) {
1475 // In order to avoid browser caching of JS files, adding a GET parameter to the files loaded via requireJS
1476 if (GeneralUtility
::getApplicationContext()->isDevelopment()) {
1477 $this->requireJsConfig
['urlArgs'] = 'bust=' . $GLOBALS['EXEC_TIME'];
1479 $this->requireJsConfig
['urlArgs'] = 'bust=' . GeneralUtility
::hmac(TYPO3_version
. PATH_site
);
1481 // first, load all paths for the namespaces, and configure contrib libs.
1482 $this->requireJsConfig
['paths'] = array(
1483 'jquery-ui' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/jquery-ui',
1484 'datatables' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/jquery.dataTables',
1485 'nprogress' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/nprogress',
1486 'moment' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/moment',
1487 'cropper' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/cropper.min',
1488 'imagesloaded' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/imagesloaded.pkgd.min',
1489 'bootstrap' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/bootstrap/bootstrap',
1490 'twbs/bootstrap-datetimepicker' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/bootstrap-datetimepicker',
1491 'autosize' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/autosize',
1492 'taboverride' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/taboverride.min',
1493 'twbs/bootstrap-slider' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/bootstrap-slider.min',
1494 'jquery/autocomplete' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/jquery.autocomplete',
1496 // get all extensions that are loaded
1497 $loadedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::getLoadedExtensionListArray();
1498 foreach ($loadedExtensions as $packageName) {
1499 $fullJsPath = 'EXT:' . $packageName . '/Resources/Public/JavaScript/';
1500 $fullJsPath = GeneralUtility
::getFileAbsFileName($fullJsPath);
1501 $fullJsPath = \TYPO3\CMS\Core\Utility\PathUtility
::getRelativePath(PATH_typo3
, $fullJsPath);
1502 $fullJsPath = rtrim($fullJsPath, '/');
1504 $this->requireJsConfig
['paths']['TYPO3/CMS/' . GeneralUtility
::underscoredToUpperCamelCase($packageName)] = $this->backPath
. $fullJsPath;
1508 // check if additional AMD modules need to be loaded if a single AMD module is initialized
1509 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules'])) {
1510 $this->addInlineSettingArray('RequireJS.PostInitializationModules', $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules']);
1514 $this->addRequireJs
= TRUE;
1518 * Add additional configuration to require js.
1520 * Configuration will be merged recursive with overrule.
1522 * To add another path mapping deliver the following configuration:
1524 * 'EXTERN/mybootstrapjs' => 'sysext/.../twbs/bootstrap.min',
1527 * @param array $configuration The configuration that will be merged with existing one.
1530 public function addRequireJsConfiguration(array $configuration) {
1531 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($this->requireJsConfig
, $configuration);
1535 * includes an AMD-compatible JS file by resolving the ModuleName, and then requires the file via a requireJS request,
1536 * additionally allowing to execute JavaScript code afterwards
1538 * this function only works for AMD-ready JS modules, used like "define('TYPO3/CMS/Backend/FormEngine..."
1541 * TYPO3/CMS/Backend/FormEngine =>
1542 * "TYPO3": Vendor Name
1543 * "CMS": Product Name
1544 * "Backend": Extension Name
1545 * "FormEngine": FileName in the Resources/Public/JavaScript folder
1547 * @param string $mainModuleName Must be in the form of "TYPO3/CMS/PackageName/ModuleName" e.g. "TYPO3/CMS/Backend/FormEngine"
1548 * @param string $callBackFunction loaded right after the requireJS loading, must be wrapped in function() {}
1551 public function loadRequireJsModule($mainModuleName, $callBackFunction = NULL) {
1552 $inlineCodeKey = $mainModuleName;
1553 // make sure requireJS is initialized
1554 $this->loadRequireJs();
1556 // execute the main module, and load a possible callback function
1557 $javaScriptCode = 'require(["' . $mainModuleName . '"]';
1558 if ($callBackFunction !== NULL) {
1559 $inlineCodeKey .= sha1($callBackFunction);
1560 $javaScriptCode .= ', ' . $callBackFunction;
1562 $javaScriptCode .= ');';
1563 $this->addJsInlineCode('RequireJS-Module-' . $inlineCodeKey, $javaScriptCode);
1568 * call this function if you need the extJS library
1570 * @param bool $css Flag, if set the ext-css will be loaded
1571 * @param bool $theme Flag, if set the ext-theme "grey" will be loaded
1574 public function loadExtJS($css = TRUE, $theme = TRUE) {
1575 $this->addExtJS
= TRUE;
1576 $this->extJStheme
= $theme;
1577 $this->extJScss
= $css;
1581 * Call this function to load debug version of ExtJS. Use this for development only
1585 public function enableExtJsDebug() {
1586 $this->enableExtJsDebug
= TRUE;
1590 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1591 * The label can be used in scripts with TYPO3.lang.<key>
1594 * @param string $key
1595 * @param string $value
1598 public function addInlineLanguageLabel($key, $value) {
1599 $this->inlineLanguageLabels
[$key] = $value;
1603 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1604 * The label can be used in scripts with TYPO3.lang.<key>
1605 * Array will be merged with existing array.
1608 * @param array $array
1609 * @param bool $parseWithLanguageService
1612 public function addInlineLanguageLabelArray(array $array, $parseWithLanguageService = FALSE) {
1613 if ($parseWithLanguageService === TRUE) {
1614 foreach ($array as $key => $value) {
1615 $array[$key] = $this->getLanguageService()->sL($value);
1619 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $array);
1623 * Gets labels to be used in JavaScript fetched from a locallang file.
1625 * @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.
1626 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1627 * @param string $stripFromSelectionName String to be removed from the label names in the output. (default: '')
1628 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1631 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1632 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1633 if ($fileRef && !isset($this->inlineLanguageLabelFiles
[$index])) {
1634 $this->inlineLanguageLabelFiles
[$index] = array(
1635 'fileRef' => $fileRef,
1636 'selectionPrefix' => $selectionPrefix,
1637 'stripFromSelectionName' => $stripFromSelectionName,
1638 'errorMode' => $errorMode
1644 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1645 * The label can be used in scripts with TYPO3.setting.<key>
1648 * @param string $namespace
1649 * @param string $key
1650 * @param string $value
1653 public function addInlineSetting($namespace, $key, $value) {
1655 if (strpos($namespace, '.')) {
1656 $parts = explode('.', $namespace);
1657 $a = &$this->inlineSettings
;
1658 foreach ($parts as $part) {
1663 $this->inlineSettings
[$namespace][$key] = $value;
1666 $this->inlineSettings
[$key] = $value;
1671 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1672 * The label can be used in scripts with TYPO3.setting.<key>
1673 * Array will be merged with existing array.
1676 * @param string $namespace
1677 * @param array $array
1680 public function addInlineSettingArray($namespace, array $array) {
1682 if (strpos($namespace, '.')) {
1683 $parts = explode('.', $namespace);
1684 $a = &$this->inlineSettings
;
1685 foreach ($parts as $part) {
1688 $a = array_merge((array)$a, $array);
1690 $this->inlineSettings
[$namespace] = array_merge((array)$this->inlineSettings
[$namespace], $array);
1693 $this->inlineSettings
= array_merge($this->inlineSettings
, $array);
1698 * Adds content to body content
1700 * @param string $content
1703 public function addBodyContent($content) {
1704 $this->bodyContent
.= $content;
1707 /*****************************************************/
1709 /* Render Functions */
1711 /*****************************************************/
1713 * Render the section (Header or Footer)
1715 * @param int $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1716 * @return string Content of rendered section
1718 public function render($part = self
::PART_COMPLETE
) {
1719 $this->prepareRendering();
1720 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1721 $metaTags = implode(LF
, $this->metaTags
);
1722 $markerArray = $this->getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags);
1723 $template = $this->getTemplateForPart($part);
1725 // The page renderer needs a full reset, even when only rendering one part of the page
1726 // This means that you can only register footer files *after* the header has been already rendered.
1727 // In case you render the footer part first, header files can only be added *after* the footer has been rendered
1729 return trim(\TYPO3\CMS\Core\Html\HtmlParser
::substituteMarkerArray($template, $markerArray, '###|###'));
1733 * Render the page but not the JavaScript and CSS Files
1735 * @param string $substituteHash The hash that is used for the placehoder markers
1737 * @return string Content of rendered section
1739 public function renderPageWithUncachedObjects($substituteHash) {
1740 $this->prepareRendering();
1741 $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
1742 $template = $this->getTemplateForPart(self
::PART_COMPLETE
);
1743 return trim(\TYPO3\CMS\Core\Html\HtmlParser
::substituteMarkerArray($template, $markerArray, '###|###'));
1747 * Renders the JavaScript and CSS files that have been added during processing
1748 * of uncached content objects (USER_INT, COA_INT)
1750 * @param string $cachedPageContent
1751 * @param string $substituteHash The hash that is used for the placehoder markers
1755 public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash) {
1756 $this->prepareRendering();
1757 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1758 $title = $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '';
1759 $markerArray = array(
1760 '<!-- ###TITLE' . $substituteHash . '### -->' => $title,
1761 '<!-- ###CSS_LIBS' . $substituteHash . '### -->' => $cssLibs,
1762 '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
1763 '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
1764 '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
1765 '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
1766 '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
1767 '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF
, $this->headerData
),
1768 '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF
, $this->footerData
),
1769 '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
1770 '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
1771 '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline
1773 foreach ($markerArray as $placeHolder => $content) {
1774 $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
1777 return $cachedPageContent;
1781 * Remove ending slashes from static header block
1782 * if the page is beeing rendered as html (not xhtml)
1783 * and define property $this->endingSlash for further use
1787 protected function prepareRendering() {
1788 if ($this->getRenderXhtml()) {
1789 $this->endingSlash
= ' /';
1791 $this->metaCharsetTag
= str_replace(' />', '>', $this->metaCharsetTag
);
1792 $this->baseUrlTag
= str_replace(' />', '>', $this->baseUrlTag
);
1793 $this->shortcutTag
= str_replace(' />', '>', $this->shortcutTag
);
1794 $this->endingSlash
= '';
1799 * Renders all JavaScript and CSS
1801 * @return array<string>
1803 protected function renderJavaScriptAndCss() {
1804 $this->executePreRenderHook();
1805 $mainJsLibs = $this->renderMainJavaScriptLibraries();
1806 if ($this->concatenateFiles ||
$this->concatenateJavascript ||
$this->concatenateCss
) {
1807 // Do the file concatenation
1808 $this->doConcatenate();
1810 if ($this->compressCss ||
$this->compressJavascript
) {
1811 // Do the file compression
1812 $this->doCompress();
1814 $this->executeRenderPostTransformHook();
1815 $cssLibs = $this->renderCssLibraries();
1816 $cssFiles = $this->renderCssFiles();
1817 $cssInline = $this->renderCssInline();
1818 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
1819 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
1820 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
1821 $jsLibs = $mainJsLibs . $jsLibs;
1822 if ($this->moveJsFromHeaderToFooter
) {
1823 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
1825 $jsFooterFiles = $jsFiles . LF
. $jsFooterFiles;
1827 $jsFooterInline = $jsInline . LF
. $jsFooterInline;
1830 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1831 return array($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1835 * Fills the marker array with the given strings and trims each value
1837 * @param $jsLibs string
1838 * @param $jsFiles string
1839 * @param $jsFooterFiles string
1840 * @param $cssLibs string
1841 * @param $cssFiles string
1842 * @param $jsInline string
1843 * @param $cssInline string
1844 * @param $jsFooterInline string
1845 * @param $jsFooterLibs string
1846 * @param $metaTags string
1847 * @return array Marker array
1849 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags) {
1850 $markerArray = array(
1851 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1852 'HTMLTAG' => $this->htmlTag
,
1853 'HEADTAG' => $this->headTag
,
1854 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1855 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
1856 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1857 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1858 'CSS_LIBS' => $cssLibs,
1859 'CSS_INCLUDE' => $cssFiles,
1860 'CSS_INLINE' => $cssInline,
1861 'JS_INLINE' => $jsInline,
1862 'JS_INCLUDE' => $jsFiles,
1863 'JS_LIBS' => $jsLibs,
1864 'TITLE' => $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '',
1865 'META' => $metaTags,
1866 'HEADERDATA' => $this->headerData ?
implode(LF
, $this->headerData
) : '',
1867 'FOOTERDATA' => $this->footerData ?
implode(LF
, $this->footerData
) : '',
1868 'JS_LIBS_FOOTER' => $jsFooterLibs,
1869 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1870 'JS_INLINE_FOOTER' => $jsFooterInline,
1871 'BODY' => $this->bodyContent
1873 $markerArray = array_map('trim', $markerArray);
1874 return $markerArray;
1878 * Fills the marker array with the given strings and trims each value
1880 * @param string $substituteHash The hash that is used for the placehoder markers
1881 * @return array Marker array
1883 protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash) {
1884 $markerArray = array(
1885 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1886 'HTMLTAG' => $this->htmlTag
,
1887 'HEADTAG' => $this->headTag
,
1888 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1889 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
1890 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1891 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1892 'META' => implode(LF
, $this->metaTags
),
1893 'BODY' => $this->bodyContent
,
1894 'TITLE' => '<!-- ###TITLE' . $substituteHash . '### -->',
1895 'CSS_LIBS' => '<!-- ###CSS_LIBS' . $substituteHash . '### -->',
1896 'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
1897 'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
1898 'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
1899 'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
1900 'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
1901 'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
1902 'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
1903 'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
1904 'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
1905 'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->'
1907 $markerArray = array_map('trim', $markerArray);
1908 return $markerArray;
1912 * Reads the template file and returns the requested part as string
1917 protected function getTemplateForPart($part) {
1918 $templateFile = GeneralUtility
::getFileAbsFileName($this->templateFile
, TRUE);
1919 $template = GeneralUtility
::getUrl($templateFile);
1920 if ($this->removeLineBreaksFromTemplate
) {
1921 $template = strtr($template, array(LF
=> '', CR
=> ''));
1923 if ($part !== self
::PART_COMPLETE
) {
1924 $templatePart = explode('###BODY###', $template);
1925 $template = $templatePart[$part - 1];
1931 * Helper function for render the main JavaScript libraries,
1932 * currently: RequireJS, jQuery, ExtJS
1934 * @return string Content with JavaScript libraries
1936 protected function renderMainJavaScriptLibraries() {
1939 // Include RequireJS
1940 if ($this->addRequireJs
) {
1941 // load the paths of the requireJS configuration
1942 $out .= GeneralUtility
::wrapJS('var require = ' . json_encode($this->requireJsConfig
)) . LF
;
1943 // directly after that, include the require.js file
1944 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $this->requireJsPath
. 'require.js')) . '" type="text/javascript"></script>' . LF
;
1947 // Include jQuery Core for each namespace, depending on the version and source
1948 if (!empty($this->jQueryVersions
)) {
1949 foreach ($this->jQueryVersions
as $namespace => $jQueryVersion) {
1950 $out .= $this->renderJqueryScriptTag($jQueryVersion['version'], $jQueryVersion['source'], $namespace);
1954 if ($this->addExtJS
) {
1955 // Use the base adapter all the time
1956 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $this->extJsPath
. 'adapter/ext-base' . ($this->enableExtJsDebug ?
'-debug' : '') . '.js')) . '" type="text/javascript"></script>' . LF
;
1957 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $this->extJsPath
. 'ext-all' . ($this->enableExtJsDebug ?
'-debug' : '') . '.js')) . '" type="text/javascript"></script>' . LF
;
1958 // Add extJS localization
1959 // Load standard ISO mapping and modify for use with ExtJS
1960 $localeMap = $this->locales
->getIsoMapping();
1961 $localeMap[''] = 'en';
1962 $localeMap['default'] = 'en';
1964 $localeMap['gr'] = 'el_GR';
1965 // Norwegian Bokmaal
1966 $localeMap['no'] = 'no_BO';
1968 $localeMap['se'] = 'se_SV';
1969 $extJsLang = isset($localeMap[$this->lang
]) ?
$localeMap[$this->lang
] : $this->lang
;
1970 // @todo autoconvert file from UTF8 to current BE charset if necessary!!!!
1971 $extJsLocaleFile = $this->extJsPath
. 'locale/ext-lang-' . $extJsLang . '.js';
1972 if (file_exists(PATH_typo3
. $extJsLocaleFile)) {
1973 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $extJsLocaleFile)) . '" type="text/javascript" charset="utf-8"></script>' . LF
;
1975 // Remove extjs from JScodeLibArray
1976 unset($this->jsFiles
[$this->backPath
. $this->extJsPath
. 'ext-all.js'], $this->jsFiles
[$this->backPath
. $this->extJsPath
. 'ext-all-debug.js']);
1978 $this->loadJavaScriptLanguageStrings();
1979 if (TYPO3_MODE
=== 'BE') {
1980 $this->addAjaxUrlsToInlineSettings();
1982 $inlineSettings = $this->inlineLanguageLabels ?
'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels
) . ';' : '';
1983 $inlineSettings .= $this->inlineSettings ?
'TYPO3.settings = ' . json_encode($this->inlineSettings
) . ';' : '';
1984 if ($this->addExtJS
) {
1985 // Set clear.gif, move it on top, add handler code
1987 if (!empty($this->extOnReadyCode
)) {
1988 foreach ($this->extOnReadyCode
as $block) {
1992 $out .= $this->inlineJavascriptWrap
[0] . '
1994 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(GeneralUtility
::locationHeaderUrl($this->backPath
. 'sysext/t3skin/icons/gfx/clear.gif')) . '";
1995 Ext.SSL_SECURE_URL = "' . htmlspecialchars(GeneralUtility
::locationHeaderUrl($this->backPath
. 'sysext/t3skin/icons/gfx/clear.gif')) . '";' . LF
1997 . 'Ext.onReady(function() {'
2000 . $this->inlineJavascriptWrap
[1];
2001 $this->extOnReadyCode
= array();
2002 // Include TYPO3.l10n object
2003 if (TYPO3_MODE
=== 'BE') {
2004 $out .= '<script src="' . $this->processJsFile(($this->backPath
. 'sysext/lang/Resources/Public/JavaScript/Typo3Lang.js')) . '" type="text/javascript" charset="utf-8"></script>' . LF
;
2006 if ($this->extJScss
) {
2007 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
2008 $this->addCssLibrary($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE);
2010 $this->addCssLibrary($this->backPath
. $this->extJsPath
. 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE);
2013 if ($this->extJStheme
) {
2014 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
2015 $this->addCssLibrary($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE);
2017 $this->addCssLibrary($this->backPath
. $this->extJsPath
. 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE);
2021 // no extJS loaded, but still inline settings
2022 if ($inlineSettings !== '') {
2023 // make sure the global TYPO3 is available
2024 $inlineSettings = 'var TYPO3 = TYPO3 || {};' . CRLF
. $inlineSettings;
2025 $out .= $this->inlineJavascriptWrap
[0] . $inlineSettings . $this->inlineJavascriptWrap
[1];
2026 // Add language module only if also jquery is guaranteed to be there
2027 if (TYPO3_MODE
=== 'BE' && !empty($this->jQueryVersions
)) {
2028 $this->loadRequireJsModule('TYPO3/CMS/Lang/Lang');
2036 * Load the language strings into JavaScript
2038 protected function loadJavaScriptLanguageStrings() {
2039 if (!empty($this->inlineLanguageLabelFiles
)) {
2040 foreach ($this->inlineLanguageLabelFiles
as $languageLabelFile) {
2041 $this->includeLanguageFileForInline($languageLabelFile['fileRef'], $languageLabelFile['selectionPrefix'], $languageLabelFile['stripFromSelectionName'], $languageLabelFile['errorMode']);
2044 $this->inlineLanguageLabelFiles
= array();
2045 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
2046 if (TYPO3_MODE
=== 'FE' && $this->getCharSet() !== 'utf-8') {
2047 if ($this->inlineLanguageLabels
) {
2048 $this->csConvObj
->convArray($this->inlineLanguageLabels
, $this->getCharSet(), 'utf-8');
2050 if ($this->inlineSettings
) {
2051 $this->csConvObj
->convArray($this->inlineSettings
, $this->getCharSet(), 'utf-8');
2057 * Make URLs to all backend ajax handlers available as inline setting.
2059 protected function addAjaxUrlsToInlineSettings() {
2060 $ajaxUrls = array();
2061 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'] as $ajaxHandler => $_) {
2062 $ajaxUrls[$ajaxHandler] = BackendUtility
::getAjaxUrl($ajaxHandler);
2064 $this->inlineSettings
['ajaxUrls'] = $ajaxUrls;
2068 * Renders the HTML script tag for the given jQuery version.
2070 * @param string $version The jQuery version that should be included, either "latest" or any available version
2071 * @param string $source The location of the jQuery source, can be "local", "google", "msn" or "jquery
2072 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored
2075 protected function renderJqueryScriptTag($version, $source, $namespace) {
2077 case isset($this->jQueryCdnUrls
[$source]):
2078 if ($this->enableJqueryDebug
) {
2081 $minifyPart = '.min';
2083 $jQueryFileName = sprintf($this->jQueryCdnUrls
[$source], $version, $minifyPart);
2085 case $source === 'local':
2086 $jQueryFileName = $this->backPath
. $this->jQueryPath
. 'jquery-' . rawurlencode($version);
2087 if ($this->enableJqueryDebug
) {
2088 $jQueryFileName .= '.js';
2090 $jQueryFileName .= '.min.js';
2094 $jQueryFileName = $source;
2096 // Include the jQuery Core
2097 $scriptTag = '<script src="' . htmlspecialchars($jQueryFileName) . '" type="text/javascript"></script>' . LF
;
2098 // Set the noConflict mode to be available via "TYPO3.jQuery" in all installations
2099 switch ($namespace) {
2100 case self
::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT
:
2101 $scriptTag .= GeneralUtility
::wrapJS('jQuery.noConflict();') . LF
;
2103 case self
::JQUERY_NAMESPACE_NONE
:
2105 case self
::JQUERY_NAMESPACE_DEFAULT
:
2108 $scriptTag .= GeneralUtility
::wrapJS('var TYPO3 = TYPO3 || {}; TYPO3.' . $namespace . ' = jQuery.noConflict(true);') . LF
;
2114 * Render CSS library files
2118 protected function renderCssLibraries() {
2120 if (!empty($this->cssLibs
)) {
2121 foreach ($this->cssLibs
as $file => $properties) {
2122 $file = GeneralUtility
::resolveBackPath($file);
2123 $file = GeneralUtility
::createVersionNumberedFilename($file);
2124 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2125 . '" type="text/css" href="' . htmlspecialchars($file)
2126 . '" media="' . htmlspecialchars($properties['media']) . '"'
2127 . ($properties['title'] ?
' title="' . htmlspecialchars($properties['title']) . '"' : '')
2128 . $this->endingSlash
. '>';
2129 if ($properties['allWrap']) {
2130 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2131 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2134 if ($properties['forceOnTop']) {
2135 $cssFiles = $tag . $cssFiles;
2149 protected function renderCssFiles() {
2151 if (!empty($this->cssFiles
)) {
2152 foreach ($this->cssFiles
as $file => $properties) {
2153 $file = GeneralUtility
::resolveBackPath($file);
2154 $file = GeneralUtility
::createVersionNumberedFilename($file);
2155 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2156 . '" type="text/css" href="' . htmlspecialchars($file)
2157 . '" media="' . htmlspecialchars($properties['media']) . '"'
2158 . ($properties['title'] ?
' title="' . htmlspecialchars($properties['title']) . '"' : '')
2159 . $this->endingSlash
. '>';
2160 if ($properties['allWrap']) {
2161 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2162 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2165 if ($properties['forceOnTop']) {
2166 $cssFiles = $tag . $cssFiles;
2180 protected function renderCssInline() {
2182 if (!empty($this->cssInline
)) {
2183 foreach ($this->cssInline
as $name => $properties) {
2184 $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2185 if ($properties['forceOnTop']) {
2186 $cssInline = $cssCode . $cssInline;
2188 $cssInline .= $cssCode;
2191 $cssInline = $this->inlineCssWrap
[0] . $cssInline . $this->inlineCssWrap
[1];
2197 * Render JavaScipt libraries
2199 * @return array<string> jsLibs and jsFooterLibs strings
2201 protected function renderAdditionalJavaScriptLibraries() {
2204 if (!empty($this->jsLibs
)) {
2205 foreach ($this->jsLibs
as $properties) {
2206 $properties['file'] = GeneralUtility
::resolveBackPath($properties['file']);
2207 $properties['file'] = GeneralUtility
::createVersionNumberedFilename($properties['file']);
2208 $async = ($properties['async']) ?
' async="async"' : '';
2209 $integrity = ($properties['integrity']) ?
' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2210 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $integrity . '></script>';
2211 if ($properties['allWrap']) {
2212 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2213 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2216 if ($properties['forceOnTop']) {
2217 if ($properties['section'] === self
::PART_HEADER
) {
2218 $jsLibs = $tag . $jsLibs;
2220 $jsFooterLibs = $tag . $jsFooterLibs;
2223 if ($properties['section'] === self
::PART_HEADER
) {
2226 $jsFooterLibs .= $tag;
2231 if ($this->moveJsFromHeaderToFooter
) {
2232 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
2235 return array($jsLibs, $jsFooterLibs);
2239 * Render JavaScript files
2241 * @return array<string> jsFiles and jsFooterFiles strings
2243 protected function renderJavaScriptFiles() {
2245 $jsFooterFiles = '';
2246 if (!empty($this->jsFiles
)) {
2247 foreach ($this->jsFiles
as $file => $properties) {
2248 $file = GeneralUtility
::resolveBackPath($file);
2249 $file = GeneralUtility
::createVersionNumberedFilename($file);
2250 $async = ($properties['async']) ?
' async="async"' : '';
2251 $integrity = ($properties['integrity']) ?
' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2252 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $integrity . '></script>';
2253 if ($properties['allWrap']) {
2254 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2255 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2258 if ($properties['forceOnTop']) {
2259 if ($properties['section'] === self
::PART_HEADER
) {
2260 $jsFiles = $tag . $jsFiles;
2262 $jsFooterFiles = $tag . $jsFooterFiles;
2265 if ($properties['section'] === self
::PART_HEADER
) {
2268 $jsFooterFiles .= $tag;
2273 if ($this->moveJsFromHeaderToFooter
) {
2274 $jsFooterFiles = $jsFiles . $jsFooterFiles;
2277 return array($jsFiles, $jsFooterFiles);
2281 * Render inline JavaScript
2283 * @return array<string> jsInline and jsFooterInline string
2285 protected function renderInlineJavaScript() {
2287 $jsFooterInline = '';
2288 if (!empty($this->jsInline
)) {
2289 foreach ($this->jsInline
as $name => $properties) {
2290 $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2291 if ($properties['forceOnTop']) {
2292 if ($properties['section'] === self
::PART_HEADER
) {
2293 $jsInline = $jsCode . $jsInline;
2295 $jsFooterInline = $jsCode . $jsFooterInline;
2298 if ($properties['section'] === self
::PART_HEADER
) {
2299 $jsInline .= $jsCode;
2301 $jsFooterInline .= $jsCode;
2307 $jsInline = $this->inlineJavascriptWrap
[0] . $jsInline . $this->inlineJavascriptWrap
[1];
2309 if ($jsFooterInline) {
2310 $jsFooterInline = $this->inlineJavascriptWrap
[0] . $jsFooterInline . $this->inlineJavascriptWrap
[1];
2312 if ($this->moveJsFromHeaderToFooter
) {
2313 $jsFooterInline = $jsInline . $jsFooterInline;
2316 return array($jsInline, $jsFooterInline);
2320 * Include language file for inline usage
2322 * @param string $fileRef
2323 * @param string $selectionPrefix
2324 * @param string $stripFromSelectionName
2325 * @param int $errorMode
2327 * @throws \RuntimeException
2329 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
2330 if (!isset($this->lang
) ||
!isset($this->charSet
)) {
2331 throw new \
RuntimeException('Language and character encoding are not set.', 1284906026);
2333 $labelsFromFile = array();
2334 $allLabels = $this->readLLfile($fileRef, $errorMode);
2335 if ($allLabels !== FALSE) {
2336 // Merge language specific translations:
2337 if ($this->lang
!== 'default' && isset($allLabels[$this->lang
])) {
2338 $labels = array_merge($allLabels['default'], $allLabels[$this->lang
]);
2340 $labels = $allLabels['default'];
2342 // Iterate through all locallang labels:
2343 foreach ($labels as $label => $value) {
2344 // If $selectionPrefix is set, only respect labels that start with $selectionPrefix
2345 if ($selectionPrefix === '' ||
strpos($label, $selectionPrefix) === 0) {
2346 // Remove substring $stripFromSelectionName from label
2347 $label = str_replace($stripFromSelectionName, '', $label);
2348 $labelsFromFile[$label] = $value;
2351 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $labelsFromFile);
2356 * Reads a locallang file.
2358 * @param string $fileRef Reference to a relative filename to include.
2359 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
2360 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2362 protected function readLLfile($fileRef, $errorMode = 0) {
2363 /** @var $languageFactory LocalizationFactory */
2364 $languageFactory = GeneralUtility
::makeInstance(LocalizationFactory
::class);
2366 if ($this->lang
!== 'default') {
2367 $languages = array_reverse($this->languageDependencies
);
2368 // At least we need to have English
2369 if (empty($languages)) {
2370 $languages[] = 'default';
2373 $languages = array('default');
2376 $localLanguage = array();
2377 foreach ($languages as $language) {
2378 $tempLL = $languageFactory->getParsedData($fileRef, $language, $this->charSet
, $errorMode);
2380 $localLanguage['default'] = $tempLL['default'];
2381 if (!isset($localLanguage[$this->lang
])) {
2382 $localLanguage[$this->lang
] = $localLanguage['default'];
2384 if ($this->lang
!== 'default' && isset($tempLL[$language])) {
2385 // Merge current language labels onto labels from previous language
2386 // This way we have a labels with fall back applied
2387 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($localLanguage[$this->lang
], $tempLL[$language], TRUE, FALSE);
2391 return $localLanguage;
2395 /*****************************************************/
2399 /*****************************************************/
2401 * Concatenate files into one file
2402 * registered handler
2406 protected function doConcatenate() {
2407 $this->doConcatenateCss();
2408 $this->doConcatenateJavaScript();
2412 * Concatenate JavaScript files according to the configuration.
2416 protected function doConcatenateJavaScript() {
2417 if ($this->concatenateFiles ||
$this->concatenateJavascript
) {
2418 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsConcatenateHandler'])) {
2419 // use external concatenation routine
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
]['jsConcatenateHandler'], $params, $this);
2429 $this->jsLibs
= $this->getCompressor()->concatenateJsFiles($this->jsLibs
);
2430 $this->jsFiles
= $this->getCompressor()->concatenateJsFiles($this->jsFiles
);
2431 $this->jsFooterFiles
= $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles
);
2437 * Concatenate CSS files according to configuration.
2441 protected function doConcatenateCss() {
2442 if ($this->concatenateFiles ||
$this->concatenateCss
) {
2443 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssConcatenateHandler'])) {
2444 // use external concatenation routine
2446 'cssFiles' => &$this->cssFiles
,
2447 'cssLibs' => &$this->cssLibs
,
2448 'headerData' => &$this->headerData
,
2449 'footerData' => &$this->footerData
2451 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssConcatenateHandler'], $params, $this);
2453 $cssOptions = array();
2454 if (TYPO3_MODE
=== 'BE') {
2455 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
2457 $this->cssLibs
= $this->getCompressor()->concatenateCssFiles($this->cssLibs
, $cssOptions);
2458 $this->cssFiles
= $this->getCompressor()->concatenateCssFiles($this->cssFiles
, $cssOptions);
2464 * Compresses inline code
2468 protected function doCompress() {
2469 $this->doCompressJavaScript();
2470 $this->doCompressCss();
2474 * Compresses CSS according to configuration.
2478 protected function doCompressCss() {
2479 if ($this->compressCss
) {
2480 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'])) {
2481 // Use external compression routine
2483 'cssInline' => &$this->cssInline
,
2484 'cssFiles' => &$this->cssFiles
,
2485 'cssLibs' => &$this->cssLibs
,
2486 'headerData' => &$this->headerData
,
2487 'footerData' => &$this->footerData
2489 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'], $params, $this);
2491 $this->cssLibs
= $this->getCompressor()->compressCssFiles($this->cssLibs
);
2492 $this->cssFiles
= $this->getCompressor()->compressCssFiles($this->cssFiles
);
2498 * Compresses JavaScript according to configuration.
2502 protected function doCompressJavaScript() {
2503 if ($this->compressJavascript
) {
2504 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'])) {
2505 // Use external compression routine
2507 'jsInline' => &$this->jsInline
,
2508 'jsFooterInline' => &$this->jsFooterInline
,
2509 'jsLibs' => &$this->jsLibs
,
2510 'jsFiles' => &$this->jsFiles
,
2511 'jsFooterFiles' => &$this->jsFooterFiles
,
2512 'headerData' => &$this->headerData
,
2513 'footerData' => &$this->footerData
2515 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'], $params, $this);
2517 // Traverse the arrays, compress files
2518 if (!empty($this->jsInline
)) {
2519 foreach ($this->jsInline
as $name => $properties) {
2520 if ($properties['compress']) {
2522 $this->jsInline
[$name]['code'] = GeneralUtility
::minifyJavaScript($properties['code'], $error);
2524 $this->compressError
.= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF
;
2529 $this->jsLibs
= $this->getCompressor()->compressJsFiles($this->jsLibs
);
2530 $this->jsFiles
= $this->getCompressor()->compressJsFiles($this->jsFiles
);
2531 $this->jsFooterFiles
= $this->getCompressor()->compressJsFiles($this->jsFooterFiles
);
2537 * Returns instance of \TYPO3\CMS\Core\Resource\ResourceCompressor
2539 * @return \TYPO3\CMS\Core\Resource\ResourceCompressor
2541 protected function getCompressor() {
2542 if ($this->compressor
=== NULL) {
2543 $this->compressor
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\
Resource\ResourceCompressor
::class);
2545 return $this->compressor
;
2549 * Processes a Javascript file dependent on the current context
2551 * Adds the version number for Frontend, compresses the file for Backend
2553 * @param string $filename Filename
2554 * @return string New filename
2556 protected function processJsFile($filename) {
2557 switch (TYPO3_MODE
) {
2559 if ($this->compressJavascript
) {
2560 $filename = $this->getCompressor()->compressJsFile($filename);
2562 $filename = GeneralUtility
::createVersionNumberedFilename($filename);
2566 if ($this->compressJavascript
) {
2567 $filename = $this->getCompressor()->compressJsFile($filename);
2575 * Returns global language service instance
2577 * @return \TYPO3\CMS\Lang\LanguageService
2579 protected function getLanguageService() {
2580 return $GLOBALS['LANG'];
2583 /*****************************************************/
2587 /*****************************************************/
2589 * Execute PreRenderHook for possible manipulation
2593 protected function executePreRenderHook() {
2594 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
2596 'jsLibs' => &$this->jsLibs
,
2597 'jsFooterLibs' => &$this->jsFooterLibs
,
2598 'jsFiles' => &$this->jsFiles
,
2599 'jsFooterFiles' => &$this->jsFooterFiles
,
2600 'cssFiles' => &$this->cssFiles
,
2601 'headerData' => &$this->headerData
,
2602 'footerData' => &$this->footerData
,
2603 'jsInline' => &$this->jsInline
,
2604 'jsFooterInline' => &$this->jsFooterInline
,
2605 'cssInline' => &$this->cssInline
2607 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
2608 GeneralUtility
::callUserFunction($hook, $params, $this);
2614 * PostTransform for possible manipulation of concatenated and compressed files
2618 protected function executeRenderPostTransformHook() {
2619 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
2621 'jsLibs' => &$this->jsLibs
,
2622 'jsFooterLibs' => &$this->jsFooterLibs
,
2623 'jsFiles' => &$this->jsFiles
,
2624 'jsFooterFiles' => &$this->jsFooterFiles
,
2625 'cssFiles' => &$this->cssFiles
,
2626 'headerData' => &$this->headerData
,
2627 'footerData' => &$this->footerData
,
2628 'jsInline' => &$this->jsInline
,
2629 'jsFooterInline' => &$this->jsFooterInline
,
2630 'cssInline' => &$this->cssInline
2632 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
2633 GeneralUtility
::callUserFunction($hook, $params, $this);
2639 * Execute postRenderHook for possible manipulation
2641 * @param $jsLibs string
2642 * @param $jsFiles string
2643 * @param $jsFooterFiles string
2644 * @param $cssLibs string
2645 * @param $cssFiles string
2646 * @param $jsInline string
2647 * @param $cssInline string
2648 * @param $jsFooterInline string
2649 * @param $jsFooterLibs string
2652 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssLibs, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs) {
2653 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
2655 'jsLibs' => &$jsLibs,
2656 'jsFiles' => &$jsFiles,
2657 'jsFooterFiles' => &$jsFooterFiles,
2658 'cssLibs' => &$cssLibs,
2659 'cssFiles' => &$cssFiles,
2660 'headerData' => &$this->headerData
,
2661 'footerData' => &$this->footerData
,
2662 'jsInline' => &$jsInline,
2663 'cssInline' => &$cssInline,
2664 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType
,
2665 'htmlTag' => &$this->htmlTag
,
2666 'headTag' => &$this->headTag
,
2667 'charSet' => &$this->charSet
,
2668 'metaCharsetTag' => &$this->metaCharsetTag
,
2669 'shortcutTag' => &$this->shortcutTag
,
2670 'inlineComments' => &$this->inlineComments
,
2671 'baseUrl' => &$this->baseUrl
,
2672 'baseUrlTag' => &$this->baseUrlTag
,
2673 'favIcon' => &$this->favIcon
,
2674 'iconMimeType' => &$this->iconMimeType
,
2675 'titleTag' => &$this->titleTag
,
2676 'title' => &$this->title
,
2677 'metaTags' => &$this->metaTags
,
2678 'jsFooterInline' => &$jsFooterInline,
2679 'jsFooterLibs' => &$jsFooterLibs,
2680 'bodyContent' => &$this->bodyContent
2682 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
2683 GeneralUtility
::callUserFunction($hook, $params, $this);