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