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