[TASK] Refactor debugger console
[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 * @return void
1159 */
1160 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE) {
1161 if (!$type) {
1162 $type = 'text/javascript';
1163 }
1164 if (!in_array(strtolower($name), $this->jsLibs)) {
1165 $this->jsLibs[strtolower($name)] = array(
1166 'file' => $file,
1167 'type' => $type,
1168 'section' => self::PART_HEADER,
1169 'compress' => $compress,
1170 'forceOnTop' => $forceOnTop,
1171 'allWrap' => $allWrap,
1172 'excludeFromConcatenation' => $excludeFromConcatenation,
1173 'splitChar' => $splitChar,
1174 'async' => $async
1175 );
1176 }
1177 }
1178
1179 /**
1180 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
1181 *
1182 * @param string $name Arbitrary identifier
1183 * @param string $file File name
1184 * @param string $type Content Type
1185 * @param bool $compress Flag if library should be compressed
1186 * @param bool $forceOnTop Flag if added library should be inserted at begin of this block
1187 * @param string $allWrap
1188 * @param bool $excludeFromConcatenation
1189 * @param string $splitChar The char used to split the allWrap value, default is "|"
1190 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1191 * @return void
1192 */
1193 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE) {
1194 if (!$type) {
1195 $type = 'text/javascript';
1196 }
1197 if (!in_array(strtolower($name), $this->jsLibs)) {
1198 $this->jsLibs[strtolower($name)] = array(
1199 'file' => $file,
1200 'type' => $type,
1201 'section' => self::PART_FOOTER,
1202 'compress' => $compress,
1203 'forceOnTop' => $forceOnTop,
1204 'allWrap' => $allWrap,
1205 'excludeFromConcatenation' => $excludeFromConcatenation,
1206 'splitChar' => $splitChar,
1207 'async' => $async
1208 );
1209 }
1210 }
1211
1212 /**
1213 * Adds JS file
1214 *
1215 * @param string $file File name
1216 * @param string $type Content Type
1217 * @param bool $compress
1218 * @param bool $forceOnTop
1219 * @param string $allWrap
1220 * @param bool $excludeFromConcatenation
1221 * @param string $splitChar The char used to split the allWrap value, default is "|"
1222 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1223 * @return void
1224 */
1225 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE) {
1226 if (!$type) {
1227 $type = 'text/javascript';
1228 }
1229 if (!isset($this->jsFiles[$file])) {
1230 if (strpos($file, 'ajax.php?') !== FALSE) {
1231 $compress = FALSE;
1232 }
1233 $this->jsFiles[$file] = array(
1234 'file' => $file,
1235 'type' => $type,
1236 'section' => self::PART_HEADER,
1237 'compress' => $compress,
1238 'forceOnTop' => $forceOnTop,
1239 'allWrap' => $allWrap,
1240 'excludeFromConcatenation' => $excludeFromConcatenation,
1241 'splitChar' => $splitChar,
1242 'async' => $async
1243 );
1244 }
1245 }
1246
1247 /**
1248 * Adds JS file to footer
1249 *
1250 * @param string $file File name
1251 * @param string $type Content Type
1252 * @param bool $compress
1253 * @param bool $forceOnTop
1254 * @param string $allWrap
1255 * @param bool $excludeFromConcatenation
1256 * @param string $splitChar The char used to split the allWrap value, default is "|"
1257 * @param bool $async Flag if property 'async="async"' should be added to JavaScript tags
1258 * @return void
1259 */
1260 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|', $async = FALSE) {
1261 if (!$type) {
1262 $type = 'text/javascript';
1263 }
1264 if (!isset($this->jsFiles[$file])) {
1265 if (strpos($file, 'ajax.php?') !== FALSE) {
1266 $compress = FALSE;
1267 }
1268 $this->jsFiles[$file] = array(
1269 'file' => $file,
1270 'type' => $type,
1271 'section' => self::PART_FOOTER,
1272 'compress' => $compress,
1273 'forceOnTop' => $forceOnTop,
1274 'allWrap' => $allWrap,
1275 'excludeFromConcatenation' => $excludeFromConcatenation,
1276 'splitChar' => $splitChar,
1277 'async' => $async
1278 );
1279 }
1280 }
1281
1282 /**
1283 * Adds JS inline code
1284 *
1285 * @param string $name
1286 * @param string $block
1287 * @param bool $compress
1288 * @param bool $forceOnTop
1289 * @return void
1290 */
1291 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1292 if (!isset($this->jsInline[$name]) && !empty($block)) {
1293 $this->jsInline[$name] = array(
1294 'code' => $block . LF,
1295 'section' => self::PART_HEADER,
1296 'compress' => $compress,
1297 'forceOnTop' => $forceOnTop
1298 );
1299 }
1300 }
1301
1302 /**
1303 * Adds JS inline code to footer
1304 *
1305 * @param string $name
1306 * @param string $block
1307 * @param bool $compress
1308 * @param bool $forceOnTop
1309 * @return void
1310 */
1311 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1312 if (!isset($this->jsInline[$name]) && !empty($block)) {
1313 $this->jsInline[$name] = array(
1314 'code' => $block . LF,
1315 'section' => self::PART_FOOTER,
1316 'compress' => $compress,
1317 'forceOnTop' => $forceOnTop
1318 );
1319 }
1320 }
1321
1322 /**
1323 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
1324 *
1325 * @param string $block Javascript code
1326 * @param bool $forceOnTop Position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
1327 * @return void
1328 */
1329 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
1330 if (!in_array($block, $this->extOnReadyCode)) {
1331 if ($forceOnTop) {
1332 array_unshift($this->extOnReadyCode, $block);
1333 } else {
1334 $this->extOnReadyCode[] = $block;
1335 }
1336 }
1337 }
1338
1339 /**
1340 * Adds the ExtDirect code
1341 *
1342 * @param array $filterNamespaces Limit the output to defined namespaces. If empty, all namespaces are generated
1343 * @return void
1344 */
1345 public function addExtDirectCode(array $filterNamespaces = array()) {
1346 if ($this->extDirectCodeAdded) {
1347 return;
1348 }
1349 $this->extDirectCodeAdded = TRUE;
1350 if (count($filterNamespaces) === 0) {
1351 $filterNamespaces = array('TYPO3');
1352 }
1353 // @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1354 // add compatibility mapping for the old flashmessage API
1355 $this->addJsFile(GeneralUtility::resolveBackPath($this->backPath .
1356 'sysext/backend/Resources/Public/JavaScript/flashmessage_compatibility.js'));
1357
1358 // Add language labels for ExtDirect
1359 if (TYPO3_MODE === 'FE') {
1360 $this->addInlineLanguageLabelArray(array(
1361 'extDirect_timeoutHeader' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutHeader'),
1362 'extDirect_timeoutMessage' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutMessage')
1363 ));
1364 } else {
1365 $this->addInlineLanguageLabelArray(array(
1366 'extDirect_timeoutHeader' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutHeader'),
1367 'extDirect_timeoutMessage' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:extDirect_timeoutMessage')
1368 ));
1369 }
1370
1371 $token = ($api = '');
1372 if (TYPO3_MODE === 'BE') {
1373 $formprotection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get();
1374 $token = $formprotection->generateToken('extDirect');
1375
1376 // Debugger Console strings
1377 $this->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/debugger.xlf');
1378 }
1379 /** @var $extDirect \TYPO3\CMS\Core\ExtDirect\ExtDirectApi */
1380 $extDirect = GeneralUtility::makeInstance(\TYPO3\CMS\Core\ExtDirect\ExtDirectApi::class);
1381 $api = $extDirect->getApiPhp($filterNamespaces);
1382 if ($api) {
1383 $this->addJsInlineCode('TYPO3ExtDirectAPI', $api, FALSE);
1384 }
1385 // Note: we need to iterate thru the object, because the addProvider method
1386 // does this only with multiple arguments
1387 $this->addExtOnReadyCode('
1388 (function() {
1389 TYPO3.ExtDirectToken = "' . $token . '";
1390 for (var api in Ext.app.ExtDirectAPI) {
1391 var provider = Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
1392 provider.on("beforecall", function(provider, transaction, meta) {
1393 if (transaction.data) {
1394 transaction.data[transaction.data.length] = TYPO3.ExtDirectToken;
1395 } else {
1396 transaction.data = [TYPO3.ExtDirectToken];
1397 }
1398 });
1399
1400 provider.on("call", function(provider, transaction, meta) {
1401 if (transaction.isForm) {
1402 transaction.params.securityToken = TYPO3.ExtDirectToken;
1403 }
1404 });
1405 }
1406 })();
1407
1408 var extDirectDebug = function(message, header, group) {
1409 var TYPO3ViewportInstance = null;
1410
1411 if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
1412 TYPO3ViewportInstance = top.TYPO3.Backend;
1413 } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
1414 TYPO3ViewportInstance = TYPO3.Backend;
1415 }
1416
1417 if (TYPO3ViewportInstance !== null) {
1418 TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
1419 } else if (typeof console === "object") {
1420 console.log(message);
1421 } else {
1422 document.write(message);
1423 }
1424 };
1425
1426 Ext.Direct.on("exception", function(event) {
1427 if (event.code === Ext.Direct.exceptions.TRANSPORT && !event.where) {
1428 top.TYPO3.Notification.error(
1429 TYPO3.l10n.localize("extDirect_timeoutHeader"),
1430 TYPO3.l10n.localize("extDirect_timeoutMessage")
1431 );
1432 } else {
1433 var backtrace = "";
1434 if (event.code === "parse") {
1435 extDirectDebug(
1436 "<p>" + event.xhr.responseText + "<\\/p>",
1437 event.type,
1438 "ExtDirect - Exception"
1439 );
1440 } else if (event.code === "router") {
1441 top.TYPO3.Notification.error(
1442 event.code,
1443 event.message
1444 );
1445 } else if (event.where) {
1446 backtrace = "<p style=\\"margin-top: 20px;\\">" +
1447 "<strong>Backtrace:<\\/strong><br \\/>" +
1448 event.where.replace(/#/g, "<br \\/>#") +
1449 "<\\/p>";
1450 extDirectDebug(
1451 "<p>" + event.message + "<\\/p>" + backtrace,
1452 event.method,
1453 "ExtDirect - Exception"
1454 );
1455 }
1456
1457
1458 }
1459 });
1460
1461 Ext.Direct.on("event", function(event, provider) {
1462 if (typeof event.debug !== "undefined" && event.debug !== "") {
1463 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
1464 }
1465 });
1466 ', TRUE);
1467 }
1468
1469 /**
1470 * Adds CSS file
1471 *
1472 * @param string $file
1473 * @param string $rel
1474 * @param string $media
1475 * @param string $title
1476 * @param bool $compress
1477 * @param bool $forceOnTop
1478 * @param string $allWrap
1479 * @param bool $excludeFromConcatenation
1480 * @param string $splitChar The char used to split the allWrap value, default is "|"
1481 * @return void
1482 */
1483 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|') {
1484 if (!isset($this->cssFiles[$file])) {
1485 $this->cssFiles[$file] = array(
1486 'file' => $file,
1487 'rel' => $rel,
1488 'media' => $media,
1489 'title' => $title,
1490 'compress' => $compress,
1491 'forceOnTop' => $forceOnTop,
1492 'allWrap' => $allWrap,
1493 'excludeFromConcatenation' => $excludeFromConcatenation,
1494 'splitChar' => $splitChar
1495 );
1496 }
1497 }
1498
1499 /**
1500 * Adds CSS file
1501 *
1502 * @param string $file
1503 * @param string $rel
1504 * @param string $media
1505 * @param string $title
1506 * @param bool $compress
1507 * @param bool $forceOnTop
1508 * @param string $allWrap
1509 * @param bool $excludeFromConcatenation
1510 * @param string $splitChar The char used to split the allWrap value, default is "|"
1511 * @return void
1512 */
1513 public function addCssLibrary($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $splitChar = '|') {
1514 if (!isset($this->cssLibs[$file])) {
1515 $this->cssLibs[$file] = array(
1516 'file' => $file,
1517 'rel' => $rel,
1518 'media' => $media,
1519 'title' => $title,
1520 'compress' => $compress,
1521 'forceOnTop' => $forceOnTop,
1522 'allWrap' => $allWrap,
1523 'excludeFromConcatenation' => $excludeFromConcatenation,
1524 'splitChar' => $splitChar
1525 );
1526 }
1527 }
1528
1529 /**
1530 * Adds CSS inline code
1531 *
1532 * @param string $name
1533 * @param string $block
1534 * @param bool $compress
1535 * @param bool $forceOnTop
1536 * @return void
1537 */
1538 public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
1539 if (!isset($this->cssInline[$name]) && !empty($block)) {
1540 $this->cssInline[$name] = array(
1541 'code' => $block,
1542 'compress' => $compress,
1543 'forceOnTop' => $forceOnTop
1544 );
1545 }
1546 }
1547
1548 /**
1549 * Call this function if you need to include the jQuery library
1550 *
1551 * @param null|string $version The jQuery version that should be included, either "latest" or any available version
1552 * @param null|string $source The location of the jQuery source, can be "local", "google", "msn", "jquery" or just an URL to your jQuery lib
1553 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored.
1554 * @return void
1555 * @throws \UnexpectedValueException
1556 */
1557 public function loadJquery($version = NULL, $source = NULL, $namespace = self::JQUERY_NAMESPACE_DEFAULT) {
1558 // Set it to the version that is shipped with the TYPO3 core
1559 if ($version === NULL || $version === 'latest') {
1560 $version = self::JQUERY_VERSION_LATEST;
1561 }
1562 // Check if the source is set, otherwise set it to "default"
1563 if ($source === NULL) {
1564 $source = 'local';
1565 }
1566 if ($source === 'local' && !in_array($version, $this->availableLocalJqueryVersions)) {
1567 throw new \UnexpectedValueException('The requested jQuery version is not available in the local filesystem.', 1341505305);
1568 }
1569 if (!preg_match('/^[a-zA-Z0-9]+$/', $namespace)) {
1570 throw new \UnexpectedValueException('The requested namespace contains non alphanumeric characters.', 1341571604);
1571 }
1572 $this->jQueryVersions[$namespace] = array(
1573 'version' => $version,
1574 'source' => $source
1575 );
1576 }
1577
1578 /**
1579 * Call function if you need the requireJS library
1580 * this automatically adds the JavaScript path of all loaded extensions in the requireJS path option
1581 * so it resolves names like TYPO3/CMS/MyExtension/MyJsFile to EXT:MyExtension/Resources/Public/JavaScript/MyJsFile.js
1582 * when using requireJS
1583 *
1584 * @return void
1585 */
1586 public function loadRequireJs() {
1587
1588 // load all paths to map to package names / namespaces
1589 if (count($this->requireJsConfig) === 0) {
1590 // first, load all paths for the namespaces, and configure contrib libs.
1591 $this->requireJsConfig['paths'] = array(
1592 'jquery-ui' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/jquery-ui',
1593 'jquery' => $this->backPath . 'contrib/jquery',
1594 'datatables' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/jquery.dataTables',
1595 'nprogress' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/nprogress',
1596 'moment' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/moment',
1597 'bootstrap' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/bootstrap/bootstrap',
1598 'twbs/bootstrap-datetimepicker' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/bootstrap-datetimepicker',
1599 'autosize' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/autosize',
1600 );
1601 // get all extensions that are loaded
1602 $loadedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getLoadedExtensionListArray();
1603 foreach ($loadedExtensions as $packageName) {
1604 $fullJsPath = 'EXT:' . $packageName . '/Resources/Public/JavaScript/';
1605 $fullJsPath = GeneralUtility::getFileAbsFileName($fullJsPath);
1606 $fullJsPath = \TYPO3\CMS\Core\Utility\PathUtility::getRelativePath(PATH_typo3, $fullJsPath);
1607 $fullJsPath = rtrim($fullJsPath, '/');
1608 if ($fullJsPath) {
1609 $this->requireJsConfig['paths']['TYPO3/CMS/' . GeneralUtility::underscoredToUpperCamelCase($packageName)] = $this->backPath . $fullJsPath;
1610 }
1611 }
1612
1613 // check if additional AMD modules need to be loaded if a single AMD module is initialized
1614 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules'])) {
1615 $this->addInlineSettingArray('RequireJS.PostInitializationModules', $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules']);
1616 }
1617 }
1618
1619 $this->addRequireJs = TRUE;
1620 }
1621
1622 /**
1623 * Add additional configuration to require js.
1624 *
1625 * Configuration will be merged recursive with overrule.
1626 *
1627 * To add another path mapping deliver the following configuration:
1628 * 'paths' => array(
1629 * 'EXTERN/mybootstrapjs' => 'contrib/twbs/bootstrap.min',
1630 * ),
1631 *
1632 * @author Daniel Siepmann <daniel.siepmann@typo3.org>
1633 *
1634 * @param array $configuration The configuration that will be merged with existing one.
1635 * @return void
1636 */
1637 public function addRequireJsConfiguration(array $configuration) {
1638 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->requireJsConfig, $configuration);
1639 }
1640
1641 /**
1642 * includes a AMD-compatible JS file by resolving the ModuleName, and then requires the file via a requireJS request,
1643 * additionally allowing to execute JavaScript code afterwards
1644 *
1645 * this function only works for AMD-ready JS modules, used like "define('TYPO3/CMS/Backend/FormEngine..."
1646 * in the JS file
1647 *
1648 * TYPO3/CMS/Backend/FormEngine =>
1649 * "TYPO3": Vendor Name
1650 * "CMS": Product Name
1651 * "Backend": Extension Name
1652 * "FormEngine": FileName in the Resources/Public/JavaScript folder
1653 *
1654 * @param string $mainModuleName Must be in the form of "TYPO3/CMS/PackageName/ModuleName" e.g. "TYPO3/CMS/Backend/FormEngine"
1655 * @param string $callBackFunction loaded right after the requireJS loading, must be wrapped in function() {}
1656 * @return void
1657 */
1658 public function loadRequireJsModule($mainModuleName, $callBackFunction = NULL) {
1659 $inlineCodeKey = $mainModuleName;
1660 // make sure requireJS is initialized
1661 $this->loadRequireJs();
1662
1663 // execute the main module, and load a possible callback function
1664 $javaScriptCode = 'require(["' . $mainModuleName . '"]';
1665 if ($callBackFunction !== NULL) {
1666 $inlineCodeKey .= sha1($callBackFunction);
1667 $javaScriptCode .= ', ' . $callBackFunction;
1668 }
1669 $javaScriptCode .= ');';
1670 $this->addJsInlineCode('RequireJS-Module-' . $inlineCodeKey, $javaScriptCode);
1671 }
1672
1673 /**
1674 * Call function if you need the prototype library
1675 *
1676 * @return void
1677 */
1678 public function loadPrototype() {
1679 $this->addPrototype = TRUE;
1680 }
1681
1682 /**
1683 * Call function if you need the Scriptaculous library
1684 *
1685 * @param string $modules Add modules you need. use "all" if you need complete modules
1686 * @return void
1687 */
1688 public function loadScriptaculous($modules = 'all') {
1689 // Scriptaculous require prototype, so load prototype too.
1690 $this->addPrototype = TRUE;
1691 $this->addScriptaculous = TRUE;
1692 if ($modules) {
1693 if ($modules == 'all') {
1694 foreach ($this->addScriptaculousModules as $key => $value) {
1695 $this->addScriptaculousModules[$key] = TRUE;
1696 }
1697 } else {
1698 $mods = GeneralUtility::trimExplode(',', $modules);
1699 foreach ($mods as $mod) {
1700 if (isset($this->addScriptaculousModules[strtolower($mod)])) {
1701 $this->addScriptaculousModules[strtolower($mod)] = TRUE;
1702 }
1703 }
1704 }
1705 }
1706 }
1707
1708 /**
1709 * call this function if you need the extJS library
1710 *
1711 * @param bool $css Flag, if set the ext-css will be loaded
1712 * @param bool $theme Flag, if set the ext-theme "grey" will be loaded
1713 * @param string $adapter Choose alternative adapter, possible values: yui, prototype, jquery
1714 * @return void
1715 */
1716 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
1717 if ($adapter) {
1718 // Empty $adapter will always load the ext adapter
1719 switch (GeneralUtility::strtolower(trim($adapter))) {
1720 case self::EXTJS_ADAPTER_YUI:
1721 $this->extJSadapter = 'yui/ext-yui-adapter.js';
1722 break;
1723 case self::EXTJS_ADAPTER_PROTOTYPE:
1724 $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
1725 break;
1726 case self::EXTJS_ADAPTER_JQUERY:
1727 $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
1728 break;
1729 }
1730 }
1731 $this->addExtJS = TRUE;
1732 $this->extJStheme = $theme;
1733 $this->extJScss = $css;
1734 }
1735
1736 /**
1737 * Enables ExtJs QuickTips
1738 * Need extJs loaded
1739 *
1740 * @return void
1741 */
1742 public function enableExtJSQuickTips() {
1743 $this->enableExtJSQuickTips = TRUE;
1744 }
1745
1746 /**
1747 * Call function if you need the ExtCore library
1748 *
1749 * @return void
1750 */
1751 public function loadExtCore() {
1752 $this->addExtCore = TRUE;
1753 }
1754
1755 /**
1756 * Call this function to load debug version of ExtJS. Use this for development only
1757 *
1758 * @return void
1759 */
1760 public function enableExtJsDebug() {
1761 $this->enableExtJsDebug = TRUE;
1762 }
1763
1764 /**
1765 * Call this function to load debug version of ExtCore. Use this for development only
1766 *
1767 * @return void
1768 */
1769 public function enableExtCoreDebug() {
1770 $this->enableExtCoreDebug = TRUE;
1771 }
1772
1773 /**
1774 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1775 * The label can be used in scripts with TYPO3.lang.<key>
1776 * Need extJs loaded
1777 *
1778 * @param string $key
1779 * @param string $value
1780 * @return void
1781 */
1782 public function addInlineLanguageLabel($key, $value) {
1783 $this->inlineLanguageLabels[$key] = $value;
1784 }
1785
1786 /**
1787 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1788 * The label can be used in scripts with TYPO3.lang.<key>
1789 * Array will be merged with existing array.
1790 * Need extJs loaded
1791 *
1792 * @param array $array
1793 * @return void
1794 */
1795 public function addInlineLanguageLabelArray(array $array) {
1796 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
1797 }
1798
1799 /**
1800 * Gets labels to be used in JavaScript fetched from a locallang file.
1801 *
1802 * @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.
1803 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1804 * @param string $stripFromSelectionName Sub-prefix to be removed from label names in the result (default: '')
1805 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1806 * @return void
1807 */
1808 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1809 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1810 if ($fileRef && !isset($this->inlineLanguageLabelFiles[$index])) {
1811 $this->inlineLanguageLabelFiles[$index] = array(
1812 'fileRef' => $fileRef,
1813 'selectionPrefix' => $selectionPrefix,
1814 'stripFromSelectionName' => $stripFromSelectionName,
1815 'errorMode' => $errorMode
1816 );
1817 }
1818 }
1819
1820 /**
1821 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1822 * The label can be used in scripts with TYPO3.setting.<key>
1823 * Need extJs loaded
1824 *
1825 * @param string $namespace
1826 * @param string $key
1827 * @param string $value
1828 * @return void
1829 */
1830 public function addInlineSetting($namespace, $key, $value) {
1831 if ($namespace) {
1832 if (strpos($namespace, '.')) {
1833 $parts = explode('.', $namespace);
1834 $a = &$this->inlineSettings;
1835 foreach ($parts as $part) {
1836 $a = &$a[$part];
1837 }
1838 $a[$key] = $value;
1839 } else {
1840 $this->inlineSettings[$namespace][$key] = $value;
1841 }
1842 } else {
1843 $this->inlineSettings[$key] = $value;
1844 }
1845 }
1846
1847 /**
1848 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1849 * The label can be used in scripts with TYPO3.setting.<key>
1850 * Array will be merged with existing array.
1851 * Need extJs loaded
1852 *
1853 * @param string $namespace
1854 * @param array $array
1855 * @return void
1856 */
1857 public function addInlineSettingArray($namespace, array $array) {
1858 if ($namespace) {
1859 if (strpos($namespace, '.')) {
1860 $parts = explode('.', $namespace);
1861 $a = &$this->inlineSettings;
1862 foreach ($parts as $part) {
1863 $a = &$a[$part];
1864 }
1865 $a = array_merge((array)$a, $array);
1866 } else {
1867 $this->inlineSettings[$namespace] = array_merge((array)$this->inlineSettings[$namespace], $array);
1868 }
1869 } else {
1870 $this->inlineSettings = array_merge($this->inlineSettings, $array);
1871 }
1872 }
1873
1874 /**
1875 * Adds content to body content
1876 *
1877 * @param string $content
1878 * @return void
1879 */
1880 public function addBodyContent($content) {
1881 $this->bodyContent .= $content;
1882 }
1883
1884 /*****************************************************/
1885 /* */
1886 /* Render Functions */
1887 /* */
1888 /*****************************************************/
1889 /**
1890 * Render the section (Header or Footer)
1891 *
1892 * @param int $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1893 * @return string Content of rendered section
1894 */
1895 public function render($part = self::PART_COMPLETE) {
1896 $this->prepareRendering();
1897 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1898 $metaTags = implode(LF, $this->metaTags);
1899 $markerArray = $this->getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags);
1900 $template = $this->getTemplateForPart($part);
1901
1902 // The page renderer needs a full reset, even when only rendering one part of the page
1903 // This means that you can only register footer files *after* the header has been already rendered.
1904 // In case you render the footer part first, header files can only be added *after* the footer has been rendered
1905 $this->reset();
1906 return trim(\TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($template, $markerArray, '###|###'));
1907 }
1908
1909 /**
1910 * Render the page but not the JavaScript and CSS Files
1911 *
1912 * @param string $substituteHash The hash that is used for the placehoder markers
1913 * @access private
1914 * @return string Content of rendered section
1915 */
1916 public function renderPageWithUncachedObjects($substituteHash) {
1917 $this->prepareRendering();
1918 $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
1919 $template = $this->getTemplateForPart(self::PART_COMPLETE);
1920 return trim(\TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($template, $markerArray, '###|###'));
1921 }
1922
1923 /**
1924 * Renders the JavaScript and CSS files that have been added during processing
1925 * of uncached content objects (USER_INT, COA_INT)
1926 *
1927 * @param string $cachedPageContent
1928 * @param string $substituteHash The hash that is used for the placehoder markers
1929 * @access private
1930 * @return string
1931 */
1932 public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash) {
1933 $this->prepareRendering();
1934 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1935 $title = $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '';
1936 $markerArray = array(
1937 '<!-- ###TITLE' . $substituteHash . '### -->' => $title,
1938 '<!-- ###CSS_LIBS' . $substituteHash . '### -->' => $cssLibs,
1939 '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
1940 '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
1941 '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
1942 '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
1943 '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
1944 '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF, $this->headerData),
1945 '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF, $this->footerData),
1946 '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
1947 '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
1948 '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline
1949 );
1950 foreach ($markerArray as $placeHolder => $content) {
1951 $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
1952 }
1953 $this->reset();
1954 return $cachedPageContent;
1955 }
1956
1957 /**
1958 * Remove ending slashes from static header block
1959 * if the page is beeing rendered as html (not xhtml)
1960 * and define property $this->endingSlash for further use
1961 *
1962 * @return void
1963 */
1964 protected function prepareRendering() {
1965 if ($this->getRenderXhtml()) {
1966 $this->endingSlash = ' /';
1967 } else {
1968 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
1969 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
1970 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
1971 $this->endingSlash = '';
1972 }
1973 }
1974
1975 /**
1976 * Renders all JavaScript and CSS
1977 *
1978 * @return array<string>
1979 */
1980 protected function renderJavaScriptAndCss() {
1981 $this->executePreRenderHook();
1982 $mainJsLibs = $this->renderMainJavaScriptLibraries();
1983 if ($this->concatenateFiles || $this->concatenateJavascript || $this->concatenateCss) {
1984 // Do the file concatenation
1985 $this->doConcatenate();
1986 }
1987 if ($this->compressCss || $this->compressJavascript) {
1988 // Do the file compression
1989 $this->doCompress();
1990 }
1991 $this->executeRenderPostTransformHook();
1992 $cssLibs = $this->renderCssLibraries();
1993 $cssFiles = $this->renderCssFiles();
1994 $cssInline = $this->renderCssInline();
1995 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
1996 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
1997 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
1998 $jsLibs = $mainJsLibs . $jsLibs;
1999 if ($this->moveJsFromHeaderToFooter) {
2000 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
2001 $jsLibs = '';
2002 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
2003 $jsFiles = '';
2004 $jsFooterInline = $jsInline . LF . $jsFooterInline;
2005 $jsInline = '';
2006 }
2007 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
2008 return array($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
2009 }
2010
2011 /**
2012 * Fills the marker array with the given strings and trims each value
2013 *
2014 * @param $jsLibs string
2015 * @param $jsFiles string
2016 * @param $jsFooterFiles string
2017 * @param $cssLibs string
2018 * @param $cssFiles string
2019 * @param $jsInline string
2020 * @param $cssInline string
2021 * @param $jsFooterInline string
2022 * @param $jsFooterLibs string
2023 * @param $metaTags string
2024 * @return array Marker array
2025 */
2026 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags) {
2027 $markerArray = array(
2028 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
2029 'HTMLTAG' => $this->htmlTag,
2030 'HEADTAG' => $this->headTag,
2031 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
2032 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
2033 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
2034 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
2035 'CSS_LIBS' => $cssLibs,
2036 'CSS_INCLUDE' => $cssFiles,
2037 'CSS_INLINE' => $cssInline,
2038 'JS_INLINE' => $jsInline,
2039 'JS_INCLUDE' => $jsFiles,
2040 'JS_LIBS' => $jsLibs,
2041 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
2042 'META' => $metaTags,
2043 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
2044 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
2045 'JS_LIBS_FOOTER' => $jsFooterLibs,
2046 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
2047 'JS_INLINE_FOOTER' => $jsFooterInline,
2048 'BODY' => $this->bodyContent
2049 );
2050 $markerArray = array_map('trim', $markerArray);
2051 return $markerArray;
2052 }
2053
2054 /**
2055 * Fills the marker array with the given strings and trims each value
2056 *
2057 * @param string $substituteHash The hash that is used for the placehoder markers
2058 * @return array Marker array
2059 */
2060 protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash) {
2061 $markerArray = array(
2062 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
2063 'HTMLTAG' => $this->htmlTag,
2064 'HEADTAG' => $this->headTag,
2065 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
2066 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
2067 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
2068 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
2069 'META' => implode(LF, $this->metaTags),
2070 'BODY' => $this->bodyContent,
2071 'TITLE' => '<!-- ###TITLE' . $substituteHash . '### -->',
2072 'CSS_LIBS' => '<!-- ###CSS_LIBS' . $substituteHash . '### -->',
2073 'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
2074 'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
2075 'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
2076 'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
2077 'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
2078 'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
2079 'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
2080 'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
2081 'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
2082 'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->'
2083 );
2084 $markerArray = array_map('trim', $markerArray);
2085 return $markerArray;
2086 }
2087
2088 /**
2089 * Reads the template file and returns the requested part as string
2090 *
2091 * @param int $part
2092 * @return string
2093 */
2094 protected function getTemplateForPart($part) {
2095 $templateFile = GeneralUtility::getFileAbsFileName($this->templateFile, TRUE);
2096 $template = GeneralUtility::getUrl($templateFile);
2097 if ($this->removeLineBreaksFromTemplate) {
2098 $template = strtr($template, array(LF => '', CR => ''));
2099 }
2100 if ($part !== self::PART_COMPLETE) {
2101 $templatePart = explode('###BODY###', $template);
2102 $template = $templatePart[$part - 1];
2103 }
2104 return $template;
2105 }
2106
2107 /**
2108 * Helper function for render the main JavaScript libraries,
2109 * currently: RequireJS, jQuery, PrototypeJS, Scriptaculous, ExtJs
2110 *
2111 * @return string Content with JavaScript libraries
2112 */
2113 protected function renderMainJavaScriptLibraries() {
2114 $out = '';
2115
2116 // Include RequireJS
2117 if ($this->addRequireJs) {
2118 // load the paths of the requireJS configuration
2119 $out .= GeneralUtility::wrapJS('var require = ' . json_encode($this->requireJsConfig)) . LF;
2120 // directly after that, include the require.js file
2121 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->requireJsPath . 'require.js')) . '" type="text/javascript"></script>' . LF;
2122 }
2123
2124 // Include jQuery Core for each namespace, depending on the version and source
2125 if (!empty($this->jQueryVersions)) {
2126 foreach ($this->jQueryVersions as $namespace => $jQueryVersion) {
2127 $out .= $this->renderJqueryScriptTag($jQueryVersion['version'], $jQueryVersion['source'], $namespace);
2128 }
2129 }
2130 if ($this->addPrototype) {
2131 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->prototypePath . 'prototype.js')) . '" type="text/javascript"></script>' . LF;
2132 unset($this->jsFiles[$this->backPath . $this->prototypePath . 'prototype.js']);
2133 }
2134 if ($this->addScriptaculous) {
2135 $mods = array();
2136 foreach ($this->addScriptaculousModules as $key => $value) {
2137 if ($this->addScriptaculousModules[$key]) {
2138 $mods[] = $key;
2139 }
2140 }
2141 // Resolve dependencies
2142 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
2143 $mods = array_merge(array('effects'), $mods);
2144 }
2145 if (count($mods)) {
2146 foreach ($mods as $module) {
2147 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->scriptaculousPath . $module . '.js')) . '" type="text/javascript"></script>' . LF;
2148 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . $module . '.js']);
2149 }
2150 }
2151 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->scriptaculousPath . 'scriptaculous.js')) . '" type="text/javascript"></script>' . LF;
2152 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . 'scriptaculous.js']);
2153 }
2154 // Include extCore, but only if ExtJS is not included
2155 if ($this->addExtCore && !$this->addExtJS) {
2156 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js')) . '" type="text/javascript"></script>' . LF;
2157 unset($this->jsFiles[$this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
2158 }
2159 // Include extJS
2160 if ($this->addExtJS) {
2161 // Use the base adapter all the time
2162 $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;
2163 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->extJsPath . 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js')) . '" type="text/javascript"></script>' . LF;
2164 // Add extJS localization
2165 // Load standard ISO mapping and modify for use with ExtJS
2166 $localeMap = $this->locales->getIsoMapping();
2167 $localeMap[''] = 'en';
2168 $localeMap['default'] = 'en';
2169 // Greek
2170 $localeMap['gr'] = 'el_GR';
2171 // Norwegian Bokmaal
2172 $localeMap['no'] = 'no_BO';
2173 // Swedish
2174 $localeMap['se'] = 'se_SV';
2175 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
2176 // @todo autoconvert file from UTF8 to current BE charset if necessary!!!!
2177 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
2178 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
2179 $out .= '<script src="' . $this->processJsFile(($this->backPath . $extJsLocaleFile)) . '" type="text/javascript" charset="utf-8"></script>' . LF;
2180 }
2181 // Remove extjs from JScodeLibArray
2182 unset($this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'], $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']);
2183 }
2184 $this->loadJavaScriptLanguageStrings();
2185 if (TYPO3_MODE === 'BE') {
2186 $this->addAjaxUrlsToInlineSettings();
2187 }
2188 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
2189 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
2190 if ($this->addExtCore || $this->addExtJS) {
2191 // Set clear.gif, move it on top, add handler code
2192 $code = '';
2193 if (count($this->extOnReadyCode)) {
2194 foreach ($this->extOnReadyCode as $block) {
2195 $code .= $block;
2196 }
2197 }
2198 $out .= $this->inlineJavascriptWrap[0] . '
2199 Ext.ns("TYPO3");
2200 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(GeneralUtility::locationHeaderUrl(($this->backPath . 'gfx/clear.gif'))) . '";
2201 Ext.SSL_SECURE_URL = "' . htmlspecialchars(GeneralUtility::locationHeaderUrl(($this->backPath . 'gfx/clear.gif'))) . '";' . LF
2202 . $inlineSettings
2203 . 'Ext.onReady(function() {'
2204 . ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '')
2205 . $code
2206 . ' });'
2207 . $this->inlineJavascriptWrap[1];
2208 $this->extOnReadyCode = array();
2209 // Include TYPO3.l10n object
2210 if (TYPO3_MODE === 'BE') {
2211 $out .= '<script src="' . $this->processJsFile(($this->backPath . 'sysext/lang/Resources/Public/JavaScript/Typo3Lang.js')) . '" type="text/javascript" charset="utf-8"></script>' . LF;
2212 }
2213 if ($this->extJScss) {
2214 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
2215 $this->addCssLibrary($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE);
2216 } else {
2217 $this->addCssLibrary($this->backPath . $this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE);
2218 }
2219 }
2220 if ($this->extJStheme) {
2221 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
2222 $this->addCssLibrary($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE);
2223 } else {
2224 $this->addCssLibrary($this->backPath . $this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE);
2225 }
2226 }
2227 } else {
2228 // no extJS loaded, but still inline settings
2229 if ($inlineSettings !== '') {
2230 // make sure the global TYPO3 is available
2231 $inlineSettings = 'var TYPO3 = TYPO3 || {};' . CRLF . $inlineSettings;
2232 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
2233 if (TYPO3_MODE === 'BE') {
2234 $this->loadRequireJsModule('TYPO3/CMS/Lang/Lang');
2235 }
2236 }
2237 }
2238 return $out;
2239 }
2240
2241 /**
2242 * Load the language strings into JavaScript
2243 */
2244 protected function loadJavaScriptLanguageStrings() {
2245 if (count($this->inlineLanguageLabelFiles)) {
2246 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
2247 $this->includeLanguageFileForInline($languageLabelFile['fileRef'], $languageLabelFile['selectionPrefix'], $languageLabelFile['stripFromSelectionName'], $languageLabelFile['errorMode']);
2248 }
2249 }
2250 $this->inlineLanguageLabelFiles = array();
2251 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
2252 if (TYPO3_MODE === 'FE' && $this->getCharSet() !== 'utf-8') {
2253 if ($this->inlineLanguageLabels) {
2254 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
2255 }
2256 if ($this->inlineSettings) {
2257 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
2258 }
2259 }
2260 }
2261
2262 /**
2263 * Make URLs to all backend ajax handlers available as inline setting.
2264 */
2265 protected function addAjaxUrlsToInlineSettings() {
2266 $ajaxUrls = array();
2267 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'] as $ajaxHandler => $_) {
2268 $ajaxUrls[$ajaxHandler] = BackendUtility::getAjaxUrl($ajaxHandler);
2269 }
2270 $this->inlineSettings['ajaxUrls'] = $ajaxUrls;
2271 }
2272
2273 /**
2274 * Renders the HTML script tag for the given jQuery version.
2275 *
2276 * @param string $version The jQuery version that should be included, either "latest" or any available version
2277 * @param string $source The location of the jQuery source, can be "local", "google", "msn" or "jquery
2278 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored
2279 * @return string
2280 */
2281 protected function renderJqueryScriptTag($version, $source, $namespace) {
2282 switch (TRUE) {
2283 case isset($this->jQueryCdnUrls[$source]):
2284 if ($this->enableJqueryDebug) {
2285 $minifyPart = '';
2286 } else {
2287 $minifyPart = '.min';
2288 }
2289 $jQueryFileName = sprintf($this->jQueryCdnUrls[$source], $version, $minifyPart);
2290 break;
2291 case $source === 'local':
2292 $jQueryFileName = $this->backPath . $this->jQueryPath . 'jquery-' . rawurlencode($version);
2293 if ($this->enableJqueryDebug) {
2294 $jQueryFileName .= '.js';
2295 } else {
2296 $jQueryFileName .= '.min.js';
2297 }
2298 break;
2299 default:
2300 $jQueryFileName = $source;
2301 }
2302 // Include the jQuery Core
2303 $scriptTag = '<script src="' . htmlspecialchars($jQueryFileName) . '" type="text/javascript"></script>' . LF;
2304 // Set the noConflict mode to be available via "TYPO3.jQuery" in all installations
2305 switch ($namespace) {
2306 case self::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT:
2307 $scriptTag .= GeneralUtility::wrapJS('jQuery.noConflict();') . LF;
2308 break;
2309 case self::JQUERY_NAMESPACE_NONE:
2310 break;
2311 case self::JQUERY_NAMESPACE_DEFAULT:
2312
2313 default:
2314 $scriptTag .= GeneralUtility::wrapJS('var TYPO3 = TYPO3 || {}; TYPO3.' . $namespace . ' = jQuery.noConflict(true);') . LF;
2315 }
2316 return $scriptTag;
2317 }
2318
2319 /**
2320 * Render CSS library files
2321 *
2322 * @return string
2323 */
2324 protected function renderCssLibraries() {
2325 $cssFiles = '';
2326 if (count($this->cssLibs)) {
2327 foreach ($this->cssLibs as $file => $properties) {
2328 $file = GeneralUtility::resolveBackPath($file);
2329 $file = GeneralUtility::createVersionNumberedFilename($file);
2330 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2331 . '" type="text/css" href="' . htmlspecialchars($file)
2332 . '" media="' . htmlspecialchars($properties['media']) . '"'
2333 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2334 . $this->endingSlash . '>';
2335 if ($properties['allWrap']) {
2336 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2337 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2338 }
2339 $tag .= LF;
2340 if ($properties['forceOnTop']) {
2341 $cssFiles = $tag . $cssFiles;
2342 } else {
2343 $cssFiles .= $tag;
2344 }
2345 }
2346 }
2347 return $cssFiles;
2348 }
2349
2350 /**
2351 * Render CSS files
2352 *
2353 * @return string
2354 */
2355 protected function renderCssFiles() {
2356 $cssFiles = '';
2357 if (count($this->cssFiles)) {
2358 foreach ($this->cssFiles as $file => $properties) {
2359 $file = GeneralUtility::resolveBackPath($file);
2360 $file = GeneralUtility::createVersionNumberedFilename($file);
2361 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2362 . '" type="text/css" href="' . htmlspecialchars($file)
2363 . '" media="' . htmlspecialchars($properties['media']) . '"'
2364 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2365 . $this->endingSlash . '>';
2366 if ($properties['allWrap']) {
2367 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2368 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2369 }
2370 $tag .= LF;
2371 if ($properties['forceOnTop']) {
2372 $cssFiles = $tag . $cssFiles;
2373 } else {
2374 $cssFiles .= $tag;
2375 }
2376 }
2377 }
2378 return $cssFiles;
2379 }
2380
2381 /**
2382 * Render inline CSS
2383 *
2384 * @return string
2385 */
2386 protected function renderCssInline() {
2387 $cssInline = '';
2388 if (count($this->cssInline)) {
2389 foreach ($this->cssInline as $name => $properties) {
2390 $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2391 if ($properties['forceOnTop']) {
2392 $cssInline = $cssCode . $cssInline;
2393 } else {
2394 $cssInline .= $cssCode;
2395 }
2396 }
2397 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
2398 }
2399 return $cssInline;
2400 }
2401
2402 /**
2403 * Render JavaScipt libraries
2404 *
2405 * @return array<string> jsLibs and jsFooterLibs strings
2406 */
2407 protected function renderAdditionalJavaScriptLibraries() {
2408 $jsLibs = '';
2409 $jsFooterLibs = '';
2410 if (count($this->jsLibs)) {
2411 foreach ($this->jsLibs as $properties) {
2412 $properties['file'] = GeneralUtility::resolveBackPath($properties['file']);
2413 $properties['file'] = GeneralUtility::createVersionNumberedFilename($properties['file']);
2414 $async = ($properties['async']) ? ' async="async"' : '';
2415 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . '></script>';
2416 if ($properties['allWrap']) {
2417 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2418 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2419 }
2420 $tag .= LF;
2421 if ($properties['forceOnTop']) {
2422 if ($properties['section'] === self::PART_HEADER) {
2423 $jsLibs = $tag . $jsLibs;
2424 } else {
2425 $jsFooterLibs = $tag . $jsFooterLibs;
2426 }
2427 } else {
2428 if ($properties['section'] === self::PART_HEADER) {
2429 $jsLibs .= $tag;
2430 } else {
2431 $jsFooterLibs .= $tag;
2432 }
2433 }
2434 }
2435 }
2436 if ($this->moveJsFromHeaderToFooter) {
2437 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
2438 $jsLibs = '';
2439 }
2440 return array($jsLibs, $jsFooterLibs);
2441 }
2442
2443 /**
2444 * Render JavaScript files
2445 *
2446 * @return array<string> jsFiles and jsFooterFiles strings
2447 */
2448 protected function renderJavaScriptFiles() {
2449 $jsFiles = '';
2450 $jsFooterFiles = '';
2451 if (count($this->jsFiles)) {
2452 foreach ($this->jsFiles as $file => $properties) {
2453 $file = GeneralUtility::resolveBackPath($file);
2454 $file = GeneralUtility::createVersionNumberedFilename($file);
2455 $async = ($properties['async']) ? ' async="async"' : '';
2456 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"' . $async . '></script>';
2457 if ($properties['allWrap']) {
2458 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2459 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2460 }
2461 $tag .= LF;
2462 if ($properties['forceOnTop']) {
2463 if ($properties['section'] === self::PART_HEADER) {
2464 $jsFiles = $tag . $jsFiles;
2465 } else {
2466 $jsFooterFiles = $tag . $jsFooterFiles;
2467 }
2468 } else {
2469 if ($properties['section'] === self::PART_HEADER) {
2470 $jsFiles .= $tag;
2471 } else {
2472 $jsFooterFiles .= $tag;
2473 }
2474 }
2475 }
2476 }
2477 if ($this->moveJsFromHeaderToFooter) {
2478 $jsFooterFiles = $jsFiles . $jsFooterFiles;
2479 $jsFiles = '';
2480 }
2481 return array($jsFiles, $jsFooterFiles);
2482 }
2483
2484 /**
2485 * Render inline JavaScript
2486 *
2487 * @return array<string> jsInline and jsFooterInline string
2488 */
2489 protected function renderInlineJavaScript() {
2490 $jsInline = '';
2491 $jsFooterInline = '';
2492 if (count($this->jsInline)) {
2493 foreach ($this->jsInline as $name => $properties) {
2494 $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2495 if ($properties['forceOnTop']) {
2496 if ($properties['section'] === self::PART_HEADER) {
2497 $jsInline = $jsCode . $jsInline;
2498 } else {
2499 $jsFooterInline = $jsCode . $jsFooterInline;
2500 }
2501 } else {
2502 if ($properties['section'] === self::PART_HEADER) {
2503 $jsInline .= $jsCode;
2504 } else {
2505 $jsFooterInline .= $jsCode;
2506 }
2507 }
2508 }
2509 }
2510 if ($jsInline) {
2511 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
2512 }
2513 if ($jsFooterInline) {
2514 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
2515 }
2516 if ($this->moveJsFromHeaderToFooter) {
2517 $jsFooterInline = $jsInline . $jsFooterInline;
2518 $jsInline = '';
2519 }
2520 return array($jsInline, $jsFooterInline);
2521 }
2522
2523 /**
2524 * Include language file for inline usage
2525 *
2526 * @param string $fileRef
2527 * @param string $selectionPrefix
2528 * @param string $stripFromSelectionName
2529 * @param int $errorMode
2530 * @return void
2531 * @throws \RuntimeException
2532 */
2533 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
2534 if (!isset($this->lang) || !isset($this->charSet)) {
2535 throw new \RuntimeException('Language and character encoding are not set.', 1284906026);
2536 }
2537 $labelsFromFile = array();
2538 $allLabels = $this->readLLfile($fileRef, $errorMode);
2539 // Regular expression to strip the selection prefix and possibly something from the label name:
2540 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
2541 if ($allLabels !== FALSE) {
2542 // Merge language specific translations:
2543 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
2544 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
2545 } else {
2546 $labels = $allLabels['default'];
2547 }
2548 // Iterate through all locallang labels:
2549 foreach ($labels as $label => $value) {
2550 if ($selectionPrefix === '') {
2551 $labelsFromFile[$label] = $value;
2552 } elseif (strpos($label, $selectionPrefix) === 0) {
2553 preg_replace($labelPattern, '', $label);
2554 $labelsFromFile[$label] = $value;
2555 }
2556 }
2557 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
2558 }
2559 }
2560
2561 /**
2562 * Reads a locallang file.
2563 *
2564 * @param string $fileRef Reference to a relative filename to include.
2565 * @param int $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
2566 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2567 */
2568 protected function readLLfile($fileRef, $errorMode = 0) {
2569 if ($this->lang !== 'default') {
2570 $languages = array_reverse($this->languageDependencies);
2571 // At least we need to have English
2572 if (empty($languages)) {
2573 $languages[] = 'default';
2574 }
2575 } else {
2576 $languages = array('default');
2577 }
2578
2579 $localLanguage = array();
2580 foreach ($languages as $language) {
2581 $tempLL = GeneralUtility::readLLfile($fileRef, $language, $this->charSet, $errorMode);
2582 $localLanguage['default'] = $tempLL['default'];
2583 if (!isset($localLanguage[$this->lang])) {
2584 $localLanguage[$this->lang] = $localLanguage['default'];
2585 }
2586 if ($this->lang !== 'default' && isset($tempLL[$language])) {
2587 // Merge current language labels onto labels from previous language
2588 // This way we have a labels with fall back applied
2589 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($localLanguage[$this->lang], $tempLL[$language], TRUE, FALSE);
2590 }
2591 }
2592
2593 return $localLanguage;
2594 }
2595
2596
2597 /*****************************************************/
2598 /* */
2599 /* Tools */
2600 /* */
2601 /*****************************************************/
2602 /**
2603 * Concatenate files into one file
2604 * registered handler
2605 *
2606 * @return void
2607 */
2608 protected function doConcatenate() {
2609 $this->doConcatenateCss();
2610 $this->doConcatenateJavaScript();
2611 }
2612
2613 /**
2614 * Concatenate JavaScript files according to the configuration.
2615 *
2616 * @return void
2617 */
2618 protected function doConcatenateJavaScript() {
2619 if ($this->concatenateFiles || $this->concatenateJavascript) {
2620 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'])) {
2621 // use external concatenation routine
2622 $params = array(
2623 'jsLibs' => &$this->jsLibs,
2624 'jsFiles' => &$this->jsFiles,
2625 'jsFooterFiles' => &$this->jsFooterFiles,
2626 'headerData' => &$this->headerData,
2627 'footerData' => &$this->footerData
2628 );
2629 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'], $params, $this);
2630 } else {
2631 $this->jsLibs = $this->getCompressor()->concatenateJsFiles($this->jsLibs);
2632 $this->jsFiles = $this->getCompressor()->concatenateJsFiles($this->jsFiles);
2633 $this->jsFooterFiles = $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles);
2634 }
2635 }
2636 }
2637
2638 /**
2639 * Concatenate CSS files according to configuration.
2640 *
2641 * @return void
2642 */
2643 protected function doConcatenateCss() {
2644 if ($this->concatenateFiles || $this->concatenateCss) {
2645 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'])) {
2646 // use external concatenation routine
2647 $params = array(
2648 'cssFiles' => &$this->cssFiles,
2649 'headerData' => &$this->headerData,
2650 'footerData' => &$this->footerData
2651 );
2652 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this);
2653 } else {
2654 $cssOptions = array();
2655 if (TYPO3_MODE === 'BE') {
2656 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
2657 }
2658 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
2659 }
2660 }
2661 }
2662
2663 /**
2664 * Compresses inline code
2665 *
2666 * @return void
2667 */
2668 protected function doCompress() {
2669 $this->doCompressJavaScript();
2670 $this->doCompressCss();
2671 }
2672
2673 /**
2674 * Compresses CSS according to configuration.
2675 *
2676 * @return void
2677 */
2678 protected function doCompressCss() {
2679 if ($this->compressCss) {
2680 // Use external compression routine
2681 $params = array(
2682 'cssInline' => &$this->cssInline,
2683 'cssFiles' => &$this->cssFiles,
2684 'headerData' => &$this->headerData,
2685 'footerData' => &$this->footerData
2686 );
2687 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'])) {
2688 // use external concatenation routine
2689 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
2690 } else {
2691 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
2692 }
2693 }
2694 }
2695
2696 /**
2697 * Compresses JavaScript according to configuration.
2698 *
2699 * @return void
2700 */
2701 protected function doCompressJavaScript() {
2702 if ($this->compressJavascript) {
2703 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'])) {
2704 // Use external compression routine
2705 $params = array(
2706 'jsInline' => &$this->jsInline,
2707 'jsFooterInline' => &$this->jsFooterInline,
2708 'jsLibs' => &$this->jsLibs,
2709 'jsFiles' => &$this->jsFiles,
2710 'jsFooterFiles' => &$this->jsFooterFiles,
2711 'headerData' => &$this->headerData,
2712 'footerData' => &$this->footerData
2713 );
2714 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
2715 } else {
2716 // Traverse the arrays, compress files
2717 if (count($this->jsInline)) {
2718 foreach ($this->jsInline as $name => $properties) {
2719 if ($properties['compress']) {
2720 $error = '';
2721 $this->jsInline[$name]['code'] = GeneralUtility::minifyJavaScript($properties['code'], $error);
2722 if ($error) {
2723 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
2724 }
2725 }
2726 }
2727 }
2728 $this->jsLibs = $this->getCompressor()->compressJsFiles($this->jsLibs);
2729 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
2730 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
2731 }
2732 }
2733 }
2734
2735 /**
2736 * Returns instance of \TYPO3\CMS\Core\Resource\ResourceCompressor
2737 *
2738 * @return \TYPO3\CMS\Core\Resource\ResourceCompressor
2739 */
2740 protected function getCompressor() {
2741 if ($this->compressor === NULL) {
2742 $this->compressor = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceCompressor::class);
2743 }
2744 return $this->compressor;
2745 }
2746
2747 /**
2748 * Processes a Javascript file dependent on the current context
2749 *
2750 * Adds the version number for Frontend, compresses the file for Backend
2751 *
2752 * @param string $filename Filename
2753 * @return string New filename
2754 */
2755 protected function processJsFile($filename) {
2756 switch (TYPO3_MODE) {
2757 case 'FE':
2758 if ($this->compressJavascript) {
2759 $filename = $this->getCompressor()->compressJsFile($filename);
2760 } else {
2761 $filename = GeneralUtility::createVersionNumberedFilename($filename);
2762 }
2763 break;
2764 case 'BE':
2765 if ($this->compressJavascript) {
2766 $filename = $this->getCompressor()->compressJsFile($filename);
2767 }
2768 break;
2769 }
2770 return $filename;
2771 }
2772
2773 /*****************************************************/
2774 /* */
2775 /* Hooks */
2776 /* */
2777 /*****************************************************/
2778 /**
2779 * Execute PreRenderHook for possible manipulation
2780 *
2781 * @return void
2782 */
2783 protected function executePreRenderHook() {
2784 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
2785 $params = array(
2786 'jsLibs' => &$this->jsLibs,
2787 'jsFooterLibs' => &$this->jsFooterLibs,
2788 'jsFiles' => &$this->jsFiles,
2789 'jsFooterFiles' => &$this->jsFooterFiles,
2790 'cssFiles' => &$this->cssFiles,
2791 'headerData' => &$this->headerData,
2792 'footerData' => &$this->footerData,
2793 'jsInline' => &$this->jsInline,
2794 'jsFooterInline' => &$this->jsFooterInline,
2795 'cssInline' => &$this->cssInline
2796 );
2797 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
2798 GeneralUtility::callUserFunction($hook, $params, $this);
2799 }
2800 }
2801 }
2802
2803 /**
2804 * PostTransform for possible manipulation of concatenated and compressed files
2805 *
2806 * @return void
2807 */
2808 protected function executeRenderPostTransformHook() {
2809 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
2810 $params = array(
2811 'jsLibs' => &$this->jsLibs,
2812 'jsFooterLibs' => &$this->jsFooterLibs,
2813 'jsFiles' => &$this->jsFiles,
2814 'jsFooterFiles' => &$this->jsFooterFiles,
2815 'cssFiles' => &$this->cssFiles,
2816 'headerData' => &$this->headerData,
2817 'footerData' => &$this->footerData,
2818 'jsInline' => &$this->jsInline,
2819 'jsFooterInline' => &$this->jsFooterInline,
2820 'cssInline' => &$this->cssInline
2821 );
2822 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
2823 GeneralUtility::callUserFunction($hook, $params, $this);
2824 }
2825 }
2826 }
2827
2828 /**
2829 * Execute postRenderHook for possible manipulation
2830 *
2831 * @param $jsLibs string
2832 * @param $jsFiles string
2833 * @param $jsFooterFiles string
2834 * @param $cssLibs string
2835 * @param $cssFiles string
2836 * @param $jsInline string
2837 * @param $cssInline string
2838 * @param $jsFooterInline string
2839 * @param $jsFooterLibs string
2840 * @return void
2841 */
2842 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssLibs, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs) {
2843 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
2844 $params = array(
2845 'jsLibs' => &$jsLibs,
2846 'jsFiles' => &$jsFiles,
2847 'jsFooterFiles' => &$jsFooterFiles,
2848 'cssLibs' => &$cssLibs,
2849 'cssFiles' => &$cssFiles,
2850 'headerData' => &$this->headerData,
2851 'footerData' => &$this->footerData,
2852 'jsInline' => &$jsInline,
2853 'cssInline' => &$cssInline,
2854 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType,
2855 'htmlTag' => &$this->htmlTag,
2856 'headTag' => &$this->headTag,
2857 'charSet' => &$this->charSet,
2858 'metaCharsetTag' => &$this->metaCharsetTag,
2859 'shortcutTag' => &$this->shortcutTag,
2860 'inlineComments' => &$this->inlineComments,
2861 'baseUrl' => &$this->baseUrl,
2862 'baseUrlTag' => &$this->baseUrlTag,
2863 'favIcon' => &$this->favIcon,
2864 'iconMimeType' => &$this->iconMimeType,
2865 'titleTag' => &$this->titleTag,
2866 'title' => &$this->title,
2867 'metaTags' => &$this->metaTags,
2868 'jsFooterInline' => &$jsFooterInline,
2869 'jsFooterLibs' => &$jsFooterLibs,
2870 'bodyContent' => &$this->bodyContent
2871 );
2872 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
2873 GeneralUtility::callUserFunction($hook, $params, $this);
2874 }
2875 }
2876 }
2877
2878 }