[FEATURE] Refactor category tree to SVG
[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 = array();
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 = array();
117
118 /**
119 * @var array
120 */
121 protected $jsFooterFiles = array();
122
123 /**
124 * @var array
125 */
126 protected $jsLibs = array();
127
128 /**
129 * @var array
130 */
131 protected $jsFooterLibs = array();
132
133 /**
134 * @var array
135 */
136 protected $cssFiles = array();
137
138 /**
139 * @var array
140 */
141 protected $cssLibs = array();
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 = array();
182
183 /**
184 * @var array
185 */
186 protected $inlineComments = array();
187
188 /**
189 * @var array
190 */
191 protected $headerData = array();
192
193 /**
194 * @var array
195 */
196 protected $footerData = array();
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 = array();
238
239 /**
240 * @var array
241 */
242 protected $jsFooterInline = array();
243
244 /**
245 * @var array
246 */
247 protected $extOnReadyCode = array();
248
249 /**
250 * @var array
251 */
252 protected $cssInline = array();
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 = array('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 = array();
308
309 /**
310 * Array of jQuery version numbers shipped with the core
311 *
312 * @var array
313 */
314 protected $availableLocalJqueryVersions = array(
315 self::JQUERY_VERSION_LATEST
316 );
317
318 /**
319 * Array of jQuery CDNs with placeholders
320 *
321 * @var array
322 */
323 protected $jQueryCdnUrls = array(
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 = array();
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 = array();
376
377 /**
378 * @var array
379 */
380 protected $inlineLanguageLabelFiles = array();
381
382 /**
383 * @var array
384 */
385 protected $inlineSettings = array();
386
387 /**
388 * @var array
389 */
390 protected $inlineJavascriptWrap = array();
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 = array(
433 '<script type="text/javascript">' . LF . '/*<![CDATA[*/' . LF,
434 '/*]]>*/' . LF . '</script>' . LF
435 );
436 $this->inlineCssWrap = array(
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 = array();
451 $this->jsFooterFiles = array();
452 $this->jsInline = array();
453 $this->jsFooterInline = array();
454 $this->jsLibs = array();
455 $this->cssFiles = array();
456 $this->cssInline = array();
457 $this->metaTags = array();
458 $this->inlineComments = array();
459 $this->headerData = array();
460 $this->footerData = array();
461 $this->extOnReadyCode = array();
462 $this->jQueryVersions = array();
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 = array();
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)] = array(
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)] = array(
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] = array(
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] = array(
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] = array(
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] = array(
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 = array())
1300 {
1301 if ($this->extDirectCodeAdded) {
1302 return;
1303 }
1304 $this->extDirectCodeAdded = true;
1305 if (empty($filterNamespaces)) {
1306 $filterNamespaces = array('TYPO3');
1307 }
1308
1309 // Add language labels for ExtDirect
1310 if (TYPO3_MODE === 'FE') {
1311 $this->addInlineLanguageLabelArray(array(
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(array(
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] = array(
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] = array(
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] = array(
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] = array(
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'] = array(
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] = array(
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 = array(
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 array($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 = array(
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 = array(
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, array(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 = array();
2141 // Include TYPO3.l10n object
2142 if (TYPO3_MODE === 'BE') {
2143 $out .= '<script src="' . $this->processJsFile(ExtensionManagementUtility::extRelPath('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 = array();
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 = array();
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 = GeneralUtility::resolveBackPath($file);
2280 $file = GeneralUtility::createVersionNumberedFilename($file);
2281 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2282 . '" type="text/css" href="' . htmlspecialchars($file)
2283 . '" media="' . htmlspecialchars($properties['media']) . '"'
2284 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2285 . $this->endingSlash . '>';
2286 if ($properties['allWrap']) {
2287 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2288 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2289 }
2290 $tag .= LF;
2291 if ($properties['forceOnTop']) {
2292 $cssFiles = $tag . $cssFiles;
2293 } else {
2294 $cssFiles .= $tag;
2295 }
2296 }
2297 }
2298 return $cssFiles;
2299 }
2300
2301 /**
2302 * Render CSS files
2303 *
2304 * @return string
2305 */
2306 protected function renderCssFiles()
2307 {
2308 $cssFiles = '';
2309 if (!empty($this->cssFiles)) {
2310 foreach ($this->cssFiles as $file => $properties) {
2311 $file = GeneralUtility::resolveBackPath($file);
2312 $file = GeneralUtility::createVersionNumberedFilename($file);
2313 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2314 . '" type="text/css" href="' . htmlspecialchars($file)
2315 . '" media="' . htmlspecialchars($properties['media']) . '"'
2316 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2317 . $this->endingSlash . '>';
2318 if ($properties['allWrap']) {
2319 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2320 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2321 }
2322 $tag .= LF;
2323 if ($properties['forceOnTop']) {
2324 $cssFiles = $tag . $cssFiles;
2325 } else {
2326 $cssFiles .= $tag;
2327 }
2328 }
2329 }
2330 return $cssFiles;
2331 }
2332
2333 /**
2334 * Render inline CSS
2335 *
2336 * @return string
2337 */
2338 protected function renderCssInline()
2339 {
2340 $cssInline = '';
2341 if (!empty($this->cssInline)) {
2342 foreach ($this->cssInline as $name => $properties) {
2343 $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2344 if ($properties['forceOnTop']) {
2345 $cssInline = $cssCode . $cssInline;
2346 } else {
2347 $cssInline .= $cssCode;
2348 }
2349 }
2350 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
2351 }
2352 return $cssInline;
2353 }
2354
2355 /**
2356 * Render JavaScipt libraries
2357 *
2358 * @return array<string> jsLibs and jsFooterLibs strings
2359 */
2360 protected function renderAdditionalJavaScriptLibraries()
2361 {
2362 $jsLibs = '';
2363 $jsFooterLibs = '';
2364 if (!empty($this->jsLibs)) {
2365 foreach ($this->jsLibs as $properties) {
2366 $properties['file'] = GeneralUtility::resolveBackPath($properties['file']);
2367 $properties['file'] = GeneralUtility::createVersionNumberedFilename($properties['file']);
2368 $async = ($properties['async']) ? ' async="async"' : '';
2369 $integrity = ($properties['integrity']) ? ' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2370 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $integrity . '></script>';
2371 if ($properties['allWrap']) {
2372 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2373 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2374 }
2375 $tag .= LF;
2376 if ($properties['forceOnTop']) {
2377 if ($properties['section'] === self::PART_HEADER) {
2378 $jsLibs = $tag . $jsLibs;
2379 } else {
2380 $jsFooterLibs = $tag . $jsFooterLibs;
2381 }
2382 } else {
2383 if ($properties['section'] === self::PART_HEADER) {
2384 $jsLibs .= $tag;
2385 } else {
2386 $jsFooterLibs .= $tag;
2387 }
2388 }
2389 }
2390 }
2391 if ($this->moveJsFromHeaderToFooter) {
2392 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
2393 $jsLibs = '';
2394 }
2395 return array($jsLibs, $jsFooterLibs);
2396 }
2397
2398 /**
2399 * Render JavaScript files
2400 *
2401 * @return array<string> jsFiles and jsFooterFiles strings
2402 */
2403 protected function renderJavaScriptFiles()
2404 {
2405 $jsFiles = '';
2406 $jsFooterFiles = '';
2407 if (!empty($this->jsFiles)) {
2408 foreach ($this->jsFiles as $file => $properties) {
2409 $file = GeneralUtility::resolveBackPath($file);
2410 $file = GeneralUtility::createVersionNumberedFilename($file);
2411 $async = ($properties['async']) ? ' async="async"' : '';
2412 $integrity = ($properties['integrity']) ? ' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2413 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $integrity . '></script>';
2414 if ($properties['allWrap']) {
2415 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2416 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2417 }
2418 $tag .= LF;
2419 if ($properties['forceOnTop']) {
2420 if ($properties['section'] === self::PART_HEADER) {
2421 $jsFiles = $tag . $jsFiles;
2422 } else {
2423 $jsFooterFiles = $tag . $jsFooterFiles;
2424 }
2425 } else {
2426 if ($properties['section'] === self::PART_HEADER) {
2427 $jsFiles .= $tag;
2428 } else {
2429 $jsFooterFiles .= $tag;
2430 }
2431 }
2432 }
2433 }
2434 if ($this->moveJsFromHeaderToFooter) {
2435 $jsFooterFiles = $jsFiles . $jsFooterFiles;
2436 $jsFiles = '';
2437 }
2438 return array($jsFiles, $jsFooterFiles);
2439 }
2440
2441 /**
2442 * Render inline JavaScript
2443 *
2444 * @return array<string> jsInline and jsFooterInline string
2445 */
2446 protected function renderInlineJavaScript()
2447 {
2448 $jsInline = '';
2449 $jsFooterInline = '';
2450 if (!empty($this->jsInline)) {
2451 foreach ($this->jsInline as $name => $properties) {
2452 $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2453 if ($properties['forceOnTop']) {
2454 if ($properties['section'] === self::PART_HEADER) {
2455 $jsInline = $jsCode . $jsInline;
2456 } else {
2457 $jsFooterInline = $jsCode . $jsFooterInline;
2458 }
2459 } else {
2460 if ($properties['section'] === self::PART_HEADER) {
2461 $jsInline .= $jsCode;
2462 } else {
2463 $jsFooterInline .= $jsCode;
2464 }
2465 }
2466 }
2467 }
2468 if ($jsInline) {
2469 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
2470 }
2471 if ($jsFooterInline) {
2472 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
2473 }
2474 if ($this->moveJsFromHeaderToFooter) {
2475 $jsFooterInline = $jsInline . $jsFooterInline;
2476 $jsInline = '';
2477 }
2478 return array($jsInline, $jsFooterInline);
2479 }
2480
2481 /**
2482 * Include language file for inline usage
2483 *
2484 * @param string $fileRef
2485 * @param string $selectionPrefix
2486 * @param string $stripFromSelectionName
2487 * @param int $errorMode
2488 * @return void
2489 * @throws \RuntimeException
2490 */
2491 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0)
2492 {
2493 if (!isset($this->lang) || !isset($this->charSet)) {
2494 throw new \RuntimeException('Language and character encoding are not set.', 1284906026);
2495 }
2496 $labelsFromFile = array();
2497 $allLabels = $this->readLLfile($fileRef, $errorMode);
2498 if ($allLabels !== false) {
2499 // Merge language specific translations:
2500 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
2501 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
2502 } else {
2503 $labels = $allLabels['default'];
2504 }
2505 // Iterate through all locallang labels:
2506 foreach ($labels as $label => $value) {
2507 // If $selectionPrefix is set, only respect labels that start with $selectionPrefix
2508 if ($selectionPrefix === '' || strpos($label, $selectionPrefix) === 0) {
2509 // Remove substring $stripFromSelectionName from label
2510 $label = str_replace($stripFromSelectionName, '', $label);
2511 $labelsFromFile[$label] = $value;
2512 }
2513 }
2514 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
2515 }
2516 }
2517
2518 /**
2519 * Reads a locallang file.
2520 *
2521 * @param string $fileRef Reference to a relative filename to include.
2522 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
2523 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2524 */
2525 protected function readLLfile($fileRef, $errorMode = 0)
2526 {
2527 /** @var $languageFactory LocalizationFactory */
2528 $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
2529
2530 if ($this->lang !== 'default') {
2531 $languages = array_reverse($this->languageDependencies);
2532 // At least we need to have English
2533 if (empty($languages)) {
2534 $languages[] = 'default';
2535 }
2536 } else {
2537 $languages = array('default');
2538 }
2539
2540 $localLanguage = array();
2541 foreach ($languages as $language) {
2542 $tempLL = $languageFactory->getParsedData($fileRef, $language, $this->charSet, $errorMode);
2543
2544 $localLanguage['default'] = $tempLL['default'];
2545 if (!isset($localLanguage[$this->lang])) {
2546 $localLanguage[$this->lang] = $localLanguage['default'];
2547 }
2548 if ($this->lang !== 'default' && isset($tempLL[$language])) {
2549 // Merge current language labels onto labels from previous language
2550 // This way we have a labels with fall back applied
2551 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($localLanguage[$this->lang], $tempLL[$language], true, false);
2552 }
2553 }
2554
2555 return $localLanguage;
2556 }
2557
2558 /*****************************************************/
2559 /* */
2560 /* Tools */
2561 /* */
2562 /*****************************************************/
2563 /**
2564 * Concatenate files into one file
2565 * registered handler
2566 *
2567 * @return void
2568 */
2569 protected function doConcatenate()
2570 {
2571 $this->doConcatenateCss();
2572 $this->doConcatenateJavaScript();
2573 }
2574
2575 /**
2576 * Concatenate JavaScript files according to the configuration.
2577 *
2578 * @return void
2579 */
2580 protected function doConcatenateJavaScript()
2581 {
2582 if ($this->concatenateFiles || $this->concatenateJavascript) {
2583 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'])) {
2584 // use external concatenation routine
2585 $params = array(
2586 'jsLibs' => &$this->jsLibs,
2587 'jsFiles' => &$this->jsFiles,
2588 'jsFooterFiles' => &$this->jsFooterFiles,
2589 'headerData' => &$this->headerData,
2590 'footerData' => &$this->footerData
2591 );
2592 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'], $params, $this);
2593 } else {
2594 $this->jsLibs = $this->getCompressor()->concatenateJsFiles($this->jsLibs);
2595 $this->jsFiles = $this->getCompressor()->concatenateJsFiles($this->jsFiles);
2596 $this->jsFooterFiles = $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles);
2597 }
2598 }
2599 }
2600
2601 /**
2602 * Concatenate CSS files according to configuration.
2603 *
2604 * @return void
2605 */
2606 protected function doConcatenateCss()
2607 {
2608 if ($this->concatenateFiles || $this->concatenateCss) {
2609 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'])) {
2610 // use external concatenation routine
2611 $params = array(
2612 'cssFiles' => &$this->cssFiles,
2613 'cssLibs' => &$this->cssLibs,
2614 'headerData' => &$this->headerData,
2615 'footerData' => &$this->footerData
2616 );
2617 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this);
2618 } else {
2619 $cssOptions = array();
2620 if (TYPO3_MODE === 'BE') {
2621 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
2622 }
2623 $this->cssLibs = $this->getCompressor()->concatenateCssFiles($this->cssLibs, $cssOptions);
2624 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
2625 }
2626 }
2627 }
2628
2629 /**
2630 * Compresses inline code
2631 *
2632 * @return void
2633 */
2634 protected function doCompress()
2635 {
2636 $this->doCompressJavaScript();
2637 $this->doCompressCss();
2638 }
2639
2640 /**
2641 * Compresses CSS according to configuration.
2642 *
2643 * @return void
2644 */
2645 protected function doCompressCss()
2646 {
2647 if ($this->compressCss) {
2648 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'])) {
2649 // Use external compression routine
2650 $params = array(
2651 'cssInline' => &$this->cssInline,
2652 'cssFiles' => &$this->cssFiles,
2653 'cssLibs' => &$this->cssLibs,
2654 'headerData' => &$this->headerData,
2655 'footerData' => &$this->footerData
2656 );
2657 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
2658 } else {
2659 $this->cssLibs = $this->getCompressor()->compressCssFiles($this->cssLibs);
2660 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
2661 }
2662 }
2663 }
2664
2665 /**
2666 * Compresses JavaScript according to configuration.
2667 *
2668 * @return void
2669 */
2670 protected function doCompressJavaScript()
2671 {
2672 if ($this->compressJavascript) {
2673 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'])) {
2674 // Use external compression routine
2675 $params = array(
2676 'jsInline' => &$this->jsInline,
2677 'jsFooterInline' => &$this->jsFooterInline,
2678 'jsLibs' => &$this->jsLibs,
2679 'jsFiles' => &$this->jsFiles,
2680 'jsFooterFiles' => &$this->jsFooterFiles,
2681 'headerData' => &$this->headerData,
2682 'footerData' => &$this->footerData
2683 );
2684 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
2685 } else {
2686 // Traverse the arrays, compress files
2687 if (!empty($this->jsInline)) {
2688 foreach ($this->jsInline as $name => $properties) {
2689 if ($properties['compress']) {
2690 $error = '';
2691 $this->jsInline[$name]['code'] = GeneralUtility::minifyJavaScript($properties['code'], $error);
2692 if ($error) {
2693 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
2694 }
2695 }
2696 }
2697 }
2698 $this->jsLibs = $this->getCompressor()->compressJsFiles($this->jsLibs);
2699 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
2700 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
2701 }
2702 }
2703 }
2704
2705 /**
2706 * Returns instance of \TYPO3\CMS\Core\Resource\ResourceCompressor
2707 *
2708 * @return \TYPO3\CMS\Core\Resource\ResourceCompressor
2709 */
2710 protected function getCompressor()
2711 {
2712 if ($this->compressor === null) {
2713 $this->compressor = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceCompressor::class);
2714 }
2715 return $this->compressor;
2716 }
2717
2718 /**
2719 * Processes a Javascript file dependent on the current context
2720 *
2721 * Adds the version number for Frontend, compresses the file for Backend
2722 *
2723 * @param string $filename Filename
2724 * @return string New filename
2725 */
2726 protected function processJsFile($filename)
2727 {
2728 if ($this->compressJavascript) {
2729 return $this->getCompressor()->compressJsFile($filename);
2730 } elseif (TYPO3_MODE === 'FE') {
2731 return GeneralUtility::createVersionNumberedFilename($filename);
2732 } else {
2733 return $filename;
2734 }
2735 }
2736
2737 /**
2738 * Returns global frontend controller
2739 *
2740 * @return TypoScriptFrontendController
2741 */
2742 protected function getTypoScriptFrontendController()
2743 {
2744 return $GLOBALS['TSFE'];
2745 }
2746
2747 /**
2748 * Returns global language service instance
2749 *
2750 * @return \TYPO3\CMS\Lang\LanguageService
2751 */
2752 protected function getLanguageService()
2753 {
2754 return $GLOBALS['LANG'];
2755 }
2756
2757 /*****************************************************/
2758 /* */
2759 /* Hooks */
2760 /* */
2761 /*****************************************************/
2762 /**
2763 * Execute PreRenderHook for possible manipulation
2764 *
2765 * @return void
2766 */
2767 protected function executePreRenderHook()
2768 {
2769 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
2770 $params = array(
2771 'jsLibs' => &$this->jsLibs,
2772 'jsFooterLibs' => &$this->jsFooterLibs,
2773 'jsFiles' => &$this->jsFiles,
2774 'jsFooterFiles' => &$this->jsFooterFiles,
2775 'cssLibs' => &$this->cssLibs,
2776 'cssFiles' => &$this->cssFiles,
2777 'headerData' => &$this->headerData,
2778 'footerData' => &$this->footerData,
2779 'jsInline' => &$this->jsInline,
2780 'jsFooterInline' => &$this->jsFooterInline,
2781 'cssInline' => &$this->cssInline
2782 );
2783 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
2784 GeneralUtility::callUserFunction($hook, $params, $this);
2785 }
2786 }
2787 }
2788
2789 /**
2790 * PostTransform for possible manipulation of concatenated and compressed files
2791 *
2792 * @return void
2793 */
2794 protected function executeRenderPostTransformHook()
2795 {
2796 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
2797 $params = array(
2798 'jsLibs' => &$this->jsLibs,
2799 'jsFooterLibs' => &$this->jsFooterLibs,
2800 'jsFiles' => &$this->jsFiles,
2801 'jsFooterFiles' => &$this->jsFooterFiles,
2802 'cssLibs' => &$this->cssLibs,
2803 'cssFiles' => &$this->cssFiles,
2804 'headerData' => &$this->headerData,
2805 'footerData' => &$this->footerData,
2806 'jsInline' => &$this->jsInline,
2807 'jsFooterInline' => &$this->jsFooterInline,
2808 'cssInline' => &$this->cssInline
2809 );
2810 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
2811 GeneralUtility::callUserFunction($hook, $params, $this);
2812 }
2813 }
2814 }
2815
2816 /**
2817 * Execute postRenderHook for possible manipulation
2818 *
2819 * @param $jsLibs string
2820 * @param $jsFiles string
2821 * @param $jsFooterFiles string
2822 * @param $cssLibs string
2823 * @param $cssFiles string
2824 * @param $jsInline string
2825 * @param $cssInline string
2826 * @param $jsFooterInline string
2827 * @param $jsFooterLibs string
2828 * @return void
2829 */
2830 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssLibs, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs)
2831 {
2832 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
2833 $params = array(
2834 'jsLibs' => &$jsLibs,
2835 'jsFiles' => &$jsFiles,
2836 'jsFooterFiles' => &$jsFooterFiles,
2837 'cssLibs' => &$cssLibs,
2838 'cssFiles' => &$cssFiles,
2839 'headerData' => &$this->headerData,
2840 'footerData' => &$this->footerData,
2841 'jsInline' => &$jsInline,
2842 'cssInline' => &$cssInline,
2843 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType,
2844 'htmlTag' => &$this->htmlTag,
2845 'headTag' => &$this->headTag,
2846 'charSet' => &$this->charSet,
2847 'metaCharsetTag' => &$this->metaCharsetTag,
2848 'shortcutTag' => &$this->shortcutTag,
2849 'inlineComments' => &$this->inlineComments,
2850 'baseUrl' => &$this->baseUrl,
2851 'baseUrlTag' => &$this->baseUrlTag,
2852 'favIcon' => &$this->favIcon,
2853 'iconMimeType' => &$this->iconMimeType,
2854 'titleTag' => &$this->titleTag,
2855 'title' => &$this->title,
2856 'metaTags' => &$this->metaTags,
2857 'jsFooterInline' => &$jsFooterInline,
2858 'jsFooterLibs' => &$jsFooterLibs,
2859 'bodyContent' => &$this->bodyContent
2860 );
2861 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
2862 GeneralUtility::callUserFunction($hook, $params, $this);
2863 }
2864 }
2865 }
2866 }