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