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