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