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