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