[TASK] Add cssLibs to pre processing hooks in page renderer
[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 );
1601
1602 foreach ($loadedExtensions as $packageName) {
1603 $fullJsPath = 'EXT:' . $packageName . '/Resources/Public/JavaScript/';
1604 $fullJsPath = GeneralUtility::getFileAbsFileName($fullJsPath);
1605 $fullJsPath = PathUtility::getAbsoluteWebPath($fullJsPath);
1606 $fullJsPath = rtrim($fullJsPath, '/');
1607 if ($fullJsPath) {
1608 $requireJsConfig['paths']['TYPO3/CMS/' . GeneralUtility::underscoredToUpperCamelCase($packageName)] = $fullJsPath;
1609 }
1610 }
1611
1612 // check if additional AMD modules need to be loaded if a single AMD module is initialized
1613 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules'])) {
1614 $this->addInlineSettingArray(
1615 'RequireJS.PostInitializationModules',
1616 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules']
1617 );
1618 }
1619
1620 return $requireJsConfig;
1621 }
1622
1623 /**
1624 * Add additional configuration to require js.
1625 *
1626 * Configuration will be merged recursive with overrule.
1627 *
1628 * To add another path mapping deliver the following configuration:
1629 * 'paths' => array(
1630 * 'EXTERN/mybootstrapjs' => 'sysext/.../twbs/bootstrap.min',
1631 * ),
1632 *
1633 * @param array $configuration The configuration that will be merged with existing one.
1634 * @return void
1635 */
1636 public function addRequireJsConfiguration(array $configuration)
1637 {
1638 if (TYPO3_MODE === 'BE') {
1639 // Load RequireJS in backend context at first. Doing this in FE could break the output
1640 $this->loadRequireJs();
1641 }
1642 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->requireJsConfig, $configuration);
1643 }
1644
1645 /**
1646 * includes an AMD-compatible JS file by resolving the ModuleName, and then requires the file via a requireJS request,
1647 * additionally allowing to execute JavaScript code afterwards
1648 *
1649 * this function only works for AMD-ready JS modules, used like "define('TYPO3/CMS/Backend/FormEngine..."
1650 * in the JS file
1651 *
1652 * TYPO3/CMS/Backend/FormEngine =>
1653 * "TYPO3": Vendor Name
1654 * "CMS": Product Name
1655 * "Backend": Extension Name
1656 * "FormEngine": FileName in the Resources/Public/JavaScript folder
1657 *
1658 * @param string $mainModuleName Must be in the form of "TYPO3/CMS/PackageName/ModuleName" e.g. "TYPO3/CMS/Backend/FormEngine"
1659 * @param string $callBackFunction loaded right after the requireJS loading, must be wrapped in function() {}
1660 * @return void
1661 */
1662 public function loadRequireJsModule($mainModuleName, $callBackFunction = null)
1663 {
1664 $inlineCodeKey = $mainModuleName;
1665 // make sure requireJS is initialized
1666 $this->loadRequireJs();
1667
1668 // execute the main module, and load a possible callback function
1669 $javaScriptCode = 'require(["' . $mainModuleName . '"]';
1670 if ($callBackFunction !== null) {
1671 $inlineCodeKey .= sha1($callBackFunction);
1672 $javaScriptCode .= ', ' . $callBackFunction;
1673 }
1674 $javaScriptCode .= ');';
1675 $this->addJsInlineCode('RequireJS-Module-' . $inlineCodeKey, $javaScriptCode);
1676 }
1677
1678 /**
1679 * call this function if you need the extJS library
1680 *
1681 * @param bool $css Flag, if set the ext-css will be loaded
1682 * @param bool $theme Flag, if set the ext-theme "grey" will be loaded
1683 * @return void
1684 */
1685 public function loadExtJS($css = true, $theme = true)
1686 {
1687 $this->addExtJS = true;
1688 $this->extJStheme = $theme;
1689 $this->extJScss = $css;
1690 }
1691
1692 /**
1693 * Call this function to load debug version of ExtJS. Use this for development only
1694 *
1695 * @return void
1696 */
1697 public function enableExtJsDebug()
1698 {
1699 $this->enableExtJsDebug = true;
1700 }
1701
1702 /**
1703 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1704 * The label can be used in scripts with TYPO3.lang.<key>
1705 * Need extJs loaded
1706 *
1707 * @param string $key
1708 * @param string $value
1709 * @return void
1710 */
1711 public function addInlineLanguageLabel($key, $value)
1712 {
1713 $this->inlineLanguageLabels[$key] = $value;
1714 }
1715
1716 /**
1717 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1718 * The label can be used in scripts with TYPO3.lang.<key>
1719 * Array will be merged with existing array.
1720 * Need extJs loaded
1721 *
1722 * @param array $array
1723 * @param bool $parseWithLanguageService
1724 * @return void
1725 */
1726 public function addInlineLanguageLabelArray(array $array, $parseWithLanguageService = false)
1727 {
1728 if ($parseWithLanguageService === true) {
1729 foreach ($array as $key => $value) {
1730 if (TYPO3_MODE === 'FE') {
1731 $array[$key] = $this->getTypoScriptFrontendController()->sL($value);
1732 } else {
1733 $array[$key] = $this->getLanguageService()->sL($value);
1734 }
1735 }
1736 }
1737
1738 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
1739 }
1740
1741 /**
1742 * Gets labels to be used in JavaScript fetched from a locallang file.
1743 *
1744 * @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.
1745 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1746 * @param string $stripFromSelectionName String to be removed from the label names in the output. (default: '')
1747 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1748 * @return void
1749 */
1750 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0)
1751 {
1752 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1753 if ($fileRef && !isset($this->inlineLanguageLabelFiles[$index])) {
1754 $this->inlineLanguageLabelFiles[$index] = array(
1755 'fileRef' => $fileRef,
1756 'selectionPrefix' => $selectionPrefix,
1757 'stripFromSelectionName' => $stripFromSelectionName,
1758 'errorMode' => $errorMode
1759 );
1760 }
1761 }
1762
1763 /**
1764 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1765 * The label can be used in scripts with TYPO3.setting.<key>
1766 * Need extJs loaded
1767 *
1768 * @param string $namespace
1769 * @param string $key
1770 * @param string $value
1771 * @return void
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 * @return void
1800 */
1801 public function addInlineSettingArray($namespace, array $array)
1802 {
1803 if ($namespace) {
1804 if (strpos($namespace, '.')) {
1805 $parts = explode('.', $namespace);
1806 $a = &$this->inlineSettings;
1807 foreach ($parts as $part) {
1808 $a = &$a[$part];
1809 }
1810 $a = array_merge((array)$a, $array);
1811 } else {
1812 $this->inlineSettings[$namespace] = array_merge((array)$this->inlineSettings[$namespace], $array);
1813 }
1814 } else {
1815 $this->inlineSettings = array_merge($this->inlineSettings, $array);
1816 }
1817 }
1818
1819 /**
1820 * Adds content to body content
1821 *
1822 * @param string $content
1823 * @return void
1824 */
1825 public function addBodyContent($content)
1826 {
1827 $this->bodyContent .= $content;
1828 }
1829
1830 /*****************************************************/
1831 /* */
1832 /* Render Functions */
1833 /* */
1834 /*****************************************************/
1835 /**
1836 * Render the section (Header or Footer)
1837 *
1838 * @param int $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1839 * @return string Content of rendered section
1840 */
1841 public function render($part = self::PART_COMPLETE)
1842 {
1843 $this->prepareRendering();
1844 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1845 $metaTags = implode(LF, $this->metaTags);
1846 $markerArray = $this->getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags);
1847 $template = $this->getTemplateForPart($part);
1848
1849 // The page renderer needs a full reset, even when only rendering one part of the page
1850 // This means that you can only register footer files *after* the header has been already rendered.
1851 // In case you render the footer part first, header files can only be added *after* the footer has been rendered
1852 $this->reset();
1853 $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
1854 return trim($templateService->substituteMarkerArray($template, $markerArray, '###|###'));
1855 }
1856
1857 /**
1858 * Render the page but not the JavaScript and CSS Files
1859 *
1860 * @param string $substituteHash The hash that is used for the placehoder markers
1861 * @access private
1862 * @return string Content of rendered section
1863 */
1864 public function renderPageWithUncachedObjects($substituteHash)
1865 {
1866 $this->prepareRendering();
1867 $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
1868 $template = $this->getTemplateForPart(self::PART_COMPLETE);
1869 $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
1870 return trim($templateService->substituteMarkerArray($template, $markerArray, '###|###'));
1871 }
1872
1873 /**
1874 * Renders the JavaScript and CSS files that have been added during processing
1875 * of uncached content objects (USER_INT, COA_INT)
1876 *
1877 * @param string $cachedPageContent
1878 * @param string $substituteHash The hash that is used for the placehoder markers
1879 * @access private
1880 * @return string
1881 */
1882 public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash)
1883 {
1884 $this->prepareRendering();
1885 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1886 $title = $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '';
1887 $markerArray = array(
1888 '<!-- ###TITLE' . $substituteHash . '### -->' => $title,
1889 '<!-- ###CSS_LIBS' . $substituteHash . '### -->' => $cssLibs,
1890 '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
1891 '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
1892 '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
1893 '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
1894 '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
1895 '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF, $this->headerData),
1896 '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF, $this->footerData),
1897 '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
1898 '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
1899 '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline
1900 );
1901 foreach ($markerArray as $placeHolder => $content) {
1902 $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
1903 }
1904 $this->reset();
1905 return $cachedPageContent;
1906 }
1907
1908 /**
1909 * Remove ending slashes from static header block
1910 * if the page is beeing rendered as html (not xhtml)
1911 * and define property $this->endingSlash for further use
1912 *
1913 * @return void
1914 */
1915 protected function prepareRendering()
1916 {
1917 if ($this->getRenderXhtml()) {
1918 $this->endingSlash = ' /';
1919 } else {
1920 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
1921 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
1922 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
1923 $this->endingSlash = '';
1924 }
1925 }
1926
1927 /**
1928 * Renders all JavaScript and CSS
1929 *
1930 * @return array<string>
1931 */
1932 protected function renderJavaScriptAndCss()
1933 {
1934 $this->executePreRenderHook();
1935 $mainJsLibs = $this->renderMainJavaScriptLibraries();
1936 if ($this->concatenateFiles || $this->concatenateJavascript || $this->concatenateCss) {
1937 // Do the file concatenation
1938 $this->doConcatenate();
1939 }
1940 if ($this->compressCss || $this->compressJavascript) {
1941 // Do the file compression
1942 $this->doCompress();
1943 }
1944 $this->executeRenderPostTransformHook();
1945 $cssLibs = $this->renderCssLibraries();
1946 $cssFiles = $this->renderCssFiles();
1947 $cssInline = $this->renderCssInline();
1948 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
1949 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
1950 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
1951 $jsLibs = $mainJsLibs . $jsLibs;
1952 if ($this->moveJsFromHeaderToFooter) {
1953 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
1954 $jsLibs = '';
1955 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
1956 $jsFiles = '';
1957 $jsFooterInline = $jsInline . LF . $jsFooterInline;
1958 $jsInline = '';
1959 }
1960 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1961 return array($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1962 }
1963
1964 /**
1965 * Fills the marker array with the given strings and trims each value
1966 *
1967 * @param $jsLibs string
1968 * @param $jsFiles string
1969 * @param $jsFooterFiles string
1970 * @param $cssLibs string
1971 * @param $cssFiles string
1972 * @param $jsInline string
1973 * @param $cssInline string
1974 * @param $jsFooterInline string
1975 * @param $jsFooterLibs string
1976 * @param $metaTags string
1977 * @return array Marker array
1978 */
1979 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags)
1980 {
1981 $markerArray = array(
1982 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1983 'HTMLTAG' => $this->htmlTag,
1984 'HEADTAG' => $this->headTag,
1985 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1986 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1987 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1988 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1989 'CSS_LIBS' => $cssLibs,
1990 'CSS_INCLUDE' => $cssFiles,
1991 'CSS_INLINE' => $cssInline,
1992 'JS_INLINE' => $jsInline,
1993 'JS_INCLUDE' => $jsFiles,
1994 'JS_LIBS' => $jsLibs,
1995 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1996 'META' => $metaTags,
1997 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
1998 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
1999 'JS_LIBS_FOOTER' => $jsFooterLibs,
2000 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
2001 'JS_INLINE_FOOTER' => $jsFooterInline,
2002 'BODY' => $this->bodyContent
2003 );
2004 $markerArray = array_map('trim', $markerArray);
2005 return $markerArray;
2006 }
2007
2008 /**
2009 * Fills the marker array with the given strings and trims each value
2010 *
2011 * @param string $substituteHash The hash that is used for the placehoder markers
2012 * @return array Marker array
2013 */
2014 protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash)
2015 {
2016 $markerArray = array(
2017 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
2018 'HTMLTAG' => $this->htmlTag,
2019 'HEADTAG' => $this->headTag,
2020 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
2021 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
2022 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
2023 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
2024 'META' => implode(LF, $this->metaTags),
2025 'BODY' => $this->bodyContent,
2026 'TITLE' => '<!-- ###TITLE' . $substituteHash . '### -->',
2027 'CSS_LIBS' => '<!-- ###CSS_LIBS' . $substituteHash . '### -->',
2028 'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
2029 'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
2030 'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
2031 'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
2032 'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
2033 'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
2034 'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
2035 'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
2036 'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
2037 'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->'
2038 );
2039 $markerArray = array_map('trim', $markerArray);
2040 return $markerArray;
2041 }
2042
2043 /**
2044 * Reads the template file and returns the requested part as string
2045 *
2046 * @param int $part
2047 * @return string
2048 */
2049 protected function getTemplateForPart($part)
2050 {
2051 $templateFile = GeneralUtility::getFileAbsFileName($this->templateFile);
2052 if (is_file($templateFile)) {
2053 $template = file_get_contents($templateFile);
2054 if ($this->removeLineBreaksFromTemplate) {
2055 $template = strtr($template, array(LF => '', CR => ''));
2056 }
2057 if ($part !== self::PART_COMPLETE) {
2058 $templatePart = explode('###BODY###', $template);
2059 $template = $templatePart[$part - 1];
2060 }
2061 } else {
2062 $template = '';
2063 }
2064 return $template;
2065 }
2066
2067 /**
2068 * Helper function for render the main JavaScript libraries,
2069 * currently: RequireJS, jQuery, ExtJS
2070 *
2071 * @return string Content with JavaScript libraries
2072 */
2073 protected function renderMainJavaScriptLibraries()
2074 {
2075 $out = '';
2076
2077 // Include RequireJS
2078 if ($this->addRequireJs) {
2079 // load the paths of the requireJS configuration
2080 $out .= GeneralUtility::wrapJS('var require = ' . json_encode($this->requireJsConfig)) . LF;
2081 // directly after that, include the require.js file
2082 $out .= '<script src="' . $this->processJsFile($this->requireJsPath . 'require.js') . '" type="text/javascript"></script>' . LF;
2083 }
2084
2085 // Include jQuery Core for each namespace, depending on the version and source
2086 if (!empty($this->jQueryVersions)) {
2087 foreach ($this->jQueryVersions as $namespace => $jQueryVersion) {
2088 $out .= $this->renderJqueryScriptTag($jQueryVersion['version'], $jQueryVersion['source'], $namespace);
2089 }
2090 }
2091 // Include extJS
2092 if ($this->addExtJS) {
2093 // Use the base adapter all the time
2094 $out .= '<script src="' . $this->processJsFile($this->extJsPath . 'adapter/ext-base' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') . '" type="text/javascript"></script>' . LF;
2095 $out .= '<script src="' . $this->processJsFile($this->extJsPath . 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') . '" type="text/javascript"></script>' . LF;
2096 // Add extJS localization
2097 // Load standard ISO mapping and modify for use with ExtJS
2098 $localeMap = $this->locales->getIsoMapping();
2099 $localeMap[''] = 'en';
2100 $localeMap['default'] = 'en';
2101 // Greek
2102 $localeMap['gr'] = 'el_GR';
2103 // Norwegian Bokmaal
2104 $localeMap['no'] = 'no_BO';
2105 // Swedish
2106 $localeMap['se'] = 'se_SV';
2107 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
2108 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
2109 if (file_exists(PATH_site . $extJsLocaleFile)) {
2110 $out .= '<script src="' . $this->processJsFile($extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
2111 }
2112 // Remove extjs from JScodeLibArray
2113 unset($this->jsFiles[$this->extJsPath . 'ext-all.js'], $this->jsFiles[$this->extJsPath . 'ext-all-debug.js']);
2114 }
2115 $this->loadJavaScriptLanguageStrings();
2116 if (TYPO3_MODE === 'BE') {
2117 $this->addAjaxUrlsToInlineSettings();
2118 }
2119 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
2120 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
2121 if ($this->addExtJS) {
2122 // Set clear.gif, move it on top, add handler code
2123 $code = '';
2124 if (!empty($this->extOnReadyCode)) {
2125 foreach ($this->extOnReadyCode as $block) {
2126 $code .= $block;
2127 }
2128 }
2129 $clearGifPath = htmlspecialchars(GeneralUtility::locationHeaderUrl(ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/Images/clear.gif'));
2130 $out .= $this->inlineJavascriptWrap[0] . '
2131 Ext.ns("TYPO3");
2132 Ext.BLANK_IMAGE_URL = "' . $clearGifPath . '";
2133 Ext.SSL_SECURE_URL = "' . $clearGifPath . '";' . LF
2134 . $inlineSettings
2135 . 'Ext.onReady(function() {'
2136 . $code
2137 . ' });'
2138 . $this->inlineJavascriptWrap[1];
2139 $this->extOnReadyCode = array();
2140 // Include TYPO3.l10n object
2141 if (TYPO3_MODE === 'BE') {
2142 $out .= '<script src="' . $this->processJsFile(ExtensionManagementUtility::extRelPath('lang') . 'Resources/Public/JavaScript/Typo3Lang.js') . '" type="text/javascript" charset="utf-8"></script>' . LF;
2143 }
2144 if ($this->extJScss) {
2145 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
2146 $this->addCssLibrary($GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', true);
2147 } else {
2148 $this->addCssLibrary($this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', true);
2149 }
2150 }
2151 if ($this->extJStheme) {
2152 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
2153 $this->addCssLibrary($GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', true);
2154 } else {
2155 $this->addCssLibrary($this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', true);
2156 }
2157 }
2158 } else {
2159 // no extJS loaded, but still inline settings
2160 if ($inlineSettings !== '') {
2161 // make sure the global TYPO3 is available
2162 $inlineSettings = 'var TYPO3 = TYPO3 || {};' . CRLF . $inlineSettings;
2163 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
2164 // Add language module only if also jquery is guaranteed to be there
2165 if (TYPO3_MODE === 'BE' && !empty($this->jQueryVersions)) {
2166 $this->loadRequireJsModule('TYPO3/CMS/Lang/Lang');
2167 }
2168 }
2169 }
2170 return $out;
2171 }
2172
2173 /**
2174 * Load the language strings into JavaScript
2175 */
2176 protected function loadJavaScriptLanguageStrings()
2177 {
2178 if (!empty($this->inlineLanguageLabelFiles)) {
2179 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
2180 $this->includeLanguageFileForInline($languageLabelFile['fileRef'], $languageLabelFile['selectionPrefix'], $languageLabelFile['stripFromSelectionName'], $languageLabelFile['errorMode']);
2181 }
2182 }
2183 $this->inlineLanguageLabelFiles = array();
2184 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
2185 if (TYPO3_MODE === 'FE' && $this->getCharSet() !== 'utf-8') {
2186 if ($this->inlineLanguageLabels) {
2187 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
2188 }
2189 if ($this->inlineSettings) {
2190 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
2191 }
2192 }
2193 }
2194
2195 /**
2196 * Make URLs to all backend ajax handlers available as inline setting.
2197 */
2198 protected function addAjaxUrlsToInlineSettings()
2199 {
2200 $ajaxUrls = array();
2201 // Note: this method of adding Ajax URLs is @deprecated as of TYPO3 v8, and will be removed in TYPO3 v9
2202 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'] as $ajaxHandler => $_) {
2203 $ajaxUrls[$ajaxHandler] = BackendUtility::getAjaxUrl($ajaxHandler);
2204 }
2205
2206 // also add the ajax-based routes
2207 /** @var UriBuilder $uriBuilder */
2208 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
2209 /** @var Router $router */
2210 $router = GeneralUtility::makeInstance(Router::class);
2211 $routes = $router->getRoutes();
2212 foreach ($routes as $routeIdentifier => $route) {
2213 if ($route->getOption('ajax')) {
2214 $uri = (string)$uriBuilder->buildUriFromRoute($routeIdentifier);
2215 // use the shortened value in order to use this in JavaScript
2216 $routeIdentifier = str_replace('ajax_', '', $routeIdentifier);
2217 $ajaxUrls[$routeIdentifier] = $uri;
2218 }
2219 }
2220
2221 $this->inlineSettings['ajaxUrls'] = $ajaxUrls;
2222 }
2223
2224 /**
2225 * Renders the HTML script tag for the given jQuery version.
2226 *
2227 * @param string $version The jQuery version that should be included, either "latest" or any available version
2228 * @param string $source The location of the jQuery source, can be "local", "google", "msn" or "jquery
2229 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored
2230 * @return string
2231 */
2232 protected function renderJqueryScriptTag($version, $source, $namespace)
2233 {
2234 switch (true) {
2235 case isset($this->jQueryCdnUrls[$source]):
2236 if ($this->enableJqueryDebug) {
2237 $minifyPart = '';
2238 } else {
2239 $minifyPart = '.min';
2240 }
2241 $jQueryFileName = sprintf($this->jQueryCdnUrls[$source], $version, $minifyPart);
2242 break;
2243 case $source === 'local':
2244 $jQueryFileName = $this->jQueryPath . 'jquery-' . rawurlencode($version);
2245 if ($this->enableJqueryDebug) {
2246 $jQueryFileName .= '.js';
2247 } else {
2248 $jQueryFileName .= '.min.js';
2249 }
2250 break;
2251 default:
2252 $jQueryFileName = $source;
2253 }
2254 // Include the jQuery Core
2255 $scriptTag = '<script src="' . htmlspecialchars($jQueryFileName) . '" type="text/javascript"></script>' . LF;
2256 // Set the noConflict mode to be available via "TYPO3.jQuery" in all installations
2257 switch ($namespace) {
2258 case self::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT:
2259 $scriptTag .= GeneralUtility::wrapJS('jQuery.noConflict();') . LF;
2260 break;
2261 case self::JQUERY_NAMESPACE_NONE:
2262 break;
2263 case self::JQUERY_NAMESPACE_DEFAULT:
2264
2265 default:
2266 $scriptTag .= GeneralUtility::wrapJS('var TYPO3 = TYPO3 || {}; TYPO3.' . $namespace . ' = jQuery.noConflict(true);') . LF;
2267 }
2268 return $scriptTag;
2269 }
2270
2271 /**
2272 * Render CSS library files
2273 *
2274 * @return string
2275 */
2276 protected function renderCssLibraries()
2277 {
2278 $cssFiles = '';
2279 if (!empty($this->cssLibs)) {
2280 foreach ($this->cssLibs as $file => $properties) {
2281 $file = GeneralUtility::resolveBackPath($file);
2282 $file = GeneralUtility::createVersionNumberedFilename($file);
2283 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2284 . '" type="text/css" href="' . htmlspecialchars($file)
2285 . '" media="' . htmlspecialchars($properties['media']) . '"'
2286 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2287 . $this->endingSlash . '>';
2288 if ($properties['allWrap']) {
2289 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2290 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2291 }
2292 $tag .= LF;
2293 if ($properties['forceOnTop']) {
2294 $cssFiles = $tag . $cssFiles;
2295 } else {
2296 $cssFiles .= $tag;
2297 }
2298 }
2299 }
2300 return $cssFiles;
2301 }
2302
2303 /**
2304 * Render CSS files
2305 *
2306 * @return string
2307 */
2308 protected function renderCssFiles()
2309 {
2310 $cssFiles = '';
2311 if (!empty($this->cssFiles)) {
2312 foreach ($this->cssFiles as $file => $properties) {
2313 $file = GeneralUtility::resolveBackPath($file);
2314 $file = GeneralUtility::createVersionNumberedFilename($file);
2315 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2316 . '" type="text/css" href="' . htmlspecialchars($file)
2317 . '" media="' . htmlspecialchars($properties['media']) . '"'
2318 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2319 . $this->endingSlash . '>';
2320 if ($properties['allWrap']) {
2321 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2322 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2323 }
2324 $tag .= LF;
2325 if ($properties['forceOnTop']) {
2326 $cssFiles = $tag . $cssFiles;
2327 } else {
2328 $cssFiles .= $tag;
2329 }
2330 }
2331 }
2332 return $cssFiles;
2333 }
2334
2335 /**
2336 * Render inline CSS
2337 *
2338 * @return string
2339 */
2340 protected function renderCssInline()
2341 {
2342 $cssInline = '';
2343 if (!empty($this->cssInline)) {
2344 foreach ($this->cssInline as $name => $properties) {
2345 $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2346 if ($properties['forceOnTop']) {
2347 $cssInline = $cssCode . $cssInline;
2348 } else {
2349 $cssInline .= $cssCode;
2350 }
2351 }
2352 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
2353 }
2354 return $cssInline;
2355 }
2356
2357 /**
2358 * Render JavaScipt libraries
2359 *
2360 * @return array<string> jsLibs and jsFooterLibs strings
2361 */
2362 protected function renderAdditionalJavaScriptLibraries()
2363 {
2364 $jsLibs = '';
2365 $jsFooterLibs = '';
2366 if (!empty($this->jsLibs)) {
2367 foreach ($this->jsLibs as $properties) {
2368 $properties['file'] = GeneralUtility::resolveBackPath($properties['file']);
2369 $properties['file'] = GeneralUtility::createVersionNumberedFilename($properties['file']);
2370 $async = ($properties['async']) ? ' async="async"' : '';
2371 $integrity = ($properties['integrity']) ? ' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2372 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $integrity . '></script>';
2373 if ($properties['allWrap']) {
2374 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2375 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2376 }
2377 $tag .= LF;
2378 if ($properties['forceOnTop']) {
2379 if ($properties['section'] === self::PART_HEADER) {
2380 $jsLibs = $tag . $jsLibs;
2381 } else {
2382 $jsFooterLibs = $tag . $jsFooterLibs;
2383 }
2384 } else {
2385 if ($properties['section'] === self::PART_HEADER) {
2386 $jsLibs .= $tag;
2387 } else {
2388 $jsFooterLibs .= $tag;
2389 }
2390 }
2391 }
2392 }
2393 if ($this->moveJsFromHeaderToFooter) {
2394 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
2395 $jsLibs = '';
2396 }
2397 return array($jsLibs, $jsFooterLibs);
2398 }
2399
2400 /**
2401 * Render JavaScript files
2402 *
2403 * @return array<string> jsFiles and jsFooterFiles strings
2404 */
2405 protected function renderJavaScriptFiles()
2406 {
2407 $jsFiles = '';
2408 $jsFooterFiles = '';
2409 if (!empty($this->jsFiles)) {
2410 foreach ($this->jsFiles as $file => $properties) {
2411 $file = GeneralUtility::resolveBackPath($file);
2412 $file = GeneralUtility::createVersionNumberedFilename($file);
2413 $async = ($properties['async']) ? ' async="async"' : '';
2414 $integrity = ($properties['integrity']) ? ' integrity="' . htmlspecialchars($properties['integrity']) . '"' : '';
2415 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . $integrity . '></script>';
2416 if ($properties['allWrap']) {
2417 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2418 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2419 }
2420 $tag .= LF;
2421 if ($properties['forceOnTop']) {
2422 if ($properties['section'] === self::PART_HEADER) {
2423 $jsFiles = $tag . $jsFiles;
2424 } else {
2425 $jsFooterFiles = $tag . $jsFooterFiles;
2426 }
2427 } else {
2428 if ($properties['section'] === self::PART_HEADER) {
2429 $jsFiles .= $tag;
2430 } else {
2431 $jsFooterFiles .= $tag;
2432 }
2433 }
2434 }
2435 }
2436 if ($this->moveJsFromHeaderToFooter) {
2437 $jsFooterFiles = $jsFiles . $jsFooterFiles;
2438 $jsFiles = '';
2439 }
2440 return array($jsFiles, $jsFooterFiles);
2441 }
2442
2443 /**
2444 * Render inline JavaScript
2445 *
2446 * @return array<string> jsInline and jsFooterInline string
2447 */
2448 protected function renderInlineJavaScript()
2449 {
2450 $jsInline = '';
2451 $jsFooterInline = '';
2452 if (!empty($this->jsInline)) {
2453 foreach ($this->jsInline as $name => $properties) {
2454 $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2455 if ($properties['forceOnTop']) {
2456 if ($properties['section'] === self::PART_HEADER) {
2457 $jsInline = $jsCode . $jsInline;
2458 } else {
2459 $jsFooterInline = $jsCode . $jsFooterInline;
2460 }
2461 } else {
2462 if ($properties['section'] === self::PART_HEADER) {
2463 $jsInline .= $jsCode;
2464 } else {
2465 $jsFooterInline .= $jsCode;
2466 }
2467 }
2468 }
2469 }
2470 if ($jsInline) {
2471 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
2472 }
2473 if ($jsFooterInline) {
2474 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
2475 }
2476 if ($this->moveJsFromHeaderToFooter) {
2477 $jsFooterInline = $jsInline . $jsFooterInline;
2478 $jsInline = '';
2479 }
2480 return array($jsInline, $jsFooterInline);
2481 }
2482
2483 /**
2484 * Include language file for inline usage
2485 *
2486 * @param string $fileRef
2487 * @param string $selectionPrefix
2488 * @param string $stripFromSelectionName
2489 * @param int $errorMode
2490 * @return void
2491 * @throws \RuntimeException
2492 */
2493 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0)
2494 {
2495 if (!isset($this->lang) || !isset($this->charSet)) {
2496 throw new \RuntimeException('Language and character encoding are not set.', 1284906026);
2497 }
2498 $labelsFromFile = array();
2499 $allLabels = $this->readLLfile($fileRef, $errorMode);
2500 if ($allLabels !== false) {
2501 // Merge language specific translations:
2502 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
2503 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
2504 } else {
2505 $labels = $allLabels['default'];
2506 }
2507 // Iterate through all locallang labels:
2508 foreach ($labels as $label => $value) {
2509 // If $selectionPrefix is set, only respect labels that start with $selectionPrefix
2510 if ($selectionPrefix === '' || strpos($label, $selectionPrefix) === 0) {
2511 // Remove substring $stripFromSelectionName from label
2512 $label = str_replace($stripFromSelectionName, '', $label);
2513 $labelsFromFile[$label] = $value;
2514 }
2515 }
2516 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
2517 }
2518 }
2519
2520 /**
2521 * Reads a locallang file.
2522 *
2523 * @param string $fileRef Reference to a relative filename to include.
2524 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
2525 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2526 */
2527 protected function readLLfile($fileRef, $errorMode = 0)
2528 {
2529 /** @var $languageFactory LocalizationFactory */
2530 $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
2531
2532 if ($this->lang !== 'default') {
2533 $languages = array_reverse($this->languageDependencies);
2534 // At least we need to have English
2535 if (empty($languages)) {
2536 $languages[] = 'default';
2537 }
2538 } else {
2539 $languages = array('default');
2540 }
2541
2542 $localLanguage = array();
2543 foreach ($languages as $language) {
2544 $tempLL = $languageFactory->getParsedData($fileRef, $language, $this->charSet, $errorMode);
2545
2546 $localLanguage['default'] = $tempLL['default'];
2547 if (!isset($localLanguage[$this->lang])) {
2548 $localLanguage[$this->lang] = $localLanguage['default'];
2549 }
2550 if ($this->lang !== 'default' && isset($tempLL[$language])) {
2551 // Merge current language labels onto labels from previous language
2552 // This way we have a labels with fall back applied
2553 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($localLanguage[$this->lang], $tempLL[$language], true, false);
2554 }
2555 }
2556
2557 return $localLanguage;
2558 }
2559
2560 /*****************************************************/
2561 /* */
2562 /* Tools */
2563 /* */
2564 /*****************************************************/
2565 /**
2566 * Concatenate files into one file
2567 * registered handler
2568 *
2569 * @return void
2570 */
2571 protected function doConcatenate()
2572 {
2573 $this->doConcatenateCss();
2574 $this->doConcatenateJavaScript();
2575 }
2576
2577 /**
2578 * Concatenate JavaScript files according to the configuration.
2579 *
2580 * @return void
2581 */
2582 protected function doConcatenateJavaScript()
2583 {
2584 if ($this->concatenateFiles || $this->concatenateJavascript) {
2585 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'])) {
2586 // use external concatenation routine
2587 $params = array(
2588 'jsLibs' => &$this->jsLibs,
2589 'jsFiles' => &$this->jsFiles,
2590 'jsFooterFiles' => &$this->jsFooterFiles,
2591 'headerData' => &$this->headerData,
2592 'footerData' => &$this->footerData
2593 );
2594 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'], $params, $this);
2595 } else {
2596 $this->jsLibs = $this->getCompressor()->concatenateJsFiles($this->jsLibs);
2597 $this->jsFiles = $this->getCompressor()->concatenateJsFiles($this->jsFiles);
2598 $this->jsFooterFiles = $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles);
2599 }
2600 }
2601 }
2602
2603 /**
2604 * Concatenate CSS files according to configuration.
2605 *
2606 * @return void
2607 */
2608 protected function doConcatenateCss()
2609 {
2610 if ($this->concatenateFiles || $this->concatenateCss) {
2611 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'])) {
2612 // use external concatenation routine
2613 $params = array(
2614 'cssFiles' => &$this->cssFiles,
2615 'cssLibs' => &$this->cssLibs,
2616 'headerData' => &$this->headerData,
2617 'footerData' => &$this->footerData
2618 );
2619 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this);
2620 } else {
2621 $cssOptions = array();
2622 if (TYPO3_MODE === 'BE') {
2623 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
2624 }
2625 $this->cssLibs = $this->getCompressor()->concatenateCssFiles($this->cssLibs, $cssOptions);
2626 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
2627 }
2628 }
2629 }
2630
2631 /**
2632 * Compresses inline code
2633 *
2634 * @return void
2635 */
2636 protected function doCompress()
2637 {
2638 $this->doCompressJavaScript();
2639 $this->doCompressCss();
2640 }
2641
2642 /**
2643 * Compresses CSS according to configuration.
2644 *
2645 * @return void
2646 */
2647 protected function doCompressCss()
2648 {
2649 if ($this->compressCss) {
2650 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'])) {
2651 // Use external compression routine
2652 $params = array(
2653 'cssInline' => &$this->cssInline,
2654 'cssFiles' => &$this->cssFiles,
2655 'cssLibs' => &$this->cssLibs,
2656 'headerData' => &$this->headerData,
2657 'footerData' => &$this->footerData
2658 );
2659 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
2660 } else {
2661 $this->cssLibs = $this->getCompressor()->compressCssFiles($this->cssLibs);
2662 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
2663 }
2664 }
2665 }
2666
2667 /**
2668 * Compresses JavaScript according to configuration.
2669 *
2670 * @return void
2671 */
2672 protected function doCompressJavaScript()
2673 {
2674 if ($this->compressJavascript) {
2675 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'])) {
2676 // Use external compression routine
2677 $params = array(
2678 'jsInline' => &$this->jsInline,
2679 'jsFooterInline' => &$this->jsFooterInline,
2680 'jsLibs' => &$this->jsLibs,
2681 'jsFiles' => &$this->jsFiles,
2682 'jsFooterFiles' => &$this->jsFooterFiles,
2683 'headerData' => &$this->headerData,
2684 'footerData' => &$this->footerData
2685 );
2686 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
2687 } else {
2688 // Traverse the arrays, compress files
2689 if (!empty($this->jsInline)) {
2690 foreach ($this->jsInline as $name => $properties) {
2691 if ($properties['compress']) {
2692 $error = '';
2693 $this->jsInline[$name]['code'] = GeneralUtility::minifyJavaScript($properties['code'], $error);
2694 if ($error) {
2695 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
2696 }
2697 }
2698 }
2699 }
2700 $this->jsLibs = $this->getCompressor()->compressJsFiles($this->jsLibs);
2701 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
2702 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
2703 }
2704 }
2705 }
2706
2707 /**
2708 * Returns instance of \TYPO3\CMS\Core\Resource\ResourceCompressor
2709 *
2710 * @return \TYPO3\CMS\Core\Resource\ResourceCompressor
2711 */
2712 protected function getCompressor()
2713 {
2714 if ($this->compressor === null) {
2715 $this->compressor = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceCompressor::class);
2716 }
2717 return $this->compressor;
2718 }
2719
2720 /**
2721 * Processes a Javascript file dependent on the current context
2722 *
2723 * Adds the version number for Frontend, compresses the file for Backend
2724 *
2725 * @param string $filename Filename
2726 * @return string New filename
2727 */
2728 protected function processJsFile($filename)
2729 {
2730 if ($this->compressJavascript) {
2731 return $this->getCompressor()->compressJsFile($filename);
2732 } elseif (TYPO3_MODE === 'FE') {
2733 return GeneralUtility::createVersionNumberedFilename($filename);
2734 } else {
2735 return $filename;
2736 }
2737 }
2738
2739 /**
2740 * Returns global frontend controller
2741 *
2742 * @return TypoScriptFrontendController
2743 */
2744 protected function getTypoScriptFrontendController()
2745 {
2746 return $GLOBALS['TSFE'];
2747 }
2748
2749 /**
2750 * Returns global language service instance
2751 *
2752 * @return \TYPO3\CMS\Lang\LanguageService
2753 */
2754 protected function getLanguageService()
2755 {
2756 return $GLOBALS['LANG'];
2757 }
2758
2759 /*****************************************************/
2760 /* */
2761 /* Hooks */
2762 /* */
2763 /*****************************************************/
2764 /**
2765 * Execute PreRenderHook for possible manipulation
2766 *
2767 * @return void
2768 */
2769 protected function executePreRenderHook()
2770 {
2771 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
2772 $params = array(
2773 'jsLibs' => &$this->jsLibs,
2774 'jsFooterLibs' => &$this->jsFooterLibs,
2775 'jsFiles' => &$this->jsFiles,
2776 'jsFooterFiles' => &$this->jsFooterFiles,
2777 'cssLibs' => &$this->cssLibs,
2778 'cssFiles' => &$this->cssFiles,
2779 'headerData' => &$this->headerData,
2780 'footerData' => &$this->footerData,
2781 'jsInline' => &$this->jsInline,
2782 'jsFooterInline' => &$this->jsFooterInline,
2783 'cssInline' => &$this->cssInline
2784 );
2785 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
2786 GeneralUtility::callUserFunction($hook, $params, $this);
2787 }
2788 }
2789 }
2790
2791 /**
2792 * PostTransform for possible manipulation of concatenated and compressed files
2793 *
2794 * @return void
2795 */
2796 protected function executeRenderPostTransformHook()
2797 {
2798 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
2799 $params = array(
2800 'jsLibs' => &$this->jsLibs,
2801 'jsFooterLibs' => &$this->jsFooterLibs,
2802 'jsFiles' => &$this->jsFiles,
2803 'jsFooterFiles' => &$this->jsFooterFiles,
2804 'cssLibs' => &$this->cssLibs,
2805 'cssFiles' => &$this->cssFiles,
2806 'headerData' => &$this->headerData,
2807 'footerData' => &$this->footerData,
2808 'jsInline' => &$this->jsInline,
2809 'jsFooterInline' => &$this->jsFooterInline,
2810 'cssInline' => &$this->cssInline
2811 );
2812 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
2813 GeneralUtility::callUserFunction($hook, $params, $this);
2814 }
2815 }
2816 }
2817
2818 /**
2819 * Execute postRenderHook for possible manipulation
2820 *
2821 * @param $jsLibs string
2822 * @param $jsFiles string
2823 * @param $jsFooterFiles string
2824 * @param $cssLibs string
2825 * @param $cssFiles string
2826 * @param $jsInline string
2827 * @param $cssInline string
2828 * @param $jsFooterInline string
2829 * @param $jsFooterLibs string
2830 * @return void
2831 */
2832 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssLibs, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs)
2833 {
2834 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
2835 $params = array(
2836 'jsLibs' => &$jsLibs,
2837 'jsFiles' => &$jsFiles,
2838 'jsFooterFiles' => &$jsFooterFiles,
2839 'cssLibs' => &$cssLibs,
2840 'cssFiles' => &$cssFiles,
2841 'headerData' => &$this->headerData,
2842 'footerData' => &$this->footerData,
2843 'jsInline' => &$jsInline,
2844 'cssInline' => &$cssInline,
2845 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType,
2846 'htmlTag' => &$this->htmlTag,
2847 'headTag' => &$this->headTag,
2848 'charSet' => &$this->charSet,
2849 'metaCharsetTag' => &$this->metaCharsetTag,
2850 'shortcutTag' => &$this->shortcutTag,
2851 'inlineComments' => &$this->inlineComments,
2852 'baseUrl' => &$this->baseUrl,
2853 'baseUrlTag' => &$this->baseUrlTag,
2854 'favIcon' => &$this->favIcon,
2855 'iconMimeType' => &$this->iconMimeType,
2856 'titleTag' => &$this->titleTag,
2857 'title' => &$this->title,
2858 'metaTags' => &$this->metaTags,
2859 'jsFooterInline' => &$jsFooterInline,
2860 'jsFooterLibs' => &$jsFooterLibs,
2861 'bodyContent' => &$this->bodyContent
2862 );
2863 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
2864 GeneralUtility::callUserFunction($hook, $params, $this);
2865 }
2866 }
2867 }
2868 }