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