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