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