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\Utility\GeneralUtility
;
21 * TYPO3 pageRender class (new in TYPO3 4.3.0)
22 * This class render the HTML of a webpage, usable for BE and FE
24 * @author Steffen Kamper <info@sk-typo3.de>
25 * @author Kai Vogel <kai.vogel@speedprogs.de>
27 class PageRenderer
implements \TYPO3\CMS\Core\SingletonInterface
{
29 // Constants for the part to be rendered
30 const PART_COMPLETE
= 0;
31 const PART_HEADER
= 1;
32 const PART_FOOTER
= 2;
33 // jQuery Core version that is shipped with TYPO3
34 const JQUERY_VERSION_LATEST
= '1.11.3';
35 // jQuery namespace options
36 const JQUERY_NAMESPACE_NONE
= 'none';
37 const JQUERY_NAMESPACE_DEFAULT
= 'jQuery';
38 const JQUERY_NAMESPACE_DEFAULT_NOCONFLICT
= 'defaultNoConflict';
43 protected $compressJavascript = FALSE;
48 protected $compressCss = FALSE;
53 protected $removeLineBreaksFromTemplate = FALSE;
58 protected $concatenateFiles = FALSE;
63 protected $concatenateJavascript = FALSE;
68 protected $concatenateCss = FALSE;
73 protected $moveJsFromHeaderToFooter = FALSE;
76 * @var \TYPO3\CMS\Core\Charset\CharsetConverter
81 * @var \TYPO3\CMS\Core\Localization\Locales
87 * Two character string or 'default'
94 * List of language dependencies for actual language. This is used for local variants of a language
95 * that depend on their "main" language, like Brazilian Portuguese or Canadian French.
99 protected $languageDependencies = array();
102 * @var \TYPO3\CMS\Core\Resource\ResourceCompressor
104 protected $compressor;
106 // Arrays containing associative array for the included files
110 protected $jsFiles = array();
115 protected $jsFooterFiles = array();
120 protected $jsLibs = array();
125 protected $jsFooterLibs = array();
130 protected $cssFiles = array();
135 protected $cssLibs = array();
138 * The title of the page
145 * Charset for the rendering
164 protected $renderXhtml = TRUE;
166 // Static header blocks
170 protected $xmlPrologAndDocType = '';
175 protected $metaTags = array();
180 protected $inlineComments = array();
185 protected $headerData = array();
190 protected $footerData = array();
195 protected $titleTag = '<title>|</title>';
200 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
205 protected $htmlTag = '<html>';
210 protected $headTag = '<head>';
215 protected $baseUrlTag = '<base href="|" />';
220 protected $iconMimeType = '';
225 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />';
227 // Static inline code blocks
231 protected $jsInline = array();
236 protected $jsFooterInline = array();
241 protected $extOnReadyCode = array();
246 protected $cssInline = array();
251 protected $bodyContent;
256 protected $templateFile;
261 protected $jsLibraryNames = array('prototype', 'scriptaculous', 'extjs');
263 // Paths to contibuted libraries
266 * default path to the requireJS library, relative to the typo3/ directory
269 protected $requireJsPath = 'sysext/core/Resources/Public/JavaScript/Contrib/';
274 protected $prototypePath = 'sysext/core/Resources/Public/JavaScript/Contrib/';
279 protected $scriptaculousPath = 'sysext/core/Resources/Public/JavaScript/Contrib/scriptaculous/';
284 protected $extJsPath = 'sysext/core/Resources/Public/JavaScript/Contrib/extjs/';
287 * The local directory where one can find jQuery versions and plugins
291 protected $jQueryPath = 'sysext/core/Resources/Public/JavaScript/Contrib/jquery/';
293 // Internal flags for JS-libraries
295 * This array holds all jQuery versions that should be included in the
297 * Each version is described by "source", "version" and "namespace"
299 * The namespace of every particular version is the key
300 * of that array, because only one version per namespace can exist.
302 * The type "source" describes where the jQuery core should be included from
303 * currently, TYPO3 supports "local" (make use of jQuery path), "google",
304 * "jquery" and "msn".
305 * Currently there are downsides to "local" and "jquery", as "local" only
306 * supports the latest/shipped jQuery core out of the box, and
307 * "jquery" does not have SSL support.
311 protected $jQueryVersions = array();
314 * Array of jQuery version numbers shipped with the core
318 protected $availableLocalJqueryVersions = array(
319 self
::JQUERY_VERSION_LATEST
323 * Array of jQuery CDNs with placeholders
327 protected $jQueryCdnUrls = array(
328 'google' => '//ajax.googleapis.com/ajax/libs/jquery/%1$s/jquery%2$s.js',
329 'msn' => '//ajax.aspnetcdn.com/ajax/jQuery/jquery-%1$s%2$s.js',
330 'jquery' => 'http://code.jquery.com/jquery-%1$s%2$s.js'
334 * if set, the requireJS library is included
337 protected $addRequireJs = FALSE;
340 * inline configuration for requireJS
343 protected $requireJsConfig = array();
348 protected $addPrototype = FALSE;
353 protected $addScriptaculous = FALSE;
358 protected $addScriptaculousModules = array('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
363 protected $addExtJS = FALSE;
368 protected $extDirectCodeAdded = FALSE;
373 protected $enableExtJsDebug = FALSE;
378 protected $enableJqueryDebug = FALSE;
383 protected $extJStheme = TRUE;
388 protected $extJScss = TRUE;
393 protected $enableExtJSQuickTips = FALSE;
398 protected $inlineLanguageLabels = array();
403 protected $inlineLanguageLabelFiles = array();
408 protected $inlineSettings = array();
413 protected $inlineJavascriptWrap = array();
416 * Saves error messages generated during compression
420 protected $compressError = '';
423 * Is empty string for HTML and ' /' for XHTML rendering
427 protected $endingSlash = '';
437 * @param string $templateFile Declare the used template file. Omit this parameter will use default template
438 * @param string $backPath Relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
440 public function __construct($templateFile = '', $backPath = NULL) {
442 $this->csConvObj
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter
::class);
443 $this->locales
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Localization\Locales
::class);
444 if ($templateFile !== '') {
445 $this->templateFile
= $templateFile;
447 $this->backPath
= isset($backPath) ?
$backPath : $GLOBALS['BACK_PATH'];
448 $this->inlineJavascriptWrap
= array(
449 '<script type="text/javascript">' . LF
. '/*<![CDATA[*/' . LF
,
450 '/*]]>*/' . LF
. '</script>' . LF
452 $this->inlineCssWrap
= array(
453 '<style type="text/css">' . LF
. '/*<![CDATA[*/' . LF
. '<!-- ' . LF
,
454 '-->' . LF
. '/*]]>*/' . LF
. '</style>' . LF
459 * Reset all vars to initial values
463 protected function reset() {
464 $this->templateFile
= 'EXT:core/Resources/Private/Templates/PageRenderer.html';
465 $this->jsFiles
= array();
466 $this->jsFooterFiles
= array();
467 $this->jsInline
= array();
468 $this->jsFooterInline
= array();
469 $this->jsLibs
= array();
470 $this->cssFiles
= array();
471 $this->cssInline
= array();
472 $this->metaTags
= array();
473 $this->inlineComments
= array();
474 $this->headerData
= array();
475 $this->footerData
= array();
476 $this->extOnReadyCode
= array();
477 $this->jQueryVersions
= array();
480 /*****************************************************/
485 /*****************************************************/
489 * @param string $title title of webpage
492 public function setTitle($title) {
493 $this->title
= $title;
497 * Enables/disables rendering of XHTML code
499 * @param bool $enable Enable XHTML
502 public function setRenderXhtml($enable) {
503 $this->renderXhtml
= $enable;
507 * Sets xml prolog and docType
509 * @param string $xmlPrologAndDocType Complete tags for xml prolog and docType
512 public function setXmlPrologAndDocType($xmlPrologAndDocType) {
513 $this->xmlPrologAndDocType
= $xmlPrologAndDocType;
519 * @param string $charSet Used charset
522 public function setCharSet($charSet) {
523 $this->charSet
= $charSet;
529 * @param string $lang Used language
532 public function setLanguage($lang) {
534 $this->languageDependencies
= array();
536 // Language is found. Configure it:
537 if (in_array($this->lang
, $this->locales
->getLocales())) {
538 $this->languageDependencies
[] = $this->lang
;
539 foreach ($this->locales
->getLocaleDependencies($this->lang
) as $language) {
540 $this->languageDependencies
[] = $language;
546 * Set the meta charset tag
548 * @param string $metaCharsetTag
551 public function setMetaCharsetTag($metaCharsetTag) {
552 $this->metaCharsetTag
= $metaCharsetTag;
558 * @param string $htmlTag Html tag
561 public function setHtmlTag($htmlTag) {
562 $this->htmlTag
= $htmlTag;
568 * @param string $headTag HTML head tag
571 public function setHeadTag($headTag) {
572 $this->headTag
= $headTag;
578 * @param string $favIcon
581 public function setFavIcon($favIcon) {
582 $this->favIcon
= $favIcon;
586 * Sets icon mime type
588 * @param string $iconMimeType
591 public function setIconMimeType($iconMimeType) {
592 $this->iconMimeType
= $iconMimeType;
598 * @param string $baseUrl HTML base URL
601 public function setBaseUrl($baseUrl) {
602 $this->baseUrl
= $baseUrl;
608 * @param string $file
611 public function setTemplateFile($file) {
612 $this->templateFile
= $file;
618 * @param string $backPath
621 public function setBackPath($backPath) {
622 $this->backPath
= $backPath;
626 * Sets Content for Body
628 * @param string $content
631 public function setBodyContent($content) {
632 $this->bodyContent
= $content;
636 * Sets path to requireJS library (relative to typo3 directory)
638 * @param string $path Path to requireJS library
641 public function setRequireJsPath($path) {
642 $this->requireJsPath
= $path;
646 * Sets path to prototype library (relative to typo3 directory)
648 * @param string $path Path to prototype library
651 public function setPrototypePath($path) {
652 $this->prototypePath
= $path;
656 * Sets Path for scriptaculous library (relative to typo3 directory)
658 * @param string $path
661 public function setScriptaculousPath($path) {
662 $this->scriptaculousPath
= $path;
666 * Sets Path for ExtJs library (relative to typo3 directory)
668 * @param string $path
671 public function setExtJsPath($path) {
672 $this->extJsPath
= $path;
675 /*****************************************************/
677 /* Public Enablers / Disablers */
680 /*****************************************************/
682 * Enables MoveJsFromHeaderToFooter
686 public function enableMoveJsFromHeaderToFooter() {
687 $this->moveJsFromHeaderToFooter
= TRUE;
691 * Disables MoveJsFromHeaderToFooter
695 public function disableMoveJsFromHeaderToFooter() {
696 $this->moveJsFromHeaderToFooter
= FALSE;
700 * Enables compression of javascript
704 public function enableCompressJavascript() {
705 $this->compressJavascript
= TRUE;
709 * Disables compression of javascript
713 public function disableCompressJavascript() {
714 $this->compressJavascript
= FALSE;
718 * Enables compression of css
722 public function enableCompressCss() {
723 $this->compressCss
= TRUE;
727 * Disables compression of css
731 public function disableCompressCss() {
732 $this->compressCss
= FALSE;
736 * Enables concatenation of js and css files
740 public function enableConcatenateFiles() {
741 $this->concatenateFiles
= TRUE;
745 * Disables concatenation of js and css files
749 public function disableConcatenateFiles() {
750 $this->concatenateFiles
= FALSE;
754 * Enables concatenation of js files
758 public function enableConcatenateJavascript() {
759 $this->concatenateJavascript
= TRUE;
763 * Disables concatenation of js files
767 public function disableConcatenateJavascript() {
768 $this->concatenateJavascript
= FALSE;
772 * Enables concatenation of css files
776 public function enableConcatenateCss() {
777 $this->concatenateCss
= TRUE;
781 * Disables concatenation of css files
785 public function disableConcatenateCss() {
786 $this->concatenateCss
= FALSE;
790 * Sets removal of all line breaks in template
794 public function enableRemoveLineBreaksFromTemplate() {
795 $this->removeLineBreaksFromTemplate
= TRUE;
799 * Unsets removal of all line breaks in template
803 public function disableRemoveLineBreaksFromTemplate() {
804 $this->removeLineBreaksFromTemplate
= FALSE;
809 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
813 public function enableDebugMode() {
814 $this->compressJavascript
= FALSE;
815 $this->compressCss
= FALSE;
816 $this->concatenateFiles
= FALSE;
817 $this->removeLineBreaksFromTemplate
= FALSE;
818 $this->enableExtJsDebug
= TRUE;
819 $this->enableJqueryDebug
= TRUE;
822 /*****************************************************/
827 /*****************************************************/
831 * @return string $title Title of webpage
833 public function getTitle() {
840 * @return string $charSet
842 public function getCharSet() {
843 return $this->charSet
;
849 * @return string $lang
851 public function getLanguage() {
856 * Returns rendering mode XHTML or HTML
858 * @return bool TRUE if XHTML, FALSE if HTML
860 public function getRenderXhtml() {
861 return $this->renderXhtml
;
867 * @return string $htmlTag Html tag
869 public function getHtmlTag() {
870 return $this->htmlTag
;
878 public function getMetaCharsetTag() {
879 return $this->metaCharsetTag
;
885 * @return string $tag Head tag
887 public function getHeadTag() {
888 return $this->headTag
;
894 * @return string $favIcon
896 public function getFavIcon() {
897 return $this->favIcon
;
901 * Gets icon mime type
903 * @return string $iconMimeType
905 public function getIconMimeType() {
906 return $this->iconMimeType
;
912 * @return string $url
914 public function getBaseUrl() {
915 return $this->baseUrl
;
923 public function getTemplateFile() {
924 return $this->templateFile
;
928 * Gets MoveJsFromHeaderToFooter
932 public function getMoveJsFromHeaderToFooter() {
933 return $this->moveJsFromHeaderToFooter
;
937 * Gets compress of javascript
941 public function getCompressJavascript() {
942 return $this->compressJavascript
;
946 * Gets compress of css
950 public function getCompressCss() {
951 return $this->compressCss
;
955 * Gets concatenate of js and css files
959 public function getConcatenateFiles() {
960 return $this->concatenateFiles
;
964 * Gets concatenate of js files
968 public function getConcatenateJavascript() {
969 return $this->concatenateJavascript
;
973 * Gets concatenate of css files
977 public function getConcatenateCss() {
978 return $this->concatenateCss
;
982 * Gets remove of empty lines from template
986 public function getRemoveLineBreaksFromTemplate() {
987 return $this->removeLineBreaksFromTemplate
;
991 * Gets content for body
995 public function getBodyContent() {
996 return $this->bodyContent
;
1000 * Gets Path for prototype library (relative to typo3 directory)
1004 public function getPrototypePath() {
1005 return $this->prototypePath
;
1009 * Gets Path for scriptaculous library (relative to typo3 directory)
1013 public function getScriptaculousPath() {
1014 return $this->scriptaculousPath
;
1018 * Gets Path for ExtJs library (relative to typo3 directory)
1022 public function getExtJsPath() {
1023 return $this->extJsPath
;
1027 * Gets the inline language labels.
1029 * @return array The inline language labels
1031 public function getInlineLanguageLabels() {
1032 return $this->inlineLanguageLabels
;
1036 * Gets the inline language files
1040 public function getInlineLanguageLabelFiles() {
1041 return $this->inlineLanguageLabelFiles
;
1044 /*****************************************************/
1046 /* Public Functions to add Data */
1049 /*****************************************************/
1053 * @param string $meta Meta data (complete metatag)
1056 public function addMetaTag($meta) {
1057 if (!in_array($meta, $this->metaTags
)) {
1058 $this->metaTags
[] = $meta;
1063 * Adds inline HTML comment
1065 * @param string $comment
1068 public function addInlineComment($comment) {
1069 if (!in_array($comment, $this->inlineComments
)) {
1070 $this->inlineComments
[] = $comment;
1077 * @param string $data Free header data for HTML header
1080 public function addHeaderData($data) {
1081 if (!in_array($data, $this->headerData
)) {
1082 $this->headerData
[] = $data;
1089 * @param string $data Free header data for HTML header
1092 public function addFooterData($data) {
1093 if (!in_array($data, $this->footerData
)) {
1094 $this->footerData
[] = $data;
1099 * Adds JS Library. JS Library block is rendered on top of the JS files.
1101 * @param string $name Arbitrary identifier
1102 * @param string $file File name
1103 * @param string $type Content Type
1104 * @param bool $compress Flag if library should be compressed
1105 * @param bool $forceOnTop Flag if added library should be inserted at begin of this block
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 addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE, $integrity = '') {
1115 $type = 'text/javascript';
1117 if (!in_array(strtolower($name), $this->jsLibs
)) {
1118 $this->jsLibs
[strtolower($name)] = 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 Library to Footer. JS Library block is rendered on top of the Footer JS files.
1136 * @param string $name Arbitrary identifier
1137 * @param string $file File name
1138 * @param string $type Content Type
1139 * @param bool $compress Flag if library should be compressed
1140 * @param bool $forceOnTop Flag if added library should be inserted at begin of this block
1141 * @param string $allWrap
1142 * @param bool $excludeFromConcatenation
1143 * @param string $splitChar The char used to split the allWrap value, default is "|"
1144 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1145 * @param string $integrity Subresource Integrity (SRI)
1148 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE, $integrity = '') {
1150 $type = 'text/javascript';
1152 if (!in_array(strtolower($name), $this->jsLibs
)) {
1153 $this->jsLibs
[strtolower($name)] = array(
1156 'section' => self
::PART_FOOTER
,
1157 'compress' => $compress,
1158 'forceOnTop' => $forceOnTop,
1159 'allWrap' => $allWrap,
1160 'excludeFromConcatenation' => $excludeFromConcatenation,
1161 'splitChar' => $splitChar,
1163 'integrity' => $integrity,
1171 * @param string $file File name
1172 * @param string $type Content Type
1173 * @param bool $compress
1174 * @param bool $forceOnTop
1175 * @param string $allWrap
1176 * @param bool $excludeFromConcatenation
1177 * @param string $splitChar The char used to split the allWrap value, default is "|"
1178 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1179 * @param string $integrity Subresource Integrity (SRI)
1182 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE, $integrity = '') {
1184 $type = 'text/javascript';
1186 if (!isset($this->jsFiles
[$file])) {
1187 if (strpos($file, 'ajax.php?') !== FALSE) {
1190 $this->jsFiles
[$file] = array(
1193 'section' => self
::PART_HEADER
,
1194 'compress' => $compress,
1195 'forceOnTop' => $forceOnTop,
1196 'allWrap' => $allWrap,
1197 'excludeFromConcatenation' => $excludeFromConcatenation,
1198 'splitChar' => $splitChar,
1200 'integrity' => $integrity,
1206 * Adds JS file to footer
1208 * @param string $file File name
1209 * @param string $type Content Type
1210 * @param bool $compress
1211 * @param bool $forceOnTop
1212 * @param string $allWrap
1213 * @param bool $excludeFromConcatenation
1214 * @param string $splitChar The char used to split the allWrap value, default is "|"
1215 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1216 * @param string $integrity Subresource Integrity (SRI)
1219 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE, $integrity = '') {
1221 $type = 'text/javascript';
1223 if (!isset($this->jsFiles
[$file])) {
1224 if (strpos($file, 'ajax.php?') !== FALSE) {
1227 $this->jsFiles
[$file] = array(
1230 'section' => self
::PART_FOOTER
,
1231 'compress' => $compress,
1232 'forceOnTop' => $forceOnTop,
1233 'allWrap' => $allWrap,
1234 'excludeFromConcatenation' => $excludeFromConcatenation,
1235 'splitChar' => $splitChar,
1237 'integrity' => $integrity,
1243 * Adds JS inline code
1245 * @param string $name
1246 * @param string $block
1247 * @param bool $compress
1248 * @param bool $forceOnTop
1251 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1252 if (!isset($this->jsInline
[$name]) && !empty($block)) {
1253 $this->jsInline
[$name] = array(
1254 'code' => $block . LF
,
1255 'section' => self
::PART_HEADER
,
1256 'compress' => $compress,
1257 'forceOnTop' => $forceOnTop
1263 * Adds JS inline code to footer
1265 * @param string $name
1266 * @param string $block
1267 * @param bool $compress
1268 * @param bool $forceOnTop
1271 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1272 if (!isset($this->jsInline
[$name]) && !empty($block)) {
1273 $this->jsInline
[$name] = array(
1274 'code' => $block . LF
,
1275 'section' => self
::PART_FOOTER
,
1276 'compress' => $compress,
1277 'forceOnTop' => $forceOnTop
1283 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
1285 * @param string $block Javascript code
1286 * @param bool $forceOnTop Position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
1289 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
1290 if (!in_array($block, $this->extOnReadyCode
)) {
1292 array_unshift($this->extOnReadyCode
, $block);
1294 $this->extOnReadyCode
[] = $block;
1300 * Adds the ExtDirect code
1302 * @param array $filterNamespaces Limit the output to defined namespaces. If empty, all namespaces are generated
1305 public function addExtDirectCode(array $filterNamespaces = array()) {
1306 if ($this->extDirectCodeAdded
) {
1309 $this->extDirectCodeAdded
= TRUE;
1310 if (empty($filterNamespaces)) {
1311 $filterNamespaces = array('TYPO3');
1313 // @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1314 // add compatibility mapping for the old flashmessage API
1315 $this->addJsFile(GeneralUtility
::resolveBackPath($this->backPath
.
1316 'sysext/backend/Resources/Public/JavaScript/flashmessage_compatibility.js'));
1318 // Add language labels for ExtDirect
1319 if (TYPO3_MODE
=== 'FE') {
1320 $this->addInlineLanguageLabelArray(array(
1321 'extDirect_timeoutHeader' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutHeader'),
1322 'extDirect_timeoutMessage' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutMessage')
1325 $this->addInlineLanguageLabelArray(array(
1326 'extDirect_timeoutHeader' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutHeader'),
1327 'extDirect_timeoutMessage' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutMessage')
1331 $token = ($api = '');
1332 if (TYPO3_MODE
=== 'BE') {
1333 $formprotection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory
::get();
1334 $token = $formprotection->generateToken('extDirect');
1336 // Debugger Console strings
1337 $this->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/debugger.xlf');
1339 /** @var $extDirect \TYPO3\CMS\Core\ExtDirect\ExtDirectApi */
1340 $extDirect = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\ExtDirect\ExtDirectApi
::class);
1341 $api = $extDirect->getApiPhp($filterNamespaces);
1343 $this->addJsInlineCode('TYPO3ExtDirectAPI', $api, FALSE);
1345 // Note: we need to iterate thru the object, because the addProvider method
1346 // does this only with multiple arguments
1347 $this->addExtOnReadyCode('
1349 TYPO3.ExtDirectToken = "' . $token . '";
1350 for (var api in Ext.app.ExtDirectAPI) {
1351 var provider = Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
1352 provider.on("beforecall", function(provider, transaction, meta) {
1353 if (transaction.data) {
1354 transaction.data[transaction.data.length] = TYPO3.ExtDirectToken;
1356 transaction.data = [TYPO3.ExtDirectToken];
1360 provider.on("call", function(provider, transaction, meta) {
1361 if (transaction.isForm) {
1362 transaction.params.securityToken = TYPO3.ExtDirectToken;
1368 var extDirectDebug = function(message, header, group) {
1369 var TYPO3ViewportInstance = null;
1371 if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
1372 TYPO3ViewportInstance = top.TYPO3.Backend;
1373 } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
1374 TYPO3ViewportInstance = TYPO3.Backend;
1377 if (TYPO3ViewportInstance !== null) {
1378 TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
1379 } else if (typeof console === "object") {
1380 console.log(message);
1382 document.write(message);
1386 Ext.Direct.on("exception", function(event) {
1387 if (event.code === Ext.Direct.exceptions.TRANSPORT && !event.where) {
1388 top.TYPO3.Notification.error(
1389 TYPO3.l10n.localize("extDirect_timeoutHeader"),
1390 TYPO3.l10n.localize("extDirect_timeoutMessage")
1394 if (event.code === "parse") {
1396 "<p>" + event.xhr.responseText + "<\\/p>",
1398 "ExtDirect - Exception"
1400 } else if (event.code === "router") {
1401 top.TYPO3.Notification.error(
1405 } else if (event.where) {
1406 backtrace = "<p style=\\"margin-top: 20px;\\">" +
1407 "<strong>Backtrace:<\\/strong><br \\/>" +
1408 event.where.replace(/#/g, "<br \\/>#") +
1411 "<p>" + event.message + "<\\/p>" + backtrace,
1413 "ExtDirect - Exception"
1421 Ext.Direct.on("event", function(event, provider) {
1422 if (typeof event.debug !== "undefined" && event.debug !== "") {
1423 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
1432 * @param string $file
1433 * @param string $rel
1434 * @param string $media
1435 * @param string $title
1436 * @param bool $compress
1437 * @param bool $forceOnTop
1438 * @param string $allWrap
1439 * @param bool $excludeFromConcatenation
1440 * @param string $splitChar The char used to split the allWrap value, default is "|"
1443 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|') {
1444 if (!isset($this->cssFiles
[$file])) {
1445 $this->cssFiles
[$file] = array(
1450 'compress' => $compress,
1451 'forceOnTop' => $forceOnTop,
1452 'allWrap' => $allWrap,
1453 'excludeFromConcatenation' => $excludeFromConcatenation,
1454 'splitChar' => $splitChar
1462 * @param string $file
1463 * @param string $rel
1464 * @param string $media
1465 * @param string $title
1466 * @param bool $compress
1467 * @param bool $forceOnTop
1468 * @param string $allWrap
1469 * @param bool $excludeFromConcatenation
1470 * @param string $splitChar The char used to split the allWrap value, default is "|"
1473 public function addCssLibrary($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|') {
1474 if (!isset($this->cssLibs
[$file])) {
1475 $this->cssLibs
[$file] = array(
1480 'compress' => $compress,
1481 'forceOnTop' => $forceOnTop,
1482 'allWrap' => $allWrap,
1483 'excludeFromConcatenation' => $excludeFromConcatenation,
1484 'splitChar' => $splitChar
1490 * Adds CSS inline code
1492 * @param string $name
1493 * @param string $block
1494 * @param bool $compress
1495 * @param bool $forceOnTop
1498 public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
1499 if (!isset($this->cssInline
[$name]) && !empty($block)) {
1500 $this->cssInline
[$name] = array(
1502 'compress' => $compress,
1503 'forceOnTop' => $forceOnTop
1509 * Call this function if you need to include the jQuery library
1511 * @param null|string $version The jQuery version that should be included, either "latest" or any available version
1512 * @param null|string $source The location of the jQuery source, can be "local", "google", "msn", "jquery" or just an URL to your jQuery lib
1513 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored.
1515 * @throws \UnexpectedValueException
1517 public function loadJquery($version = NULL, $source = NULL, $namespace = self
::JQUERY_NAMESPACE_DEFAULT
) {
1518 // Set it to the version that is shipped with the TYPO3 core
1519 if ($version === NULL ||
$version === 'latest') {
1520 $version = self
::JQUERY_VERSION_LATEST
;
1522 // Check if the source is set, otherwise set it to "default"
1523 if ($source === NULL) {
1526 if ($source === 'local' && !in_array($version, $this->availableLocalJqueryVersions
)) {
1527 throw new \
UnexpectedValueException('The requested jQuery version is not available in the local filesystem.', 1341505305);
1529 if (!preg_match('/^[a-zA-Z0-9]+$/', $namespace)) {
1530 throw new \
UnexpectedValueException('The requested namespace contains non alphanumeric characters.', 1341571604);
1532 $this->jQueryVersions
[$namespace] = array(
1533 'version' => $version,
1539 * Call function if you need the requireJS library
1540 * this automatically adds the JavaScript path of all loaded extensions in the requireJS path option
1541 * so it resolves names like TYPO3/CMS/MyExtension/MyJsFile to EXT:MyExtension/Resources/Public/JavaScript/MyJsFile.js
1542 * when using requireJS
1546 public function loadRequireJs() {
1548 // load all paths to map to package names / namespaces
1549 if (empty($this->requireJsConfig
)) {
1550 // first, load all paths for the namespaces, and configure contrib libs.
1551 $this->requireJsConfig
['paths'] = array(
1552 'jquery-ui' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/jquery-ui',
1553 'jquery' => $this->backPath
. rtrim($this->jQueryPath
, '/'),
1554 'datatables' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/jquery.dataTables',
1555 'nprogress' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/nprogress',
1556 'moment' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/moment',
1557 'cropper' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/cropper.min',
1558 'imagesloaded' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/imagesloaded.pkgd.min',
1559 'bootstrap' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/bootstrap/bootstrap',
1560 'twbs/bootstrap-datetimepicker' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/bootstrap-datetimepicker',
1561 'autosize' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/autosize',
1562 'taboverride' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/taboverride.min',
1563 'twbs/bootstrap-slider' => $this->backPath
. 'sysext/core/Resources/Public/JavaScript/Contrib/bootstrap-slider.min',
1565 // get all extensions that are loaded
1566 $loadedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::getLoadedExtensionListArray();
1567 foreach ($loadedExtensions as $packageName) {
1568 $fullJsPath = 'EXT:' . $packageName . '/Resources/Public/JavaScript/';
1569 $fullJsPath = GeneralUtility
::getFileAbsFileName($fullJsPath);
1570 $fullJsPath = \TYPO3\CMS\Core\Utility\PathUtility
::getRelativePath(PATH_typo3
, $fullJsPath);
1571 $fullJsPath = rtrim($fullJsPath, '/');
1573 $this->requireJsConfig
['paths']['TYPO3/CMS/' . GeneralUtility
::underscoredToUpperCamelCase($packageName)] = $this->backPath
. $fullJsPath;
1577 // check if additional AMD modules need to be loaded if a single AMD module is initialized
1578 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules'])) {
1579 $this->addInlineSettingArray('RequireJS.PostInitializationModules', $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules']);
1583 $this->addRequireJs
= TRUE;
1587 * Add additional configuration to require js.
1589 * Configuration will be merged recursive with overrule.
1591 * To add another path mapping deliver the following configuration:
1593 * 'EXTERN/mybootstrapjs' => 'contrib/twbs/bootstrap.min',
1596 * @author Daniel Siepmann <daniel.siepmann@typo3.org>
1598 * @param array $configuration The configuration that will be merged with existing one.
1601 public function addRequireJsConfiguration(array $configuration) {
1602 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($this->requireJsConfig
, $configuration);
1606 * includes a AMD-compatible JS file by resolving the ModuleName, and then requires the file via a requireJS request,
1607 * additionally allowing to execute JavaScript code afterwards
1609 * this function only works for AMD-ready JS modules, used like "define('TYPO3/CMS/Backend/FormEngine..."
1612 * TYPO3/CMS/Backend/FormEngine =>
1613 * "TYPO3": Vendor Name
1614 * "CMS": Product Name
1615 * "Backend": Extension Name
1616 * "FormEngine": FileName in the Resources/Public/JavaScript folder
1618 * @param string $mainModuleName Must be in the form of "TYPO3/CMS/PackageName/ModuleName" e.g. "TYPO3/CMS/Backend/FormEngine"
1619 * @param string $callBackFunction loaded right after the requireJS loading, must be wrapped in function() {}
1622 public function loadRequireJsModule($mainModuleName, $callBackFunction = NULL) {
1623 $inlineCodeKey = $mainModuleName;
1624 // make sure requireJS is initialized
1625 $this->loadRequireJs();
1627 // execute the main module, and load a possible callback function
1628 $javaScriptCode = 'require(["' . $mainModuleName . '"]';
1629 if ($callBackFunction !== NULL) {
1630 $inlineCodeKey .= sha1($callBackFunction);
1631 $javaScriptCode .= ', ' . $callBackFunction;
1633 $javaScriptCode .= ');';
1634 $this->addJsInlineCode('RequireJS-Module-' . $inlineCodeKey, $javaScriptCode);
1638 * Call function if you need the prototype library
1642 public function loadPrototype() {
1643 $this->addPrototype
= TRUE;
1647 * Call function if you need the Scriptaculous library
1649 * @param string $modules Add modules you need. use "all" if you need complete modules
1652 public function loadScriptaculous($modules = 'all') {
1653 // Scriptaculous require prototype, so load prototype too.
1654 $this->addPrototype
= TRUE;
1655 $this->addScriptaculous
= TRUE;
1657 if ($modules == 'all') {
1658 foreach ($this->addScriptaculousModules
as $key => $value) {
1659 $this->addScriptaculousModules
[$key] = TRUE;
1662 $mods = GeneralUtility
::trimExplode(',', $modules);
1663 foreach ($mods as $mod) {
1664 if (isset($this->addScriptaculousModules
[strtolower($mod)])) {
1665 $this->addScriptaculousModules
[strtolower($mod)] = TRUE;
1673 * call this function if you need the extJS library
1675 * @param bool $css Flag, if set the ext-css will be loaded
1676 * @param bool $theme Flag, if set the ext-theme "grey" will be loaded
1679 public function loadExtJS($css = TRUE, $theme = TRUE) {
1680 $this->addExtJS
= TRUE;
1681 $this->extJStheme
= $theme;
1682 $this->extJScss
= $css;
1686 * Enables ExtJs QuickTips
1691 public function enableExtJSQuickTips() {
1692 $this->enableExtJSQuickTips
= TRUE;
1696 * Call this function to load debug version of ExtJS. Use this for development only
1700 public function enableExtJsDebug() {
1701 $this->enableExtJsDebug
= TRUE;
1705 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1706 * The label can be used in scripts with TYPO3.lang.<key>
1709 * @param string $key
1710 * @param string $value
1713 public function addInlineLanguageLabel($key, $value) {
1714 $this->inlineLanguageLabels
[$key] = $value;
1718 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1719 * The label can be used in scripts with TYPO3.lang.<key>
1720 * Array will be merged with existing array.
1723 * @param array $array
1724 * @param bool $parseWithLanguageService
1727 public function addInlineLanguageLabelArray(array $array, $parseWithLanguageService = FALSE) {
1728 if ($parseWithLanguageService === TRUE) {
1729 foreach ($array as $key => $value) {
1730 $array[$key] = $this->getLanguageService()->sL($value);
1734 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $array);
1738 * Gets labels to be used in JavaScript fetched from a locallang file.
1740 * @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.
1741 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1742 * @param string $stripFromSelectionName Sub-prefix to be removed from label names in the result (default: '')
1743 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1746 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1747 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1748 if ($fileRef && !isset($this->inlineLanguageLabelFiles
[$index])) {
1749 $this->inlineLanguageLabelFiles
[$index] = array(
1750 'fileRef' => $fileRef,
1751 'selectionPrefix' => $selectionPrefix,
1752 'stripFromSelectionName' => $stripFromSelectionName,
1753 'errorMode' => $errorMode
1759 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1760 * The label can be used in scripts with TYPO3.setting.<key>
1763 * @param string $namespace
1764 * @param string $key
1765 * @param string $value
1768 public function addInlineSetting($namespace, $key, $value) {
1770 if (strpos($namespace, '.')) {
1771 $parts = explode('.', $namespace);
1772 $a = &$this->inlineSettings
;
1773 foreach ($parts as $part) {
1778 $this->inlineSettings
[$namespace][$key] = $value;
1781 $this->inlineSettings
[$key] = $value;
1786 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1787 * The label can be used in scripts with TYPO3.setting.<key>
1788 * Array will be merged with existing array.
1791 * @param string $namespace
1792 * @param array $array
1795 public function addInlineSettingArray($namespace, array $array) {
1797 if (strpos($namespace, '.')) {
1798 $parts = explode('.', $namespace);
1799 $a = &$this->inlineSettings
;
1800 foreach ($parts as $part) {
1803 $a = array_merge((array)$a, $array);
1805 $this->inlineSettings
[$namespace] = array_merge((array)$this->inlineSettings
[$namespace], $array);
1808 $this->inlineSettings
= array_merge($this->inlineSettings
, $array);
1813 * Adds content to body content
1815 * @param string $content
1818 public function addBodyContent($content) {
1819 $this->bodyContent
.= $content;
1822 /*****************************************************/
1824 /* Render Functions */
1826 /*****************************************************/
1828 * Render the section (Header or Footer)
1830 * @param int $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1831 * @return string Content of rendered section
1833 public function render($part = self
::PART_COMPLETE
) {
1834 $this->prepareRendering();
1835 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1836 $metaTags = implode(LF
, $this->metaTags
);
1837 $markerArray = $this->getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags);
1838 $template = $this->getTemplateForPart($part);
1840 // The page renderer needs a full reset, even when only rendering one part of the page
1841 // This means that you can only register footer files *after* the header has been already rendered.
1842 // In case you render the footer part first, header files can only be added *after* the footer has been rendered
1844 return trim(\TYPO3\CMS\Core\Html\HtmlParser
::substituteMarkerArray($template, $markerArray, '###|###'));
1848 * Render the page but not the JavaScript and CSS Files
1850 * @param string $substituteHash The hash that is used for the placehoder markers
1852 * @return string Content of rendered section
1854 public function renderPageWithUncachedObjects($substituteHash) {
1855 $this->prepareRendering();
1856 $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
1857 $template = $this->getTemplateForPart(self
::PART_COMPLETE
);
1858 return trim(\TYPO3\CMS\Core\Html\HtmlParser
::substituteMarkerArray($template, $markerArray, '###|###'));
1862 * Renders the JavaScript and CSS files that have been added during processing
1863 * of uncached content objects (USER_INT, COA_INT)
1865 * @param string $cachedPageContent
1866 * @param string $substituteHash The hash that is used for the placehoder markers
1870 public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash) {
1871 $this->prepareRendering();
1872 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1873 $title = $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '';
1874 $markerArray = array(
1875 '<!-- ###TITLE' . $substituteHash . '### -->' => $title,
1876 '<!-- ###CSS_LIBS' . $substituteHash . '### -->' => $cssLibs,
1877 '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
1878 '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
1879 '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
1880 '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
1881 '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
1882 '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF
, $this->headerData
),
1883 '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF
, $this->footerData
),
1884 '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
1885 '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
1886 '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline
1888 foreach ($markerArray as $placeHolder => $content) {
1889 $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
1892 return $cachedPageContent;
1896 * Remove ending slashes from static header block
1897 * if the page is beeing rendered as html (not xhtml)
1898 * and define property $this->endingSlash for further use
1902 protected function prepareRendering() {
1903 if ($this->getRenderXhtml()) {
1904 $this->endingSlash
= ' /';
1906 $this->metaCharsetTag
= str_replace(' />', '>', $this->metaCharsetTag
);
1907 $this->baseUrlTag
= str_replace(' />', '>', $this->baseUrlTag
);
1908 $this->shortcutTag
= str_replace(' />', '>', $this->shortcutTag
);
1909 $this->endingSlash
= '';
1914 * Renders all JavaScript and CSS
1916 * @return array<string>
1918 protected function renderJavaScriptAndCss() {
1919 $this->executePreRenderHook();
1920 $mainJsLibs = $this->renderMainJavaScriptLibraries();
1921 if ($this->concatenateFiles ||
$this->concatenateJavascript ||
$this->concatenateCss
) {
1922 // Do the file concatenation
1923 $this->doConcatenate();
1925 if ($this->compressCss ||
$this->compressJavascript
) {
1926 // Do the file compression
1927 $this->doCompress();
1929 $this->executeRenderPostTransformHook();
1930 $cssLibs = $this->renderCssLibraries();
1931 $cssFiles = $this->renderCssFiles();
1932 $cssInline = $this->renderCssInline();
1933 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
1934 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
1935 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
1936 $jsLibs = $mainJsLibs . $jsLibs;
1937 if ($this->moveJsFromHeaderToFooter
) {
1938 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
1940 $jsFooterFiles = $jsFiles . LF
. $jsFooterFiles;
1942 $jsFooterInline = $jsInline . LF
. $jsFooterInline;
1945 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1946 return array($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1950 * Fills the marker array with the given strings and trims each value
1952 * @param $jsLibs string
1953 * @param $jsFiles string
1954 * @param $jsFooterFiles string
1955 * @param $cssLibs string
1956 * @param $cssFiles string
1957 * @param $jsInline string
1958 * @param $cssInline string
1959 * @param $jsFooterInline string
1960 * @param $jsFooterLibs string
1961 * @param $metaTags string
1962 * @return array Marker array
1964 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags) {
1965 $markerArray = array(
1966 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1967 'HTMLTAG' => $this->htmlTag
,
1968 'HEADTAG' => $this->headTag
,
1969 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1970 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
1971 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1972 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1973 'CSS_LIBS' => $cssLibs,
1974 'CSS_INCLUDE' => $cssFiles,
1975 'CSS_INLINE' => $cssInline,
1976 'JS_INLINE' => $jsInline,
1977 'JS_INCLUDE' => $jsFiles,
1978 'JS_LIBS' => $jsLibs,
1979 'TITLE' => $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '',
1980 'META' => $metaTags,
1981 'HEADERDATA' => $this->headerData ?
implode(LF
, $this->headerData
) : '',
1982 'FOOTERDATA' => $this->footerData ?
implode(LF
, $this->footerData
) : '',
1983 'JS_LIBS_FOOTER' => $jsFooterLibs,
1984 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1985 'JS_INLINE_FOOTER' => $jsFooterInline,
1986 'BODY' => $this->bodyContent
1988 $markerArray = array_map('trim', $markerArray);
1989 return $markerArray;
1993 * Fills the marker array with the given strings and trims each value
1995 * @param string $substituteHash The hash that is used for the placehoder markers
1996 * @return array Marker array
1998 protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash) {
1999 $markerArray = array(
2000 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
2001 'HTMLTAG' => $this->htmlTag
,
2002 'HEADTAG' => $this->headTag
,
2003 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
2004 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
2005 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
2006 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
2007 'META' => implode(LF
, $this->metaTags
),
2008 'BODY' => $this->bodyContent
,
2009 'TITLE' => '<!-- ###TITLE' . $substituteHash . '### -->',
2010 'CSS_LIBS' => '<!-- ###CSS_LIBS' . $substituteHash . '### -->',
2011 'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
2012 'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
2013 'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
2014 'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
2015 'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
2016 'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
2017 'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
2018 'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
2019 'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
2020 'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->'
2022 $markerArray = array_map('trim', $markerArray);
2023 return $markerArray;
2027 * Reads the template file and returns the requested part as string
2032 protected function getTemplateForPart($part) {
2033 $templateFile = GeneralUtility
::getFileAbsFileName($this->templateFile
, TRUE);
2034 $template = GeneralUtility
::getUrl($templateFile);
2035 if ($this->removeLineBreaksFromTemplate
) {
2036 $template = strtr($template, array(LF
=> '', CR
=> ''));
2038 if ($part !== self
::PART_COMPLETE
) {
2039 $templatePart = explode('###BODY###', $template);
2040 $template = $templatePart[$part - 1];
2046 * Helper function for render the main JavaScript libraries,
2047 * currently: RequireJS, jQuery, PrototypeJS, Scriptaculous, ExtJs
2049 * @return string Content with JavaScript libraries
2051 protected function renderMainJavaScriptLibraries() {
2054 // Include RequireJS
2055 if ($this->addRequireJs
) {
2056 // load the paths of the requireJS configuration
2057 $out .= GeneralUtility
::wrapJS('var require = ' . json_encode($this->requireJsConfig
)) . LF
;
2058 // directly after that, include the require.js file
2059 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $this->requireJsPath
. 'require.js')) . '" type="text/javascript"></script>' . LF
;
2062 // Include jQuery Core for each namespace, depending on the version and source
2063 if (!empty($this->jQueryVersions
)) {
2064 foreach ($this->jQueryVersions
as $namespace => $jQueryVersion) {
2065 $out .= $this->renderJqueryScriptTag($jQueryVersion['version'], $jQueryVersion['source'], $namespace);
2068 if ($this->addPrototype
) {
2069 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $this->prototypePath
. 'prototype.js')) . '" type="text/javascript"></script>' . LF
;
2070 unset($this->jsFiles
[$this->backPath
. $this->prototypePath
. 'prototype.js']);
2072 if ($this->addScriptaculous
) {
2074 foreach ($this->addScriptaculousModules
as $key => $value) {
2075 if ($this->addScriptaculousModules
[$key]) {
2079 // Resolve dependencies
2080 if (in_array('dragdrop', $mods) ||
in_array('controls', $mods)) {
2081 $mods = array_merge(array('effects'), $mods);
2083 if (!empty($mods)) {
2084 foreach ($mods as $module) {
2085 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $this->scriptaculousPath
. $module . '.js')) . '" type="text/javascript"></script>' . LF
;
2086 unset($this->jsFiles
[$this->backPath
. $this->scriptaculousPath
. $module . '.js']);
2089 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $this->scriptaculousPath
. 'scriptaculous.js')) . '" type="text/javascript"></script>' . LF
;
2090 unset($this->jsFiles
[$this->backPath
. $this->scriptaculousPath
. 'scriptaculous.js']);
2093 if ($this->addExtJS
) {
2094 // Use the base adapter all the time
2095 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $this->extJsPath
. 'adapter/ext-base' . ($this->enableExtJsDebug ?
'-debug' : '') . '.js')) . '" type="text/javascript"></script>' . LF
;
2096 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $this->extJsPath
. 'ext-all' . ($this->enableExtJsDebug ?
'-debug' : '') . '.js')) . '" type="text/javascript"></script>' . LF
;
2097 // Add extJS localization
2098 // Load standard ISO mapping and modify for use with ExtJS
2099 $localeMap = $this->locales
->getIsoMapping();
2100 $localeMap[''] = 'en';
2101 $localeMap['default'] = 'en';
2103 $localeMap['gr'] = 'el_GR';
2104 // Norwegian Bokmaal
2105 $localeMap['no'] = 'no_BO';
2107 $localeMap['se'] = 'se_SV';
2108 $extJsLang = isset($localeMap[$this->lang
]) ?
$localeMap[$this->lang
] : $this->lang
;
2109 // @todo autoconvert file from UTF8 to current BE charset if necessary!!!!
2110 $extJsLocaleFile = $this->extJsPath
. 'locale/ext-lang-' . $extJsLang . '.js';
2111 if (file_exists(PATH_typo3
. $extJsLocaleFile)) {
2112 $out .= '<script src="' . $this->processJsFile(($this->backPath
. $extJsLocaleFile)) . '" type="text/javascript" charset="utf-8"></script>' . LF
;
2114 // Remove extjs from JScodeLibArray
2115 unset($this->jsFiles
[$this->backPath
. $this->extJsPath
. 'ext-all.js'], $this->jsFiles
[$this->backPath
. $this->extJsPath
. 'ext-all-debug.js']);
2117 $this->loadJavaScriptLanguageStrings();
2118 if (TYPO3_MODE
=== 'BE') {
2119 $this->addAjaxUrlsToInlineSettings();
2121 $inlineSettings = $this->inlineLanguageLabels ?
'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels
) . ';' : '';
2122 $inlineSettings .= $this->inlineSettings ?
'TYPO3.settings = ' . json_encode($this->inlineSettings
) . ';' : '';
2123 if ($this->addExtJS
) {
2124 // Set clear.gif, move it on top, add handler code
2126 if (!empty($this->extOnReadyCode
)) {
2127 foreach ($this->extOnReadyCode
as $block) {
2131 $out .= $this->inlineJavascriptWrap
[0] . '
2133 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(GeneralUtility
::locationHeaderUrl(($this->backPath
. 'gfx/clear.gif'))) . '";
2134 Ext.SSL_SECURE_URL = "' . htmlspecialchars(GeneralUtility
::locationHeaderUrl(($this->backPath
. 'gfx/clear.gif'))) . '";' . LF
2136 . 'Ext.onReady(function() {'
2137 . ($this->enableExtJSQuickTips ?
'Ext.QuickTips.init();' . LF
: '')
2140 . $this->inlineJavascriptWrap
[1];
2141 $this->extOnReadyCode
= array();
2142 // Include TYPO3.l10n object
2143 if (TYPO3_MODE
=== 'BE') {
2144 $out .= '<script src="' . $this->processJsFile(($this->backPath
. 'sysext/lang/Resources/Public/JavaScript/Typo3Lang.js')) . '" type="text/javascript" charset="utf-8"></script>' . LF
;
2146 if ($this->extJScss
) {
2147 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
2148 $this->addCssLibrary($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE);
2150 $this->addCssLibrary($this->backPath
. $this->extJsPath
. 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE);
2153 if ($this->extJStheme
) {
2154 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
2155 $this->addCssLibrary($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE);
2157 $this->addCssLibrary($this->backPath
. $this->extJsPath
. 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE);
2161 // no extJS loaded, but still inline settings
2162 if ($inlineSettings !== '') {
2163 // make sure the global TYPO3 is available
2164 $inlineSettings = 'var TYPO3 = TYPO3 || {};' . CRLF
. $inlineSettings;
2165 $out .= $this->inlineJavascriptWrap
[0] . $inlineSettings . $this->inlineJavascriptWrap
[1];
2166 if (TYPO3_MODE
=== 'BE') {
2167 $this->loadRequireJsModule('TYPO3/CMS/Lang/Lang');
2175 * Load the language strings into JavaScript
2177 protected function loadJavaScriptLanguageStrings() {
2178 if (!empty($this->inlineLanguageLabelFiles
)) {
2179 foreach ($this->inlineLanguageLabelFiles
as $languageLabelFile) {
2180 $this->includeLanguageFileForInline($languageLabelFile['fileRef'], $languageLabelFile['selectionPrefix'], $languageLabelFile['stripFromSelectionName'], $languageLabelFile['errorMode']);
2183 $this->inlineLanguageLabelFiles
= array();
2184 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
2185 if (TYPO3_MODE
=== 'FE' && $this->getCharSet() !== 'utf-8') {
2186 if ($this->inlineLanguageLabels
) {
2187 $this->csConvObj
->convArray($this->inlineLanguageLabels
, $this->getCharSet(), 'utf-8');
2189 if ($this->inlineSettings
) {
2190 $this->csConvObj
->convArray($this->inlineSettings
, $this->getCharSet(), 'utf-8');
2196 * Make URLs to all backend ajax handlers available as inline setting.
2198 protected function addAjaxUrlsToInlineSettings() {
2199 $ajaxUrls = array();
2200 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'] as $ajaxHandler => $_) {
2201 $ajaxUrls[$ajaxHandler] = BackendUtility
::getAjaxUrl($ajaxHandler);
2203 $this->inlineSettings
['ajaxUrls'] = $ajaxUrls;
2207 * Renders the HTML script tag for the given jQuery version.
2209 * @param string $version The jQuery version that should be included, either "latest" or any available version
2210 * @param string $source The location of the jQuery source, can be "local", "google", "msn" or "jquery
2211 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored
2214 protected function renderJqueryScriptTag($version, $source, $namespace) {
2216 case isset($this->jQueryCdnUrls
[$source]):
2217 if ($this->enableJqueryDebug
) {
2220 $minifyPart = '.min';
2222 $jQueryFileName = sprintf($this->jQueryCdnUrls
[$source], $version, $minifyPart);
2224 case $source === 'local':
2225 $jQueryFileName = $this->backPath
. $this->jQueryPath
. 'jquery-' . rawurlencode($version);
2226 if ($this->enableJqueryDebug
) {
2227 $jQueryFileName .= '.js';
2229 $jQueryFileName .= '.min.js';
2233 $jQueryFileName = $source;
2235 // Include the jQuery Core
2236 $scriptTag = '<script src="' . htmlspecialchars($jQueryFileName) . '" type="text/javascript"></script>' . LF
;
2237 // Set the noConflict mode to be available via "TYPO3.jQuery" in all installations
2238 switch ($namespace) {
2239 case self
::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT
:
2240 $scriptTag .= GeneralUtility
::wrapJS('jQuery.noConflict();') . LF
;
2242 case self
::JQUERY_NAMESPACE_NONE
:
2244 case self
::JQUERY_NAMESPACE_DEFAULT
:
2247 $scriptTag .= GeneralUtility
::wrapJS('var TYPO3 = TYPO3 || {}; TYPO3.' . $namespace . ' = jQuery.noConflict(true);') . LF
;
2253 * Render CSS library files
2257 protected function renderCssLibraries() {
2259 if (!empty($this->cssLibs
)) {
2260 foreach ($this->cssLibs
as $file => $properties) {
2261 $file = GeneralUtility
::resolveBackPath($file);
2262 $file = GeneralUtility
::createVersionNumberedFilename($file);
2263 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2264 . '" type="text/css" href="' . htmlspecialchars($file)
2265 . '" media="' . htmlspecialchars($properties['media']) . '"'
2266 . ($properties['title'] ?
' title="' . htmlspecialchars($properties['title']) . '"' : '')
2267 . $this->endingSlash
. '>';
2268 if ($properties['allWrap']) {
2269 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2270 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2273 if ($properties['forceOnTop']) {
2274 $cssFiles = $tag . $cssFiles;
2288 protected function renderCssFiles() {
2290 if (!empty($this->cssFiles
)) {
2291 foreach ($this->cssFiles
as $file => $properties) {
2292 $file = GeneralUtility
::resolveBackPath($file);
2293 $file = GeneralUtility
::createVersionNumberedFilename($file);
2294 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2295 . '" type="text/css" href="' . htmlspecialchars($file)
2296 . '" media="' . htmlspecialchars($properties['media']) . '"'
2297 . ($properties['title'] ?
' title="' . htmlspecialchars($properties['title']) . '"' : '')
2298 . $this->endingSlash
. '>';
2299 if ($properties['allWrap']) {
2300 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2301 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2304 if ($properties['forceOnTop']) {
2305 $cssFiles = $tag . $cssFiles;
2319 protected function renderCssInline() {
2321 if (!empty($this->cssInline
)) {
2322 foreach ($this->cssInline
as $name => $properties) {
2323 $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2324 if ($properties['forceOnTop']) {
2325 $cssInline = $cssCode . $cssInline;
2327 $cssInline .= $cssCode;
2330 $cssInline = $this->inlineCssWrap
[0] . $cssInline . $this->inlineCssWrap
[1];
2336 * Render JavaScipt libraries
2338 * @return array<string> jsLibs and jsFooterLibs strings
2340 protected function renderAdditionalJavaScriptLibraries() {
2343 if (!empty($this->jsLibs
)) {
2344 foreach ($this->jsLibs
as $properties) {
2345 $properties['file'] = GeneralUtility
::resolveBackPath($properties['file']);
2346 $properties['file'] = GeneralUtility
::createVersionNumberedFilename($properties['file']);
2347 $async = ($properties['async']) ?
' async="async"' : '';
2348 $integrity = ($properties['integrity']) ?
' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2349 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $integrity . '></script>';
2350 if ($properties['allWrap']) {
2351 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2352 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2355 if ($properties['forceOnTop']) {
2356 if ($properties['section'] === self
::PART_HEADER
) {
2357 $jsLibs = $tag . $jsLibs;
2359 $jsFooterLibs = $tag . $jsFooterLibs;
2362 if ($properties['section'] === self
::PART_HEADER
) {
2365 $jsFooterLibs .= $tag;
2370 if ($this->moveJsFromHeaderToFooter
) {
2371 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
2374 return array($jsLibs, $jsFooterLibs);
2378 * Render JavaScript files
2380 * @return array<string> jsFiles and jsFooterFiles strings
2382 protected function renderJavaScriptFiles() {
2384 $jsFooterFiles = '';
2385 if (!empty($this->jsFiles
)) {
2386 foreach ($this->jsFiles
as $file => $properties) {
2387 $file = GeneralUtility
::resolveBackPath($file);
2388 $file = GeneralUtility
::createVersionNumberedFilename($file);
2389 $async = ($properties['async']) ?
' async="async"' : '';
2390 $integrity = ($properties['integrity']) ?
' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2391 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $integrity . '></script>';
2392 if ($properties['allWrap']) {
2393 $wrapArr = explode($properties['splitChar'] ?
: '|', $properties['allWrap'], 2);
2394 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2397 if ($properties['forceOnTop']) {
2398 if ($properties['section'] === self
::PART_HEADER
) {
2399 $jsFiles = $tag . $jsFiles;
2401 $jsFooterFiles = $tag . $jsFooterFiles;
2404 if ($properties['section'] === self
::PART_HEADER
) {
2407 $jsFooterFiles .= $tag;
2412 if ($this->moveJsFromHeaderToFooter
) {
2413 $jsFooterFiles = $jsFiles . $jsFooterFiles;
2416 return array($jsFiles, $jsFooterFiles);
2420 * Render inline JavaScript
2422 * @return array<string> jsInline and jsFooterInline string
2424 protected function renderInlineJavaScript() {
2426 $jsFooterInline = '';
2427 if (!empty($this->jsInline
)) {
2428 foreach ($this->jsInline
as $name => $properties) {
2429 $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2430 if ($properties['forceOnTop']) {
2431 if ($properties['section'] === self
::PART_HEADER
) {
2432 $jsInline = $jsCode . $jsInline;
2434 $jsFooterInline = $jsCode . $jsFooterInline;
2437 if ($properties['section'] === self
::PART_HEADER
) {
2438 $jsInline .= $jsCode;
2440 $jsFooterInline .= $jsCode;
2446 $jsInline = $this->inlineJavascriptWrap
[0] . $jsInline . $this->inlineJavascriptWrap
[1];
2448 if ($jsFooterInline) {
2449 $jsFooterInline = $this->inlineJavascriptWrap
[0] . $jsFooterInline . $this->inlineJavascriptWrap
[1];
2451 if ($this->moveJsFromHeaderToFooter
) {
2452 $jsFooterInline = $jsInline . $jsFooterInline;
2455 return array($jsInline, $jsFooterInline);
2459 * Include language file for inline usage
2461 * @param string $fileRef
2462 * @param string $selectionPrefix
2463 * @param string $stripFromSelectionName
2464 * @param int $errorMode
2466 * @throws \RuntimeException
2468 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
2469 if (!isset($this->lang
) ||
!isset($this->charSet
)) {
2470 throw new \
RuntimeException('Language and character encoding are not set.', 1284906026);
2472 $labelsFromFile = array();
2473 $allLabels = $this->readLLfile($fileRef, $errorMode);
2474 // Regular expression to strip the selection prefix and possibly something from the label name:
2475 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
2476 if ($allLabels !== FALSE) {
2477 // Merge language specific translations:
2478 if ($this->lang
!== 'default' && isset($allLabels[$this->lang
])) {
2479 $labels = array_merge($allLabels['default'], $allLabels[$this->lang
]);
2481 $labels = $allLabels['default'];
2483 // Iterate through all locallang labels:
2484 foreach ($labels as $label => $value) {
2485 if ($selectionPrefix === '') {
2486 $labelsFromFile[$label] = $value;
2487 } elseif (strpos($label, $selectionPrefix) === 0) {
2488 preg_replace($labelPattern, '', $label);
2489 $labelsFromFile[$label] = $value;
2492 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $labelsFromFile);
2497 * Reads a locallang file.
2499 * @param string $fileRef Reference to a relative filename to include.
2500 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
2501 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2503 protected function readLLfile($fileRef, $errorMode = 0) {
2504 if ($this->lang
!== 'default') {
2505 $languages = array_reverse($this->languageDependencies
);
2506 // At least we need to have English
2507 if (empty($languages)) {
2508 $languages[] = 'default';
2511 $languages = array('default');
2514 $localLanguage = array();
2515 foreach ($languages as $language) {
2516 $tempLL = GeneralUtility
::readLLfile($fileRef, $language, $this->charSet
, $errorMode);
2517 $localLanguage['default'] = $tempLL['default'];
2518 if (!isset($localLanguage[$this->lang
])) {
2519 $localLanguage[$this->lang
] = $localLanguage['default'];
2521 if ($this->lang
!== 'default' && isset($tempLL[$language])) {
2522 // Merge current language labels onto labels from previous language
2523 // This way we have a labels with fall back applied
2524 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($localLanguage[$this->lang
], $tempLL[$language], TRUE, FALSE);
2528 return $localLanguage;
2532 /*****************************************************/
2536 /*****************************************************/
2538 * Concatenate files into one file
2539 * registered handler
2543 protected function doConcatenate() {
2544 $this->doConcatenateCss();
2545 $this->doConcatenateJavaScript();
2549 * Concatenate JavaScript files according to the configuration.
2553 protected function doConcatenateJavaScript() {
2554 if ($this->concatenateFiles ||
$this->concatenateJavascript
) {
2555 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsConcatenateHandler'])) {
2556 // use external concatenation routine
2558 'jsLibs' => &$this->jsLibs
,
2559 'jsFiles' => &$this->jsFiles
,
2560 'jsFooterFiles' => &$this->jsFooterFiles
,
2561 'headerData' => &$this->headerData
,
2562 'footerData' => &$this->footerData
2564 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsConcatenateHandler'], $params, $this);
2566 $this->jsLibs
= $this->getCompressor()->concatenateJsFiles($this->jsLibs
);
2567 $this->jsFiles
= $this->getCompressor()->concatenateJsFiles($this->jsFiles
);
2568 $this->jsFooterFiles
= $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles
);
2574 * Concatenate CSS files according to configuration.
2578 protected function doConcatenateCss() {
2579 if ($this->concatenateFiles ||
$this->concatenateCss
) {
2580 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssConcatenateHandler'])) {
2581 // use external concatenation routine
2583 'cssFiles' => &$this->cssFiles
,
2584 'headerData' => &$this->headerData
,
2585 'footerData' => &$this->footerData
2587 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssConcatenateHandler'], $params, $this);
2589 $cssOptions = array();
2590 if (TYPO3_MODE
=== 'BE') {
2591 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
2593 $this->cssFiles
= $this->getCompressor()->concatenateCssFiles($this->cssFiles
, $cssOptions);
2599 * Compresses inline code
2603 protected function doCompress() {
2604 $this->doCompressJavaScript();
2605 $this->doCompressCss();
2609 * Compresses CSS according to configuration.
2613 protected function doCompressCss() {
2614 if ($this->compressCss
) {
2615 // Use external compression routine
2617 'cssInline' => &$this->cssInline
,
2618 'cssFiles' => &$this->cssFiles
,
2619 'headerData' => &$this->headerData
,
2620 'footerData' => &$this->footerData
2622 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'])) {
2623 // use external concatenation routine
2624 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'], $params, $this);
2626 $this->cssFiles
= $this->getCompressor()->compressCssFiles($this->cssFiles
);
2632 * Compresses JavaScript according to configuration.
2636 protected function doCompressJavaScript() {
2637 if ($this->compressJavascript
) {
2638 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'])) {
2639 // Use external compression routine
2641 'jsInline' => &$this->jsInline
,
2642 'jsFooterInline' => &$this->jsFooterInline
,
2643 'jsLibs' => &$this->jsLibs
,
2644 'jsFiles' => &$this->jsFiles
,
2645 'jsFooterFiles' => &$this->jsFooterFiles
,
2646 'headerData' => &$this->headerData
,
2647 'footerData' => &$this->footerData
2649 GeneralUtility
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'], $params, $this);
2651 // Traverse the arrays, compress files
2652 if (!empty($this->jsInline
)) {
2653 foreach ($this->jsInline
as $name => $properties) {
2654 if ($properties['compress']) {
2656 $this->jsInline
[$name]['code'] = GeneralUtility
::minifyJavaScript($properties['code'], $error);
2658 $this->compressError
.= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF
;
2663 $this->jsLibs
= $this->getCompressor()->compressJsFiles($this->jsLibs
);
2664 $this->jsFiles
= $this->getCompressor()->compressJsFiles($this->jsFiles
);
2665 $this->jsFooterFiles
= $this->getCompressor()->compressJsFiles($this->jsFooterFiles
);
2671 * Returns instance of \TYPO3\CMS\Core\Resource\ResourceCompressor
2673 * @return \TYPO3\CMS\Core\Resource\ResourceCompressor
2675 protected function getCompressor() {
2676 if ($this->compressor
=== NULL) {
2677 $this->compressor
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\
Resource\ResourceCompressor
::class);
2679 return $this->compressor
;
2683 * Processes a Javascript file dependent on the current context
2685 * Adds the version number for Frontend, compresses the file for Backend
2687 * @param string $filename Filename
2688 * @return string New filename
2690 protected function processJsFile($filename) {
2691 switch (TYPO3_MODE
) {
2693 if ($this->compressJavascript
) {
2694 $filename = $this->getCompressor()->compressJsFile($filename);
2696 $filename = GeneralUtility
::createVersionNumberedFilename($filename);
2700 if ($this->compressJavascript
) {
2701 $filename = $this->getCompressor()->compressJsFile($filename);
2709 * Returns global language service instance
2711 * @return \TYPO3\CMS\Lang\LanguageService
2713 protected function getLanguageService() {
2714 return $GLOBALS['LANG'];
2717 /*****************************************************/
2721 /*****************************************************/
2723 * Execute PreRenderHook for possible manipulation
2727 protected function executePreRenderHook() {
2728 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
2730 'jsLibs' => &$this->jsLibs
,
2731 'jsFooterLibs' => &$this->jsFooterLibs
,
2732 'jsFiles' => &$this->jsFiles
,
2733 'jsFooterFiles' => &$this->jsFooterFiles
,
2734 'cssFiles' => &$this->cssFiles
,
2735 'headerData' => &$this->headerData
,
2736 'footerData' => &$this->footerData
,
2737 'jsInline' => &$this->jsInline
,
2738 'jsFooterInline' => &$this->jsFooterInline
,
2739 'cssInline' => &$this->cssInline
2741 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
2742 GeneralUtility
::callUserFunction($hook, $params, $this);
2748 * PostTransform for possible manipulation of concatenated and compressed files
2752 protected function executeRenderPostTransformHook() {
2753 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
2755 'jsLibs' => &$this->jsLibs
,
2756 'jsFooterLibs' => &$this->jsFooterLibs
,
2757 'jsFiles' => &$this->jsFiles
,
2758 'jsFooterFiles' => &$this->jsFooterFiles
,
2759 'cssFiles' => &$this->cssFiles
,
2760 'headerData' => &$this->headerData
,
2761 'footerData' => &$this->footerData
,
2762 'jsInline' => &$this->jsInline
,
2763 'jsFooterInline' => &$this->jsFooterInline
,
2764 'cssInline' => &$this->cssInline
2766 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
2767 GeneralUtility
::callUserFunction($hook, $params, $this);
2773 * Execute postRenderHook for possible manipulation
2775 * @param $jsLibs string
2776 * @param $jsFiles string
2777 * @param $jsFooterFiles string
2778 * @param $cssLibs string
2779 * @param $cssFiles string
2780 * @param $jsInline string
2781 * @param $cssInline string
2782 * @param $jsFooterInline string
2783 * @param $jsFooterLibs string
2786 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssLibs, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs) {
2787 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
2789 'jsLibs' => &$jsLibs,
2790 'jsFiles' => &$jsFiles,
2791 'jsFooterFiles' => &$jsFooterFiles,
2792 'cssLibs' => &$cssLibs,
2793 'cssFiles' => &$cssFiles,
2794 'headerData' => &$this->headerData
,
2795 'footerData' => &$this->footerData
,
2796 'jsInline' => &$jsInline,
2797 'cssInline' => &$cssInline,
2798 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType
,
2799 'htmlTag' => &$this->htmlTag
,
2800 'headTag' => &$this->headTag
,
2801 'charSet' => &$this->charSet
,
2802 'metaCharsetTag' => &$this->metaCharsetTag
,
2803 'shortcutTag' => &$this->shortcutTag
,
2804 'inlineComments' => &$this->inlineComments
,
2805 'baseUrl' => &$this->baseUrl
,
2806 'baseUrlTag' => &$this->baseUrlTag
,
2807 'favIcon' => &$this->favIcon
,
2808 'iconMimeType' => &$this->iconMimeType
,
2809 'titleTag' => &$this->titleTag
,
2810 'title' => &$this->title
,
2811 'metaTags' => &$this->metaTags
,
2812 'jsFooterInline' => &$jsFooterInline,
2813 'jsFooterLibs' => &$jsFooterLibs,
2814 'bodyContent' => &$this->bodyContent
2816 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
2817 GeneralUtility
::callUserFunction($hook, $params, $this);