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