[FEATURE] Add crossorigin property to JavaScript files
[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 * @param string $crossorigin CORS settings attribute
1042 */
1043 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = false, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '', $defer = false, $crossorigin = '')
1044 {
1045 if (!$type) {
1046 $type = 'text/javascript';
1047 }
1048 if (!in_array(strtolower($name), $this->jsLibs)) {
1049 $this->jsLibs[strtolower($name)] = [
1050 'file' => $file,
1051 'type' => $type,
1052 'section' => self::PART_HEADER,
1053 'compress' => $compress,
1054 'forceOnTop' => $forceOnTop,
1055 'allWrap' => $allWrap,
1056 'excludeFromConcatenation' => $excludeFromConcatenation,
1057 'splitChar' => $splitChar,
1058 'async' => $async,
1059 'integrity' => $integrity,
1060 'defer' => $defer,
1061 'crossorigin' => $crossorigin,
1062 ];
1063 }
1064 }
1065
1066 /**
1067 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
1068 *
1069 * @param string $name Arbitrary identifier
1070 * @param string $file File name
1071 * @param string $type Content Type
1072 * @param bool $compress Flag if library should be compressed
1073 * @param bool $forceOnTop Flag if added library should be inserted at begin of this block
1074 * @param string $allWrap
1075 * @param bool $excludeFromConcatenation
1076 * @param string $splitChar The char used to split the allWrap value, default is "|"
1077 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1078 * @param string $integrity Subresource Integrity (SRI)
1079 * @param bool $defer Flag if property 'defer="defer"' should be added to JavaScript tags
1080 * @param string $crossorigin CORS settings attribute
1081 */
1082 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = false, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '', $defer = false, $crossorigin = '')
1083 {
1084 if (!$type) {
1085 $type = 'text/javascript';
1086 }
1087 if (!in_array(strtolower($name), $this->jsLibs)) {
1088 $this->jsLibs[strtolower($name)] = [
1089 'file' => $file,
1090 'type' => $type,
1091 'section' => self::PART_FOOTER,
1092 'compress' => $compress,
1093 'forceOnTop' => $forceOnTop,
1094 'allWrap' => $allWrap,
1095 'excludeFromConcatenation' => $excludeFromConcatenation,
1096 'splitChar' => $splitChar,
1097 'async' => $async,
1098 'integrity' => $integrity,
1099 'defer' => $defer,
1100 'crossorigin' => $crossorigin,
1101 ];
1102 }
1103 }
1104
1105 /**
1106 * Adds JS file
1107 *
1108 * @param string $file File name
1109 * @param string $type Content Type
1110 * @param bool $compress
1111 * @param bool $forceOnTop
1112 * @param string $allWrap
1113 * @param bool $excludeFromConcatenation
1114 * @param string $splitChar The char used to split the allWrap value, default is "|"
1115 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1116 * @param string $integrity Subresource Integrity (SRI)
1117 * @param bool $defer Flag if property 'defer="defer"' should be added to JavaScript tags
1118 * @param string $crossorigin CORS settings attribute
1119 */
1120 public function addJsFile($file, $type = 'text/javascript', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '', $defer = false, $crossorigin = '')
1121 {
1122 if (!$type) {
1123 $type = 'text/javascript';
1124 }
1125 if (!isset($this->jsFiles[$file])) {
1126 $this->jsFiles[$file] = [
1127 'file' => $file,
1128 'type' => $type,
1129 'section' => self::PART_HEADER,
1130 'compress' => $compress,
1131 'forceOnTop' => $forceOnTop,
1132 'allWrap' => $allWrap,
1133 'excludeFromConcatenation' => $excludeFromConcatenation,
1134 'splitChar' => $splitChar,
1135 'async' => $async,
1136 'integrity' => $integrity,
1137 'defer' => $defer,
1138 'crossorigin' => $crossorigin,
1139 ];
1140 }
1141 }
1142
1143 /**
1144 * Adds JS file to footer
1145 *
1146 * @param string $file File name
1147 * @param string $type Content Type
1148 * @param bool $compress
1149 * @param bool $forceOnTop
1150 * @param string $allWrap
1151 * @param bool $excludeFromConcatenation
1152 * @param string $splitChar The char used to split the allWrap value, default is "|"
1153 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1154 * @param string $integrity Subresource Integrity (SRI)
1155 * @param string $defer Flag if property 'defer="defer"' should be added to JavaScript tags
1156 * @param string $crossorigin CORS settings attribute
1157 */
1158 public function addJsFooterFile($file, $type = 'text/javascript', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $async = false, $integrity = '', $defer = false, $crossorigin = '')
1159 {
1160 if (!$type) {
1161 $type = 'text/javascript';
1162 }
1163 if (!isset($this->jsFiles[$file])) {
1164 $this->jsFiles[$file] = [
1165 'file' => $file,
1166 'type' => $type,
1167 'section' => self::PART_FOOTER,
1168 'compress' => $compress,
1169 'forceOnTop' => $forceOnTop,
1170 'allWrap' => $allWrap,
1171 'excludeFromConcatenation' => $excludeFromConcatenation,
1172 'splitChar' => $splitChar,
1173 'async' => $async,
1174 'integrity' => $integrity,
1175 'defer' => $defer,
1176 'crossorigin' => $crossorigin,
1177 ];
1178 }
1179 }
1180
1181 /**
1182 * Adds JS inline code
1183 *
1184 * @param string $name
1185 * @param string $block
1186 * @param bool $compress
1187 * @param bool $forceOnTop
1188 */
1189 public function addJsInlineCode($name, $block, $compress = true, $forceOnTop = false)
1190 {
1191 if (!isset($this->jsInline[$name]) && !empty($block)) {
1192 $this->jsInline[$name] = [
1193 'code' => $block . LF,
1194 'section' => self::PART_HEADER,
1195 'compress' => $compress,
1196 'forceOnTop' => $forceOnTop
1197 ];
1198 }
1199 }
1200
1201 /**
1202 * Adds JS inline code to footer
1203 *
1204 * @param string $name
1205 * @param string $block
1206 * @param bool $compress
1207 * @param bool $forceOnTop
1208 */
1209 public function addJsFooterInlineCode($name, $block, $compress = true, $forceOnTop = false)
1210 {
1211 if (!isset($this->jsInline[$name]) && !empty($block)) {
1212 $this->jsInline[$name] = [
1213 'code' => $block . LF,
1214 'section' => self::PART_FOOTER,
1215 'compress' => $compress,
1216 'forceOnTop' => $forceOnTop
1217 ];
1218 }
1219 }
1220
1221 /**
1222 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
1223 *
1224 * @param string $block Javascript code
1225 * @param bool $forceOnTop Position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
1226 */
1227 public function addExtOnReadyCode($block, $forceOnTop = false)
1228 {
1229 if (!in_array($block, $this->extOnReadyCode)) {
1230 if ($forceOnTop) {
1231 array_unshift($this->extOnReadyCode, $block);
1232 } else {
1233 $this->extOnReadyCode[] = $block;
1234 }
1235 }
1236 }
1237
1238 /**
1239 * Adds the ExtDirect code
1240 *
1241 * @param array $filterNamespaces Limit the output to defined namespaces. If empty, all namespaces are generated
1242 */
1243 public function addExtDirectCode(array $filterNamespaces = [])
1244 {
1245 if ($this->extDirectCodeAdded) {
1246 return;
1247 }
1248 $this->extDirectCodeAdded = true;
1249 if (empty($filterNamespaces)) {
1250 $filterNamespaces = ['TYPO3'];
1251 }
1252
1253 // Add language labels for ExtDirect
1254 $this->addInlineLanguageLabelArray([
1255 'extDirect_timeoutHeader' => 'LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:extDirect_timeoutHeader',
1256 'extDirect_timeoutMessage' => 'LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:extDirect_timeoutMessage'
1257 ], true);
1258
1259 $token = ($api = '');
1260 if (TYPO3_MODE === 'BE') {
1261 $formprotection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get();
1262 $token = $formprotection->generateToken('extDirect');
1263
1264 // Debugger Console strings
1265 $this->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/debugger.xlf');
1266
1267 $this->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/wizard.xlf');
1268 }
1269 /** @var $extDirect \TYPO3\CMS\Core\ExtDirect\ExtDirectApi */
1270 $extDirect = GeneralUtility::makeInstance(\TYPO3\CMS\Core\ExtDirect\ExtDirectApi::class);
1271 $api = $extDirect->getApiPhp($filterNamespaces);
1272 if ($api) {
1273 $this->addJsInlineCode('TYPO3ExtDirectAPI', $api, false);
1274 }
1275 // Note: we need to iterate through the object, because the addProvider method
1276 // does this only with multiple arguments
1277 $this->addExtOnReadyCode('
1278 (function() {
1279 TYPO3.ExtDirectToken = "' . $token . '";
1280 for (var api in Ext.app.ExtDirectAPI) {
1281 var provider = Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
1282 provider.on("beforecall", function(provider, transaction, meta) {
1283 if (transaction.data) {
1284 transaction.data[transaction.data.length] = TYPO3.ExtDirectToken;
1285 } else {
1286 transaction.data = [TYPO3.ExtDirectToken];
1287 }
1288 });
1289
1290 provider.on("call", function(provider, transaction, meta) {
1291 if (transaction.isForm) {
1292 transaction.params.securityToken = TYPO3.ExtDirectToken;
1293 }
1294 });
1295 }
1296 })();
1297
1298 var extDirectDebug = function(message, header, group) {
1299 var DebugConsole = null;
1300
1301 if (top && top.TYPO3 && typeof top.TYPO3.DebugConsole === "object") {
1302 DebugConsole = top.TYPO3.DebugConsole;
1303 } else if (typeof TYPO3 === "object" && typeof TYPO3.DebugConsole === "object") {
1304 DebugConsole = TYPO3.DebugConsole;
1305 }
1306
1307 if (DebugConsole !== null) {
1308 DebugConsole.add(message, header, group);
1309 } else if (typeof console === "object") {
1310 console.log(message);
1311 } else {
1312 document.write(message);
1313 }
1314 };
1315
1316 Ext.Direct.on("exception", function(event) {
1317 if (event.code === Ext.Direct.exceptions.TRANSPORT && !event.where) {
1318 top.TYPO3.Notification.error(
1319 TYPO3.l10n.localize("extDirect_timeoutHeader"),
1320 TYPO3.l10n.localize("extDirect_timeoutMessage")
1321 );
1322 } else {
1323 var backtrace = "";
1324 if (event.code === "parse") {
1325 extDirectDebug(
1326 "<p>" + event.xhr.responseText + "<\\/p>",
1327 event.type,
1328 "ExtDirect - Exception"
1329 );
1330 } else if (event.code === "router") {
1331 top.TYPO3.Notification.error(
1332 event.code,
1333 event.message
1334 );
1335 } else if (event.where) {
1336 backtrace = "<p style=\\"margin-top: 20px;\\">" +
1337 "<strong>Backtrace:<\\/strong><br \\/>" +
1338 event.where.replace(/#/g, "<br \\/>#") +
1339 "<\\/p>";
1340 extDirectDebug(
1341 "<p>" + event.message + "<\\/p>" + backtrace,
1342 event.method,
1343 "ExtDirect - Exception"
1344 );
1345 }
1346
1347
1348 }
1349 });
1350
1351 Ext.Direct.on("event", function(event, provider) {
1352 if (typeof event.debug !== "undefined" && event.debug !== "") {
1353 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
1354 }
1355 });
1356 ', true);
1357 }
1358
1359 /**
1360 * Adds CSS file
1361 *
1362 * @param string $file
1363 * @param string $rel
1364 * @param string $media
1365 * @param string $title
1366 * @param bool $compress
1367 * @param bool $forceOnTop
1368 * @param string $allWrap
1369 * @param bool $excludeFromConcatenation
1370 * @param string $splitChar The char used to split the allWrap value, default is "|"
1371 * @param bool $inline
1372 */
1373 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $inline = false)
1374 {
1375 if (!isset($this->cssFiles[$file])) {
1376 $this->cssFiles[$file] = [
1377 'file' => $file,
1378 'rel' => $rel,
1379 'media' => $media,
1380 'title' => $title,
1381 'compress' => $compress,
1382 'forceOnTop' => $forceOnTop,
1383 'allWrap' => $allWrap,
1384 'excludeFromConcatenation' => $excludeFromConcatenation,
1385 'splitChar' => $splitChar,
1386 'inline' => $inline
1387 ];
1388 }
1389 }
1390
1391 /**
1392 * Adds CSS file
1393 *
1394 * @param string $file
1395 * @param string $rel
1396 * @param string $media
1397 * @param string $title
1398 * @param bool $compress
1399 * @param bool $forceOnTop
1400 * @param string $allWrap
1401 * @param bool $excludeFromConcatenation
1402 * @param string $splitChar The char used to split the allWrap value, default is "|"
1403 * @param bool $inline
1404 */
1405 public function addCssLibrary($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = true, $forceOnTop = false, $allWrap = '', $excludeFromConcatenation = false, $splitChar = '|', $inline = false)
1406 {
1407 if (!isset($this->cssLibs[$file])) {
1408 $this->cssLibs[$file] = [
1409 'file' => $file,
1410 'rel' => $rel,
1411 'media' => $media,
1412 'title' => $title,
1413 'compress' => $compress,
1414 'forceOnTop' => $forceOnTop,
1415 'allWrap' => $allWrap,
1416 'excludeFromConcatenation' => $excludeFromConcatenation,
1417 'splitChar' => $splitChar,
1418 'inline' => $inline
1419 ];
1420 }
1421 }
1422
1423 /**
1424 * Adds CSS inline code
1425 *
1426 * @param string $name
1427 * @param string $block
1428 * @param bool $compress
1429 * @param bool $forceOnTop
1430 */
1431 public function addCssInlineBlock($name, $block, $compress = false, $forceOnTop = false)
1432 {
1433 if (!isset($this->cssInline[$name]) && !empty($block)) {
1434 $this->cssInline[$name] = [
1435 'code' => $block,
1436 'compress' => $compress,
1437 'forceOnTop' => $forceOnTop
1438 ];
1439 }
1440 }
1441
1442 /**
1443 * Call this function if you need to include the jQuery library
1444 *
1445 * @param null|string $version The jQuery version that should be included, either "latest" or any available version
1446 * @param null|string $source The location of the jQuery source, can be "local", "google", "msn", "jquery" or just an URL to your jQuery lib
1447 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored.
1448 * @throws \UnexpectedValueException
1449 */
1450 public function loadJquery($version = null, $source = null, $namespace = self::JQUERY_NAMESPACE_NONE)
1451 {
1452 // Set it to the version that is shipped with the TYPO3 core
1453 if ($version === null || $version === 'latest') {
1454 $version = self::JQUERY_VERSION_LATEST;
1455 }
1456 // Check if the source is set, otherwise set it to "default"
1457 if ($source === null) {
1458 $source = 'local';
1459 }
1460 if ($source === 'local' && !in_array($version, $this->availableLocalJqueryVersions)) {
1461 throw new \UnexpectedValueException('The requested jQuery version is not available in the local filesystem.', 1341505305);
1462 }
1463 if (!preg_match('/^[a-zA-Z0-9]+$/', $namespace)) {
1464 throw new \UnexpectedValueException('The requested namespace contains non alphanumeric characters.', 1341571604);
1465 }
1466 $this->jQueryVersions[$namespace] = [
1467 'version' => $version,
1468 'source' => $source
1469 ];
1470 }
1471
1472 /**
1473 * Call function if you need the requireJS library
1474 * this automatically adds the JavaScript path of all loaded extensions in the requireJS path option
1475 * so it resolves names like TYPO3/CMS/MyExtension/MyJsFile to EXT:MyExtension/Resources/Public/JavaScript/MyJsFile.js
1476 * when using requireJS
1477 */
1478 public function loadRequireJs()
1479 {
1480 $this->addRequireJs = true;
1481 if (!empty($this->requireJsConfig)) {
1482 return;
1483 }
1484
1485 $loadedExtensions = ExtensionManagementUtility::getLoadedExtensionListArray();
1486 $isDevelopment = GeneralUtility::getApplicationContext()->isDevelopment();
1487 $cacheIdentifier = 'requireJS_' . md5(implode(',', $loadedExtensions) . ($isDevelopment ? ':dev' : '') . GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT'));
1488 /** @var VariableFrontend $cache */
1489 $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('assets');
1490 $this->requireJsConfig = $cache->get($cacheIdentifier);
1491
1492 // if we did not get a configuration from the cache, compute and store it in the cache
1493 if (empty($this->requireJsConfig)) {
1494 $this->requireJsConfig = $this->computeRequireJsConfig($isDevelopment, $loadedExtensions);
1495 $cache->set($cacheIdentifier, $this->requireJsConfig);
1496 }
1497 }
1498
1499 /**
1500 * Computes the RequireJS configuration, mainly consisting of the paths to the core and all extension JavaScript
1501 * resource folders plus some additional generic configuration.
1502 *
1503 * @param bool $isDevelopment
1504 * @param array $loadedExtensions
1505 * @return array The RequireJS configuration
1506 */
1507 protected function computeRequireJsConfig($isDevelopment, array $loadedExtensions)
1508 {
1509 // load all paths to map to package names / namespaces
1510 $requireJsConfig = [];
1511
1512 // In order to avoid browser caching of JS files, adding a GET parameter to the files loaded via requireJS
1513 if ($isDevelopment) {
1514 $requireJsConfig['urlArgs'] = 'bust=' . $GLOBALS['EXEC_TIME'];
1515 } else {
1516 $requireJsConfig['urlArgs'] = 'bust=' . GeneralUtility::hmac(TYPO3_version . PATH_site);
1517 }
1518 $corePath = ExtensionManagementUtility::extPath('core', 'Resources/Public/JavaScript/Contrib/');
1519 $corePath = PathUtility::getAbsoluteWebPath($corePath);
1520 // first, load all paths for the namespaces, and configure contrib libs.
1521 $requireJsConfig['paths'] = [
1522 'jquery-ui' => $corePath . 'jquery-ui',
1523 'datatables' => $corePath . 'jquery.dataTables',
1524 'nprogress' => $corePath . 'nprogress',
1525 'moment' => $corePath . 'moment',
1526 'cropper' => $corePath . 'cropper.min',
1527 'imagesloaded' => $corePath . 'imagesloaded.pkgd.min',
1528 'bootstrap' => $corePath . 'bootstrap/bootstrap',
1529 'twbs/bootstrap-datetimepicker' => $corePath . 'bootstrap-datetimepicker',
1530 'autosize' => $corePath . 'autosize',
1531 'taboverride' => $corePath . 'taboverride.min',
1532 'twbs/bootstrap-slider' => $corePath . 'bootstrap-slider.min',
1533 'jquery/autocomplete' => $corePath . 'jquery.autocomplete',
1534 'd3' => $corePath . 'd3/d3'
1535 ];
1536
1537 foreach ($loadedExtensions as $packageName) {
1538 $fullJsPath = 'EXT:' . $packageName . '/Resources/Public/JavaScript/';
1539 $fullJsPath = GeneralUtility::getFileAbsFileName($fullJsPath);
1540 $fullJsPath = PathUtility::getAbsoluteWebPath($fullJsPath);
1541 $fullJsPath = rtrim($fullJsPath, '/');
1542 if ($fullJsPath) {
1543 $requireJsConfig['paths']['TYPO3/CMS/' . GeneralUtility::underscoredToUpperCamelCase($packageName)] = $fullJsPath;
1544 }
1545 }
1546
1547 // check if additional AMD modules need to be loaded if a single AMD module is initialized
1548 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules'])) {
1549 $this->addInlineSettingArray(
1550 'RequireJS.PostInitializationModules',
1551 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules']
1552 );
1553 }
1554
1555 return $requireJsConfig;
1556 }
1557
1558 /**
1559 * Add additional configuration to require js.
1560 *
1561 * Configuration will be merged recursive with overrule.
1562 *
1563 * To add another path mapping deliver the following configuration:
1564 * 'paths' => array(
1565 * 'EXTERN/mybootstrapjs' => 'sysext/.../twbs/bootstrap.min',
1566 * ),
1567 *
1568 * @param array $configuration The configuration that will be merged with existing one.
1569 */
1570 public function addRequireJsConfiguration(array $configuration)
1571 {
1572 if (TYPO3_MODE === 'BE') {
1573 // Load RequireJS in backend context at first. Doing this in FE could break the output
1574 $this->loadRequireJs();
1575 }
1576 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->requireJsConfig, $configuration);
1577 }
1578
1579 /**
1580 * includes an AMD-compatible JS file by resolving the ModuleName, and then requires the file via a requireJS request,
1581 * additionally allowing to execute JavaScript code afterwards
1582 *
1583 * this function only works for AMD-ready JS modules, used like "define('TYPO3/CMS/Backend/FormEngine..."
1584 * in the JS file
1585 *
1586 * TYPO3/CMS/Backend/FormEngine =>
1587 * "TYPO3": Vendor Name
1588 * "CMS": Product Name
1589 * "Backend": Extension Name
1590 * "FormEngine": FileName in the Resources/Public/JavaScript folder
1591 *
1592 * @param string $mainModuleName Must be in the form of "TYPO3/CMS/PackageName/ModuleName" e.g. "TYPO3/CMS/Backend/FormEngine"
1593 * @param string $callBackFunction loaded right after the requireJS loading, must be wrapped in function() {}
1594 */
1595 public function loadRequireJsModule($mainModuleName, $callBackFunction = null)
1596 {
1597 $inlineCodeKey = $mainModuleName;
1598 // make sure requireJS is initialized
1599 $this->loadRequireJs();
1600
1601 // execute the main module, and load a possible callback function
1602 $javaScriptCode = 'require(["' . $mainModuleName . '"]';
1603 if ($callBackFunction !== null) {
1604 $inlineCodeKey .= sha1($callBackFunction);
1605 $javaScriptCode .= ', ' . $callBackFunction;
1606 }
1607 $javaScriptCode .= ');';
1608 $this->addJsInlineCode('RequireJS-Module-' . $inlineCodeKey, $javaScriptCode);
1609 }
1610
1611 /**
1612 * call this function if you need the extJS library
1613 *
1614 * @param bool $css Flag, if set the ext-css will be loaded
1615 * @param bool $theme Flag, if set the ext-theme "grey" will be loaded
1616 */
1617 public function loadExtJS($css = true, $theme = true)
1618 {
1619 $this->addExtJS = true;
1620 $this->extJStheme = $theme;
1621 $this->extJScss = $css;
1622 }
1623
1624 /**
1625 * Call this function to load debug version of ExtJS. Use this for development only
1626 */
1627 public function enableExtJsDebug()
1628 {
1629 $this->enableExtJsDebug = true;
1630 }
1631
1632 /**
1633 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1634 * The label can be used in scripts with TYPO3.lang.<key>
1635 * Need extJs loaded
1636 *
1637 * @param string $key
1638 * @param string $value
1639 */
1640 public function addInlineLanguageLabel($key, $value)
1641 {
1642 $this->inlineLanguageLabels[$key] = $value;
1643 }
1644
1645 /**
1646 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1647 * The label can be used in scripts with TYPO3.lang.<key>
1648 * Array will be merged with existing array.
1649 * Need extJs loaded
1650 *
1651 * @param array $array
1652 * @param bool $parseWithLanguageService
1653 */
1654 public function addInlineLanguageLabelArray(array $array, $parseWithLanguageService = false)
1655 {
1656 if ($parseWithLanguageService === true) {
1657 foreach ($array as $key => $value) {
1658 if (TYPO3_MODE === 'FE') {
1659 $array[$key] = $this->getTypoScriptFrontendController()->sL($value);
1660 } else {
1661 $array[$key] = $this->getLanguageService()->sL($value);
1662 }
1663 }
1664 }
1665
1666 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
1667 }
1668
1669 /**
1670 * Gets labels to be used in JavaScript fetched from a locallang file.
1671 *
1672 * @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.
1673 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1674 * @param string $stripFromSelectionName String to be removed from the label names in the output. (default: '')
1675 */
1676 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '')
1677 {
1678 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1679 if ($fileRef && !isset($this->inlineLanguageLabelFiles[$index])) {
1680 $this->inlineLanguageLabelFiles[$index] = [
1681 'fileRef' => $fileRef,
1682 'selectionPrefix' => $selectionPrefix,
1683 'stripFromSelectionName' => $stripFromSelectionName
1684 ];
1685 }
1686 }
1687
1688 /**
1689 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1690 * The label can be used in scripts with TYPO3.setting.<key>
1691 * Need extJs loaded
1692 *
1693 * @param string $namespace
1694 * @param string $key
1695 * @param string $value
1696 */
1697 public function addInlineSetting($namespace, $key, $value)
1698 {
1699 if ($namespace) {
1700 if (strpos($namespace, '.')) {
1701 $parts = explode('.', $namespace);
1702 $a = &$this->inlineSettings;
1703 foreach ($parts as $part) {
1704 $a = &$a[$part];
1705 }
1706 $a[$key] = $value;
1707 } else {
1708 $this->inlineSettings[$namespace][$key] = $value;
1709 }
1710 } else {
1711 $this->inlineSettings[$key] = $value;
1712 }
1713 }
1714
1715 /**
1716 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1717 * The label can be used in scripts with TYPO3.setting.<key>
1718 * Array will be merged with existing array.
1719 * Need extJs loaded
1720 *
1721 * @param string $namespace
1722 * @param array $array
1723 */
1724 public function addInlineSettingArray($namespace, array $array)
1725 {
1726 if ($namespace) {
1727 if (strpos($namespace, '.')) {
1728 $parts = explode('.', $namespace);
1729 $a = &$this->inlineSettings;
1730 foreach ($parts as $part) {
1731 $a = &$a[$part];
1732 }
1733 $a = array_merge((array)$a, $array);
1734 } else {
1735 $this->inlineSettings[$namespace] = array_merge((array)$this->inlineSettings[$namespace], $array);
1736 }
1737 } else {
1738 $this->inlineSettings = array_merge($this->inlineSettings, $array);
1739 }
1740 }
1741
1742 /**
1743 * Adds content to body content
1744 *
1745 * @param string $content
1746 */
1747 public function addBodyContent($content)
1748 {
1749 $this->bodyContent .= $content;
1750 }
1751
1752 /*****************************************************/
1753 /* */
1754 /* Render Functions */
1755 /* */
1756 /*****************************************************/
1757 /**
1758 * Render the section (Header or Footer)
1759 *
1760 * @param int $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1761 * @return string Content of rendered section
1762 */
1763 public function render($part = self::PART_COMPLETE)
1764 {
1765 $this->prepareRendering();
1766 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1767 $metaTags = implode(LF, $this->metaTags);
1768 $markerArray = $this->getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags);
1769 $template = $this->getTemplateForPart($part);
1770
1771 // The page renderer needs a full reset, even when only rendering one part of the page
1772 // This means that you can only register footer files *after* the header has been already rendered.
1773 // In case you render the footer part first, header files can only be added *after* the footer has been rendered
1774 $this->reset();
1775 $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
1776 return trim($templateService->substituteMarkerArray($template, $markerArray, '###|###'));
1777 }
1778
1779 /**
1780 * Render the page but not the JavaScript and CSS Files
1781 *
1782 * @param string $substituteHash The hash that is used for the placehoder markers
1783 * @access private
1784 * @return string Content of rendered section
1785 */
1786 public function renderPageWithUncachedObjects($substituteHash)
1787 {
1788 $this->prepareRendering();
1789 $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
1790 $template = $this->getTemplateForPart(self::PART_COMPLETE);
1791 $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
1792 return trim($templateService->substituteMarkerArray($template, $markerArray, '###|###'));
1793 }
1794
1795 /**
1796 * Renders the JavaScript and CSS files that have been added during processing
1797 * of uncached content objects (USER_INT, COA_INT)
1798 *
1799 * @param string $cachedPageContent
1800 * @param string $substituteHash The hash that is used for the placehoder markers
1801 * @access private
1802 * @return string
1803 */
1804 public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash)
1805 {
1806 $this->prepareRendering();
1807 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1808 $title = $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '';
1809 $markerArray = [
1810 '<!-- ###TITLE' . $substituteHash . '### -->' => $title,
1811 '<!-- ###CSS_LIBS' . $substituteHash . '### -->' => $cssLibs,
1812 '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
1813 '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
1814 '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
1815 '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
1816 '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
1817 '<!-- ###META' . $substituteHash . '### -->' => implode(LF, $this->metaTags),
1818 '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF, $this->headerData),
1819 '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF, $this->footerData),
1820 '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
1821 '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
1822 '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline
1823 ];
1824 foreach ($markerArray as $placeHolder => $content) {
1825 $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
1826 }
1827 $this->reset();
1828 return $cachedPageContent;
1829 }
1830
1831 /**
1832 * Remove ending slashes from static header block
1833 * if the page is being rendered as html (not xhtml)
1834 * and define property $this->endingSlash for further use
1835 */
1836 protected function prepareRendering()
1837 {
1838 if ($this->getRenderXhtml()) {
1839 $this->endingSlash = ' /';
1840 } else {
1841 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
1842 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
1843 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
1844 $this->endingSlash = '';
1845 }
1846 }
1847
1848 /**
1849 * Renders all JavaScript and CSS
1850 *
1851 * @return array<string>
1852 */
1853 protected function renderJavaScriptAndCss()
1854 {
1855 $this->executePreRenderHook();
1856 $mainJsLibs = $this->renderMainJavaScriptLibraries();
1857 if ($this->concatenateFiles || $this->concatenateJavascript || $this->concatenateCss) {
1858 // Do the file concatenation
1859 $this->doConcatenate();
1860 }
1861 if ($this->compressCss || $this->compressJavascript) {
1862 // Do the file compression
1863 $this->doCompress();
1864 }
1865 $this->executeRenderPostTransformHook();
1866 $cssLibs = $this->renderCssLibraries();
1867 $cssFiles = $this->renderCssFiles();
1868 $cssInline = $this->renderCssInline();
1869 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
1870 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
1871 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
1872 $jsLibs = $mainJsLibs . $jsLibs;
1873 if ($this->moveJsFromHeaderToFooter) {
1874 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
1875 $jsLibs = '';
1876 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
1877 $jsFiles = '';
1878 $jsFooterInline = $jsInline . LF . $jsFooterInline;
1879 $jsInline = '';
1880 }
1881 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1882 return [$jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs];
1883 }
1884
1885 /**
1886 * Fills the marker array with the given strings and trims each value
1887 *
1888 * @param $jsLibs string
1889 * @param $jsFiles string
1890 * @param $jsFooterFiles string
1891 * @param $cssLibs string
1892 * @param $cssFiles string
1893 * @param $jsInline string
1894 * @param $cssInline string
1895 * @param $jsFooterInline string
1896 * @param $jsFooterLibs string
1897 * @param $metaTags string
1898 * @return array Marker array
1899 */
1900 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags)
1901 {
1902 $markerArray = [
1903 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1904 'HTMLTAG' => $this->htmlTag,
1905 'HEADTAG' => $this->headTag,
1906 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1907 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1908 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1909 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1910 'CSS_LIBS' => $cssLibs,
1911 'CSS_INCLUDE' => $cssFiles,
1912 'CSS_INLINE' => $cssInline,
1913 'JS_INLINE' => $jsInline,
1914 'JS_INCLUDE' => $jsFiles,
1915 'JS_LIBS' => $jsLibs,
1916 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1917 'META' => $metaTags,
1918 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
1919 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
1920 'JS_LIBS_FOOTER' => $jsFooterLibs,
1921 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1922 'JS_INLINE_FOOTER' => $jsFooterInline,
1923 'BODY' => $this->bodyContent
1924 ];
1925 $markerArray = array_map('trim', $markerArray);
1926 return $markerArray;
1927 }
1928
1929 /**
1930 * Fills the marker array with the given strings and trims each value
1931 *
1932 * @param string $substituteHash The hash that is used for the placehoder markers
1933 * @return array Marker array
1934 */
1935 protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash)
1936 {
1937 $markerArray = [
1938 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1939 'HTMLTAG' => $this->htmlTag,
1940 'HEADTAG' => $this->headTag,
1941 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1942 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1943 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1944 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1945 'META' => '<!-- ###META' . $substituteHash . '### -->',
1946 'BODY' => $this->bodyContent,
1947 'TITLE' => '<!-- ###TITLE' . $substituteHash . '### -->',
1948 'CSS_LIBS' => '<!-- ###CSS_LIBS' . $substituteHash . '### -->',
1949 'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
1950 'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
1951 'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
1952 'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
1953 'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
1954 'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
1955 'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
1956 'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
1957 'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
1958 'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->'
1959 ];
1960 $markerArray = array_map('trim', $markerArray);
1961 return $markerArray;
1962 }
1963
1964 /**
1965 * Reads the template file and returns the requested part as string
1966 *
1967 * @param int $part
1968 * @return string
1969 */
1970 protected function getTemplateForPart($part)
1971 {
1972 $templateFile = GeneralUtility::getFileAbsFileName($this->templateFile);
1973 if (is_file($templateFile)) {
1974 $template = file_get_contents($templateFile);
1975 if ($this->removeLineBreaksFromTemplate) {
1976 $template = strtr($template, [LF => '', CR => '']);
1977 }
1978 if ($part !== self::PART_COMPLETE) {
1979 $templatePart = explode('###BODY###', $template);
1980 $template = $templatePart[$part - 1];
1981 }
1982 } else {
1983 $template = '';
1984 }
1985 return $template;
1986 }
1987
1988 /**
1989 * Helper function for render the main JavaScript libraries,
1990 * currently: RequireJS, jQuery, ExtJS
1991 *
1992 * @return string Content with JavaScript libraries
1993 */
1994 protected function renderMainJavaScriptLibraries()
1995 {
1996 $out = '';
1997
1998 // Include RequireJS
1999 if ($this->addRequireJs) {
2000 // load the paths of the requireJS configuration
2001 $out .= GeneralUtility::wrapJS('var require = ' . json_encode($this->requireJsConfig)) . LF;
2002 // directly after that, include the require.js file
2003 $out .= '<script src="' . $this->processJsFile($this->requireJsPath . 'require.js') . '" type="text/javascript"></script>' . LF;
2004 }
2005
2006 // Include jQuery Core for each namespace, depending on the version and source
2007 if (!empty($this->jQueryVersions)) {
2008 foreach ($this->jQueryVersions as $namespace => $jQueryVersion) {
2009 $out .= $this->renderJqueryScriptTag($jQueryVersion['version'], $jQueryVersion['source'], $namespace);
2010 }
2011 }
2012
2013 // Include extJS
2014 if ($this->addExtJS) {
2015 // Use the base adapter all the time
2016 $out .= '<script src="' . $this->processJsFile($this->extJsPath . 'adapter/ext-base' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') . '" type="text/javascript"></script>' . LF;
2017 $out .= '<script src="' . $this->processJsFile($this->extJsPath . 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') . '" type="text/javascript"></script>' . LF;
2018 // Add extJS localization
2019 // Load standard ISO mapping and modify for use with ExtJS
2020 $localeMap = $this->locales->getIsoMapping();
2021 $localeMap[''] = 'en';
2022 $localeMap['default'] = 'en';
2023 // Greek
2024 $localeMap['gr'] = 'el_GR';
2025 // Norwegian Bokmaal
2026 $localeMap['no'] = 'no_BO';
2027 // Swedish
2028 $localeMap['se'] = 'se_SV';
2029 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
2030 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
2031 if (file_exists(PATH_site . $extJsLocaleFile)) {
2032 $out .= '<script src="' . $this->processJsFile($extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
2033 }
2034 // Remove extjs from JScodeLibArray
2035 unset($this->jsFiles[$this->extJsPath . 'ext-all.js'], $this->jsFiles[$this->extJsPath . 'ext-all-debug.js']);
2036 }
2037 $this->loadJavaScriptLanguageStrings();
2038 if (TYPO3_MODE === 'BE') {
2039 $this->addAjaxUrlsToInlineSettings();
2040 }
2041 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
2042 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
2043 if ($this->addExtJS) {
2044 // Set clear.gif, move it on top, add handler code
2045 $code = '';
2046 if (!empty($this->extOnReadyCode)) {
2047 foreach ($this->extOnReadyCode as $block) {
2048 $code .= $block;
2049 }
2050 }
2051 $clearGifPath = GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Public/Images/clear.gif');
2052 $clearGifPath = htmlspecialchars(PathUtility::getAbsoluteWebPath($clearGifPath));
2053 $out .= $this->inlineJavascriptWrap[0] . '
2054 Ext.ns("TYPO3");
2055 Ext.BLANK_IMAGE_URL = "' . $clearGifPath . '";
2056 Ext.SSL_SECURE_URL = "' . $clearGifPath . '";' . LF
2057 . $inlineSettings
2058 . 'Ext.onReady(function() {'
2059 . $code
2060 . ' });'
2061 . $this->inlineJavascriptWrap[1];
2062 $this->extOnReadyCode = [];
2063 // Include TYPO3.l10n object
2064 if (TYPO3_MODE === 'BE') {
2065 $out .= '<script src="' . $this->processJsFile('EXT:lang/Resources/Public/JavaScript/Typo3Lang.js') . '" type="text/javascript" charset="utf-8"></script>' . LF;
2066 }
2067 if ($this->extJScss) {
2068 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
2069 $this->addCssLibrary($GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', true);
2070 } else {
2071 $this->addCssLibrary($this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', true);
2072 }
2073 }
2074 if ($this->extJStheme) {
2075 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
2076 $this->addCssLibrary($GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', true);
2077 } else {
2078 $this->addCssLibrary($this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', true);
2079 }
2080 }
2081 } else {
2082 // no extJS loaded, but still inline settings
2083 if ($inlineSettings !== '') {
2084 // make sure the global TYPO3 is available
2085 $inlineSettings = 'var TYPO3 = TYPO3 || {};' . CRLF . $inlineSettings;
2086 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
2087 // Add language module only if also jquery is guaranteed to be there
2088 if (TYPO3_MODE === 'BE' && !empty($this->jQueryVersions)) {
2089 $this->loadRequireJsModule('TYPO3/CMS/Lang/Lang');
2090 }
2091 }
2092 }
2093 return $out;
2094 }
2095
2096 /**
2097 * Load the language strings into JavaScript
2098 */
2099 protected function loadJavaScriptLanguageStrings()
2100 {
2101 if (!empty($this->inlineLanguageLabelFiles)) {
2102 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
2103 $this->includeLanguageFileForInline($languageLabelFile['fileRef'], $languageLabelFile['selectionPrefix'], $languageLabelFile['stripFromSelectionName']);
2104 }
2105 }
2106 $this->inlineLanguageLabelFiles = [];
2107 // Convert settings back to UTF-8 since json_encode() only works with UTF-8:
2108 if ($this->getCharSet() && $this->getCharSet() !== 'utf-8' && is_array($this->inlineSettings)) {
2109 $this->convertCharsetRecursivelyToUtf8($this->inlineSettings, $this->getCharSet());
2110 }
2111 }
2112
2113 /**
2114 * Small helper function to convert charsets for arrays into utf-8
2115 *
2116 * @param mixed $data given by reference (string/array usually)
2117 * @param string $fromCharset convert FROM this charset
2118 */
2119 protected function convertCharsetRecursivelyToUtf8(&$data, string $fromCharset)
2120 {
2121 foreach ($data as $key => $value) {
2122 if (is_array($data[$key])) {
2123 $this->convertCharsetRecursivelyToUtf8($data[$key], $fromCharset);
2124 } elseif (is_string($data[$key])) {
2125 $data[$key] = mb_convert_encoding($data[$key], 'utf-8', $fromCharset);
2126 }
2127 }
2128 }
2129
2130 /**
2131 * Make URLs to all backend ajax handlers available as inline setting.
2132 */
2133 protected function addAjaxUrlsToInlineSettings()
2134 {
2135 $ajaxUrls = [];
2136 // Add the ajax-based routes
2137 /** @var UriBuilder $uriBuilder */
2138 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
2139 /** @var Router $router */
2140 $router = GeneralUtility::makeInstance(Router::class);
2141 $routes = $router->getRoutes();
2142 foreach ($routes as $routeIdentifier => $route) {
2143 if ($route->getOption('ajax')) {
2144 $uri = (string)$uriBuilder->buildUriFromRoute($routeIdentifier);
2145 // use the shortened value in order to use this in JavaScript
2146 $routeIdentifier = str_replace('ajax_', '', $routeIdentifier);
2147 $ajaxUrls[$routeIdentifier] = $uri;
2148 }
2149 }
2150
2151 $this->inlineSettings['ajaxUrls'] = $ajaxUrls;
2152 }
2153
2154 /**
2155 * Renders the HTML script tag for the given jQuery version.
2156 *
2157 * @param string $version The jQuery version that should be included, either "latest" or any available version
2158 * @param string $source The location of the jQuery source, can be "local", "google", "msn" or "jquery
2159 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored
2160 * @return string
2161 */
2162 protected function renderJqueryScriptTag($version, $source, $namespace)
2163 {
2164 switch (true) {
2165 case isset($this->jQueryCdnUrls[$source]):
2166 if ($this->enableJqueryDebug) {
2167 $minifyPart = '';
2168 } else {
2169 $minifyPart = '.min';
2170 }
2171 $jQueryFileName = sprintf($this->jQueryCdnUrls[$source], $version, $minifyPart);
2172 break;
2173 case $source === 'local':
2174 $jQueryFileName = $this->jQueryPath . 'jquery-' . rawurlencode($version);
2175 if ($this->enableJqueryDebug) {
2176 $jQueryFileName .= '.js';
2177 } else {
2178 $jQueryFileName .= '.min.js';
2179 }
2180 $jQueryFileName = $this->processJsFile($jQueryFileName);
2181 break;
2182 default:
2183 $jQueryFileName = $source;
2184 }
2185 $scriptTag = '<script src="' . htmlspecialchars($jQueryFileName) . '" type="text/javascript"></script>' . LF;
2186 // Set the noConflict mode to be globally available via "jQuery"
2187 if ($namespace !== self::JQUERY_NAMESPACE_NONE) {
2188 $scriptTag .= GeneralUtility::wrapJS('jQuery.noConflict();') . LF;
2189 }
2190 return $scriptTag;
2191 }
2192
2193 /**
2194 * Render CSS library files
2195 *
2196 * @return string
2197 */
2198 protected function renderCssLibraries()
2199 {
2200 $cssFiles = '';
2201 if (!empty($this->cssLibs)) {
2202 foreach ($this->cssLibs as $file => $properties) {
2203 $tag = $this->createCssTag($properties, $file);
2204 if ($properties['forceOnTop']) {
2205 $cssFiles = $tag . $cssFiles;
2206 } else {
2207 $cssFiles .= $tag;
2208 }
2209 }
2210 }
2211 return $cssFiles;
2212 }
2213
2214 /**
2215 * Render CSS files
2216 *
2217 * @return string
2218 */
2219 protected function renderCssFiles()
2220 {
2221 $cssFiles = '';
2222 if (!empty($this->cssFiles)) {
2223 foreach ($this->cssFiles as $file => $properties) {
2224 $tag = $this->createCssTag($properties, $file);
2225 if ($properties['forceOnTop']) {
2226 $cssFiles = $tag . $cssFiles;
2227 } else {
2228 $cssFiles .= $tag;
2229 }
2230 }
2231 }
2232 return $cssFiles;
2233 }
2234
2235 /**
2236 * Create link (inline=0) or style (inline=1) tag
2237 *
2238 * @param array $properties
2239 * @param string $file
2240 * @return string
2241 */
2242 private function createCssTag(array $properties, string $file): string
2243 {
2244 if ($properties['inline'] && @is_file($file)) {
2245 $tag = $this->createInlineCssTagFromFile($file, $properties);
2246 } else {
2247 $href = $this->getStreamlinedFileName($file);
2248 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2249 . '" type="text/css" href="' . htmlspecialchars($href)
2250 . '" media="' . htmlspecialchars($properties['media']) . '"'
2251 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2252 . $this->endingSlash . '>';
2253 }
2254 if ($properties['allWrap']) {
2255 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2256 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2257 }
2258 $tag .= LF;
2259
2260 return $tag;
2261 }
2262
2263 /**
2264 * Render inline CSS
2265 *
2266 * @return string
2267 */
2268 protected function renderCssInline()
2269 {
2270 $cssInline = '';
2271 if (!empty($this->cssInline)) {
2272 foreach ($this->cssInline as $name => $properties) {
2273 $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2274 if ($properties['forceOnTop']) {
2275 $cssInline = $cssCode . $cssInline;
2276 } else {
2277 $cssInline .= $cssCode;
2278 }
2279 }
2280 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
2281 }
2282 return $cssInline;
2283 }
2284
2285 /**
2286 * Render JavaScipt libraries
2287 *
2288 * @return array<string> jsLibs and jsFooterLibs strings
2289 */
2290 protected function renderAdditionalJavaScriptLibraries()
2291 {
2292 $jsLibs = '';
2293 $jsFooterLibs = '';
2294 if (!empty($this->jsLibs)) {
2295 foreach ($this->jsLibs as $properties) {
2296 $properties['file'] = $this->getStreamlinedFileName($properties['file']);
2297 $async = ($properties['async']) ? ' async="async"' : '';
2298 $defer = ($properties['defer']) ? ' defer="defer"' : '';
2299 $integrity = ($properties['integrity']) ? ' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2300 $crossorigin = ($properties['crossorigin']) ? ' crossorigin="' . htmlspecialchars($properties['crossorigin']) . '"' : '';
2301 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $defer . $integrity . $crossorigin . '></script>';
2302 if ($properties['allWrap']) {
2303 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2304 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2305 }
2306 $tag .= LF;
2307 if ($properties['forceOnTop']) {
2308 if ($properties['section'] === self::PART_HEADER) {
2309 $jsLibs = $tag . $jsLibs;
2310 } else {
2311 $jsFooterLibs = $tag . $jsFooterLibs;
2312 }
2313 } else {
2314 if ($properties['section'] === self::PART_HEADER) {
2315 $jsLibs .= $tag;
2316 } else {
2317 $jsFooterLibs .= $tag;
2318 }
2319 }
2320 }
2321 }
2322 if ($this->moveJsFromHeaderToFooter) {
2323 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
2324 $jsLibs = '';
2325 }
2326 return [$jsLibs, $jsFooterLibs];
2327 }
2328
2329 /**
2330 * Render JavaScript files
2331 *
2332 * @return array<string> jsFiles and jsFooterFiles strings
2333 */
2334 protected function renderJavaScriptFiles()
2335 {
2336 $jsFiles = '';
2337 $jsFooterFiles = '';
2338 if (!empty($this->jsFiles)) {
2339 foreach ($this->jsFiles as $file => $properties) {
2340 $file = $this->getStreamlinedFileName($file);
2341 $async = ($properties['async']) ? ' async="async"' : '';
2342 $defer = ($properties['defer']) ? ' defer="defer"' : '';
2343 $integrity = ($properties['integrity']) ? ' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2344 $crossorigin = ($properties['crossorigin']) ? ' crossorigin="' . htmlspecialchars($properties['crossorigin']) . '"' : '';
2345 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $defer . $integrity . $crossorigin . '></script>';
2346 if ($properties['allWrap']) {
2347 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2348 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2349 }
2350 $tag .= LF;
2351 if ($properties['forceOnTop']) {
2352 if ($properties['section'] === self::PART_HEADER) {
2353 $jsFiles = $tag . $jsFiles;
2354 } else {
2355 $jsFooterFiles = $tag . $jsFooterFiles;
2356 }
2357 } else {
2358 if ($properties['section'] === self::PART_HEADER) {
2359 $jsFiles .= $tag;
2360 } else {
2361 $jsFooterFiles .= $tag;
2362 }
2363 }
2364 }
2365 }
2366 if ($this->moveJsFromHeaderToFooter) {
2367 $jsFooterFiles = $jsFiles . $jsFooterFiles;
2368 $jsFiles = '';
2369 }
2370 return [$jsFiles, $jsFooterFiles];
2371 }
2372
2373 /**
2374 * Render inline JavaScript
2375 *
2376 * @return array<string> jsInline and jsFooterInline string
2377 */
2378 protected function renderInlineJavaScript()
2379 {
2380 $jsInline = '';
2381 $jsFooterInline = '';
2382 if (!empty($this->jsInline)) {
2383 foreach ($this->jsInline as $name => $properties) {
2384 $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2385 if ($properties['forceOnTop']) {
2386 if ($properties['section'] === self::PART_HEADER) {
2387 $jsInline = $jsCode . $jsInline;
2388 } else {
2389 $jsFooterInline = $jsCode . $jsFooterInline;
2390 }
2391 } else {
2392 if ($properties['section'] === self::PART_HEADER) {
2393 $jsInline .= $jsCode;
2394 } else {
2395 $jsFooterInline .= $jsCode;
2396 }
2397 }
2398 }
2399 }
2400 if ($jsInline) {
2401 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
2402 }
2403 if ($jsFooterInline) {
2404 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
2405 }
2406 if ($this->moveJsFromHeaderToFooter) {
2407 $jsFooterInline = $jsInline . $jsFooterInline;
2408 $jsInline = '';
2409 }
2410 return [$jsInline, $jsFooterInline];
2411 }
2412
2413 /**
2414 * Include language file for inline usage
2415 *
2416 * @param string $fileRef
2417 * @param string $selectionPrefix
2418 * @param string $stripFromSelectionName
2419 * @throws \RuntimeException
2420 */
2421 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '')
2422 {
2423 if (!isset($this->lang) || !isset($this->charSet)) {
2424 throw new \RuntimeException('Language and character encoding are not set.', 1284906026);
2425 }
2426 $labelsFromFile = [];
2427 $allLabels = $this->readLLfile($fileRef);
2428 if ($allLabels !== false) {
2429 // Merge language specific translations:
2430 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
2431 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
2432 } else {
2433 $labels = $allLabels['default'];
2434 }
2435 // Iterate through all locallang labels:
2436 foreach ($labels as $label => $value) {
2437 // If $selectionPrefix is set, only respect labels that start with $selectionPrefix
2438 if ($selectionPrefix === '' || strpos($label, $selectionPrefix) === 0) {
2439 // Remove substring $stripFromSelectionName from label
2440 $label = str_replace($stripFromSelectionName, '', $label);
2441 $labelsFromFile[$label] = $value;
2442 }
2443 }
2444 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
2445 }
2446 }
2447
2448 /**
2449 * Reads a locallang file.
2450 *
2451 * @param string $fileRef Reference to a relative filename to include.
2452 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2453 */
2454 protected function readLLfile($fileRef)
2455 {
2456 /** @var $languageFactory LocalizationFactory */
2457 $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
2458
2459 if ($this->lang !== 'default') {
2460 $languages = array_reverse($this->languageDependencies);
2461 // At least we need to have English
2462 if (empty($languages)) {
2463 $languages[] = 'default';
2464 }
2465 } else {
2466 $languages = ['default'];
2467 }
2468
2469 $localLanguage = [];
2470 foreach ($languages as $language) {
2471 $tempLL = $languageFactory->getParsedData($fileRef, $language);
2472
2473 $localLanguage['default'] = $tempLL['default'];
2474 if (!isset($localLanguage[$this->lang])) {
2475 $localLanguage[$this->lang] = $localLanguage['default'];
2476 }
2477 if ($this->lang !== 'default' && isset($tempLL[$language])) {
2478 // Merge current language labels onto labels from previous language
2479 // This way we have a labels with fall back applied
2480 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($localLanguage[$this->lang], $tempLL[$language], true, false);
2481 }
2482 }
2483
2484 return $localLanguage;
2485 }
2486
2487 /*****************************************************/
2488 /* */
2489 /* Tools */
2490 /* */
2491 /*****************************************************/
2492 /**
2493 * Concatenate files into one file
2494 * registered handler
2495 */
2496 protected function doConcatenate()
2497 {
2498 $this->doConcatenateCss();
2499 $this->doConcatenateJavaScript();
2500 }
2501
2502 /**
2503 * Concatenate JavaScript files according to the configuration.
2504 */
2505 protected function doConcatenateJavaScript()
2506 {
2507 if ($this->concatenateFiles || $this->concatenateJavascript) {
2508 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'])) {
2509 // use external concatenation routine
2510 $params = [
2511 'jsLibs' => &$this->jsLibs,
2512 'jsFiles' => &$this->jsFiles,
2513 'jsFooterFiles' => &$this->jsFooterFiles,
2514 'headerData' => &$this->headerData,
2515 'footerData' => &$this->footerData
2516 ];
2517 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'], $params, $this);
2518 } else {
2519 $this->jsLibs = $this->getCompressor()->concatenateJsFiles($this->jsLibs);
2520 $this->jsFiles = $this->getCompressor()->concatenateJsFiles($this->jsFiles);
2521 $this->jsFooterFiles = $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles);
2522 }
2523 }
2524 }
2525
2526 /**
2527 * Concatenate CSS files according to configuration.
2528 */
2529 protected function doConcatenateCss()
2530 {
2531 if ($this->concatenateFiles || $this->concatenateCss) {
2532 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'])) {
2533 // use external concatenation routine
2534 $params = [
2535 'cssFiles' => &$this->cssFiles,
2536 'cssLibs' => &$this->cssLibs,
2537 'headerData' => &$this->headerData,
2538 'footerData' => &$this->footerData
2539 ];
2540 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this);
2541 } else {
2542 $cssOptions = [];
2543 if (TYPO3_MODE === 'BE') {
2544 $cssOptions = ['baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories()];
2545 }
2546 $this->cssLibs = $this->getCompressor()->concatenateCssFiles($this->cssLibs, $cssOptions);
2547 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
2548 }
2549 }
2550 }
2551
2552 /**
2553 * Compresses inline code
2554 */
2555 protected function doCompress()
2556 {
2557 $this->doCompressJavaScript();
2558 $this->doCompressCss();
2559 }
2560
2561 /**
2562 * Compresses CSS according to configuration.
2563 */
2564 protected function doCompressCss()
2565 {
2566 if ($this->compressCss) {
2567 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'])) {
2568 // Use external compression routine
2569 $params = [
2570 'cssInline' => &$this->cssInline,
2571 'cssFiles' => &$this->cssFiles,
2572 'cssLibs' => &$this->cssLibs,
2573 'headerData' => &$this->headerData,
2574 'footerData' => &$this->footerData
2575 ];
2576 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
2577 } else {
2578 $this->cssLibs = $this->getCompressor()->compressCssFiles($this->cssLibs);
2579 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
2580 }
2581 }
2582 }
2583
2584 /**
2585 * Compresses JavaScript according to configuration.
2586 */
2587 protected function doCompressJavaScript()
2588 {
2589 if ($this->compressJavascript) {
2590 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'])) {
2591 // Use external compression routine
2592 $params = [
2593 'jsInline' => &$this->jsInline,
2594 'jsFooterInline' => &$this->jsFooterInline,
2595 'jsLibs' => &$this->jsLibs,
2596 'jsFiles' => &$this->jsFiles,
2597 'jsFooterFiles' => &$this->jsFooterFiles,
2598 'headerData' => &$this->headerData,
2599 'footerData' => &$this->footerData
2600 ];
2601 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
2602 } else {
2603 // Traverse the arrays, compress files
2604 if (!empty($this->jsInline)) {
2605 foreach ($this->jsInline as $name => $properties) {
2606 if ($properties['compress']) {
2607 $error = '';
2608 $this->jsInline[$name]['code'] = GeneralUtility::minifyJavaScript($properties['code'], $error);
2609 if ($error) {
2610 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
2611 }
2612 }
2613 }
2614 }
2615 $this->jsLibs = $this->getCompressor()->compressJsFiles($this->jsLibs);
2616 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
2617 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
2618 }
2619 }
2620 }
2621
2622 /**
2623 * Returns instance of \TYPO3\CMS\Core\Resource\ResourceCompressor
2624 *
2625 * @return \TYPO3\CMS\Core\Resource\ResourceCompressor
2626 */
2627 protected function getCompressor()
2628 {
2629 if ($this->compressor === null) {
2630 $this->compressor = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceCompressor::class);
2631 }
2632 return $this->compressor;
2633 }
2634
2635 /**
2636 * Processes a Javascript file dependent on the current context
2637 *
2638 * Adds the version number for Frontend, compresses the file for Backend
2639 *
2640 * @param string $filename Filename
2641 * @return string New filename
2642 */
2643 protected function processJsFile($filename)
2644 {
2645 $filename = $this->getStreamlinedFileName($filename, false);
2646 if ($this->compressJavascript) {
2647 $filename = $this->getCompressor()->compressJsFile($filename);
2648 } elseif (TYPO3_MODE === 'FE') {
2649 $filename = GeneralUtility::createVersionNumberedFilename($filename);
2650 }
2651 return PathUtility::getAbsoluteWebPath($filename);
2652 }
2653
2654 /**
2655 * This function acts as a wrapper to allow relative and paths starting with EXT: to be dealt with
2656 * in this very case to always return the absolute web path to be included directly before output.
2657 *
2658 * This is mainly added so the EXT: syntax can be resolved for PageRenderer in one central place,
2659 * and hopefully removed in the future by one standard API call.
2660 *
2661 * @param string $file the filename to process
2662 * @param bool $prepareForOutput whether the file should be prepared as version numbered file and prefixed as absolute webpath
2663 * @return string
2664 * @internal
2665 */
2666 protected function getStreamlinedFileName($file, $prepareForOutput = true)
2667 {
2668 if (strpos($file, 'EXT:') === 0) {
2669 $file = GeneralUtility::getFileAbsFileName($file);
2670 // as the path is now absolute, make it "relative" to the current script to stay compatible
2671 $file = PathUtility::getRelativePathTo($file);
2672 $file = rtrim($file, '/');
2673 } else {
2674 $file = GeneralUtility::resolveBackPath($file);
2675 }
2676 if ($prepareForOutput) {
2677 $file = GeneralUtility::createVersionNumberedFilename($file);
2678 $file = PathUtility::getAbsoluteWebPath($file);
2679 }
2680 return $file;
2681 }
2682
2683 /**
2684 * Returns global frontend controller
2685 *
2686 * @return TypoScriptFrontendController
2687 */
2688 protected function getTypoScriptFrontendController()
2689 {
2690 return $GLOBALS['TSFE'];
2691 }
2692
2693 /**
2694 * Returns global language service instance
2695 *
2696 * @return \TYPO3\CMS\Core\Localization\LanguageService
2697 */
2698 protected function getLanguageService()
2699 {
2700 return $GLOBALS['LANG'];
2701 }
2702
2703 /*****************************************************/
2704 /* */
2705 /* Hooks */
2706 /* */
2707 /*****************************************************/
2708 /**
2709 * Execute PreRenderHook for possible manipulation
2710 */
2711 protected function executePreRenderHook()
2712 {
2713 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
2714 $params = [
2715 'jsLibs' => &$this->jsLibs,
2716 'jsFooterLibs' => &$this->jsFooterLibs,
2717 'jsFiles' => &$this->jsFiles,
2718 'jsFooterFiles' => &$this->jsFooterFiles,
2719 'cssLibs' => &$this->cssLibs,
2720 'cssFiles' => &$this->cssFiles,
2721 'headerData' => &$this->headerData,
2722 'footerData' => &$this->footerData,
2723 'jsInline' => &$this->jsInline,
2724 'jsFooterInline' => &$this->jsFooterInline,
2725 'cssInline' => &$this->cssInline
2726 ];
2727 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
2728 GeneralUtility::callUserFunction($hook, $params, $this);
2729 }
2730 }
2731 }
2732
2733 /**
2734 * PostTransform for possible manipulation of concatenated and compressed files
2735 */
2736 protected function executeRenderPostTransformHook()
2737 {
2738 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
2739 $params = [
2740 'jsLibs' => &$this->jsLibs,
2741 'jsFooterLibs' => &$this->jsFooterLibs,
2742 'jsFiles' => &$this->jsFiles,
2743 'jsFooterFiles' => &$this->jsFooterFiles,
2744 'cssLibs' => &$this->cssLibs,
2745 'cssFiles' => &$this->cssFiles,
2746 'headerData' => &$this->headerData,
2747 'footerData' => &$this->footerData,
2748 'jsInline' => &$this->jsInline,
2749 'jsFooterInline' => &$this->jsFooterInline,
2750 'cssInline' => &$this->cssInline
2751 ];
2752 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
2753 GeneralUtility::callUserFunction($hook, $params, $this);
2754 }
2755 }
2756 }
2757
2758 /**
2759 * Execute postRenderHook for possible manipulation
2760 *
2761 * @param $jsLibs string
2762 * @param $jsFiles string
2763 * @param $jsFooterFiles string
2764 * @param $cssLibs string
2765 * @param $cssFiles string
2766 * @param $jsInline string
2767 * @param $cssInline string
2768 * @param $jsFooterInline string
2769 * @param $jsFooterLibs string
2770 */
2771 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssLibs, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs)
2772 {
2773 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
2774 $params = [
2775 'jsLibs' => &$jsLibs,
2776 'jsFiles' => &$jsFiles,
2777 'jsFooterFiles' => &$jsFooterFiles,
2778 'cssLibs' => &$cssLibs,
2779 'cssFiles' => &$cssFiles,
2780 'headerData' => &$this->headerData,
2781 'footerData' => &$this->footerData,
2782 'jsInline' => &$jsInline,
2783 'cssInline' => &$cssInline,
2784 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType,
2785 'htmlTag' => &$this->htmlTag,
2786 'headTag' => &$this->headTag,
2787 'charSet' => &$this->charSet,
2788 'metaCharsetTag' => &$this->metaCharsetTag,
2789 'shortcutTag' => &$this->shortcutTag,
2790 'inlineComments' => &$this->inlineComments,
2791 'baseUrl' => &$this->baseUrl,
2792 'baseUrlTag' => &$this->baseUrlTag,
2793 'favIcon' => &$this->favIcon,
2794 'iconMimeType' => &$this->iconMimeType,
2795 'titleTag' => &$this->titleTag,
2796 'title' => &$this->title,
2797 'metaTags' => &$this->metaTags,
2798 'jsFooterInline' => &$jsFooterInline,
2799 'jsFooterLibs' => &$jsFooterLibs,
2800 'bodyContent' => &$this->bodyContent
2801 ];
2802 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
2803 GeneralUtility::callUserFunction($hook, $params, $this);
2804 }
2805 }
2806 }
2807
2808 /**
2809 * Creates an CSS inline tag
2810 *
2811 * @param string $file the filename to process
2812 * @param array $properties
2813 * @return string
2814 */
2815 protected function createInlineCssTagFromFile(string $file, array $properties): string
2816 {
2817 $cssInline = file_get_contents($file);
2818
2819 return '<style type="text/css"'
2820 . ' media="' . htmlspecialchars($properties['media']) . '"'
2821 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2822 . '>' . LF
2823 . '/*<![CDATA[*/' . LF . '<!-- ' . LF
2824 . $cssInline
2825 . '-->' . LF . '/*]]>*/' . LF . '</style>' . LF;
2826 }
2827 }