Revert "[BUGFIX] Do not reset Page Renderer on partial rendering"
[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 $this->reset();
1953 return trim(\TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($template, $markerArray, '###|###'));
1954 }
1955
1956 /**
1957 * Render the page but not the JavaScript and CSS Files
1958 *
1959 * @param string $substituteHash The hash that is used for the placehoder markers
1960 * @access private
1961 * @return string Content of rendered section
1962 */
1963 public function renderPageWithUncachedObjects($substituteHash) {
1964 $this->prepareRendering();
1965 $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
1966 $template = $this->getTemplateForPart(self::PART_COMPLETE);
1967 return trim(\TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($template, $markerArray, '###|###'));
1968 }
1969
1970 /**
1971 * Renders the JavaScript and CSS files that have been added during processing
1972 * of uncached content objects (USER_INT, COA_INT)
1973 *
1974 * @param string $cachedPageContent
1975 * @param string $substituteHash The hash that is used for the placehoder markers
1976 * @access private
1977 * @return string
1978 */
1979 public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash) {
1980 $this->prepareRendering();
1981 list($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
1982 $title = $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '';
1983 $markerArray = array(
1984 '<!-- ###TITLE' . $substituteHash . '### -->' => $title,
1985 '<!-- ###CSS_LIBS' . $substituteHash . '### -->' => $cssLibs,
1986 '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
1987 '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
1988 '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
1989 '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
1990 '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
1991 '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF, $this->headerData),
1992 '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF, $this->footerData),
1993 '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
1994 '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
1995 '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline
1996 );
1997 foreach ($markerArray as $placeHolder => $content) {
1998 $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
1999 }
2000 $this->reset();
2001 return $cachedPageContent;
2002 }
2003
2004 /**
2005 * Remove ending slashes from static header block
2006 * if the page is beeing rendered as html (not xhtml)
2007 * and define property $this->endingSlash for further use
2008 *
2009 * @return void
2010 */
2011 protected function prepareRendering() {
2012 if ($this->getRenderXhtml()) {
2013 $this->endingSlash = ' /';
2014 } else {
2015 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
2016 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
2017 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
2018 $this->endingSlash = '';
2019 }
2020 }
2021
2022 /**
2023 * Renders all JavaScript and CSS
2024 *
2025 * @return array<string>
2026 */
2027 protected function renderJavaScriptAndCss() {
2028 $this->executePreRenderHook();
2029 $mainJsLibs = $this->renderMainJavaScriptLibraries();
2030 if ($this->concatenateFiles || $this->concatenateJavascript || $this->concatenateCss) {
2031 // Do the file concatenation
2032 $this->doConcatenate();
2033 }
2034 if ($this->compressCss || $this->compressJavascript) {
2035 // Do the file compression
2036 $this->doCompress();
2037 }
2038 $this->executeRenderPostTransformHook();
2039 $cssLibs = $this->renderCssLibraries();
2040 $cssFiles = $this->renderCssFiles();
2041 $cssInline = $this->renderCssInline();
2042 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
2043 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
2044 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
2045 $jsLibs = $mainJsLibs . $jsLibs;
2046 if ($this->moveJsFromHeaderToFooter) {
2047 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
2048 $jsLibs = '';
2049 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
2050 $jsFiles = '';
2051 $jsFooterInline = $jsInline . LF . $jsFooterInline;
2052 $jsInline = '';
2053 }
2054 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
2055 return array($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
2056 }
2057
2058 /**
2059 * Fills the marker array with the given strings and trims each value
2060 *
2061 * @param $jsLibs string
2062 * @param $jsFiles string
2063 * @param $jsFooterFiles string
2064 * @param $cssLibs string
2065 * @param $cssFiles string
2066 * @param $jsInline string
2067 * @param $cssInline string
2068 * @param $jsFooterInline string
2069 * @param $jsFooterLibs string
2070 * @param $metaTags string
2071 * @return array Marker array
2072 */
2073 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags) {
2074 $markerArray = array(
2075 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
2076 'HTMLTAG' => $this->htmlTag,
2077 'HEADTAG' => $this->headTag,
2078 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
2079 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
2080 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
2081 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
2082 'CSS_LIBS' => $cssLibs,
2083 'CSS_INCLUDE' => $cssFiles,
2084 'CSS_INLINE' => $cssInline,
2085 'JS_INLINE' => $jsInline,
2086 'JS_INCLUDE' => $jsFiles,
2087 'JS_LIBS' => $jsLibs,
2088 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
2089 'META' => $metaTags,
2090 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
2091 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
2092 'JS_LIBS_FOOTER' => $jsFooterLibs,
2093 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
2094 'JS_INLINE_FOOTER' => $jsFooterInline,
2095 'BODY' => $this->bodyContent
2096 );
2097 $markerArray = array_map('trim', $markerArray);
2098 return $markerArray;
2099 }
2100
2101 /**
2102 * Fills the marker array with the given strings and trims each value
2103 *
2104 * @param string $substituteHash The hash that is used for the placehoder markers
2105 * @return array Marker array
2106 */
2107 protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash) {
2108 $markerArray = array(
2109 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
2110 'HTMLTAG' => $this->htmlTag,
2111 'HEADTAG' => $this->headTag,
2112 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
2113 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
2114 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
2115 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
2116 'META' => implode(LF, $this->metaTags),
2117 'BODY' => $this->bodyContent,
2118 'TITLE' => '<!-- ###TITLE' . $substituteHash . '### -->',
2119 'CSS_LIBS' => '<!-- ###CSS_LIBS' . $substituteHash . '### -->',
2120 'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
2121 'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
2122 'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
2123 'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
2124 'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
2125 'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
2126 'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
2127 'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
2128 'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
2129 'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->'
2130 );
2131 $markerArray = array_map('trim', $markerArray);
2132 return $markerArray;
2133 }
2134
2135 /**
2136 * Reads the template file and returns the requested part as string
2137 *
2138 * @param integer $part
2139 * @return string
2140 */
2141 protected function getTemplateForPart($part) {
2142 $templateFile = GeneralUtility::getFileAbsFileName($this->templateFile, TRUE);
2143 $template = GeneralUtility::getUrl($templateFile);
2144 if ($this->removeLineBreaksFromTemplate) {
2145 $template = strtr($template, array(LF => '', CR => ''));
2146 }
2147 if ($part != self::PART_COMPLETE) {
2148 $templatePart = explode('###BODY###', $template);
2149 $template = $templatePart[$part - 1];
2150 }
2151 return $template;
2152 }
2153
2154 /**
2155 * Helper function for render the main JavaScript libraries,
2156 * currently: RequireJS, jQuery, PrototypeJS, Scriptaculous, SVG, ExtJs
2157 *
2158 * @return string Content with JavaScript libraries
2159 */
2160 protected function renderMainJavaScriptLibraries() {
2161 $out = '';
2162
2163 // Include RequireJS
2164 if ($this->addRequireJs) {
2165 // load the paths of the requireJS configuration
2166 $out .= GeneralUtility::wrapJS('var require = ' . json_encode($this->requireJsConfig)) . LF;
2167 // directly after that, include the require.js file
2168 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->requireJsPath . 'require.js')) . '" type="text/javascript"></script>' . LF;
2169 }
2170
2171 if ($this->addSvg) {
2172 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->svgPath . 'svg.js')) . '" data-path="' . $this->backPath . $this->svgPath . '"' . ($this->enableSvgDebug ? ' data-debug="true"' : '') . '></script>' . LF;
2173 }
2174 // Include jQuery Core for each namespace, depending on the version and source
2175 if (!empty($this->jQueryVersions)) {
2176 foreach ($this->jQueryVersions as $namespace => $jQueryVersion) {
2177 $out .= $this->renderJqueryScriptTag($jQueryVersion['version'], $jQueryVersion['source'], $namespace);
2178 }
2179 }
2180 if ($this->addPrototype) {
2181 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->prototypePath . 'prototype.js')) . '" type="text/javascript"></script>' . LF;
2182 unset($this->jsFiles[$this->backPath . $this->prototypePath . 'prototype.js']);
2183 }
2184 if ($this->addScriptaculous) {
2185 $mods = array();
2186 foreach ($this->addScriptaculousModules as $key => $value) {
2187 if ($this->addScriptaculousModules[$key]) {
2188 $mods[] = $key;
2189 }
2190 }
2191 // Resolve dependencies
2192 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
2193 $mods = array_merge(array('effects'), $mods);
2194 }
2195 if (count($mods)) {
2196 foreach ($mods as $module) {
2197 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->scriptaculousPath . $module . '.js')) . '" type="text/javascript"></script>' . LF;
2198 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . $module . '.js']);
2199 }
2200 }
2201 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->scriptaculousPath . 'scriptaculous.js')) . '" type="text/javascript"></script>' . LF;
2202 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . 'scriptaculous.js']);
2203 }
2204 // Include extCore, but only if ExtJS is not included
2205 if ($this->addExtCore && !$this->addExtJS) {
2206 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js')) . '" type="text/javascript"></script>' . LF;
2207 unset($this->jsFiles[$this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
2208 }
2209 // Include extJS
2210 if ($this->addExtJS) {
2211 // Use the base adapter all the time
2212 $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;
2213 $out .= '<script src="' . $this->processJsFile(($this->backPath . $this->extJsPath . 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js')) . '" type="text/javascript"></script>' . LF;
2214 // Add extJS localization
2215 // Load standard ISO mapping and modify for use with ExtJS
2216 $localeMap = $this->locales->getIsoMapping();
2217 $localeMap[''] = 'en';
2218 $localeMap['default'] = 'en';
2219 // Greek
2220 $localeMap['gr'] = 'el_GR';
2221 // Norwegian Bokmaal
2222 $localeMap['no'] = 'no_BO';
2223 // Swedish
2224 $localeMap['se'] = 'se_SV';
2225 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
2226 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
2227 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
2228 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
2229 $out .= '<script src="' . $this->processJsFile(($this->backPath . $extJsLocaleFile)) . '" type="text/javascript" charset="utf-8"></script>' . LF;
2230 }
2231 // Remove extjs from JScodeLibArray
2232 unset($this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'], $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']);
2233 }
2234 if (count($this->inlineLanguageLabelFiles)) {
2235 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
2236 $this->includeLanguageFileForInline($languageLabelFile['fileRef'], $languageLabelFile['selectionPrefix'], $languageLabelFile['stripFromSelectionName'], $languageLabelFile['$errorMode']);
2237 }
2238 }
2239 $this->inlineLanguageLabelFiles = array();
2240 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
2241 if ($this->getCharSet() !== 'utf-8') {
2242 if ($this->inlineLanguageLabels) {
2243 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
2244 }
2245 if ($this->inlineSettings) {
2246 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
2247 }
2248 }
2249 if (TYPO3_MODE === 'BE') {
2250 $this->addAjaxUrlsToInlineSettings();
2251 }
2252 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
2253 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
2254 if ($this->addExtCore || $this->addExtJS) {
2255 // Set clear.gif, move it on top, add handler code
2256 $code = '';
2257 if (count($this->extOnReadyCode)) {
2258 foreach ($this->extOnReadyCode as $block) {
2259 $code .= $block;
2260 }
2261 }
2262 $out .= $this->inlineJavascriptWrap[0] . '
2263 Ext.ns("TYPO3");
2264 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(GeneralUtility::locationHeaderUrl(($this->backPath . 'gfx/clear.gif'))) . '";' . LF
2265 . $inlineSettings
2266 . 'Ext.onReady(function() {'
2267 . ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '')
2268 . $code
2269 . ' });'
2270 . $this->inlineJavascriptWrap[1];
2271 $this->extOnReadyCode = array();
2272 // Include TYPO3.l10n object
2273 if (TYPO3_MODE === 'BE') {
2274 $out .= '<script src="' . $this->processJsFile(($this->backPath . 'sysext/lang/Resources/Public/JavaScript/Typo3Lang.js')) . '" type="text/javascript" charset="utf-8"></script>' . LF;
2275 }
2276 if ($this->extJScss) {
2277 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
2278 $this->addCssLibrary($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE);
2279 } else {
2280 $this->addCssLibrary($this->backPath . $this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE);
2281 }
2282 }
2283 if ($this->extJStheme) {
2284 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
2285 $this->addCssLibrary($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE);
2286 } else {
2287 $this->addCssLibrary($this->backPath . $this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE);
2288 }
2289 }
2290 } else {
2291 // no extJS loaded, but still inline settings
2292 if ($inlineSettings !== '') {
2293 // make sure the global TYPO3 is available
2294 $inlineSettings = 'var TYPO3 = TYPO3 || {};' . CRLF . $inlineSettings;
2295 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
2296 }
2297 }
2298 return $out;
2299 }
2300
2301 /**
2302 * Make URLs to all backend ajax handlers available as inline setting.
2303 */
2304 protected function addAjaxUrlsToInlineSettings() {
2305 $ajaxUrls = array();
2306 foreach (array_keys($GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']) as $ajaxHandler) {
2307 $ajaxUrls[$ajaxHandler] = BackendUtility::getAjaxUrl($ajaxHandler);
2308 }
2309 $this->inlineSettings['ajaxUrls'] = $ajaxUrls;
2310 }
2311
2312 /**
2313 * Renders the HTML script tag for the given jQuery version.
2314 *
2315 * @param string $version The jQuery version that should be included, either "latest" or any available version
2316 * @param string $source The location of the jQuery source, can be "local", "google", "msn" or "jquery
2317 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored
2318 * @return string
2319 */
2320 protected function renderJqueryScriptTag($version, $source, $namespace) {
2321 switch (TRUE) {
2322 case isset($this->jQueryCdnUrls[$source]):
2323 if ($this->enableJqueryDebug) {
2324 $minifyPart = '';
2325 } else {
2326 $minifyPart = '.min';
2327 }
2328 $jQueryFileName = sprintf($this->jQueryCdnUrls[$source], $version, $minifyPart);
2329 break;
2330 case $source === 'local':
2331 $jQueryFileName = $this->backPath . $this->jQueryPath . 'jquery-' . rawurlencode($version);
2332 if ($this->enableJqueryDebug) {
2333 $jQueryFileName .= '.js';
2334 } else {
2335 $jQueryFileName .= '.min.js';
2336 }
2337 break;
2338 default:
2339 $jQueryFileName = $source;
2340 }
2341 // Include the jQuery Core
2342 $scriptTag = '<script src="' . htmlspecialchars($jQueryFileName) . '" type="text/javascript"></script>' . LF;
2343 // Set the noConflict mode to be available via "TYPO3.jQuery" in all installations
2344 switch ($namespace) {
2345 case self::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT:
2346 $scriptTag .= GeneralUtility::wrapJS('jQuery.noConflict();') . LF;
2347 break;
2348 case self::JQUERY_NAMESPACE_NONE:
2349 break;
2350 case self::JQUERY_NAMESPACE_DEFAULT:
2351
2352 default:
2353 $scriptTag .= GeneralUtility::wrapJS('var TYPO3 = TYPO3 || {}; TYPO3.' . $namespace . ' = jQuery.noConflict(true);') . LF;
2354 }
2355 return $scriptTag;
2356 }
2357
2358 /**
2359 * Render CSS library files
2360 *
2361 * @return string
2362 */
2363 protected function renderCssLibraries() {
2364 $cssFiles = '';
2365 if (count($this->cssLibs)) {
2366 foreach ($this->cssLibs as $file => $properties) {
2367 $file = GeneralUtility::resolveBackPath($file);
2368 $file = GeneralUtility::createVersionNumberedFilename($file);
2369 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2370 . '" type="text/css" href="' . htmlspecialchars($file)
2371 . '" media="' . htmlspecialchars($properties['media']) . '"'
2372 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2373 . $this->endingSlash . '>';
2374 if ($properties['allWrap']) {
2375 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2376 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2377 }
2378 $tag .= LF;
2379 if ($properties['forceOnTop']) {
2380 $cssFiles = $tag . $cssFiles;
2381 } else {
2382 $cssFiles .= $tag;
2383 }
2384 }
2385 }
2386 return $cssFiles;
2387 }
2388
2389 /**
2390 * Render CSS files
2391 *
2392 * @return string
2393 */
2394 protected function renderCssFiles() {
2395 $cssFiles = '';
2396 if (count($this->cssFiles)) {
2397 foreach ($this->cssFiles as $file => $properties) {
2398 $file = GeneralUtility::resolveBackPath($file);
2399 $file = GeneralUtility::createVersionNumberedFilename($file);
2400 $tag = '<link rel="' . htmlspecialchars($properties['rel'])
2401 . '" type="text/css" href="' . htmlspecialchars($file)
2402 . '" media="' . htmlspecialchars($properties['media']) . '"'
2403 . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '')
2404 . $this->endingSlash . '>';
2405 if ($properties['allWrap']) {
2406 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2407 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2408 }
2409 $tag .= LF;
2410 if ($properties['forceOnTop']) {
2411 $cssFiles = $tag . $cssFiles;
2412 } else {
2413 $cssFiles .= $tag;
2414 }
2415 }
2416 }
2417 return $cssFiles;
2418 }
2419
2420 /**
2421 * Render inline CSS
2422 *
2423 * @return string
2424 */
2425 protected function renderCssInline() {
2426 $cssInline = '';
2427 if (count($this->cssInline)) {
2428 foreach ($this->cssInline as $name => $properties) {
2429 $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2430 if ($properties['forceOnTop']) {
2431 $cssInline = $cssCode . $cssInline;
2432 } else {
2433 $cssInline .= $cssCode;
2434 }
2435 }
2436 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
2437 }
2438 return $cssInline;
2439 }
2440
2441 /**
2442 * Render JavaScipt libraries
2443 *
2444 * @return array<string> jsLibs and jsFooterLibs strings
2445 */
2446 protected function renderAdditionalJavaScriptLibraries() {
2447 $jsLibs = '';
2448 $jsFooterLibs = '';
2449 if (count($this->jsLibs)) {
2450 foreach ($this->jsLibs as $properties) {
2451 $properties['file'] = GeneralUtility::resolveBackPath($properties['file']);
2452 $properties['file'] = GeneralUtility::createVersionNumberedFilename($properties['file']);
2453 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
2454 if ($properties['allWrap']) {
2455 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2456 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2457 }
2458 $tag .= LF;
2459 if ($properties['forceOnTop']) {
2460 if ($properties['section'] === self::PART_HEADER) {
2461 $jsLibs = $tag . $jsLibs;
2462 } else {
2463 $jsFooterLibs = $tag . $jsFooterLibs;
2464 }
2465 } else {
2466 if ($properties['section'] === self::PART_HEADER) {
2467 $jsLibs .= $tag;
2468 } else {
2469 $jsFooterLibs .= $tag;
2470 }
2471 }
2472 }
2473 }
2474 if ($this->moveJsFromHeaderToFooter) {
2475 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
2476 $jsLibs = '';
2477 }
2478 return array($jsLibs, $jsFooterLibs);
2479 }
2480
2481 /**
2482 * Render JavaScript files
2483 *
2484 * @return array<string> jsFiles and jsFooterFiles strings
2485 */
2486 protected function renderJavaScriptFiles() {
2487 $jsFiles = '';
2488 $jsFooterFiles = '';
2489 if (count($this->jsFiles)) {
2490 foreach ($this->jsFiles as $file => $properties) {
2491 $file = GeneralUtility::resolveBackPath($file);
2492 $file = GeneralUtility::createVersionNumberedFilename($file);
2493 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
2494 if ($properties['allWrap']) {
2495 $wrapArr = explode($properties['splitChar'] ?: '|', $properties['allWrap'], 2);
2496 $tag = $wrapArr[0] . $tag . $wrapArr[1];
2497 }
2498 $tag .= LF;
2499 if ($properties['forceOnTop']) {
2500 if ($properties['section'] === self::PART_HEADER) {
2501 $jsFiles = $tag . $jsFiles;
2502 } else {
2503 $jsFooterFiles = $tag . $jsFooterFiles;
2504 }
2505 } else {
2506 if ($properties['section'] === self::PART_HEADER) {
2507 $jsFiles .= $tag;
2508 } else {
2509 $jsFooterFiles .= $tag;
2510 }
2511 }
2512 }
2513 }
2514 if ($this->moveJsFromHeaderToFooter) {
2515 $jsFooterFiles = $jsFiles . $jsFooterFiles;
2516 $jsFiles = '';
2517 }
2518 return array($jsFiles, $jsFooterFiles);
2519 }
2520
2521 /**
2522 * Render inline JavaScript
2523 *
2524 * @return array<string> jsInline and jsFooterInline string
2525 */
2526 protected function renderInlineJavaScript() {
2527 $jsInline = '';
2528 $jsFooterInline = '';
2529 if (count($this->jsInline)) {
2530 foreach ($this->jsInline as $name => $properties) {
2531 $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2532 if ($properties['forceOnTop']) {
2533 if ($properties['section'] === self::PART_HEADER) {
2534 $jsInline = $jsCode . $jsInline;
2535 } else {
2536 $jsFooterInline = $jsCode . $jsFooterInline;
2537 }
2538 } else {
2539 if ($properties['section'] === self::PART_HEADER) {
2540 $jsInline .= $jsCode;
2541 } else {
2542 $jsFooterInline .= $jsCode;
2543 }
2544 }
2545 }
2546 }
2547 if ($jsInline) {
2548 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
2549 }
2550 if ($jsFooterInline) {
2551 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
2552 }
2553 if ($this->moveJsFromHeaderToFooter) {
2554 $jsFooterInline = $jsInline . $jsFooterInline;
2555 $jsInline = '';
2556 }
2557 return array($jsInline, $jsFooterInline);
2558 }
2559
2560 /**
2561 * Include language file for inline usage
2562 *
2563 * @param string $fileRef
2564 * @param string $selectionPrefix
2565 * @param string $stripFromSelectionName
2566 * @param integer $errorMode
2567 * @return void
2568 * @throws \RuntimeException
2569 */
2570 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
2571 if (!isset($this->lang) || !isset($this->charSet)) {
2572 throw new \RuntimeException('Language and character encoding are not set.', 1284906026);
2573 }
2574 $labelsFromFile = array();
2575 $allLabels = $this->readLLfile($fileRef, $errorMode);
2576 // Regular expression to strip the selection prefix and possibly something from the label name:
2577 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
2578 if ($allLabels !== FALSE) {
2579 // Merge language specific translations:
2580 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
2581 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
2582 } else {
2583 $labels = $allLabels['default'];
2584 }
2585 // Iterate through all locallang labels:
2586 foreach ($labels as $label => $value) {
2587 if ($selectionPrefix === '') {
2588 $labelsFromFile[$label] = $value;
2589 } elseif (strpos($label, $selectionPrefix) === 0) {
2590 preg_replace($labelPattern, '', $label);
2591 $labelsFromFile[$label] = $value;
2592 }
2593 }
2594 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
2595 }
2596 }
2597
2598 /**
2599 * Reads a locallang file.
2600 *
2601 * @param string $fileRef Reference to a relative filename to include.
2602 * @param integer $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
2603 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2604 */
2605 protected function readLLfile($fileRef, $errorMode = 0) {
2606 if ($this->lang !== 'default') {
2607 $languages = array_reverse($this->languageDependencies);
2608 // At least we need to have English
2609 if (empty($languages)) {
2610 $languages[] = 'default';
2611 }
2612 } else {
2613 $languages = array('default');
2614 }
2615
2616 $localLanguage = array();
2617 foreach ($languages as $language) {
2618 $tempLL = GeneralUtility::readLLfile($fileRef, $language, $this->charSet, $errorMode);
2619 $localLanguage['default'] = $tempLL['default'];
2620 if (!isset($localLanguage[$this->lang])) {
2621 $localLanguage[$this->lang] = $localLanguage['default'];
2622 }
2623 if ($this->lang !== 'default' && isset($tempLL[$language])) {
2624 // Merge current language labels onto labels from previous language
2625 // This way we have a labels with fall back applied
2626 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($localLanguage[$this->lang], $tempLL[$language], TRUE, FALSE);
2627 }
2628 }
2629
2630 return $localLanguage;
2631 }
2632
2633
2634 /*****************************************************/
2635 /* */
2636 /* Tools */
2637 /* */
2638 /*****************************************************/
2639 /**
2640 * Concatenate files into one file
2641 * registered handler
2642 *
2643 * @return void
2644 */
2645 protected function doConcatenate() {
2646 $this->doConcatenateCss();
2647 $this->doConcatenateJavaScript();
2648 }
2649
2650 /**
2651 * Concatenate JavaScript files according to the configuration.
2652 *
2653 * @return void
2654 */
2655 protected function doConcatenateJavaScript() {
2656 if ($this->concatenateFiles || $this->concatenateJavascript) {
2657 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'])) {
2658 // use external concatenation routine
2659 $params = array(
2660 'jsLibs' => &$this->jsLibs,
2661 'jsFiles' => &$this->jsFiles,
2662 'jsFooterFiles' => &$this->jsFooterFiles,
2663 'headerData' => &$this->headerData,
2664 'footerData' => &$this->footerData
2665 );
2666 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'], $params, $this);
2667 } else {
2668 $this->jsLibs = $this->getCompressor()->concatenateJsFiles($this->jsLibs);
2669 $this->jsFiles = $this->getCompressor()->concatenateJsFiles($this->jsFiles);
2670 $this->jsFooterFiles = $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles);
2671 }
2672 }
2673 }
2674
2675 /**
2676 * Concatenate CSS files according to configuration.
2677 *
2678 * @return void
2679 */
2680 protected function doConcatenateCss() {
2681 if ($this->concatenateFiles || $this->concatenateCss) {
2682 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'])) {
2683 // use external concatenation routine
2684 $params = array(
2685 'cssFiles' => &$this->cssFiles,
2686 'headerData' => &$this->headerData,
2687 'footerData' => &$this->footerData
2688 );
2689 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this);
2690 } else {
2691 $cssOptions = array();
2692 if (TYPO3_MODE === 'BE') {
2693 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
2694 }
2695 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
2696 }
2697 }
2698 }
2699
2700 /**
2701 * Compresses inline code
2702 *
2703 * @return void
2704 */
2705 protected function doCompress() {
2706 $this->doCompressJavaScript();
2707 $this->doCompressCss();
2708 }
2709
2710 /**
2711 * Compresses CSS according to configuration.
2712 *
2713 * @return void
2714 */
2715 protected function doCompressCss() {
2716 if ($this->compressCss) {
2717 // Use external compression routine
2718 $params = array(
2719 'cssInline' => &$this->cssInline,
2720 'cssFiles' => &$this->cssFiles,
2721 'headerData' => &$this->headerData,
2722 'footerData' => &$this->footerData
2723 );
2724 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'])) {
2725 // use external concatenation routine
2726 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
2727 } else {
2728 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
2729 }
2730 }
2731 }
2732
2733 /**
2734 * Compresses JavaScript according to configuration.
2735 *
2736 * @return void
2737 */
2738 protected function doCompressJavaScript() {
2739 if ($this->compressJavascript) {
2740 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'])) {
2741 // Use external compression routine
2742 $params = array(
2743 'jsInline' => &$this->jsInline,
2744 'jsFooterInline' => &$this->jsFooterInline,
2745 'jsLibs' => &$this->jsLibs,
2746 'jsFiles' => &$this->jsFiles,
2747 'jsFooterFiles' => &$this->jsFooterFiles,
2748 'headerData' => &$this->headerData,
2749 'footerData' => &$this->footerData
2750 );
2751 GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
2752 } else {
2753 // Traverse the arrays, compress files
2754 if (count($this->jsInline)) {
2755 foreach ($this->jsInline as $name => $properties) {
2756 if ($properties['compress']) {
2757 $error = '';
2758 $this->jsInline[$name]['code'] = GeneralUtility::minifyJavaScript($properties['code'], $error);
2759 if ($error) {
2760 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
2761 }
2762 }
2763 }
2764 }
2765 $this->jsLibs = $this->getCompressor()->compressJsFiles($this->jsLibs);
2766 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
2767 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
2768 }
2769 }
2770 }
2771
2772 /**
2773 * Returns instance of \TYPO3\CMS\Core\Resource\ResourceCompressor
2774 *
2775 * @return \TYPO3\CMS\Core\Resource\ResourceCompressor
2776 */
2777 protected function getCompressor() {
2778 if ($this->compressor === NULL) {
2779 $this->compressor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceCompressor');
2780 }
2781 return $this->compressor;
2782 }
2783
2784 /**
2785 * Processes a Javascript file dependent on the current context
2786 *
2787 * Adds the version number for Frontend, compresses the file for Backend
2788 *
2789 * @param string $filename Filename
2790 * @return string New filename
2791 */
2792 protected function processJsFile($filename) {
2793 switch (TYPO3_MODE) {
2794 case 'FE':
2795 if ($this->compressJavascript) {
2796 $filename = $this->getCompressor()->compressJsFile($filename);
2797 } else {
2798 $filename = GeneralUtility::createVersionNumberedFilename($filename);
2799 }
2800 break;
2801 case 'BE':
2802 if ($this->compressJavascript) {
2803 $filename = $this->getCompressor()->compressJsFile($filename);
2804 }
2805 break;
2806 }
2807 return $filename;
2808 }
2809
2810 /*****************************************************/
2811 /* */
2812 /* Hooks */
2813 /* */
2814 /*****************************************************/
2815 /**
2816 * Execute PreRenderHook for possible manipulation
2817 *
2818 * @return void
2819 */
2820 protected function executePreRenderHook() {
2821 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
2822 $params = array(
2823 'jsLibs' => &$this->jsLibs,
2824 'jsFooterLibs' => &$this->jsFooterLibs,
2825 'jsFiles' => &$this->jsFiles,
2826 'jsFooterFiles' => &$this->jsFooterFiles,
2827 'cssFiles' => &$this->cssFiles,
2828 'headerData' => &$this->headerData,
2829 'footerData' => &$this->footerData,
2830 'jsInline' => &$this->jsInline,
2831 'jsFooterInline' => &$this->jsFooterInline,
2832 'cssInline' => &$this->cssInline
2833 );
2834 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
2835 GeneralUtility::callUserFunction($hook, $params, $this);
2836 }
2837 }
2838 }
2839
2840 /**
2841 * PostTransform for possible manipulation of concatenated and compressed files
2842 *
2843 * @return void
2844 */
2845 protected function executeRenderPostTransformHook() {
2846 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
2847 $params = array(
2848 'jsLibs' => &$this->jsLibs,
2849 'jsFooterLibs' => &$this->jsFooterLibs,
2850 'jsFiles' => &$this->jsFiles,
2851 'jsFooterFiles' => &$this->jsFooterFiles,
2852 'cssFiles' => &$this->cssFiles,
2853 'headerData' => &$this->headerData,
2854 'footerData' => &$this->footerData,
2855 'jsInline' => &$this->jsInline,
2856 'jsFooterInline' => &$this->jsFooterInline,
2857 'cssInline' => &$this->cssInline
2858 );
2859 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
2860 GeneralUtility::callUserFunction($hook, $params, $this);
2861 }
2862 }
2863 }
2864
2865 /**
2866 * Execute postRenderHook for possible manipulation
2867 *
2868 * @param $jsLibs string
2869 * @param $jsFiles string
2870 * @param $jsFooterFiles string
2871 * @param $cssLibs string
2872 * @param $cssFiles string
2873 * @param $jsInline string
2874 * @param $cssInline string
2875 * @param $jsFooterInline string
2876 * @param $jsFooterLibs string
2877 * @return void
2878 */
2879 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssLibs, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs) {
2880 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
2881 $params = array(
2882 'jsLibs' => &$jsLibs,
2883 'jsFiles' => &$jsFiles,
2884 'jsFooterFiles' => &$jsFooterFiles,
2885 'cssLibs' => &$cssLibs,
2886 'cssFiles' => &$cssFiles,
2887 'headerData' => &$this->headerData,
2888 'footerData' => &$this->footerData,
2889 'jsInline' => &$jsInline,
2890 'cssInline' => &$cssInline,
2891 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType,
2892 'htmlTag' => &$this->htmlTag,
2893 'headTag' => &$this->headTag,
2894 'charSet' => &$this->charSet,
2895 'metaCharsetTag' => &$this->metaCharsetTag,
2896 'shortcutTag' => &$this->shortcutTag,
2897 'inlineComments' => &$this->inlineComments,
2898 'baseUrl' => &$this->baseUrl,
2899 'baseUrlTag' => &$this->baseUrlTag,
2900 'favIcon' => &$this->favIcon,
2901 'iconMimeType' => &$this->iconMimeType,
2902 'titleTag' => &$this->titleTag,
2903 'title' => &$this->title,
2904 'metaTags' => &$this->metaTags,
2905 'jsFooterInline' => &$jsFooterInline,
2906 'jsFooterLibs' => &$jsFooterLibs,
2907 'bodyContent' => &$this->bodyContent
2908 );
2909 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
2910 GeneralUtility::callUserFunction($hook, $params, $this);
2911 }
2912 }
2913 }
2914
2915 }