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