[BUGFIX] Include CORS settings attribute when using integrity
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Page / PageRenderer.php
1 <?php
2 namespace TYPO3\CMS\Core\Page;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
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.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Routing\Router;
18 use TYPO3\CMS\Backend\Routing\UriBuilder;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Localization\LocalizationFactory;
21 use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
22 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
25
26 /**
27 * TYPO3 pageRender class (new in TYPO3 4.3.0)
28 * This class render the HTML of a webpage, usable for BE and FE
29 */
30 class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
31 {
32 // Constants for the part to be rendered
33 const PART_COMPLETE = 0;
34 const PART_HEADER = 1;
35 const PART_FOOTER = 2;
36 // jQuery Core version that is shipped with TYPO3
37 const JQUERY_VERSION_LATEST = '2.1.4';
38 // jQuery namespace options
39 const JQUERY_NAMESPACE_NONE = 'none';
40 const JQUERY_NAMESPACE_DEFAULT = 'jQuery';
41 const JQUERY_NAMESPACE_DEFAULT_NOCONFLICT = 'defaultNoConflict';
42
43 /**
44 * @var bool
45 */
46 protected $compressJavascript = false;
47
48 /**
49 * @var bool
50 */
51 protected $compressCss = false;
52
53 /**
54 * @var bool
55 */
56 protected $removeLineBreaksFromTemplate = false;
57
58 /**
59 * @var bool
60 */
61 protected $concatenateFiles = false;
62
63 /**
64 * @var bool
65 */
66 protected $concatenateJavascript = false;
67
68 /**
69 * @var bool
70 */
71 protected $concatenateCss = false;
72
73 /**
74 * @var bool
75 */
76 protected $moveJsFromHeaderToFooter = false;
77
78 /**
79 * @var \TYPO3\CMS\Core\Charset\CharsetConverter
80 */
81 protected $csConvObj;
82
83 /**
84 * @var \TYPO3\CMS\Core\Localization\Locales
85 */
86 protected $locales;
87
88 /**
89 * The language key
90 * Two character string or 'default'
91 *
92 * @var string
93 */
94 protected $lang;
95
96 /**
97 * List of language dependencies for actual language. This is used for local variants of a language
98 * that depend on their "main" language, like Brazilian Portuguese or Canadian French.
99 *
100 * @var array
101 */
102 protected $languageDependencies = [];
103
104 /**
105 * @var \TYPO3\CMS\Core\Resource\ResourceCompressor
106 */
107 protected $compressor;
108
109 // Arrays containing associative array for the included files
110 /**
111 * @var array
112 */
113 protected $jsFiles = [];
114
115 /**
116 * @var array
117 */
118 protected $jsFooterFiles = [];
119
120 /**
121 * @var array
122 */
123 protected $jsLibs = [];
124
125 /**
126 * @var array
127 */
128 protected $jsFooterLibs = [];
129
130 /**
131 * @var array
132 */
133 protected $cssFiles = [];
134
135 /**
136 * @var array
137 */
138 protected $cssLibs = [];
139
140 /**
141 * The title of the page
142 *
143 * @var string
144 */
145 protected $title;
146
147 /**
148 * Charset for the rendering
149 *
150 * @var string
151 */
152 protected $charSet;
153
154 /**
155 * @var string
156 */
157 protected $favIcon;
158
159 /**
160 * @var string
161 */
162 protected $baseUrl;
163
164 /**
165 * @var bool
166 */
167 protected $renderXhtml = true;
168
169 // Static header blocks
170 /**
171 * @var string
172 */
173 protected $xmlPrologAndDocType = '';
174
175 /**
176 * @var array
177 */
178 protected $metaTags = [];
179
180 /**
181 * @var array
182 */
183 protected $inlineComments = [];
184
185 /**
186 * @var array
187 */
188 protected $headerData = [];
189
190 /**
191 * @var array
192 */
193 protected $footerData = [];
194
195 /**
196 * @var string
197 */
198 protected $titleTag = '<title>|</title>';
199
200 /**
201 * @var string
202 */
203 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
204
205 /**
206 * @var string
207 */
208 protected $htmlTag = '<html>';
209
210 /**
211 * @var string
212 */
213 protected $headTag = '<head>';
214
215 /**
216 * @var string
217 */
218 protected $baseUrlTag = '<base href="|" />';
219
220 /**
221 * @var string
222 */
223 protected $iconMimeType = '';
224
225 /**
226 * @var string
227 */
228 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />';
229
230 // Static inline code blocks
231 /**
232 * @var array
233 */
234 protected $jsInline = [];
235
236 /**
237 * @var array
238 */
239 protected $jsFooterInline = [];
240
241 /**
242 * @var array
243 */
244 protected $extOnReadyCode = [];
245
246 /**
247 * @var array
248 */
249 protected $cssInline = [];
250
251 /**
252 * @var string
253 */
254 protected $bodyContent;
255
256 /**
257 * @var string
258 */
259 protected $templateFile;
260
261 /**
262 * @var array
263 */
264 protected $jsLibraryNames = ['extjs'];
265
266 // Paths to contibuted libraries
267
268 /**
269 * default path to the requireJS library, relative to the typo3/ directory
270 * @var string
271 */
272 protected $requireJsPath = 'Resources/Public/JavaScript/Contrib/';
273
274 /**
275 * @var string
276 */
277 protected $extJsPath = 'Resources/Public/JavaScript/Contrib/extjs/';
278
279 /**
280 * The local directory where one can find jQuery versions and plugins
281 *
282 * @var string
283 */
284 protected $jQueryPath = 'Resources/Public/JavaScript/Contrib/jquery/';
285
286 // Internal flags for JS-libraries
287 /**
288 * This array holds all jQuery versions that should be included in the
289 * current page.
290 * Each version is described by "source", "version" and "namespace"
291 *
292 * The namespace of every particular version is the key
293 * of that array, because only one version per namespace can exist.
294 *
295 * The type "source" describes where the jQuery core should be included from
296 * currently, TYPO3 supports "local" (make use of jQuery path), "google",
297 * "jquery", "msn" and "cloudflare".
298 *
299 * Currently there are downsides to "local" which supports only the latest/shipped
300 * jQuery core out of the box.
301 *
302 * @var array
303 */
304 protected $jQueryVersions = [];
305
306 /**
307 * Array of jQuery version numbers shipped with the core
308 *
309 * @var array
310 */
311 protected $availableLocalJqueryVersions = [
312 self::JQUERY_VERSION_LATEST
313 ];
314
315 /**
316 * Array of jQuery CDNs with placeholders
317 *
318 * @var array
319 */
320 protected $jQueryCdnUrls = [
321 'google' => 'https://ajax.googleapis.com/ajax/libs/jquery/%1$s/jquery%2$s.js',
322 'msn' => 'https://ajax.aspnetcdn.com/ajax/jQuery/jquery-%1$s%2$s.js',
323 'jquery' => 'https://code.jquery.com/jquery-%1$s%2$s.js',
324 'cloudflare' => 'https://cdnjs.cloudflare.com/ajax/libs/jquery/%1$s/jquery%2$s.js'
325 ];
326
327 /**
328 * if set, the requireJS library is included
329 * @var bool
330 */
331 protected $addRequireJs = false;
332
333 /**
334 * inline configuration for requireJS
335 * @var array
336 */
337 protected $requireJsConfig = [];
338
339 /**
340 * @var bool
341 */
342 protected $addExtJS = false;
343
344 /**
345 * @var bool
346 */
347 protected $extDirectCodeAdded = false;
348
349 /**
350 * @var bool
351 */
352 protected $enableExtJsDebug = false;
353
354 /**
355 * @var bool
356 */
357 protected $enableJqueryDebug = false;
358
359 /**
360 * @var bool
361 */
362 protected $extJStheme = true;
363
364 /**
365 * @var bool
366 */
367 protected $extJScss = true;
368
369 /**
370 * @var array
371 */
372 protected $inlineLanguageLabels = [];
373
374 /**
375 * @var array
376 */
377 protected $inlineLanguageLabelFiles = [];
378
379 /**
380 * @var array
381 */
382 protected $inlineSettings = [];
383
384 /**
385 * @var array
386 */
387 protected $inlineJavascriptWrap = [];
388
389 /**
390 * Saves error messages generated during compression
391 *
392 * @var string
393 */
394 protected $compressError = '';
395
396 /**
397 * Is empty string for HTML and ' /' for XHTML rendering
398 *
399 * @var string
400 */
401 protected $endingSlash = '';
402
403 /**
404 * Used by BE modules
405 *
406 * @var null|string
407 */
408 public $backPath;
409
410 /**
411 * @param string $templateFile Declare the used template file. Omit this parameter will use default template
412 * @param string $backPath Relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
413 */
414 public function __construct($templateFile = '', $backPath = null)
415 {
416 $this->reset();
417
418 $coreRelPath = ExtensionManagementUtility::extRelPath('core');
419 $this->requireJsPath = $coreRelPath . $this->requireJsPath;
420 $this->extJsPath = $coreRelPath . $this->extJsPath;
421 $this->jQueryPath = $coreRelPath . $this->jQueryPath;
422
423 $this->csConvObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
424 $this->locales = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\Locales::class);
425 if ($templateFile !== '') {
426 $this->templateFile = $templateFile;
427 }
428 $this->backPath = isset($backPath) ? $backPath : $GLOBALS['BACK_PATH'];
429 $this->inlineJavascriptWrap = [
430 '<script type="text/javascript">' . LF . '/*<![CDATA[*/' . LF,
431 '/*]]>*/' . LF . '</script>' . LF
432 ];
433 $this->inlineCssWrap = [
434 '<style type="text/css">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
435 '-->' . LF . '/*]]>*/' . LF . '</style>' . LF
436 ];
437 }
438
439 /**
440 * Reset all vars to initial values
441 *
442 * @return void
443 */
444 protected function reset()
445 {
446 $this->templateFile = 'EXT:core/Resources/Private/Templates/PageRenderer.html';
447 $this->jsFiles = [];
448 $this->jsFooterFiles = [];
449 $this->jsInline = [];
450 $this->jsFooterInline = [];
451 $this->jsLibs = [];
452 $this->cssFiles = [];
453 $this->cssInline = [];
454 $this->metaTags = [];
455 $this->inlineComments = [];
456 $this->headerData = [];
457 $this->footerData = [];
458 $this->extOnReadyCode = [];
459 $this->jQueryVersions = [];
460 }
461
462 /*****************************************************/
463 /* */
464 /* Public Setters */
465 /* */
466 /* */
467 /*****************************************************/
468 /**
469 * Sets the title
470 *
471 * @param string $title title of webpage
472 * @return void
473 */
474 public function setTitle($title)
475 {
476 $this->title = $title;
477 }
478
479 /**
480 * Enables/disables rendering of XHTML code
481 *
482 * @param bool $enable Enable XHTML
483 * @return void
484 */
485 public function setRenderXhtml($enable)
486 {
487 $this->renderXhtml = $enable;
488 }
489
490 /**
491 * Sets xml prolog and docType
492 *
493 * @param string $xmlPrologAndDocType Complete tags for xml prolog and docType
494 * @return void
495 */
496 public function setXmlPrologAndDocType($xmlPrologAndDocType)
497 {
498 $this->xmlPrologAndDocType = $xmlPrologAndDocType;
499 }
500
501 /**
502 * Sets meta charset
503 *
504 * @param string $charSet Used charset
505 * @return void
506 */
507 public function setCharSet($charSet)
508 {
509 $this->charSet = $charSet;
510 }
511
512 /**
513 * Sets language
514 *
515 * @param string $lang Used language
516 * @return void
517 */
518 public function setLanguage($lang)
519 {
520 $this->lang = $lang;
521 $this->languageDependencies = [];
522
523 // Language is found. Configure it:
524 if (in_array($this->lang, $this->locales->getLocales())) {
525 $this->languageDependencies[] = $this->lang;
526 foreach ($this->locales->getLocaleDependencies($this->lang) as $language) {
527 $this->languageDependencies[] = $language;
528 }
529 }
530 }
531
532 /**
533 * Set the meta charset tag
534 *
535 * @param string $metaCharsetTag
536 * @return void
537 */
538 public function setMetaCharsetTag($metaCharsetTag)
539 {
540 $this->metaCharsetTag = $metaCharsetTag;
541 }
542
543 /**
544 * Sets html tag
545 *
546 * @param string $htmlTag Html tag
547 * @return void
548 */
549 public function setHtmlTag($htmlTag)
550 {
551 $this->htmlTag = $htmlTag;
552 }
553
554 /**
555 * Sets HTML head tag
556 *
557 * @param string $headTag HTML head tag
558 * @return void
559 */
560 public function setHeadTag($headTag)
561 {
562 $this->headTag = $headTag;
563 }
564
565 /**
566 * Sets favicon
567 *
568 * @param string $favIcon
569 * @return void
570 */
571 public function setFavIcon($favIcon)
572 {
573 $this->favIcon = $favIcon;
574 }
575
576 /**
577 * Sets icon mime type
578 *
579 * @param string $iconMimeType
580 * @return void
581 */
582 public function setIconMimeType($iconMimeType)
583 {
584 $this->iconMimeType = $iconMimeType;
585 }
586
587 /**
588 * Sets HTML base URL
589 *
590 * @param string $baseUrl HTML base URL
591 * @return void
592 */
593 public function setBaseUrl($baseUrl)
594 {
595 $this->baseUrl = $baseUrl;
596 }
597
598 /**
599 * Sets template file
600 *
601 * @param string $file
602 * @return void
603 */
604 public function setTemplateFile($file)
605 {
606 $this->templateFile = $file;
607 }
608
609 /**
610 * Sets back path
611 *
612 * @param string $backPath
613 * @return void
614 */
615 public function setBackPath($backPath)
616 {
617 $this->backPath = $backPath;
618 }
619
620 /**
621 * Sets Content for Body
622 *
623 * @param string $content
624 * @return void
625 */
626 public function setBodyContent($content)
627 {
628 $this->bodyContent = $content;
629 }
630
631 /**
632 * Sets path to requireJS library (relative to typo3 directory)
633 *
634 * @param string $path Path to requireJS library
635 * @return void
636 */
637 public function setRequireJsPath($path)
638 {
639 $this->requireJsPath = $path;
640 }
641
642 /**
643 * Sets Path for ExtJs library (relative to typo3 directory)
644 *
645 * @param string $path
646 * @return void
647 */
648 public function setExtJsPath($path)
649 {
650 $this->extJsPath = $path;
651 }
652
653 /*****************************************************/
654 /* */
655 /* Public Enablers / Disablers */
656 /* */
657 /* */
658 /*****************************************************/
659 /**
660 * Enables MoveJsFromHeaderToFooter
661 *
662 * @return void
663 */
664 public function enableMoveJsFromHeaderToFooter()
665 {
666 $this->moveJsFromHeaderToFooter = true;
667 }
668
669 /**
670 * Disables MoveJsFromHeaderToFooter
671 *
672 * @return void
673 */
674 public function disableMoveJsFromHeaderToFooter()
675 {
676 $this->moveJsFromHeaderToFooter = false;
677 }
678
679 /**
680 * Enables compression of javascript
681 *
682 * @return void
683 */
684 public function enableCompressJavascript()
685 {
686 $this->compressJavascript = true;
687 }
688
689 /**
690 * Disables compression of javascript
691 *
692 * @return void
693 */
694 public function disableCompressJavascript()
695 {
696 $this->compressJavascript = false;
697 }
698
699 /**
700 * Enables compression of css
701 *
702 * @return void
703 */
704 public function enableCompressCss()
705 {
706 $this->compressCss = true;
707 }
708
709 /**
710 * Disables compression of css
711 *
712 * @return void
713 */
714 public function disableCompressCss()
715 {
716 $this->compressCss = false;
717 }
718
719 /**
720 * Enables concatenation of js and css files
721 *
722 * @return void
723 */
724 public function enableConcatenateFiles()
725 {
726 $this->concatenateFiles = true;
727 }
728
729 /**
730 * Disables concatenation of js and css files
731 *
732 * @return void
733 */
734 public function disableConcatenateFiles()
735 {
736 $this->concatenateFiles = false;
737 }
738
739 /**
740 * Enables concatenation of js files
741 *
742 * @return void
743 */
744 public function enableConcatenateJavascript()
745 {
746 $this->concatenateJavascript = true;
747 }
748
749 /**
750 * Disables concatenation of js files
751 *
752 * @return void
753 */
754 public function disableConcatenateJavascript()
755 {
756 $this->concatenateJavascript = false;
757 }
758
759 /**
760 * Enables concatenation of css files
761 *
762 * @return void
763 */
764 public function enableConcatenateCss()
765 {
766 $this->concatenateCss = true;
767 }
768
769 /**
770 * Disables concatenation of css files
771 *
772 * @return void
773 */
774 public function disableConcatenateCss()
775 {
776 $this->concatenateCss = false;
777 }
778
779 /**
780 * Sets removal of all line breaks in template
781 *
782 * @return void
783 */
784 public function enableRemoveLineBreaksFromTemplate()
785 {
786 $this->removeLineBreaksFromTemplate = true;
787 }
788
789 /**
790 * Unsets removal of all line breaks in template
791 *
792 * @return void
793 */
794 public function disableRemoveLineBreaksFromTemplate()
795 {
796 $this->removeLineBreaksFromTemplate = false;
797 }
798
799 /**
800 * Enables Debug Mode
801 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
802 *
803 * @return void
804 */
805 public function enableDebugMode()
806 {
807 $this->compressJavascript = false;
808 $this->compressCss = false;
809 $this->concatenateFiles = false;
810 $this->removeLineBreaksFromTemplate = false;
811 $this->enableExtJsDebug = true;
812 $this->enableJqueryDebug = true;
813 }
814
815 /*****************************************************/
816 /* */
817 /* Public Getters */
818 /* */
819 /* */
820 /*****************************************************/
821 /**
822 * Gets the title
823 *
824 * @return string $title Title of webpage
825 */
826 public function getTitle()
827 {
828 return $this->title;
829 }
830
831 /**
832 * Gets the charSet
833 *
834 * @return string $charSet
835 */
836 public function getCharSet()
837 {
838 return $this->charSet;
839 }
840
841 /**
842 * Gets the language
843 *
844 * @return string $lang
845 */
846 public function getLanguage()
847 {
848 return $this->lang;
849 }
850
851 /**
852 * Returns rendering mode XHTML or HTML
853 *
854 * @return bool TRUE if XHTML, FALSE if HTML
855 */
856 public function getRenderXhtml()
857 {
858 return $this->renderXhtml;
859 }
860
861 /**
862 * Gets html tag
863 *
864 * @return string $htmlTag Html tag
865 */
866 public function getHtmlTag()
867 {
868 return $this->htmlTag;
869 }
870
871 /**
872 * Get meta charset
873 *
874 * @return string
875 */
876 public function getMetaCharsetTag()
877 {
878 return $this->metaCharsetTag;
879 }
880
881 /**
882 * Gets head tag
883 *
884 * @return string $tag Head tag
885 */
886 public function getHeadTag()
887 {
888 return $this->headTag;
889 }
890
891 /**
892 * Gets favicon
893 *
894 * @return string $favIcon
895 */
896 public function getFavIcon()
897 {
898 return $this->favIcon;
899 }
900
901 /**
902 * Gets icon mime type
903 *
904 * @return string $iconMimeType
905 */
906 public function getIconMimeType()
907 {
908 return $this->iconMimeType;
909 }
910
911 /**
912 * Gets HTML base URL
913 *
914 * @return string $url
915 */
916 public function getBaseUrl()
917 {
918 return $this->baseUrl;
919 }
920
921 /**
922 * Gets template file
923 *
924 * @return string
925 */
926 public function getTemplateFile()
927 {
928 return $this->templateFile;
929 }
930
931 /**
932 * Gets MoveJsFromHeaderToFooter
933 *
934 * @return bool
935 */
936 public function getMoveJsFromHeaderToFooter()
937 {
938 return $this->moveJsFromHeaderToFooter;
939 }
940
941 /**
942 * Gets compress of javascript
943 *
944 * @return bool
945 */
946 public function getCompressJavascript()
947 {
948 return $this->compressJavascript;
949 }
950
951 /**
952 * Gets compress of css
953 *
954 * @return bool
955 */
956 public function getCompressCss()
957 {
958 return $this->compressCss;
959 }
960
961 /**
962 * Gets concatenate of js and css files
963 *
964 * @return bool
965 */
966 public function getConcatenateFiles()
967 {
968 return $this->concatenateFiles;
969 }
970
971 /**
972 * Gets concatenate of js files
973 *
974 * @return bool
975 */
976 public function getConcatenateJavascript()
977 {
978 return $this->concatenateJavascript;
979 }
980
981 /**
982 * Gets concatenate of css files
983 *
984 * @return bool
985 */
986 public function getConcatenateCss()
987 {
988 return $this->concatenateCss;
989 }
990
991 /**
992 * Gets remove of empty lines from template
993 *
994 * @return bool
995 */
996 public function getRemoveLineBreaksFromTemplate()
997 {
998 return $this->removeLineBreaksFromTemplate;
999 }
1000
1001 /**
1002 * Gets content for body
1003 *
1004 * @return string
1005 */
1006 public function getBodyContent()
1007 {
1008 return $this->bodyContent;
1009 }
1010
1011 /**
1012 * Gets Path for ExtJs library (relative to typo3 directory)
1013 *
1014 * @return string
1015 */
1016 public function getExtJsPath()
1017 {
1018 return $this->extJsPath;
1019 }
1020
1021 /**
1022 * Gets the inline language labels.
1023 *
1024 * @return array The inline language labels
1025 */
1026 public function getInlineLanguageLabels()
1027 {
1028 return $this->inlineLanguageLabels;
1029 }
1030
1031 /**
1032 * Gets the inline language files
1033 *
1034 * @return array
1035 */
1036 public function getInlineLanguageLabelFiles()
1037 {
1038 return $this->inlineLanguageLabelFiles;
1039 }
1040
1041 /*****************************************************/
1042 /* */
1043 /* Public Functions to add Data */
1044 /* */
1045 /* */
1046 /*****************************************************/
1047 /**
1048 * Adds meta data
1049 *
1050 * @param string $meta Meta data (complete metatag)
1051 * @return void
1052 */
1053 public function addMetaTag($meta)
1054 {
1055 if (!in_array($meta, $this->metaTags)) {
1056 $this->metaTags[] = $meta;
1057 }
1058 }
1059
1060 /**
1061 * Adds inline HTML comment
1062 *
1063 * @param string $comment
1064 * @return void
1065 */
1066 public function addInlineComment($comment)
1067 {
1068 if (!in_array($comment, $this->inlineComments)) {
1069 $this->inlineComments[] = $comment;
1070 }
1071 }
1072
1073 /**
1074 * Adds header data
1075 *
1076 * @param string $data Free header data for HTML header
1077 * @return void
1078 */
1079 public function addHeaderData($data)
1080 {
1081 if (!in_array($data, $this->headerData)) {
1082 $this->headerData[] = $data;
1083 }
1084 }
1085
1086 /**
1087 * Adds footer data
1088 *
1089 * @param string $data Free header data for HTML header
1090 * @return void
1091 */
1092 public function addFooterData($data)
1093 {
1094 if (!in_array($data, $this->footerData)) {
1095 $this->footerData[] = $data;
1096 }
1097 }
1098
1099 /**
1100 * Adds JS Library. JS Library block is rendered on top of the JS files.
1101 *
1102 * @param string $name Arbitrary identifier
1103 * @param string $file File name
1104 * @param string $type Content Type
1105 * @param bool $compress Flag if library should be compressed
1106 * @param bool $forceOnTop Flag if added library should be inserted at begin of this block
1107 * @param string $allWrap
1108 * @param bool $excludeFromConcatenation
1109 * @param string $splitChar The char used to split the allWrap value, default is "|"
1110 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1111 * @param string $integrity Subresource Integrity (SRI)
1112 * @return void
1113 */
1114 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = false, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '')
1115 {
1116 if (!$type) {
1117 $type = 'text/javascript';
1118 }
1119 if (!in_array(strtolower($name), $this->jsLibs)) {
1120 $this->jsLibs[strtolower($name)] = [
1121 'file' => $file,
1122 'type' => $type,
1123 'section' => self::PART_HEADER,
1124 'compress' => $compress,
1125 'forceOnTop' => $forceOnTop,
1126 'allWrap' => $allWrap,
1127 'excludeFromConcatenation' => $excludeFromConcatenation,
1128 'splitChar' => $splitChar,
1129 'async' => $async,
1130 'integrity' => $integrity,
1131 ];
1132 }
1133 }
1134
1135 /**
1136 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
1137 *
1138 * @param string $name Arbitrary identifier
1139 * @param string $file File name
1140 * @param string $type Content Type
1141 * @param bool $compress Flag if library should be compressed
1142 * @param bool $forceOnTop Flag if added library should be inserted at begin of this block
1143 * @param string $allWrap
1144 * @param bool $excludeFromConcatenation
1145 * @param string $splitChar The char used to split the allWrap value, default is "|"
1146 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1147 * @param string $integrity Subresource Integrity (SRI)
1148 * @return void
1149 */
1150 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = false, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '')
1151 {
1152 if (!$type) {
1153 $type = 'text/javascript';
1154 }
1155 if (!in_array(strtolower($name), $this->jsLibs)) {
1156 $this->jsLibs[strtolower($name)] = [
1157 'file' => $file,
1158 'type' => $type,
1159 'section' => self::PART_FOOTER,
1160 'compress' => $compress,
1161 'forceOnTop' => $forceOnTop,
1162 'allWrap' => $allWrap,
1163 'excludeFromConcatenation' => $excludeFromConcatenation,
1164 'splitChar' => $splitChar,
1165 'async' => $async,
1166 'integrity' => $integrity,
1167 ];
1168 }
1169 }
1170
1171 /**
1172 * Adds JS file
1173 *
1174 * @param string $file File name
1175 * @param string $type Content Type
1176 * @param bool $compress
1177 * @param bool $forceOnTop
1178 * @param string $allWrap
1179 * @param bool $excludeFromConcatenation
1180 * @param string $splitChar The char used to split the allWrap value, default is "|"
1181 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1182 * @param string $integrity Subresource Integrity (SRI)
1183 * @return void
1184 */
1185 public function addJsFile($file, $type = 'text/javascript', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '')
1186 {
1187 if (!$type) {
1188 $type = 'text/javascript';
1189 }
1190 if (!isset($this->jsFiles[$file])) {
1191 $this->jsFiles[$file] = [
1192 'file' => $file,
1193 'type' => $type,
1194 'section' => self::PART_HEADER,
1195 'compress' => $compress,
1196 'forceOnTop' => $forceOnTop,
1197 'allWrap' => $allWrap,
1198 'excludeFromConcatenation' => $excludeFromConcatenation,
1199 'splitChar' => $splitChar,
1200 'async' => $async,
1201 'integrity' => $integrity,
1202 ];
1203 }
1204 }
1205
1206 /**
1207 * Adds JS file to footer
1208 *
1209 * @param string $file File name
1210 * @param string $type Content Type
1211 * @param bool $compress
1212 * @param bool $forceOnTop
1213 * @param string $allWrap
1214 * @param bool $excludeFromConcatenation
1215 * @param string $splitChar The char used to split the allWrap value, default is "|"
1216 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1217 * @param string $integrity Subresource Integrity (SRI)
1218 * @return void
1219 */
1220 public function addJsFooterFile($file, $type = 'text/javascript', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '')
1221 {
1222 if (!$type) {
1223 $type = 'text/javascript';
1224 }
1225 if (!isset($this->jsFiles[$file])) {
1226 $this->jsFiles[$file] = [
1227 'file' => $file,
1228 'type' => $type,
1229 'section' => self::PART_FOOTER,
1230 'compress' => $compress,
1231 'forceOnTop' => $forceOnTop,
1232 'allWrap' => $allWrap,
1233 'excludeFromConcatenation' => $excludeFromConcatenation,
1234 'splitChar' => $splitChar,
1235 'async' => $async,
1236 'integrity' => $integrity,
1237 ];
1238 }
1239 }
1240
1241 /**
1242 * Adds JS inline code
1243 *
1244 * @param string $name
1245 * @param string $block
1246 * @param bool $compress
1247 * @param bool $forceOnTop
1248 * @return void
1249 */
1250 public function addJsInlineCode($name, $block, $compress = true, $forceOnTop = false)
1251 {
1252 if (!isset($this->jsInline[$name]) && !empty($block)) {
1253 $this->jsInline[$name] = [
1254 'code' => $block . LF,
1255 'section' => self::PART_HEADER,
1256 'compress' => $compress,
1257 'forceOnTop' => $forceOnTop
1258 ];
1259 }
1260 }
1261
1262 /**
1263 * Adds JS inline code to footer
1264 *
1265 * @param string $name
1266 * @param string $block
1267 * @param bool $compress
1268 * @param bool $forceOnTop
1269 * @return void
1270 */
1271 public function addJsFooterInlineCode($name, $block, $compress = true, $forceOnTop = false)
1272 {
1273 if (!isset($this->jsInline[$name]) && !empty($block)) {
1274 $this->jsInline[$name] = [
1275 'code' => $block . LF,
1276 'section' => self::PART_FOOTER,
1277 'compress' => $compress,
1278 'forceOnTop' => $forceOnTop
1279 ];
1280 }
1281 }
1282
1283 /**
1284 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
1285 *
1286 * @param string $block Javascript code
1287 * @param bool $forceOnTop Position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
1288 * @return void
1289 */
1290 public function addExtOnReadyCode($block, $forceOnTop = false)
1291 {
1292 if (!in_array($block, $this->extOnReadyCode)) {
1293 if ($forceOnTop) {
1294 array_unshift($this->extOnReadyCode, $block);
1295 } else {
1296 $this->extOnReadyCode[] = $block;
1297 }
1298 }
1299 }
1300
1301 /**
1302 * Adds the ExtDirect code
1303 *
1304 * @param array $filterNamespaces Limit the output to defined namespaces. If empty, all namespaces are generated
1305 * @return void
1306 */
1307 public function addExtDirectCode(array $filterNamespaces = [])
1308 {
1309 if ($this->extDirectCodeAdded) {
1310 return;
1311 }
1312 $this->extDirectCodeAdded = true;
1313 if (empty($filterNamespaces)) {
1314 $filterNamespaces = ['TYPO3'];
1315 }
1316 // @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1317 // add compatibility mapping for the old flashmessage API
1318 $this->addJsFile(GeneralUtility::resolveBackPath($this->backPath .
1319 ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/JavaScript/flashmessage_compatibility.js'));
1320
1321 // Add language labels for ExtDirect
1322 if (TYPO3_MODE === 'FE') {
1323 $this->addInlineLanguageLabelArray([
1324 'extDirect_timeoutHeader' => $this->getTypoScriptFrontendController()->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutHeader'),
1325 'extDirect_timeoutMessage' => $this->getTypoScriptFrontendController()->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutMessage')
1326 ]);
1327 } else {
1328 $this->addInlineLanguageLabelArray([
1329 'extDirect_timeoutHeader' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutHeader'),
1330 'extDirect_timeoutMessage' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutMessage')
1331 ]);
1332 }
1333
1334 $token = ($api = '');
1335 if (TYPO3_MODE === 'BE') {
1336 $formprotection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get();
1337 $token = $formprotection->generateToken('extDirect');
1338
1339 // Debugger Console strings
1340 $this->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/debugger.xlf');
1341 }
1342 /** @var $extDirect \TYPO3\CMS\Core\ExtDirect\ExtDirectApi */
1343 $extDirect = GeneralUtility::makeInstance(\TYPO3\CMS\Core\ExtDirect\ExtDirectApi::class);
1344 $api = $extDirect->getApiPhp($filterNamespaces);
1345 if ($api) {
1346 $this->addJsInlineCode('TYPO3ExtDirectAPI', $api, false);
1347 }
1348 // Note: we need to iterate thru the object, because the addProvider method
1349 // does this only with multiple arguments
1350 $this->addExtOnReadyCode('
1351 (function() {
1352 TYPO3.ExtDirectToken = "' . $token . '";
1353 for (var api in Ext.app.ExtDirectAPI) {
1354 var provider = Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
1355 provider.on("beforecall", function(provider, transaction, meta) {
1356 if (transaction.data) {
1357 transaction.data[transaction.data.length] = TYPO3.ExtDirectToken;
1358 } else {
1359 transaction.data = [TYPO3.ExtDirectToken];
1360 }
1361 });
1362
1363 provider.on("call", function(provider, transaction, meta) {
1364 if (transaction.isForm) {
1365 transaction.params.securityToken = TYPO3.ExtDirectToken;
1366 }
1367 });
1368 }
1369 })();
1370
1371 var extDirectDebug = function(message, header, group) {
1372 var DebugConsole = null;
1373
1374 if (top && top.TYPO3 && typeof top.TYPO3.DebugConsole === "object") {
1375 DebugConsole = top.TYPO3.DebugConsole;
1376 } else if (typeof TYPO3 === "object" && typeof TYPO3.DebugConsole === "object") {
1377 DebugConsole = TYPO3.DebugConsole;
1378 }
1379
1380 if (DebugConsole !== null) {
1381 DebugConsole.add(message, header, group);
1382 } else if (typeof console === "object") {
1383 console.log(message);
1384 } else {
1385 document.write(message);
1386 }
1387 };
1388
1389 Ext.Direct.on("exception", function(event) {
1390 if (event.code === Ext.Direct.exceptions.TRANSPORT && !event.where) {
1391 top.TYPO3.Notification.error(
1392 TYPO3.l10n.localize("extDirect_timeoutHeader"),
1393 TYPO3.l10n.localize("extDirect_timeoutMessage")
1394 );
1395 } else {
1396 var backtrace = "";
1397 if (event.code === "parse") {
1398 extDirectDebug(
1399 "<p>" + event.xhr.responseText + "<\\/p>",
1400 event.type,
1401 "ExtDirect - Exception"
1402 );
1403 } else if (event.code === "router") {
1404 top.TYPO3.Notification.error(
1405 event.code,
1406 event.message
1407 );
1408 } else if (event.where) {
1409 backtrace = "<p style=\\"margin-top: 20px;\\">" +
1410 "<strong>Backtrace:<\\/strong><br \\/>" +
1411 event.where.replace(/#/g, "<br \\/>#") +
1412 "<\\/p>";
1413 extDirectDebug(
1414 "<p>" + event.message + "<\\/p>" + backtrace,
1415 event.method,
1416 "ExtDirect - Exception"
1417 );
1418 }
1419
1420
1421 }
1422 });
1423
1424 Ext.Direct.on("event", function(event, provider) {
1425 if (typeof event.debug !== "undefined" && event.debug !== "") {
1426 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
1427 }
1428 });
1429 ', true);
1430 }
1431
1432 /**
1433 * Adds CSS file
1434 *
1435 * @param string $file
1436 * @param string $rel
1437 * @param string $media
1438 * @param string $title
1439 * @param bool $compress
1440 * @param bool $forceOnTop
1441 * @param string $allWrap
1442 * @param bool $excludeFromConcatenation
1443 * @param string $splitChar The char used to split the allWrap value, default is "|"
1444 * @return void
1445 */
1446 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|')
1447 {
1448 if (!isset($this->cssFiles[$file])) {
1449 $this->cssFiles[$file] = [
1450 'file' => $file,
1451 'rel' => $rel,
1452 'media' => $media,
1453 'title' => $title,
1454 'compress' => $compress,
1455 'forceOnTop' => $forceOnTop,
1456 'allWrap' => $allWrap,
1457 'excludeFromConcatenation' => $excludeFromConcatenation,
1458 'splitChar' => $splitChar
1459 ];
1460 }
1461 }
1462
1463 /**
1464 * Adds CSS file
1465 *
1466 * @param string $file
1467 * @param string $rel
1468 * @param string $media
1469 * @param string $title
1470 * @param bool $compress
1471 * @param bool $forceOnTop
1472 * @param string $allWrap
1473 * @param bool $excludeFromConcatenation
1474 * @param string $splitChar The char used to split the allWrap value, default is "|"
1475 * @return void
1476 */
1477 public function addCssLibrary($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|')
1478 {
1479 if (!isset($this->cssLibs[$file])) {
1480 $this->cssLibs[$file] = [
1481 'file' => $file,
1482 'rel' => $rel,
1483 'media' => $media,
1484 'title' => $title,
1485 'compress' => $compress,
1486 'forceOnTop' => $forceOnTop,
1487 'allWrap' => $allWrap,
1488 'excludeFromConcatenation' => $excludeFromConcatenation,
1489 'splitChar' => $splitChar
1490 ];
1491 }
1492 }
1493
1494 /**
1495 * Adds CSS inline code
1496 *
1497 * @param string $name
1498 * @param string $block
1499 * @param bool $compress
1500 * @param bool $forceOnTop
1501 * @return void
1502 */
1503 public function addCssInlineBlock($name, $block, $compress = false, $forceOnTop = false)
1504 {
1505 if (!isset($this->cssInline[$name]) && !empty($block)) {
1506 $this->cssInline[$name] = [
1507 'code' => $block,
1508 'compress' => $compress,
1509 'forceOnTop' => $forceOnTop
1510 ];
1511 }
1512 }
1513
1514 /**
1515 * Call this function if you need to include the jQuery library
1516 *
1517 * @param null|string $version The jQuery version that should be included, either "latest" or any available version
1518 * @param null|string $source The location of the jQuery source, can be "local", "google", "msn", "jquery" or just an URL to your jQuery lib
1519 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored.
1520 * @return void
1521 * @throws \UnexpectedValueException
1522 */
1523 public function loadJquery($version = null, $source = null, $namespace = self::JQUERY_NAMESPACE_DEFAULT)
1524 {
1525 // Set it to the version that is shipped with the TYPO3 core
1526 if ($version === null || $version === 'latest') {
1527 $version = self::JQUERY_VERSION_LATEST;
1528 }
1529 // Check if the source is set, otherwise set it to "default"
1530 if ($source === null) {
1531 $source = 'local';
1532 }
1533 if ($source === 'local' && !in_array($version, $this->availableLocalJqueryVersions)) {
1534 throw new \UnexpectedValueException('The requested jQuery version is not available in the local filesystem.', 1341505305);
1535 }
1536 if (!preg_match('/^[a-zA-Z0-9]+$/', $namespace)) {
1537 throw new \UnexpectedValueException('The requested namespace contains non alphanumeric characters.', 1341571604);
1538 }
1539 $this->jQueryVersions[$namespace] = [
1540 'version' => $version,
1541 'source' => $source
1542 ];
1543 }
1544
1545 /**
1546 * Call function if you need the requireJS library
1547 * this automatically adds the JavaScript path of all loaded extensions in the requireJS path option
1548 * so it resolves names like TYPO3/CMS/MyExtension/MyJsFile to EXT:MyExtension/Resources/Public/JavaScript/MyJsFile.js
1549 * when using requireJS
1550 *
1551 * @return void
1552 */
1553 public function loadRequireJs()
1554 {
1555
1556 // load all paths to map to package names / namespaces
1557 if (empty($this->requireJsConfig)) {
1558 // In order to avoid browser caching of JS files, adding a GET parameter to the files loaded via requireJS
1559 if (GeneralUtility::getApplicationContext()->isDevelopment()) {
1560 $this->requireJsConfig['urlArgs'] = 'bust=' . $GLOBALS['EXEC_TIME'];
1561 } else {
1562 $this->requireJsConfig['urlArgs'] = 'bust=' . GeneralUtility::hmac(TYPO3_version . PATH_site);
1563 }
1564 $coreRelPath = ExtensionManagementUtility::extRelPath('core');
1565 // first, load all paths for the namespaces, and configure contrib libs.
1566 $this->requireJsConfig['paths'] = [
1567 'jquery-ui' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/jquery-ui',
1568 'datatables' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/jquery.dataTables',
1569 'nprogress' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/nprogress',
1570 'moment' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/moment',
1571 'cropper' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/cropper.min',
1572 'imagesloaded' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/imagesloaded.pkgd.min',
1573 'bootstrap' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/bootstrap/bootstrap',
1574 'twbs/bootstrap-datetimepicker' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/bootstrap-datetimepicker',
1575 'autosize' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/autosize',
1576 'taboverride' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/taboverride.min',
1577 'twbs/bootstrap-slider' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/bootstrap-slider.min',
1578 'jquery/autocomplete' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/jquery.autocomplete',
1579 ];
1580 // get all extensions that are loaded
1581 $loadedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getLoadedExtensionListArray();
1582 foreach ($loadedExtensions as $packageName) {
1583 $fullJsPath = 'EXT:' . $packageName . '/Resources/Public/JavaScript/';
1584 $fullJsPath = GeneralUtility::getFileAbsFileName($fullJsPath);
1585 $fullJsPath = \TYPO3\CMS\Core\Utility\PathUtility::getRelativePath(PATH_typo3, $fullJsPath);
1586 $fullJsPath = rtrim($fullJsPath, '/');
1587 if ($fullJsPath) {
1588 $this->requireJsConfig['paths']['TYPO3/CMS/' . GeneralUtility::underscoredToUpperCamelCase($packageName)] = $this->backPath . $fullJsPath;
1589 }
1590 }
1591
1592 // check if additional AMD modules need to be loaded if a single AMD module is initialized
1593 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules'])) {
1594 $this->addInlineSettingArray('RequireJS.PostInitializationModules', $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules']);
1595 }
1596 }
1597
1598 $this->addRequireJs = true;
1599 }
1600
1601 /**
1602 * Add additional configuration to require js.
1603 *
1604 * Configuration will be merged recursive with overrule.
1605 *
1606 * To add another path mapping deliver the following configuration:
1607 * 'paths' => array(
1608 * 'EXTERN/mybootstrapjs' => 'sysext/.../twbs/bootstrap.min',
1609 * ),
1610 *
1611 * @param array $configuration The configuration that will be merged with existing one.
1612 * @return void
1613 */
1614 public function addRequireJsConfiguration(array $configuration)
1615 {
1616 if (TYPO3_MODE === 'BE') {
1617 // Load RequireJS in backend context at first. Doing this in FE could break the output
1618 $this->loadRequireJs();
1619 }
1620 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->requireJsConfig, $configuration);
1621 }
1622
1623 /**
1624 * includes an AMD-compatible JS file by resolving the ModuleName, and then requires the file via a requireJS request,
1625 * additionally allowing to execute JavaScript code afterwards
1626 *
1627 * this function only works for AMD-ready JS modules, used like "define('TYPO3/CMS/Backend/FormEngine..."
1628 * in the JS file
1629 *
1630 * TYPO3/CMS/Backend/FormEngine =>
1631 * "TYPO3": Vendor Name
1632 * "CMS": Product Name
1633 * "Backend": Extension Name
1634 * "FormEngine": FileName in the Resources/Public/JavaScript folder
1635 *
1636 * @param string $mainModuleName Must be in the form of "TYPO3/CMS/PackageName/ModuleName" e.g. "TYPO3/CMS/Backend/FormEngine"
1637 * @param string $callBackFunction loaded right after the requireJS loading, must be wrapped in function() {}
1638 * @return void
1639 */
1640 public function loadRequireJsModule($mainModuleName, $callBackFunction = null)
1641 {
1642 $inlineCodeKey = $mainModuleName;
1643 // make sure requireJS is initialized
1644 $this->loadRequireJs();
1645
1646 // execute the main module, and load a possible callback function
1647 $javaScriptCode = 'require(["' . $mainModuleName . '"]';
1648 if ($callBackFunction !== null) {
1649 $inlineCodeKey .= sha1($callBackFunction);
1650 $javaScriptCode .= ', ' . $callBackFunction;
1651 }
1652 $javaScriptCode .= ');';
1653 $this->addJsInlineCode('RequireJS-Module-' . $inlineCodeKey, $javaScriptCode);
1654 }
1655
1656 /**
1657 * call this function if you need the extJS library
1658 *
1659 * @param bool $css Flag, if set the ext-css will be loaded
1660 * @param bool $theme Flag, if set the ext-theme "grey" will be loaded
1661 * @return void
1662 */
1663 public function loadExtJS($css = true, $theme = true)
1664 {
1665 $this->addExtJS = true;
1666 $this->extJStheme = $theme;
1667 $this->extJScss = $css;
1668 }
1669
1670 /**
1671 * Call this function to load debug version of ExtJS. Use this for development only
1672 *
1673 * @return void
1674 */
1675 public function enableExtJsDebug()
1676 {
1677 $this->enableExtJsDebug = true;
1678 }
1679
1680 /**
1681 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1682 * The label can be used in scripts with TYPO3.lang.<key>
1683 * Need extJs loaded
1684 *
1685 * @param string $key
1686 * @param string $value
1687 * @return void
1688 */
1689 public function addInlineLanguageLabel($key, $value)
1690 {
1691 $this->inlineLanguageLabels[$key] = $value;
1692 }
1693
1694 /**
1695 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1696 * The label can be used in scripts with TYPO3.lang.<key>
1697 * Array will be merged with existing array.
1698 * Need extJs loaded
1699 *
1700 * @param array $array
1701 * @param bool $parseWithLanguageService
1702 * @return void
1703 */
1704 public function addInlineLanguageLabelArray(array $array, $parseWithLanguageService = false)
1705 {
1706 if ($parseWithLanguageService === true) {
1707 foreach ($array as $key => $value) {
1708 if (TYPO3_MODE === 'FE') {
1709 $array[$key] = $this->getTypoScriptFrontendController()->sL($value);
1710 } else {
1711 $array[$key] = $this->getLanguageService()->sL($value);
1712 }
1713 }
1714 }
1715
1716 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
1717 }
1718
1719 /**
1720 * Gets labels to be used in JavaScript fetched from a locallang file.
1721 *
1722 * @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.
1723 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1724 * @param string $stripFromSelectionName String to be removed from the label names in the output. (default: '')
1725 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1726 * @return void
1727 */
1728 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0)
1729 {
1730 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1731 if ($fileRef && !isset($this->inlineLanguageLabelFiles[$index])) {
1732 $this->inlineLanguageLabelFiles[$index] = [
1733 'fileRef' => $fileRef,
1734 'selectionPrefix' => $selectionPrefix,
1735 'stripFromSelectionName' => $stripFromSelectionName,
1736 'errorMode' => $errorMode
1737 ];
1738 }
1739 }
1740
1741 /**
1742 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1743 * The label can be used in scripts with TYPO3.setting.<key>
1744 * Need extJs loaded
1745 *
1746 * @param string $namespace
1747 * @param string $key
1748 * @param string $value
1749 * @return void
1750 */
1751 public function addInlineSetting($namespace, $key, $value)
1752 {
1753 if ($namespace) {
1754 if (strpos($namespace, '.')) {
1755 $parts = explode('.', $namespace);
1756 $a = &$this->inlineSettings;
1757 foreach ($parts as $part) {
1758 $a = &$a[$part];
1759 }
1760 $a[$key] = $value;
1761 } else {
1762 $this->inlineSettings[$namespace][$key] = $value;
1763 }
1764 } else {
1765 $this->inlineSettings[$key] = $value;
1766 }
1767 }
1768
1769 /**
1770 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1771 * The label can be used in scripts with TYPO3.setting.<key>
1772 * Array will be merged with existing array.
1773 * Need extJs loaded
1774 *
1775 * @param string $namespace
1776 * @param array $array
1777 * @return void
1778 */
1779 public function addInlineSettingArray($namespace, array $array)
1780 {
1781 if ($namespace) {
1782 if (strpos($namespace, '.')) {
1783 $parts = explode('.', $namespace);
1784 $a = &$this->inlineSettings;
1785 foreach ($parts as $part) {
1786 $a = &$a[$part];
1787 }
1788 $a = array_merge((array)$a, $array);
1789 } else {
1790 $this->inlineSettings[$namespace] = array_merge((array)$this->inlineSettings[$namespace], $array);
1791 }
1792 } else {
1793 $this->inlineSettings = array_merge($this->inlineSettings, $array);
1794 }
1795 }
1796
1797 /**
1798 * Adds content to body content
1799 *
1800 * @param string $content
1801 * @return void
1802 */
1803 public function addBodyContent($content)
1804 {
1805 $this->bodyContent .= $content;
1806 }
1807
1808 /*****************************************************/
1809 /* */
1810 /* Render Functions */
1811 /* */
1812 /*****************************************************/
1813 /**
1814 * Render the section (Header or Footer)
1815 *
1816 * @param int $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1817 * @return string Content of rendered section
1818 */
1819 public function render($part = self::PART_COMPLETE)
1820 {
1821 $this->prepareRendering();
1822 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1823 $metaTags = implode(LF, $this->metaTags);
1824 $markerArray = $this->getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags);
1825 $template = $this->getTemplateForPart($part);
1826
1827 // The page renderer needs a full reset, even when only rendering one part of the page
1828 // This means that you can only register footer files *after* the header has been already rendered.
1829 // In case you render the footer part first, header files can only be added *after* the footer has been rendered
1830 $this->reset();
1831 $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
1832 return trim($templateService->substituteMarkerArray($template, $markerArray, '###|###'));
1833 }
1834
1835 /**
1836 * Render the page but not the JavaScript and CSS Files
1837 *
1838 * @param string $substituteHash The hash that is used for the placehoder markers
1839 * @access private
1840 * @return string Content of rendered section
1841 */
1842 public function renderPageWithUncachedObjects($substituteHash)
1843 {
1844 $this->prepareRendering();
1845 $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
1846 $template = $this->getTemplateForPart(self::PART_COMPLETE);
1847 $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
1848 return trim($templateService->substituteMarkerArray($template, $markerArray, '###|###'));
1849 }
1850
1851 /**
1852 * Renders the JavaScript and CSS files that have been added during processing
1853 * of uncached content objects (USER_INT, COA_INT)
1854 *
1855 * @param string $cachedPageContent
1856 * @param string $substituteHash The hash that is used for the placehoder markers
1857 * @access private
1858 * @return string
1859 */
1860 public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash)
1861 {
1862 $this->prepareRendering();
1863 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1864 $title = $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '';
1865 $markerArray = [
1866 '<!-- ###TITLE' . $substituteHash . '### -->' => $title,
1867 '<!-- ###CSS_LIBS' . $substituteHash . '### -->' => $cssLibs,
1868 '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
1869 '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
1870 '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
1871 '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
1872 '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
1873 '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF, $this->headerData),
1874 '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF, $this->footerData),
1875 '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
1876 '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
1877 '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline
1878 ];
1879 foreach ($markerArray as $placeHolder => $content) {
1880 $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
1881 }
1882 $this->reset();
1883 return $cachedPageContent;
1884 }
1885
1886 /**
1887 * Remove ending slashes from static header block
1888 * if the page is beeing rendered as html (not xhtml)
1889 * and define property $this->endingSlash for further use
1890 *
1891 * @return void
1892 */
1893 protected function prepareRendering()
1894 {
1895 if ($this->getRenderXhtml()) {
1896 $this->endingSlash = ' /';
1897 } else {
1898 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
1899 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
1900 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
1901 $this->endingSlash = '';
1902 }
1903 }
1904
1905 /**
1906 * Renders all JavaScript and CSS
1907 *
1908 * @return array<string>
1909 */
1910 protected function renderJavaScriptAndCss()
1911 {
1912 $this->executePreRenderHook();
1913 $mainJsLibs = $this->renderMainJavaScriptLibraries();
1914 if ($this->concatenateFiles || $this->concatenateJavascript || $this->concatenateCss) {
1915 // Do the file concatenation
1916 $this->doConcatenate();
1917 }
1918 if ($this->compressCss || $this->compressJavascript) {
1919 // Do the file compression
1920 $this->doCompress();
1921 }
1922 $this->executeRenderPostTransformHook();
1923 $cssLibs = $this->renderCssLibraries();
1924 $cssFiles = $this->renderCssFiles();
1925 $cssInline = $this->renderCssInline();
1926 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
1927 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
1928 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
1929 $jsLibs = $mainJsLibs . $jsLibs;
1930 if ($this->moveJsFromHeaderToFooter) {
1931 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
1932 $jsLibs = '';
1933 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
1934 $jsFiles = '';
1935 $jsFooterInline = $jsInline . LF . $jsFooterInline;
1936 $jsInline = '';
1937 }
1938 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1939 return [$jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs];
1940 }
1941
1942 /**
1943 * Fills the marker array with the given strings and trims each value
1944 *
1945 * @param $jsLibs string
1946 * @param $jsFiles string
1947 * @param $jsFooterFiles string
1948 * @param $cssLibs string
1949 * @param $cssFiles string
1950 * @param $jsInline string
1951 * @param $cssInline string
1952 * @param $jsFooterInline string
1953 * @param $jsFooterLibs string
1954 * @param $metaTags string
1955 * @return array Marker array
1956 */
1957 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags)
1958 {
1959 $markerArray = [
1960 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1961 'HTMLTAG' => $this->htmlTag,
1962 'HEADTAG' => $this->headTag,
1963 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1964 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1965 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1966 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1967 'CSS_LIBS' => $cssLibs,
1968 'CSS_INCLUDE' => $cssFiles,
1969 'CSS_INLINE' => $cssInline,
1970 'JS_INLINE' => $jsInline,
1971 'JS_INCLUDE' => $jsFiles,
1972 'JS_LIBS' => $jsLibs,
1973 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1974 'META' => $metaTags,
1975 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
1976 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
1977 'JS_LIBS_FOOTER' => $jsFooterLibs,
1978 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1979 'JS_INLINE_FOOTER' => $jsFooterInline,
1980 'BODY' => $this->bodyContent
1981 ];
1982 $markerArray = array_map('trim', $markerArray);
1983 return $markerArray;
1984 }
1985
1986 /**
1987 * Fills the marker array with the given strings and trims each value
1988 *
1989 * @param string $substituteHash The hash that is used for the placehoder markers
1990 * @return array Marker array
1991 */
1992 protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash)
1993 {
1994 $markerArray = [
1995 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1996 'HTMLTAG' => $this->htmlTag,
1997 'HEADTAG' => $this->headTag,
1998 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1999 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
2000 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
2001 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
2002 'META' => implode(LF, $this->metaTags),
2003 'BODY' => $this->bodyContent,
2004 'TITLE' => '<!-- ###TITLE' . $substituteHash . '### -->',
2005 'CSS_LIBS' => '<!-- ###CSS_LIBS' . $substituteHash . '### -->',
2006 'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
2007 'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
2008 'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
2009 'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
2010 'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
2011 'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
2012 'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
2013 'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
2014 'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
2015 'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->'
2016 ];
2017 $markerArray = array_map('trim', $markerArray);
2018 return $markerArray;
2019 }
2020
2021 /**
2022 * Reads the template file and returns the requested part as string
2023 *
2024 * @param int $part
2025 * @return string
2026 */
2027 protected function getTemplateForPart($part)
2028 {
2029 $templateFile = GeneralUtility::getFileAbsFileName($this->templateFile, true);
2030 $template = GeneralUtility::getUrl($templateFile);
2031 if ($this->removeLineBreaksFromTemplate) {
2032 $template = strtr($template, [LF => '', CR => '']);
2033 }
2034 if ($part !== self::PART_COMPLETE) {
2035 $templatePart = explode('###BODY###', $template);
2036 $template = $templatePart[$part - 1];
2037 }
2038 return $template;
2039 }
2040
2041 /**
2042 * Helper function for render the main JavaScript libraries,
2043 * currently: RequireJS, jQuery, ExtJS
2044 *
2045 * @return string Content with JavaScript libraries
2046 */
2047 protected function renderMainJavaScriptLibraries()
2048 {
2049 $out = '';
2050
2051 // Include RequireJS
2052 if ($this->addRequireJs) {
2053 // load the paths of the requireJS configuration
2054 $out .= GeneralUtility::wrapJS('var require = ' . json_encode($this->requireJsConfig)) . LF;
2055 // directly after that, include the require.js file
2056 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->requireJsPath . 'require.js')) . '" type="text/javascript"></script>' . LF;
2057 }
2058
2059 // Include jQuery Core for each namespace, depending on the version and source
2060 if (!empty($this->jQueryVersions)) {
2061 foreach ($this->jQueryVersions as $namespace => $jQueryVersion) {
2062 $out .= $this->renderJqueryScriptTag($jQueryVersion['version'], $jQueryVersion['source'], $namespace);
2063 }
2064 }
2065 // Include extJS
2066 if ($this->addExtJS) {
2067 // Use the base adapter all the time
2068 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->extJsPath . 'adapter/ext-base' . ($this->enableExtJsDebug ? '-debug' : '') . '.js')) . '" type="text/javascript"></script>' . LF;
2069 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->extJsPath . 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js')) . '" type="text/javascript"></script>' . LF;
2070 // Add extJS localization
2071 // Load standard ISO mapping and modify for use with ExtJS
2072 $localeMap = $this->locales->getIsoMapping();
2073 $localeMap[''] = 'en';
2074 $localeMap['default'] = 'en';
2075 // Greek
2076 $localeMap['gr'] = 'el_GR';
2077 // Norwegian Bokmaal
2078 $localeMap['no'] = 'no_BO';
2079 // Swedish
2080 $localeMap['se'] = 'se_SV';
2081 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
2082 // @todo autoconvert file from UTF8 to current BE charset if necessary!!!!
2083 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
2084 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
2085 $out .= '<script src="' . $this->processJsFile(($this->backPath . $extJsLocaleFile)) . '" type="text/javascript" charset="utf-8"></script>' . LF;
2086 }
2087 // Remove extjs from JScodeLibArray
2088 unset($this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'], $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']);
2089 }
2090 $this->loadJavaScriptLanguageStrings();
2091 if (TYPO3_MODE === 'BE') {
2092 $this->addAjaxUrlsToInlineSettings();
2093 }
2094 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
2095 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
2096 if ($this->addExtJS) {
2097 // Set clear.gif, move it on top, add handler code
2098 $code = '';
2099 if (!empty($this->extOnReadyCode)) {
2100 foreach ($this->extOnReadyCode as $block) {
2101 $code .= $block;
2102 }
2103 }
2104 $clearGifPath = htmlspecialchars(GeneralUtility::locationHeaderUrl($this->backPath . ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/Images/clear.gif'));
2105 $out .= $this->inlineJavascriptWrap[0] . '
2106 Ext.ns("TYPO3");
2107 Ext.BLANK_IMAGE_URL = "' . $clearGifPath . '";
2108 Ext.SSL_SECURE_URL = "' . $clearGifPath . '";' . LF
2109 . $inlineSettings
2110 . 'Ext.onReady(function() {'
2111 . $code
2112 . ' });'
2113 . $this->inlineJavascriptWrap[1];
2114 $this->extOnReadyCode = [];
2115 // Include TYPO3.l10n object
2116 if (TYPO3_MODE === 'BE') {
2117 $out .= '<script src="' . $this->processJsFile(($this->backPath . ExtensionManagementUtility::extRelPath('lang') . 'Resources/Public/JavaScript/Typo3Lang.js')) . '" type="text/javascript" charset="utf-8"></script>' . LF;
2118 }
2119 if ($this->extJScss) {
2120 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
2121 $this->addCssLibrary($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', true);
2122 } else {
2123 $this->addCssLibrary($this->backPath . $this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', true);
2124 }
2125 }
2126 if ($this->extJStheme) {
2127 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
2128 $this->addCssLibrary($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', true);
2129 } else {
2130 $this->addCssLibrary($this->backPath . $this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', true);
2131 }
2132 }
2133 } else {
2134 // no extJS loaded, but still inline settings
2135 if ($inlineSettings !== '') {
2136 // make sure the global TYPO3 is available
2137 $inlineSettings = 'var TYPO3 = TYPO3 || {};' . CRLF . $inlineSettings;
2138 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
2139 // Add language module only if also jquery is guaranteed to be there
2140 if (TYPO3_MODE === 'BE' && !empty($this->jQueryVersions)) {
2141 $this->loadRequireJsModule('TYPO3/CMS/Lang/Lang');
2142 }
2143 }
2144 }
2145 return $out;
2146 }
2147
2148 /**
2149 * Load the language strings into JavaScript
2150 */
2151 protected function loadJavaScriptLanguageStrings()
2152 {
2153 if (!empty($this->inlineLanguageLabelFiles)) {
2154 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
2155 $this->includeLanguageFileForInline($languageLabelFile['fileRef'], $languageLabelFile['selectionPrefix'], $languageLabelFile['stripFromSelectionName'], $languageLabelFile['errorMode']);
2156 }
2157 }
2158 $this->inlineLanguageLabelFiles = [];
2159 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
2160 if (TYPO3_MODE === 'FE' && $this->getCharSet() !== 'utf-8') {
2161 if ($this->inlineLanguageLabels) {
2162 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
2163 }
2164 if ($this->inlineSettings) {
2165 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
2166 }
2167 }
2168 }
2169
2170 /**
2171 * Make URLs to all backend ajax handlers available as inline setting.
2172 */
2173 protected function addAjaxUrlsToInlineSettings()
2174 {
2175 $ajaxUrls = [];
2176 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'] as $ajaxHandler => $_) {
2177 $ajaxUrls[$ajaxHandler] = BackendUtility::getAjaxUrl($ajaxHandler);
2178 }
2179
2180 // also add the ajax-based routes
2181 /** @var UriBuilder $uriBuilder */
2182 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
2183 /** @var Router $router */
2184 $router = GeneralUtility::makeInstance(Router::class);
2185 $routes = $router->getRoutes();
2186 foreach ($routes as $routeIdentifier => $route) {
2187 if ($route->getOption('ajax')) {
2188 $uri = (string)$uriBuilder->buildUriFromRoute($routeIdentifier);
2189 // use the shortened value in order to use this in JavaScript
2190 $routeIdentifier = str_replace('ajax_', '', $routeIdentifier);
2191 $ajaxUrls[$routeIdentifier] = $uri;
2192 }
2193 }
2194
2195 $this->inlineSettings['ajaxUrls'] = $ajaxUrls;
2196 }
2197
2198 /**
2199 * Renders the HTML script tag for the given jQuery version.
2200 *
2201 * @param string $version The jQuery version that should be included, either "latest" or any available version
2202 * @param string $source The location of the jQuery source, can be "local", "google", "msn" or "jquery
2203 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored
2204 * @return string
2205 */
2206 protected function renderJqueryScriptTag($version, $source, $namespace)
2207 {
2208 switch (true) {
2209 case isset($this->jQueryCdnUrls[$source]):
2210 if ($this->enableJqueryDebug) {
2211 $minifyPart = '';
2212 } else {
2213 $minifyPart = '.min';
2214 }
2215 $jQueryFileName = sprintf($this->jQueryCdnUrls[$source], $version, $minifyPart);
2216 break;
2217 case $source === 'local':
2218 $jQueryFileName = $this->backPath . $this->jQueryPath . 'jquery-' . rawurlencode($version);
2219 if ($this->enableJqueryDebug) {
2220 $jQueryFileName .= '.js';
2221 } else {
2222 $jQueryFileName .= '.min.js';
2223 }
2224 break;
2225 default:
2226 $jQueryFileName = $source;
2227 }
2228 // Include the jQuery Core
2229 $scriptTag = '<script src="' . htmlspecialchars($jQueryFileName) . '" type="text/javascript"></script>' . LF;
2230 // Set the noConflict mode to be available via "TYPO3.jQuery" in all installations
2231 switch ($namespace) {
2232 case self::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT:
2233 $scriptTag .= GeneralUtility::wrapJS('jQuery.noConflict();') . LF;
2234 break;
2235 case self::JQUERY_NAMESPACE_NONE:
2236 break;
2237 case self::JQUERY_NAMESPACE_DEFAULT:
2238
2239 default:
2240 $scriptTag .= GeneralUtility::wrapJS('var TYPO3 = TYPO3 || {}; TYPO3.' . $namespace . ' = jQuery.noConflict(true);') . LF;
2241 }
2242 return $scriptTag;
2243 }
2244
2245 /**
2246 * Render CSS library files
2247 *
2248 * @return string
2249 */
2250 protected function renderCssLibraries()
2251 {
2252 $cssFiles = '';
2253 if (!empty($this->cssLibs)) {
2254 foreach ($this->cssLibs as $file => $properties) {
2255 $file = GeneralUtility::resolveBackPath($file);
2256 $file = GeneralUtility::createVersionNumberedFilename($file);
2257 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2258 . '" type="text/css" href="' . htmlspecialchars($file)
2259 . '" media="' . htmlspecialchars($properties['media']) . '"'
2260 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2261 . $this->endingSlash . '>';
2262 if ($properties['allWrap']) {
2263 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2264 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2265 }
2266 $tag .= LF;
2267 if ($properties['forceOnTop']) {
2268 $cssFiles = $tag . $cssFiles;
2269 } else {
2270 $cssFiles .= $tag;
2271 }
2272 }
2273 }
2274 return $cssFiles;
2275 }
2276
2277 /**
2278 * Render CSS files
2279 *
2280 * @return string
2281 */
2282 protected function renderCssFiles()
2283 {
2284 $cssFiles = '';
2285 if (!empty($this->cssFiles)) {
2286 foreach ($this->cssFiles as $file => $properties) {
2287 $file = GeneralUtility::resolveBackPath($file);
2288 $file = GeneralUtility::createVersionNumberedFilename($file);
2289 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2290 . '" type="text/css" href="' . htmlspecialchars($file)
2291 . '" media="' . htmlspecialchars($properties['media']) . '"'
2292 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2293 . $this->endingSlash . '>';
2294 if ($properties['allWrap']) {
2295 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2296 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2297 }
2298 $tag .= LF;
2299 if ($properties['forceOnTop']) {
2300 $cssFiles = $tag . $cssFiles;
2301 } else {
2302 $cssFiles .= $tag;
2303 }
2304 }
2305 }
2306 return $cssFiles;
2307 }
2308
2309 /**
2310 * Render inline CSS
2311 *
2312 * @return string
2313 */
2314 protected function renderCssInline()
2315 {
2316 $cssInline = '';
2317 if (!empty($this->cssInline)) {
2318 foreach ($this->cssInline as $name => $properties) {
2319 $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2320 if ($properties['forceOnTop']) {
2321 $cssInline = $cssCode . $cssInline;
2322 } else {
2323 $cssInline .= $cssCode;
2324 }
2325 }
2326 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
2327 }
2328 return $cssInline;
2329 }
2330
2331 /**
2332 * Render JavaScipt libraries
2333 *
2334 * @return array<string> jsLibs and jsFooterLibs strings
2335 */
2336 protected function renderAdditionalJavaScriptLibraries()
2337 {
2338 $jsLibs = '';
2339 $jsFooterLibs = '';
2340 if (!empty($this->jsLibs)) {
2341 foreach ($this->jsLibs as $properties) {
2342 $properties['file'] = GeneralUtility::resolveBackPath($properties['file']);
2343 $properties['file'] = GeneralUtility::createVersionNumberedFilename($properties['file']);
2344 $async = ($properties['async']) ? ' async="async"' : '';
2345 $integrity = ($properties['integrity']) ? ' integrity="' . htmlspecialchars($properties['integrity']) . '" crossorigin="anonymous"' : '';
2346 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $integrity . '></script>';
2347 if ($properties['allWrap']) {
2348 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2349 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2350 }
2351 $tag .= LF;
2352 if ($properties['forceOnTop']) {
2353 if ($properties['section'] === self::PART_HEADER) {
2354 $jsLibs = $tag . $jsLibs;
2355 } else {
2356 $jsFooterLibs = $tag . $jsFooterLibs;
2357 }
2358 } else {
2359 if ($properties['section'] === self::PART_HEADER) {
2360 $jsLibs .= $tag;
2361 } else {
2362 $jsFooterLibs .= $tag;
2363 }
2364 }
2365 }
2366 }
2367 if ($this->moveJsFromHeaderToFooter) {
2368 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
2369 $jsLibs = '';
2370 }
2371 return [$jsLibs, $jsFooterLibs];
2372 }
2373
2374 /**
2375 * Render JavaScript files
2376 *
2377 * @return array<string> jsFiles and jsFooterFiles strings
2378 */
2379 protected function renderJavaScriptFiles()
2380 {
2381 $jsFiles = '';
2382 $jsFooterFiles = '';
2383 if (!empty($this->jsFiles)) {
2384 foreach ($this->jsFiles as $file => $properties) {
2385 $file = GeneralUtility::resolveBackPath($file);
2386 $file = GeneralUtility::createVersionNumberedFilename($file);
2387 $async = ($properties['async']) ? ' async="async"' : '';
2388 $integrity = ($properties['integrity']) ? ' integrity="' . htmlspecialchars($properties['integrity']) . '" crossorigin="anonymous"' : '';
2389 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $integrity . '></script>';
2390 if ($properties['allWrap']) {
2391 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2392 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2393 }
2394 $tag .= LF;
2395 if ($properties['forceOnTop']) {
2396 if ($properties['section'] === self::PART_HEADER) {
2397 $jsFiles = $tag . $jsFiles;
2398 } else {
2399 $jsFooterFiles = $tag . $jsFooterFiles;
2400 }
2401 } else {
2402 if ($properties['section'] === self::PART_HEADER) {
2403 $jsFiles .= $tag;
2404 } else {
2405 $jsFooterFiles .= $tag;
2406 }
2407 }
2408 }
2409 }
2410 if ($this->moveJsFromHeaderToFooter) {
2411 $jsFooterFiles = $jsFiles . $jsFooterFiles;
2412 $jsFiles = '';
2413 }
2414 return [$jsFiles, $jsFooterFiles];
2415 }
2416
2417 /**
2418 * Render inline JavaScript
2419 *
2420 * @return array<string> jsInline and jsFooterInline string
2421 */
2422 protected function renderInlineJavaScript()
2423 {
2424 $jsInline = '';
2425 $jsFooterInline = '';
2426 if (!empty($this->jsInline)) {
2427 foreach ($this->jsInline as $name => $properties) {
2428 $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2429 if ($properties['forceOnTop']) {
2430 if ($properties['section'] === self::PART_HEADER) {
2431 $jsInline = $jsCode . $jsInline;
2432 } else {
2433 $jsFooterInline = $jsCode . $jsFooterInline;
2434 }
2435 } else {
2436 if ($properties['section'] === self::PART_HEADER) {
2437 $jsInline .= $jsCode;
2438 } else {
2439 $jsFooterInline .= $jsCode;
2440 }
2441 }
2442 }
2443 }
2444 if ($jsInline) {
2445 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
2446 }
2447 if ($jsFooterInline) {
2448 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
2449 }
2450 if ($this->moveJsFromHeaderToFooter) {
2451 $jsFooterInline = $jsInline . $jsFooterInline;
2452 $jsInline = '';
2453 }
2454 return [$jsInline, $jsFooterInline];
2455 }
2456
2457 /**
2458 * Include language file for inline usage
2459 *
2460 * @param string $fileRef
2461 * @param string $selectionPrefix
2462 * @param string $stripFromSelectionName
2463 * @param int $errorMode
2464 * @return void
2465 * @throws \RuntimeException
2466 */
2467 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0)
2468 {
2469 if (!isset($this->lang) || !isset($this->charSet)) {
2470 throw new \RuntimeException('Language and character encoding are not set.', 1284906026);
2471 }
2472 $labelsFromFile = [];
2473 $allLabels = $this->readLLfile($fileRef, $errorMode);
2474 if ($allLabels !== false) {
2475 // Merge language specific translations:
2476 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
2477 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
2478 } else {
2479 $labels = $allLabels['default'];
2480 }
2481 // Iterate through all locallang labels:
2482 foreach ($labels as $label => $value) {
2483 // If $selectionPrefix is set, only respect labels that start with $selectionPrefix
2484 if ($selectionPrefix === '' || strpos($label, $selectionPrefix) === 0) {
2485 // Remove substring $stripFromSelectionName from label
2486 $label = str_replace($stripFromSelectionName, '', $label);
2487 $labelsFromFile[$label] = $value;
2488 }
2489 }
2490 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
2491 }
2492 }
2493
2494 /**
2495 * Reads a locallang file.
2496 *
2497 * @param string $fileRef Reference to a relative filename to include.
2498 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
2499 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2500 */
2501 protected function readLLfile($fileRef, $errorMode = 0)
2502 {
2503 /** @var $languageFactory LocalizationFactory */
2504 $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
2505
2506 if ($this->lang !== 'default') {
2507 $languages = array_reverse($this->languageDependencies);
2508 // At least we need to have English
2509 if (empty($languages)) {
2510 $languages[] = 'default';
2511 }
2512 } else {
2513 $languages = ['default'];
2514 }
2515
2516 $localLanguage = [];
2517 foreach ($languages as $language) {
2518 $tempLL = $languageFactory->getParsedData($fileRef, $language, $this->charSet, $errorMode);
2519
2520 $localLanguage['default'] = $tempLL['default'];
2521 if (!isset($localLanguage[$this->lang])) {
2522 $localLanguage[$this->lang] = $localLanguage['default'];
2523 }
2524 if ($this->lang !== 'default' && isset($tempLL[$language])) {
2525 // Merge current language labels onto labels from previous language
2526 // This way we have a labels with fall back applied
2527 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($localLanguage[$this->lang], $tempLL[$language], true, false);
2528 }
2529 }
2530
2531 return $localLanguage;
2532 }
2533
2534 /*****************************************************/
2535 /* */
2536 /* Tools */
2537 /* */
2538 /*****************************************************/
2539 /**
2540 * Concatenate files into one file
2541 * registered handler
2542 *
2543 * @return void
2544 */
2545 protected function doConcatenate()
2546 {
2547 $this->doConcatenateCss();
2548 $this->doConcatenateJavaScript();
2549 }
2550
2551 /**
2552 * Concatenate JavaScript files according to the configuration.
2553 *
2554 * @return void
2555 */
2556 protected function doConcatenateJavaScript()
2557 {
2558 if ($this->concatenateFiles || $this->concatenateJavascript) {
2559 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'])) {
2560 // use external concatenation routine
2561 $params = [
2562 'jsLibs' => &$this->jsLibs,
2563 'jsFiles' => &$this->jsFiles,
2564 'jsFooterFiles' => &$this->jsFooterFiles,
2565 'headerData' => &$this->headerData,
2566 'footerData' => &$this->footerData
2567 ];
2568 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'], $params, $this);
2569 } else {
2570 $this->jsLibs = $this->getCompressor()->concatenateJsFiles($this->jsLibs);
2571 $this->jsFiles = $this->getCompressor()->concatenateJsFiles($this->jsFiles);
2572 $this->jsFooterFiles = $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles);
2573 }
2574 }
2575 }
2576
2577 /**
2578 * Concatenate CSS files according to configuration.
2579 *
2580 * @return void
2581 */
2582 protected function doConcatenateCss()
2583 {
2584 if ($this->concatenateFiles || $this->concatenateCss) {
2585 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'])) {
2586 // use external concatenation routine
2587 $params = [
2588 'cssFiles' => &$this->cssFiles,
2589 'cssLibs' => &$this->cssLibs,
2590 'headerData' => &$this->headerData,
2591 'footerData' => &$this->footerData
2592 ];
2593 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this);
2594 } else {
2595 $cssOptions = [];
2596 if (TYPO3_MODE === 'BE') {
2597 $cssOptions = ['baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories()];
2598 }
2599 $this->cssLibs = $this->getCompressor()->concatenateCssFiles($this->cssLibs, $cssOptions);
2600 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
2601 }
2602 }
2603 }
2604
2605 /**
2606 * Compresses inline code
2607 *
2608 * @return void
2609 */
2610 protected function doCompress()
2611 {
2612 $this->doCompressJavaScript();
2613 $this->doCompressCss();
2614 }
2615
2616 /**
2617 * Compresses CSS according to configuration.
2618 *
2619 * @return void
2620 */
2621 protected function doCompressCss()
2622 {
2623 if ($this->compressCss) {
2624 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'])) {
2625 // Use external compression routine
2626 $params = [
2627 'cssInline' => &$this->cssInline,
2628 'cssFiles' => &$this->cssFiles,
2629 'cssLibs' => &$this->cssLibs,
2630 'headerData' => &$this->headerData,
2631 'footerData' => &$this->footerData
2632 ];
2633 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
2634 } else {
2635 $this->cssLibs = $this->getCompressor()->compressCssFiles($this->cssLibs);
2636 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
2637 }
2638 }
2639 }
2640
2641 /**
2642 * Compresses JavaScript according to configuration.
2643 *
2644 * @return void
2645 */
2646 protected function doCompressJavaScript()
2647 {
2648 if ($this->compressJavascript) {
2649 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'])) {
2650 // Use external compression routine
2651 $params = [
2652 'jsInline' => &$this->jsInline,
2653 'jsFooterInline' => &$this->jsFooterInline,
2654 'jsLibs' => &$this->jsLibs,
2655 'jsFiles' => &$this->jsFiles,
2656 'jsFooterFiles' => &$this->jsFooterFiles,
2657 'headerData' => &$this->headerData,
2658 'footerData' => &$this->footerData
2659 ];
2660 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
2661 } else {
2662 // Traverse the arrays, compress files
2663 if (!empty($this->jsInline)) {
2664 foreach ($this->jsInline as $name => $properties) {
2665 if ($properties['compress']) {
2666 $error = '';
2667 $this->jsInline[$name]['code'] = GeneralUtility::minifyJavaScript($properties['code'], $error);
2668 if ($error) {
2669 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
2670 }
2671 }
2672 }
2673 }
2674 $this->jsLibs = $this->getCompressor()->compressJsFiles($this->jsLibs);
2675 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
2676 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
2677 }
2678 }
2679 }
2680
2681 /**
2682 * Returns instance of \TYPO3\CMS\Core\Resource\ResourceCompressor
2683 *
2684 * @return \TYPO3\CMS\Core\Resource\ResourceCompressor
2685 */
2686 protected function getCompressor()
2687 {
2688 if ($this->compressor === null) {
2689 $this->compressor = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceCompressor::class);
2690 }
2691 return $this->compressor;
2692 }
2693
2694 /**
2695 * Processes a Javascript file dependent on the current context
2696 *
2697 * Adds the version number for Frontend, compresses the file for Backend
2698 *
2699 * @param string $filename Filename
2700 * @return string New filename
2701 */
2702 protected function processJsFile($filename)
2703 {
2704 switch (TYPO3_MODE) {
2705 case 'FE':
2706 if ($this->compressJavascript) {
2707 $filename = $this->getCompressor()->compressJsFile($filename);
2708 } else {
2709 $filename = GeneralUtility::createVersionNumberedFilename($filename);
2710 }
2711 break;
2712 case 'BE':
2713 if ($this->compressJavascript) {
2714 $filename = $this->getCompressor()->compressJsFile($filename);
2715 }
2716 break;
2717 }
2718 return $filename;
2719 }
2720
2721 /**
2722 * Returns global frontend controller
2723 *
2724 * @return TypoScriptFrontendController
2725 */
2726 protected function getTypoScriptFrontendController()
2727 {
2728 return $GLOBALS['TSFE'];
2729 }
2730
2731 /**
2732 * Returns global language service instance
2733 *
2734 * @return \TYPO3\CMS\Lang\LanguageService
2735 */
2736 protected function getLanguageService()
2737 {
2738 return $GLOBALS['LANG'];
2739 }
2740
2741 /*****************************************************/
2742 /* */
2743 /* Hooks */
2744 /* */
2745 /*****************************************************/
2746 /**
2747 * Execute PreRenderHook for possible manipulation
2748 *
2749 * @return void
2750 */
2751 protected function executePreRenderHook()
2752 {
2753 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
2754 $params = [
2755 'jsLibs' => &$this->jsLibs,
2756 'jsFooterLibs' => &$this->jsFooterLibs,
2757 'jsFiles' => &$this->jsFiles,
2758 'jsFooterFiles' => &$this->jsFooterFiles,
2759 'cssLibs' => &$this->cssLibs,
2760 'cssFiles' => &$this->cssFiles,
2761 'headerData' => &$this->headerData,
2762 'footerData' => &$this->footerData,
2763 'jsInline' => &$this->jsInline,
2764 'jsFooterInline' => &$this->jsFooterInline,
2765 'cssInline' => &$this->cssInline
2766 ];
2767 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
2768 GeneralUtility::callUserFunction($hook, $params, $this);
2769 }
2770 }
2771 }
2772
2773 /**
2774 * PostTransform for possible manipulation of concatenated and compressed files
2775 *
2776 * @return void
2777 */
2778 protected function executeRenderPostTransformHook()
2779 {
2780 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
2781 $params = [
2782 'jsLibs' => &$this->jsLibs,
2783 'jsFooterLibs' => &$this->jsFooterLibs,
2784 'jsFiles' => &$this->jsFiles,
2785 'jsFooterFiles' => &$this->jsFooterFiles,
2786 'cssLibs' => &$this->cssLibs,
2787 'cssFiles' => &$this->cssFiles,
2788 'headerData' => &$this->headerData,
2789 'footerData' => &$this->footerData,
2790 'jsInline' => &$this->jsInline,
2791 'jsFooterInline' => &$this->jsFooterInline,
2792 'cssInline' => &$this->cssInline
2793 ];
2794 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
2795 GeneralUtility::callUserFunction($hook, $params, $this);
2796 }
2797 }
2798 }
2799
2800 /**
2801 * Execute postRenderHook for possible manipulation
2802 *
2803 * @param $jsLibs string
2804 * @param $jsFiles string
2805 * @param $jsFooterFiles string
2806 * @param $cssLibs string
2807 * @param $cssFiles string
2808 * @param $jsInline string
2809 * @param $cssInline string
2810 * @param $jsFooterInline string
2811 * @param $jsFooterLibs string
2812 * @return void
2813 */
2814 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssLibs, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs)
2815 {
2816 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
2817 $params = [
2818 'jsLibs' => &$jsLibs,
2819 'jsFiles' => &$jsFiles,
2820 'jsFooterFiles' => &$jsFooterFiles,
2821 'cssLibs' => &$cssLibs,
2822 'cssFiles' => &$cssFiles,
2823 'headerData' => &$this->headerData,
2824 'footerData' => &$this->footerData,
2825 'jsInline' => &$jsInline,
2826 'cssInline' => &$cssInline,
2827 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType,
2828 'htmlTag' => &$this->htmlTag,
2829 'headTag' => &$this->headTag,
2830 'charSet' => &$this->charSet,
2831 'metaCharsetTag' => &$this->metaCharsetTag,
2832 'shortcutTag' => &$this->shortcutTag,
2833 'inlineComments' => &$this->inlineComments,
2834 'baseUrl' => &$this->baseUrl,
2835 'baseUrlTag' => &$this->baseUrlTag,
2836 'favIcon' => &$this->favIcon,
2837 'iconMimeType' => &$this->iconMimeType,
2838 'titleTag' => &$this->titleTag,
2839 'title' => &$this->title,
2840 'metaTags' => &$this->metaTags,
2841 'jsFooterInline' => &$jsFooterInline,
2842 'jsFooterLibs' => &$jsFooterLibs,
2843 'bodyContent' => &$this->bodyContent
2844 ];
2845 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
2846 GeneralUtility::callUserFunction($hook, $params, $this);
2847 }
2848 }
2849 }
2850 }