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