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