[TASK] Clean up php doc headers in pageRenderer
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_pagerenderer.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Steffen Kamper <info@sk-typo3.de>
6 * (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * TYPO3 pageRender class (new in TYPO3 4.3.0)
31 * This class render the HTML of a webpage, usable for BE and FE
32 *
33 * @author Steffen Kamper <info@sk-typo3.de>
34 * @author Kai Vogel <kai.vogel@speedprogs.de>
35 * @package TYPO3
36 * @subpackage t3lib
37 */
38 class t3lib_PageRenderer implements t3lib_Singleton {
39 // Constants for the part to be rendered
40 const PART_COMPLETE = 0;
41 const PART_HEADER = 1;
42 const PART_FOOTER = 2;
43
44 // Available adapters for extJs
45 const EXTJS_ADAPTER_JQUERY = 'jquery';
46 const EXTJS_ADAPTER_PROTOTYPE = 'prototype';
47 const EXTJS_ADAPTER_YUI = 'yui';
48
49 /**
50 * @var boolean
51 */
52 protected $compressJavascript = FALSE;
53
54 /**
55 * @var boolean
56 */
57 protected $compressCss = FALSE;
58
59 /**
60 * @var boolean
61 */
62 protected $removeLineBreaksFromTemplate = FALSE;
63
64 /**
65 * @var boolean
66 */
67 protected $concatenateFiles = FALSE;
68
69 /**
70 * @var boolean
71 */
72 protected $concatenateJavascript = FALSE;
73
74 /**
75 * @var boolean
76 */
77 protected $concatenateCss = FALSE;
78
79 /**
80 * @var boolean
81 */
82 protected $moveJsFromHeaderToFooter = FALSE;
83
84 /**
85 * @var t3lib_cs
86 */
87 protected $csConvObj;
88
89 /**
90 * @var t3lib_l10n_Locales
91 */
92 protected $locales;
93
94 /**
95 * The language key
96 * Two character string or 'default'
97 *
98 * @var string
99 */
100 protected $lang;
101
102 /**
103 * @var t3lib_Compressor
104 */
105 protected $compressor;
106
107 // Arrays containing associative array for the included files
108
109 /**
110 * @var array
111 */
112 protected $jsFiles = array();
113
114 /**
115 * @var array
116 */
117 protected $jsFooterFiles = array();
118
119 /**
120 * @var array
121 */
122 protected $jsLibs = array();
123
124 /**
125 * @var array
126 */
127 protected $jsFooterLibs = array();
128
129 /**
130 * @var array
131 */
132 protected $cssFiles = array();
133
134 /**
135 * The title of the page
136 *
137 * @var string
138 */
139 protected $title;
140
141 /**
142 * Charset for the rendering
143 *
144 * @var string
145 */
146 protected $charSet;
147
148 /**
149 * @var string
150 */
151 protected $favIcon;
152
153 /**
154 * @var string
155 */
156 protected $baseUrl;
157
158 /**
159 * @var boolean
160 */
161 protected $renderXhtml = TRUE;
162
163
164 // Static header blocks
165
166 /**
167 * @var string
168 */
169 protected $xmlPrologAndDocType = '';
170
171 /**
172 * @var array
173 */
174 protected $metaTags = array();
175
176 /**
177 * @var array
178 */
179 protected $inlineComments = array();
180
181 /**
182 * @var array
183 */
184 protected $headerData = array();
185
186 /**
187 * @var array
188 */
189 protected $footerData = array();
190
191 /**
192 * @var string
193 */
194 protected $titleTag = '<title>|</title>';
195
196 /**
197 * @var string
198 */
199 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
200
201 /**
202 * @var string
203 */
204 protected $htmlTag = '<html>';
205
206 /**
207 * @var string
208 */
209 protected $headTag = '<head>';
210
211 /**
212 * @var string
213 */
214 protected $baseUrlTag = '<base href="|" />';
215
216 /**
217 * @var string
218 */
219 protected $iconMimeType = '';
220
221 /**
222 * @var string
223 */
224 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />
225 <link rel="icon" href="%1$s"%2$s />';
226
227 // Static inline code blocks
228
229 /**
230 * @var array
231 */
232 protected $jsInline = array();
233
234 /**
235 * @var array
236 */
237 protected $jsFooterInline = array();
238
239 /**
240 * @var array
241 */
242 protected $extOnReadyCode = array();
243
244 /**
245 * @var array
246 */
247 protected $cssInline = array();
248
249 /**
250 * @var string
251 */
252 protected $bodyContent;
253
254 /**
255 * @var string
256 */
257 protected $templateFile;
258
259 /**
260 * @var array
261 */
262 protected $jsLibraryNames = array('prototype', 'scriptaculous', 'extjs');
263
264 // Paths to contibuted libraries
265
266 /**
267 * @var string
268 */
269 protected $prototypePath = 'contrib/prototype/';
270
271 /**
272 * @var string
273 */
274 protected $scriptaculousPath = 'contrib/scriptaculous/';
275
276 /**
277 * @var string
278 */
279 protected $extCorePath = 'contrib/extjs/';
280
281 /**
282 * @var string
283 */
284 protected $extJsPath = 'contrib/extjs/';
285
286 /**
287 * @var string
288 */
289 protected $svgPath = 'contrib/websvg/';
290
291 // Internal flags for JS-libraries
292
293 /**
294 * @var boolean
295 */
296 protected $addPrototype = FALSE;
297
298 /**
299 * @var boolean
300 */
301 protected $addScriptaculous = FALSE;
302
303 /**
304 * @var array
305 */
306 protected $addScriptaculousModules = array('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
307
308 /**
309 * @var boolean
310 */
311 protected $addExtJS = FALSE;
312
313 /**
314 * @var boolean
315 */
316 protected $addExtCore = FALSE;
317
318 /**
319 * @var string
320 */
321 protected $extJSadapter = 'ext/ext-base.js';
322
323 /**
324 * @var boolean
325 */
326 protected $extDirectCodeAdded = FALSE;
327
328 /**
329 * @var boolean
330 */
331 protected $enableExtJsDebug = FALSE;
332
333 /**
334 * @var boolean
335 */
336 protected $enableExtCoreDebug = FALSE;
337
338 /**
339 * @var boolean
340 */
341 protected $extJStheme = TRUE;
342
343 /**
344 * @var boolean
345 */
346 protected $extJScss = TRUE;
347
348 /**
349 * @var boolean
350 */
351 protected $enableExtJSQuickTips = FALSE;
352
353 /**
354 * @var array
355 */
356 protected $inlineLanguageLabels = array();
357
358 /**
359 * @var array
360 */
361 protected $inlineLanguageLabelFiles = array();
362
363 /**
364 * @var array
365 */
366 protected $inlineSettings = array();
367
368 /**
369 * @var array
370 */
371 protected $inlineJavascriptWrap = array();
372
373 /**
374 * Saves error messages generated during compression
375 *
376 * @var string
377 */
378 protected $compressError = '';
379
380 /**
381 * SVG library
382 *
383 * @var boolean
384 */
385 protected $addSvg = FALSE;
386
387 /**
388 * @var boolean
389 */
390 protected $enableSvgDebug = FALSE;
391
392 /**
393 * Used by BE modules
394 *
395 * @var null|string
396 */
397 public $backPath;
398
399 /**
400 * @param string $templateFile Declare the used template file. Omit this parameter will use default template
401 * @param string $backPath Relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
402 */
403 public function __construct($templateFile = '', $backPath = NULL) {
404
405 $this->reset();
406 $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
407 $this->locales = t3lib_div::makeInstance('t3lib_l10n_Locales');
408
409 if (strlen($templateFile)) {
410 $this->templateFile = $templateFile;
411 }
412 $this->backPath = isset($backPath) ? $backPath : $GLOBALS['BACK_PATH'];
413
414 $this->inlineJavascriptWrap = array(
415 '<script type="text/javascript">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
416 '// -->' . LF . '/*]]>*/' . LF . '</script>' . LF
417 );
418 $this->inlineCssWrap = array(
419 '<style type="text/css">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
420 '-->' . LF . '/*]]>*/' . LF . '</style>' . LF
421 );
422 }
423
424 /**
425 * Reset all vars to initial values
426 *
427 * @return void
428 */
429 protected function reset() {
430 $this->templateFile = TYPO3_mainDir . 'templates/template_page_backend.html';
431 $this->jsFiles = array();
432 $this->jsFooterFiles = array();
433 $this->jsInline = array();
434 $this->jsFooterInline = array();
435 $this->jsLibs = array();
436 $this->cssFiles = array();
437 $this->cssInline = array();
438 $this->metaTags = array();
439 $this->inlineComments = array();
440 $this->headerData = array();
441 $this->footerData = array();
442 $this->extOnReadyCode = array();
443 }
444
445 /*****************************************************/
446 /* */
447 /* Public Setters */
448 /* */
449 /* */
450 /*****************************************************/
451
452 /**
453 * Sets the title
454 *
455 * @param string $title title of webpage
456 * @return void
457 */
458 public function setTitle($title) {
459 $this->title = $title;
460 }
461
462 /**
463 * Enables/disables rendering of XHTML code
464 *
465 * @param boolean $enable Enable XHTML
466 * @return void
467 */
468 public function setRenderXhtml($enable) {
469 $this->renderXhtml = $enable;
470 }
471
472 /**
473 * Sets xml prolog and docType
474 *
475 * @param string $xmlPrologAndDocType Complete tags for xml prolog and docType
476 * @return void
477 */
478 public function setXmlPrologAndDocType($xmlPrologAndDocType) {
479 $this->xmlPrologAndDocType = $xmlPrologAndDocType;
480 }
481
482 /**
483 * Sets meta charset
484 *
485 * @param string $charSet Used charset
486 * @return void
487 */
488 public function setCharSet($charSet) {
489 $this->charSet = $charSet;
490 }
491
492 /**
493 * Sets language
494 *
495 * @param string $lang Used language
496 * @return void
497 */
498 public function setLanguage($lang) {
499 $this->lang = $lang;
500 }
501
502 /**
503 * Set the meta charset tag
504 *
505 * @param string $metaCharsetTag
506 * @return void
507 */
508 public function setMetaCharsetTag($metaCharsetTag) {
509 $this->metaCharsetTag = $metaCharsetTag;
510 }
511
512 /**
513 * Sets html tag
514 *
515 * @param string $htmlTag Html tag
516 * @return void
517 */
518 public function setHtmlTag($htmlTag) {
519 $this->htmlTag = $htmlTag;
520 }
521
522 /**
523 * Sets HTML head tag
524 *
525 * @param string $headTag HTML head tag
526 * @return void
527 */
528 public function setHeadTag($headTag) {
529 $this->headTag = $headTag;
530 }
531
532 /**
533 * Sets favicon
534 *
535 * @param string $favIcon
536 * @return void
537 */
538 public function setFavIcon($favIcon) {
539 $this->favIcon = $favIcon;
540 }
541
542 /**
543 * Sets icon mime type
544 *
545 * @param string $iconMimeType
546 * @return void
547 */
548 public function setIconMimeType($iconMimeType) {
549 $this->iconMimeType = $iconMimeType;
550 }
551
552 /**
553 * Sets HTML base URL
554 *
555 * @param string $baseUrl HTML base URL
556 * @return void
557 */
558 public function setBaseUrl($baseUrl) {
559 $this->baseUrl = $baseUrl;
560 }
561
562 /**
563 * Sets template file
564 *
565 * @param string $file
566 * @return void
567 */
568 public function setTemplateFile($file) {
569 $this->templateFile = $file;
570 }
571
572 /**
573 * Sets back path
574 *
575 * @param string $backPath
576 * @return void
577 */
578 public function setBackPath($backPath) {
579 $this->backPath = $backPath;
580 }
581
582 /**
583 * Sets Content for Body
584 *
585 * @param string $content
586 * @return void
587 */
588 public function setBodyContent($content) {
589 $this->bodyContent = $content;
590 }
591
592 /**
593 * Sets path to prototype library (relative to typo3 directory)
594 *
595 * @param string $path Path to prototype library
596 * @return void
597 */
598 public function setPrototypePath($path) {
599 $this->prototypePath = $path;
600 }
601
602 /**
603 * Sets Path for scriptaculous library (relative to typo3 directory)
604 *
605 * @param string $path
606 * @return void
607 */
608 public function setScriptaculousPath($path) {
609 $this->scriptaculousPath = $path;
610 }
611
612 /**
613 * Sets Path for Ext Core library (relative to typo3 directory)
614 *
615 * @param string $path
616 * @return void
617 */
618 public function setExtCorePath($path) {
619 $this->extCorePath = $path;
620 }
621
622 /**
623 * Sets Path for ExtJs library (relative to typo3 directory)
624 *
625 * @param string $path
626 * @return void
627 */
628 public function setExtJsPath($path) {
629 $this->extJsPath = $path;
630 }
631
632 /**
633 * Sets Path for SVG library (websvg)
634 *
635 * @param string $path
636 * @return void
637 */
638 public function setSvgPath($path) {
639 $this->svgPath = $path;
640 }
641
642 /*****************************************************/
643 /* */
644 /* Public Enablers / Disablers */
645 /* */
646 /* */
647 /*****************************************************/
648
649 /**
650 * Enables MoveJsFromHeaderToFooter
651 * @return void
652 */
653 public function enableMoveJsFromHeaderToFooter() {
654 $this->moveJsFromHeaderToFooter = TRUE;
655 }
656
657 /**
658 * Disables MoveJsFromHeaderToFooter
659 * @return void
660 */
661 public function disableMoveJsFromHeaderToFooter() {
662 $this->moveJsFromHeaderToFooter = FALSE;
663 }
664
665 /**
666 * Enables compression of javascript
667 * @return void
668 */
669 public function enableCompressJavascript() {
670 $this->compressJavascript = TRUE;
671 }
672
673 /**
674 * Disables compression of javascript
675 * @return void
676 */
677 public function disableCompressJavascript() {
678 $this->compressJavascript = FALSE;
679 }
680
681 /**
682 * Enables compression of css
683 * @return void
684 */
685 public function enableCompressCss() {
686 $this->compressCss = TRUE;
687 }
688
689 /**
690 * Disables compression of css
691 * @return void
692 */
693 public function disableCompressCss() {
694 $this->compressCss = FALSE;
695 }
696
697 /**
698 * Enables concatenation of js and css files
699 * @return void
700 */
701 public function enableConcatenateFiles() {
702 $this->concatenateFiles = TRUE;
703 }
704
705 /**
706 * Disables concatenation of js and css files
707 * @return void
708 */
709 public function disableConcatenateFiles() {
710 $this->concatenateFiles = FALSE;
711 }
712
713 /**
714 * Enables concatenation of js files
715 * @return void
716 */
717 public function enableConcatenateJavascript() {
718 $this->concatenateJavascript = TRUE;
719 }
720
721 /**
722 * Disables concatenation of js files
723 * @return void
724 */
725 public function disableConcatenateJavascript() {
726 $this->concatenateJavascript = FALSE;
727 }
728
729 /**
730 * Enables concatenation of css files
731 * @return void
732 */
733 public function enableConcatenateCss() {
734 $this->concatenateCss = TRUE;
735 }
736
737 /**
738 * Disables concatenation of css files
739 * @return void
740 */
741 public function disableConcatenateCss() {
742 $this->concatenateCss = FALSE;
743 }
744
745 /**
746 * Sets removal of all line breaks in template
747 * @return void
748 */
749 public function enableRemoveLineBreaksFromTemplate() {
750 $this->removeLineBreaksFromTemplate = TRUE;
751 }
752
753 /**
754 * Unsets removal of all line breaks in template
755 * @return void
756 */
757 public function disableRemoveLineBreaksFromTemplate() {
758 $this->removeLineBreaksFromTemplate = FALSE;
759 }
760
761 /**
762 * Enables Debug Mode
763 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
764 * @return void
765 */
766 public function enableDebugMode() {
767 $this->compressJavascript = FALSE;
768 $this->compressCss = FALSE;
769 $this->concatenateFiles = FALSE;
770 $this->removeLineBreaksFromTemplate = FALSE;
771 $this->enableExtCoreDebug = TRUE;
772 $this->enableExtJsDebug = TRUE;
773 $this->enableSvgDebug = TRUE;
774 }
775
776 /*****************************************************/
777 /* */
778 /* Public Getters */
779 /* */
780 /* */
781 /*****************************************************/
782
783 /**
784 * Gets the title
785 *
786 * @return string $title Title of webpage
787 */
788 public function getTitle() {
789 return $this->title;
790 }
791
792 /**
793 * Gets the charSet
794 *
795 * @return string $charSet
796 */
797 public function getCharSet() {
798 return $this->charSet;
799 }
800
801 /**
802 * Gets the language
803 *
804 * @return string $lang
805 */
806 public function getLanguage() {
807 return $this->lang;
808 }
809
810 /**
811 * Returns rendering mode XHTML or HTML
812 *
813 * @return boolean TRUE if XHTML, FALSE if HTML
814 */
815 public function getRenderXhtml() {
816 return $this->renderXhtml;
817 }
818
819 /**
820 * Gets html tag
821 *
822 * @return string $htmlTag Html tag
823 */
824 public function getHtmlTag() {
825 return $this->htmlTag;
826 }
827
828 /**
829 * Get meta charset
830 *
831 * @return string
832 */
833 public function getMetaCharsetTag() {
834 return $this->metaCharsetTag;
835 }
836
837 /**
838 * Gets head tag
839 *
840 * @return string $tag Head tag
841 */
842 public function getHeadTag() {
843 return $this->headTag;
844 }
845
846 /**
847 * Gets favicon
848 *
849 * @return string $favIcon
850 */
851 public function getFavIcon() {
852 return $this->favIcon;
853 }
854
855 /**
856 * Gets icon mime type
857 *
858 * @return string $iconMimeType
859 */
860 public function getIconMimeType() {
861 return $this->iconMimeType;
862 }
863
864 /**
865 * Gets HTML base URL
866 *
867 * @return string $url
868 */
869 public function getBaseUrl() {
870 return $this->baseUrl;
871 }
872
873 /**
874 * Gets template file
875 *
876 * @return string
877 */
878 public function getTemplateFile() {
879 return $this->templateFile;
880 }
881
882 /**
883 * Gets MoveJsFromHeaderToFooter
884 *
885 * @return boolean
886 */
887 public function getMoveJsFromHeaderToFooter() {
888 return $this->moveJsFromHeaderToFooter;
889 }
890
891 /**
892 * Gets compress of javascript
893 *
894 * @return boolean
895 */
896 public function getCompressJavascript() {
897 return $this->compressJavascript;
898 }
899
900 /**
901 * Gets compress of css
902 *
903 * @return boolean
904 */
905 public function getCompressCss() {
906 return $this->compressCss;
907 }
908
909 /**
910 * Gets concatenate of js and css files
911 *
912 * @return boolean
913 */
914 public function getConcatenateFiles() {
915 return $this->concatenateFiles;
916 }
917
918 /**
919 * Gets concatenate of js files
920 *
921 * @return boolean
922 */
923 public function getConcatenateJavascript() {
924 return $this->concatenateJavascript;
925 }
926
927 /**
928 * Gets concatenate of css files
929 *
930 * @return boolean
931 */
932 public function getConcatenateCss() {
933 return $this->concatenateCss;
934 }
935
936 /**
937 * Gets remove of empty lines from template
938 *
939 * @return boolean
940 */
941 public function getRemoveLineBreaksFromTemplate() {
942 return $this->removeLineBreaksFromTemplate;
943 }
944
945 /**
946 * Gets content for body
947 *
948 * @return string
949 */
950 public function getBodyContent() {
951 return $this->bodyContent;
952 }
953
954 /**
955 * Gets Path for prototype library (relative to typo3 directory)
956 *
957 * @return string
958 */
959 public function getPrototypePath() {
960 return $this->prototypePath;
961 }
962
963 /**
964 * Gets Path for scriptaculous library (relative to typo3 directory)
965 *
966 * @return string
967 */
968 public function getScriptaculousPath() {
969 return $this->scriptaculousPath;
970 }
971
972 /**
973 * Gets Path for Ext Core library (relative to typo3 directory)
974 *
975 * @return string
976 */
977 public function getExtCorePath() {
978 return $this->extCorePath;
979 }
980
981 /**
982 * Gets Path for ExtJs library (relative to typo3 directory)
983 *
984 * @return string
985 */
986 public function getExtJsPath() {
987 return $this->extJsPath;
988 }
989
990 /**
991 * Gets Path for SVG library (relative to typo3 directory)
992 *
993 * @return string
994 */
995 public function getSvgPath() {
996 return $this->svgPath;
997 }
998
999 /**
1000 * Gets the inline language labels.
1001 *
1002 * @return array The inline language labels
1003 */
1004 public function getInlineLanguageLabels() {
1005 return $this->inlineLanguageLabels;
1006 }
1007
1008 /**
1009 * Gets the inline language files
1010 *
1011 * @return array
1012 */
1013 public function getInlineLanguageLabelFiles() {
1014 return $this->inlineLanguageLabelFiles;
1015 }
1016
1017 /*****************************************************/
1018 /* */
1019 /* Public Functions to add Data */
1020 /* */
1021 /* */
1022 /*****************************************************/
1023
1024 /**
1025 * Adds meta data
1026 *
1027 * @param string $meta Meta data (complete metatag)
1028 * @return void
1029 */
1030 public function addMetaTag($meta) {
1031 if (!in_array($meta, $this->metaTags)) {
1032 $this->metaTags[] = $meta;
1033 }
1034 }
1035
1036 /**
1037 * Adds inline HTML comment
1038 *
1039 * @param string $comment
1040 * @return void
1041 */
1042 public function addInlineComment($comment) {
1043 if (!in_array($comment, $this->inlineComments)) {
1044 $this->inlineComments[] = $comment;
1045 }
1046 }
1047
1048 /**
1049 * Adds header data
1050 *
1051 * @param string $data Free header data for HTML header
1052 * @return void
1053 */
1054 public function addHeaderData($data) {
1055 if (!in_array($data, $this->headerData)) {
1056 $this->headerData[] = $data;
1057 }
1058 }
1059
1060 /**
1061 * Adds footer data
1062 *
1063 * @param string $data Free header data for HTML header
1064 * @return void
1065 */
1066 public function addFooterData($data) {
1067 if (!in_array($data, $this->footerData)) {
1068 $this->footerData[] = $data;
1069 }
1070 }
1071
1072 /**
1073 * Adds JS Library. JS Library block is rendered on top of the JS files.
1074 *
1075 * @param string $name Arbitrary identifier
1076 * @param string $file File name
1077 * @param string $type Content Type
1078 * @param boolean $compress Flag if library should be compressed
1079 * @param boolean $forceOnTop Flag if added library should be inserted at begin of this block
1080 * @param string $allWrap
1081 * @param boolean $excludeFromConcatenation
1082 * @return void
1083 */
1084 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1085 if (!$type) {
1086 $type = 'text/javascript';
1087 }
1088 if (!in_array(strtolower($name), $this->jsLibs)) {
1089 $this->jsLibs[strtolower($name)] = array(
1090 'file' => $file,
1091 'type' => $type,
1092 'section' => self::PART_HEADER,
1093 'compress' => $compress,
1094 'forceOnTop' => $forceOnTop,
1095 'allWrap' => $allWrap,
1096 'excludeFromConcatenation' => $excludeFromConcatenation,
1097 );
1098 }
1099 }
1100
1101 /**
1102 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
1103 *
1104 * @param string $name Arbitrary identifier
1105 * @param string $file File name
1106 * @param string $type Content Type
1107 * @param boolean $compress Flag if library should be compressed
1108 * @param boolean $forceOnTop Flag if added library should be inserted at begin of this block
1109 * @param string $allWrap
1110 * @param boolean $excludeFromConcatenation
1111 * @return void
1112 */
1113 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1114 if (!$type) {
1115 $type = 'text/javascript';
1116 }
1117 if (!in_array(strtolower($name), $this->jsLibs)) {
1118 $this->jsLibs[strtolower($name)] = array(
1119 'file' => $file,
1120 'type' => $type,
1121 'section' => self::PART_FOOTER,
1122 'compress' => $compress,
1123 'forceOnTop' => $forceOnTop,
1124 'allWrap' => $allWrap,
1125 'excludeFromConcatenation' => $excludeFromConcatenation,
1126 );
1127 }
1128 }
1129
1130 /**
1131 * Adds JS file
1132 *
1133 * @param string $file File name
1134 * @param string $type Content Type
1135 * @param boolean $compress
1136 * @param boolean $forceOnTop
1137 * @param string $allWrap
1138 * @param boolean $excludeFromConcatenation
1139 * @return void
1140 */
1141 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1142 if (!$type) {
1143 $type = 'text/javascript';
1144 }
1145 if (!isset($this->jsFiles[$file])) {
1146 if (strpos($file, 'ajax.php?') !== FALSE) {
1147 $compress = FALSE;
1148 }
1149 $this->jsFiles[$file] = array(
1150 'file' => $file,
1151 'type' => $type,
1152 'section' => self::PART_HEADER,
1153 'compress' => $compress,
1154 'forceOnTop' => $forceOnTop,
1155 'allWrap' => $allWrap,
1156 'excludeFromConcatenation' => $excludeFromConcatenation,
1157 );
1158 }
1159 }
1160
1161 /**
1162 * Adds JS file to footer
1163 *
1164 * @param string $file File name
1165 * @param string $type Content Type
1166 * @param boolean $compress
1167 * @param boolean $forceOnTop
1168 * @param string $allWrap
1169 * @param boolean $excludeFromConcatenation
1170 * @return void
1171 */
1172 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1173 if (!$type) {
1174 $type = 'text/javascript';
1175 }
1176 if (!isset($this->jsFiles[$file])) {
1177 if (strpos($file, 'ajax.php?') !== FALSE) {
1178 $compress = FALSE;
1179 }
1180 $this->jsFiles[$file] = array(
1181 'file' => $file,
1182 'type' => $type,
1183 'section' => self::PART_FOOTER,
1184 'compress' => $compress,
1185 'forceOnTop' => $forceOnTop,
1186 'allWrap' => $allWrap,
1187 'excludeFromConcatenation' => $excludeFromConcatenation,
1188 );
1189 }
1190 }
1191
1192 /**
1193 * Adds JS inline code
1194 *
1195 * @param string $name
1196 * @param string $block
1197 * @param boolean $compress
1198 * @param boolean $forceOnTop
1199 * @return void
1200 */
1201 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1202 if (!isset($this->jsInline[$name]) && !empty($block)) {
1203 $this->jsInline[$name] = array(
1204 'code' => $block . LF,
1205 'section' => self::PART_HEADER,
1206 'compress' => $compress,
1207 'forceOnTop' => $forceOnTop
1208 );
1209 }
1210 }
1211
1212 /**
1213 * Adds JS inline code to footer
1214 *
1215 * @param string $name
1216 * @param string $block
1217 * @param boolean $compress
1218 * @param boolean $forceOnTop
1219 * @return void
1220 */
1221 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1222 if (!isset($this->jsInline[$name]) && !empty($block)) {
1223 $this->jsInline[$name] = array(
1224 'code' => $block . LF,
1225 'section' => self::PART_FOOTER,
1226 'compress' => $compress,
1227 'forceOnTop' => $forceOnTop
1228 );
1229 }
1230 }
1231
1232 /**
1233 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
1234 *
1235 * @param string $block Javascript code
1236 * @param boolean $forceOnTop Position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
1237 * @return void
1238 */
1239 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
1240 if (!in_array($block, $this->extOnReadyCode)) {
1241 if ($forceOnTop) {
1242 array_unshift($this->extOnReadyCode, $block);
1243 } else {
1244 $this->extOnReadyCode[] = $block;
1245 }
1246 }
1247 }
1248
1249 /**
1250 * Adds the ExtDirect code
1251 *
1252 * @param array $filterNamespaces Limit the output to defined namespaces. If empty, all namespaces are generated
1253 * @return void
1254 */
1255 public function addExtDirectCode(array $filterNamespaces = array()) {
1256 if ($this->extDirectCodeAdded) {
1257 return;
1258 }
1259 $this->extDirectCodeAdded = TRUE;
1260
1261 if (count($filterNamespaces) === 0) {
1262 $filterNamespaces = array('TYPO3');
1263 }
1264
1265 // For ExtDirect we need flash message support
1266 $this->addJsFile(t3lib_div::resolveBackPath($this->backPath . '../t3lib/js/extjs/ux/flashmessages.js'));
1267
1268 // Add language labels for ExtDirect
1269 if (TYPO3_MODE === 'FE') {
1270 $this->addInlineLanguageLabelArray(array(
1271 'extDirect_timeoutHeader' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutHeader'),
1272 'extDirect_timeoutMessage' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutMessage'),
1273 ));
1274 } else {
1275 $this->addInlineLanguageLabelArray(array(
1276 'extDirect_timeoutHeader' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutHeader'),
1277 'extDirect_timeoutMessage' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutMessage'),
1278 ));
1279 }
1280
1281 $token = $api = '';
1282 if (TYPO3_MODE === 'BE') {
1283 $formprotection = t3lib_formprotection_Factory::get();
1284 $token = $formprotection->generateToken('extDirect');
1285 }
1286
1287 /** @var $extDirect t3lib_extjs_ExtDirectApi */
1288 $extDirect = t3lib_div::makeInstance('t3lib_extjs_ExtDirectApi');
1289 $api = $extDirect->getApiPhp($filterNamespaces);
1290 if ($api) {
1291 $this->addJsInlineCode('TYPO3ExtDirectAPI', $api, FALSE);
1292 }
1293 // Note: we need to iterate thru the object, because the addProvider method
1294 // does this only with multiple arguments
1295 $this->addExtOnReadyCode('
1296 (function() {
1297 TYPO3.ExtDirectToken = "' . $token . '";
1298 for (var api in Ext.app.ExtDirectAPI) {
1299 var provider = Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
1300 provider.on("beforecall", function(provider, transaction, meta) {
1301 if (transaction.data) {
1302 transaction.data[transaction.data.length] = TYPO3.ExtDirectToken;
1303 } else {
1304 transaction.data = [TYPO3.ExtDirectToken];
1305 }
1306 });
1307
1308 provider.on("call", function(provider, transaction, meta) {
1309 if (transaction.isForm) {
1310 transaction.params.securityToken = TYPO3.ExtDirectToken;
1311 }
1312 });
1313 }
1314 })();
1315
1316 var extDirectDebug = function(message, header, group) {
1317 var TYPO3ViewportInstance = null;
1318
1319 if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
1320 TYPO3ViewportInstance = top.TYPO3.Backend;
1321 } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
1322 TYPO3ViewportInstance = TYPO3.Backend;
1323 }
1324
1325 if (TYPO3ViewportInstance !== null) {
1326 TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
1327 } else if (typeof console === "object") {
1328 console.log(message);
1329 } else {
1330 document.write(message);
1331 }
1332 };
1333
1334 Ext.Direct.on("exception", function(event) {
1335 if (event.code === Ext.Direct.exceptions.TRANSPORT && !event.where) {
1336 TYPO3.Flashmessage.display(
1337 TYPO3.Severity.error,
1338 TYPO3.l10n.localize("extDirect_timeoutHeader"),
1339 TYPO3.l10n.localize("extDirect_timeoutMessage"),
1340 30
1341 );
1342 } else {
1343 var backtrace = "";
1344 if (event.code === "parse") {
1345 extDirectDebug(
1346 "<p>" + event.xhr.responseText + "<\/p>",
1347 event.type,
1348 "ExtDirect - Exception"
1349 );
1350 } else if (event.code === "router") {
1351 TYPO3.Flashmessage.display(
1352 TYPO3.Severity.error,
1353 event.code,
1354 event.message,
1355 30
1356 );
1357 } else if (event.where) {
1358 backtrace = "<p style=\"margin-top: 20px;\">" +
1359 "<strong>Backtrace:<\/strong><br \/>" +
1360 event.where.replace(/#/g, "<br \/>#") +
1361 "<\/p>";
1362 extDirectDebug(
1363 "<p>" + event.message + "<\/p>" + backtrace,
1364 event.method,
1365 "ExtDirect - Exception"
1366 );
1367 }
1368
1369
1370 }
1371 });
1372
1373 Ext.Direct.on("event", function(event, provider) {
1374 if (typeof event.debug !== "undefined" && event.debug !== "") {
1375 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
1376 }
1377 });
1378 ',
1379 TRUE
1380 );
1381 }
1382
1383 /**
1384 * Adds CSS file
1385 *
1386 * @param string $file
1387 * @param string $rel
1388 * @param string $media
1389 * @param string $title
1390 * @param boolean $compress
1391 * @param boolean $forceOnTop
1392 * @param string $allWrap
1393 * @param boolean $excludeFromConcatenation
1394 * @return void
1395 */
1396 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1397 if (!isset($this->cssFiles[$file])) {
1398 $this->cssFiles[$file] = array(
1399 'file' => $file,
1400 'rel' => $rel,
1401 'media' => $media,
1402 'title' => $title,
1403 'compress' => $compress,
1404 'forceOnTop' => $forceOnTop,
1405 'allWrap' => $allWrap,
1406 'excludeFromConcatenation' => $excludeFromConcatenation,
1407 );
1408 }
1409 }
1410
1411 /**
1412 * Adds CSS inline code
1413 *
1414 * @param string $name
1415 * @param string $block
1416 * @param boolean $compress
1417 * @param boolean $forceOnTop
1418 * @return void
1419 */
1420 public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
1421 if (!isset($this->cssInline[$name]) && !empty($block)) {
1422 $this->cssInline[$name] = array(
1423 'code' => $block,
1424 'compress' => $compress,
1425 'forceOnTop' => $forceOnTop
1426 );
1427 }
1428 }
1429
1430 /**
1431 * Call function if you need the prototype library
1432 *
1433 * @return void
1434 */
1435 public function loadPrototype() {
1436 $this->addPrototype = TRUE;
1437 }
1438
1439 /**
1440 * Call function if you need the Scriptaculous library
1441 *
1442 * @param string $modules Add modules you need. use "all" if you need complete modules
1443 * @return void
1444 */
1445 public function loadScriptaculous($modules = 'all') {
1446 // Scriptaculous require prototype, so load prototype too.
1447 $this->addPrototype = TRUE;
1448 $this->addScriptaculous = TRUE;
1449 if ($modules) {
1450 if ($modules == 'all') {
1451 foreach ($this->addScriptaculousModules as $key => $value) {
1452 $this->addScriptaculousModules[$key] = TRUE;
1453 }
1454 } else {
1455 $mods = t3lib_div::trimExplode(',', $modules);
1456 foreach ($mods as $mod) {
1457 if (isset($this->addScriptaculousModules[strtolower($mod)])) {
1458 $this->addScriptaculousModules[strtolower($mod)] = TRUE;
1459 }
1460 }
1461 }
1462 }
1463 }
1464
1465 /**
1466 * call this function if you need the extJS library
1467 *
1468 * @param boolean $css Flag, if set the ext-css will be loaded
1469 * @param boolean $theme Flag, if set the ext-theme "grey" will be loaded
1470 * @param string $adapter Choose alternative adapter, possible values: yui, prototype, jquery
1471 * @return void
1472 */
1473 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
1474 if ($adapter) {
1475 // Empty $adapter will always load the ext adapter
1476 switch (t3lib_div::strtolower(trim($adapter))) {
1477 case self::EXTJS_ADAPTER_YUI :
1478 $this->extJSadapter = 'yui/ext-yui-adapter.js';
1479 break;
1480 case self::EXTJS_ADAPTER_PROTOTYPE :
1481 $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
1482 break;
1483 case self::EXTJS_ADAPTER_JQUERY :
1484 $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
1485 break;
1486 }
1487 }
1488 $this->addExtJS = TRUE;
1489 $this->extJStheme = $theme;
1490 $this->extJScss = $css;
1491 }
1492
1493 /**
1494 * Enables ExtJs QuickTips
1495 * Need extJs loaded
1496 *
1497 * @return void
1498 */
1499 public function enableExtJSQuickTips() {
1500 $this->enableExtJSQuickTips = TRUE;
1501 }
1502
1503 /**
1504 * Call function if you need the ExtCore library
1505 *
1506 * @return void
1507 */
1508 public function loadExtCore() {
1509 $this->addExtCore = TRUE;
1510 }
1511
1512 /**
1513 * Call function if you need the SVG library
1514 *
1515 * @return void
1516 */
1517 public function loadSvg() {
1518 $this->addSvg = TRUE;
1519 }
1520
1521 /**
1522 * Call this function to load debug version of ExtJS. Use this for development only
1523 * @return void
1524 */
1525 public function enableSvgDebug() {
1526 $this->enableSvgDebug = TRUE;
1527 }
1528
1529 /**
1530 * Call this function to force flash usage with SVG library
1531 * @return void
1532 */
1533 public function svgForceFlash() {
1534 $this->addMetaTag('<meta name="svg.render.forceflash" content="true" />');
1535 }
1536
1537 /**
1538 * Call this function to load debug version of ExtJS. Use this for development only
1539 * @return void
1540 */
1541 public function enableExtJsDebug() {
1542 $this->enableExtJsDebug = TRUE;
1543 }
1544
1545 /**
1546 * Call this function to load debug version of ExtCore. Use this for development only
1547 * @return void
1548 */
1549 public function enableExtCoreDebug() {
1550 $this->enableExtCoreDebug = TRUE;
1551 }
1552
1553 /**
1554 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1555 * The label can be used in scripts with TYPO3.lang.<key>
1556 * Need extJs loaded
1557 *
1558 * @param string $key
1559 * @param string $value
1560 * @return void
1561 */
1562 public function addInlineLanguageLabel($key, $value) {
1563 $this->inlineLanguageLabels[$key] = $value;
1564 }
1565
1566 /**
1567 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1568 * The label can be used in scripts with TYPO3.lang.<key>
1569 * Array will be merged with existing array.
1570 * Need extJs loaded
1571 *
1572 * @param array $array
1573 * @return void
1574 */
1575 public function addInlineLanguageLabelArray(array $array) {
1576 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
1577 }
1578
1579 /**
1580 * Gets labels to be used in JavaScript fetched from a locallang file.
1581 *
1582 * @param string $fileRef Input is a file-reference (see t3lib_div::getFileAbsFileName). That file is expected to be a 'locallang.xml' file containing a valid XML TYPO3 language structure.
1583 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1584 * @param string $stripFromSelectionName Sub-prefix to be removed from label names in the result (default: '')
1585 * @param integer $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1586 * @return void
1587 */
1588 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1589 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1590 if ($fileRef && !isset($this->inlineLanguageLabelFiles[$index])) {
1591 $this->inlineLanguageLabelFiles[$index] = array(
1592 'fileRef' => $fileRef,
1593 'selectionPrefix' => $selectionPrefix,
1594 'stripFromSelectionName' => $stripFromSelectionName,
1595 'errorMode' => $errorMode
1596 );
1597 }
1598 }
1599
1600
1601 /**
1602 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1603 * The label can be used in scripts with TYPO3.setting.<key>
1604 * Need extJs loaded
1605 *
1606 * @param string $namespace
1607 * @param string $key
1608 * @param string $value
1609 * @return void
1610 */
1611 public function addInlineSetting($namespace, $key, $value) {
1612 if ($namespace) {
1613 if (strpos($namespace, '.')) {
1614 $parts = explode('.', $namespace);
1615 $a = &$this->inlineSettings;
1616 foreach ($parts as $part) {
1617 $a = &$a[$part];
1618 }
1619 $a[$key] = $value;
1620 } else {
1621 $this->inlineSettings[$namespace][$key] = $value;
1622 }
1623 } else {
1624 $this->inlineSettings[$key] = $value;
1625 }
1626 }
1627
1628 /**
1629 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1630 * The label can be used in scripts with TYPO3.setting.<key>
1631 * Array will be merged with existing array.
1632 * Need extJs loaded
1633 *
1634 * @param string $namespace
1635 * @param array $array
1636 * @return void
1637 */
1638 public function addInlineSettingArray($namespace, array $array) {
1639 if ($namespace) {
1640 if (strpos($namespace, '.')) {
1641 $parts = explode('.', $namespace);
1642 $a = &$this->inlineSettings;
1643 foreach ($parts as $part) {
1644 $a = &$a[$part];
1645 }
1646 $a = array_merge((array) $a, $array);
1647 } else {
1648 $this->inlineSettings[$namespace] = array_merge((array) $this->inlineSettings[$namespace], $array);
1649 }
1650 } else {
1651 $this->inlineSettings = array_merge($this->inlineSettings, $array);
1652 }
1653 }
1654
1655 /**
1656 * Adds content to body content
1657 *
1658 * @param string $content
1659 * @return void
1660 */
1661 public function addBodyContent($content) {
1662 $this->bodyContent .= $content;
1663 }
1664
1665 /*****************************************************/
1666 /* */
1667 /* Render Functions */
1668 /* */
1669 /* */
1670 /*****************************************************/
1671
1672 /**
1673 * Render the section (Header or Footer)
1674 *
1675 * @param integer $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1676 * @return string Content of rendered section
1677 */
1678 public function render($part = self::PART_COMPLETE) {
1679
1680 $jsFiles = '';
1681 $cssFiles = '';
1682 $cssInline = '';
1683 $jsInline = '';
1684 $jsFooterInline = '';
1685 $jsFooterLibs = '';
1686 $jsFooterFiles = '';
1687
1688 // PreRenderHook for possible manuipulation
1689 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
1690 $params = array(
1691 'jsLibs' => &$this->jsLibs,
1692 'jsFooterLibs' => &$this->jsFooterLibs,
1693 'jsFiles' => &$this->jsFiles,
1694 'jsFooterFiles' => &$this->jsFooterFiles,
1695 'cssFiles' => &$this->cssFiles,
1696 'headerData' => &$this->headerData,
1697 'footerData' => &$this->footerData,
1698 'jsInline' => &$this->jsInline,
1699 'jsFooterInline' => &$this->jsFooterInline,
1700 'cssInline' => &$this->cssInline,
1701 );
1702 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
1703 t3lib_div::callUserFunction($hook, $params, $this);
1704 }
1705 }
1706
1707 $jsLibs = $this->renderJsLibraries();
1708
1709 if ($this->concatenateFiles || $this->concatenateJavascript || $this->concatenateCss) {
1710 // Do the file concatenation
1711 $this->doConcatenate();
1712 }
1713 if ($this->compressCss || $this->compressJavascript) {
1714 // Do the file compression
1715 $this->doCompress();
1716 }
1717 // PostTransform for possible manuipulation of concatenated and compressed files
1718 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
1719 $params = array(
1720 'jsLibs' => &$this->jsLibs,
1721 'jsFooterLibs' => &$this->jsFooterLibs,
1722 'jsFiles' => &$this->jsFiles,
1723 'jsFooterFiles' => &$this->jsFooterFiles,
1724 'cssFiles' => &$this->cssFiles,
1725 'headerData' => &$this->headerData,
1726 'footerData' => &$this->footerData,
1727 'jsInline' => &$this->jsInline,
1728 'jsFooterInline' => &$this->jsFooterInline,
1729 'cssInline' => &$this->cssInline,
1730 );
1731 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
1732 t3lib_div::callUserFunction($hook, $params, $this);
1733 }
1734 }
1735 $metaTags = implode(LF, $this->metaTags);
1736
1737 // Remove ending slashes from static header block
1738 // if the page is beeing rendered as html (not xhtml)
1739 // and define variable $endingSlash for further use
1740 if ($this->getRenderXhtml()) {
1741 $endingSlash = ' /';
1742 } else {
1743 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
1744 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
1745 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
1746 $endingSlash = '';
1747 }
1748
1749 if (count($this->cssFiles)) {
1750 foreach ($this->cssFiles as $name => $properties) {
1751 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
1752 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
1753 $tag = '<link rel="' . htmlspecialchars($properties['rel']) . '" type="text/css" href="' .
1754 htmlspecialchars($properties['file']) . '" media="' . htmlspecialchars($properties['media']) . '"' .
1755 ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '') .
1756 $endingSlash . '>';
1757 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1758 $tag = str_replace('|', $tag, $properties['allWrap']);
1759 }
1760 if ($properties['forceOnTop']) {
1761 $cssFiles = $tag . LF . $cssFiles;
1762 } else {
1763 $cssFiles .= LF . $tag;
1764 }
1765 }
1766 }
1767
1768 if (count($this->cssInline)) {
1769 foreach ($this->cssInline as $name => $properties) {
1770 if ($properties['forceOnTop']) {
1771 $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $cssInline;
1772 } else {
1773 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1774 }
1775 }
1776 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
1777 }
1778
1779 if (count($this->jsLibs)) {
1780 foreach ($this->jsLibs as $name => $properties) {
1781 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
1782 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
1783 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
1784 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1785 $tag = str_replace('|', $tag, $properties['allWrap']);
1786 }
1787 if ($properties['forceOnTop']) {
1788 if ($properties['section'] === self::PART_HEADER) {
1789 $jsLibs = $tag . LF . $jsLibs;
1790 } else {
1791 $jsFooterLibs = $tag . LF . $jsFooterLibs;
1792 }
1793 } else {
1794 if ($properties['section'] === self::PART_HEADER) {
1795 $jsLibs .= LF . $tag;
1796 } else {
1797 $jsFooterLibs .= LF . $tag;
1798 }
1799 }
1800 }
1801 }
1802
1803 if (count($this->jsFiles)) {
1804 foreach ($this->jsFiles as $name => $properties) {
1805 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
1806 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
1807 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
1808 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1809 $tag = str_replace('|', $tag, $properties['allWrap']);
1810 }
1811 if ($properties['forceOnTop']) {
1812 if ($properties['section'] === self::PART_HEADER) {
1813 $jsFiles = $tag . LF . $jsFiles;
1814 } else {
1815 $jsFooterFiles = $tag . LF . $jsFooterFiles;
1816 }
1817 } else {
1818 if ($properties['section'] === self::PART_HEADER) {
1819 $jsFiles .= LF . $tag;
1820 } else {
1821 $jsFooterFiles .= LF . $tag;
1822 }
1823 }
1824 }
1825 }
1826
1827 if (count($this->jsInline)) {
1828 foreach ($this->jsInline as $name => $properties) {
1829 if ($properties['forceOnTop']) {
1830 if ($properties['section'] === self::PART_HEADER) {
1831 $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsInline;
1832 } else {
1833 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsFooterInline;
1834 }
1835 } else {
1836 if ($properties['section'] === self::PART_HEADER) {
1837 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1838 } else {
1839 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1840 }
1841 }
1842 }
1843 }
1844
1845
1846 if ($jsInline) {
1847 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
1848 }
1849
1850 if ($jsFooterInline) {
1851 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
1852 }
1853
1854
1855 // Get template
1856 $templateFile = t3lib_div::getFileAbsFileName($this->templateFile, TRUE);
1857 $template = t3lib_div::getUrl($templateFile);
1858
1859 if ($this->removeLineBreaksFromTemplate) {
1860 $template = strtr($template, array(LF => '', CR => ''));
1861 }
1862 if ($part != self::PART_COMPLETE) {
1863 $templatePart = explode('###BODY###', $template);
1864 $template = $templatePart[$part - 1];
1865 }
1866
1867 if ($this->moveJsFromHeaderToFooter) {
1868 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
1869 $jsLibs = '';
1870 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
1871 $jsFiles = '';
1872 $jsFooterInline = $jsInline . LF . $jsFooterInline;
1873 $jsInline = '';
1874 }
1875
1876 // PostRenderHook for possible manipulation
1877 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
1878 $params = array (
1879 'jsLibs' => &$jsLibs,
1880 'jsFiles' => &$jsFiles,
1881 'jsFooterFiles' => &$jsFooterFiles,
1882 'cssFiles' => &$cssFiles,
1883 'headerData' => &$this->headerData,
1884 'footerData' => &$this->footerData,
1885 'jsInline' => &$jsInline,
1886 'cssInline' => &$cssInline,
1887 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType,
1888 'htmlTag' => &$this->htmlTag,
1889 'headTag' => &$this->headTag,
1890 'charSet' => &$this->charSet,
1891 'metaCharsetTag' => &$this->metaCharsetTag,
1892 'shortcutTag' => &$this->shortcutTag,
1893 'inlineComments' => &$this->inlineComments,
1894 'baseUrl' => &$this->baseUrl,
1895 'baseUrlTag' => &$this->baseUrlTag,
1896 'favIcon' => &$this->favIcon,
1897 'iconMimeType' => &$this->iconMimeType,
1898 'titleTag' => &$this->titleTag,
1899 'title' => &$this->title,
1900 'metaTags' => &$metaTags,
1901 'jsFooterInline' => &$jsFooterInline,
1902 'jsFooterLibs' => &$jsFooterLibs,
1903 'bodyContent' => &$this->bodyContent,
1904 );
1905 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
1906 t3lib_div::callUserFunction($hook, $params, $this);
1907 }
1908 }
1909
1910 $markerArray = array(
1911 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1912 'HTMLTAG' => $this->htmlTag,
1913 'HEADTAG' => $this->headTag,
1914 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1915 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1916 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1917 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1918 'CSS_INCLUDE' => $cssFiles,
1919 'CSS_INLINE' => $cssInline,
1920 'JS_INLINE' => $jsInline,
1921 'JS_INCLUDE' => $jsFiles,
1922 'JS_LIBS' => $jsLibs,
1923 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1924 'META' => $metaTags,
1925 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
1926 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
1927 'JS_LIBS_FOOTER' => $jsFooterLibs,
1928 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1929 'JS_INLINE_FOOTER' => $jsFooterInline,
1930 'BODY' => $this->bodyContent,
1931 );
1932
1933 $markerArray = array_map('trim', $markerArray);
1934
1935 $this->reset();
1936 return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
1937 }
1938
1939 /**
1940 * helper function for render the javascript libraries
1941 *
1942 * @return string Content with javascript libraries
1943 */
1944 protected function renderJsLibraries() {
1945 $out = '';
1946
1947 if ($this->addSvg) {
1948 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->svgPath . 'svg.js') .
1949 '" data-path="' . $this->backPath . $this->svgPath .
1950 '"' . ($this->enableSvgDebug ? ' data-debug="true"' : '') . '></script>';
1951 }
1952
1953 if ($this->addPrototype) {
1954 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->prototypePath . 'prototype.js') .
1955 '" type="text/javascript"></script>' . LF;
1956 unset($this->jsFiles[$this->backPath . $this->prototypePath . 'prototype.js']);
1957 }
1958
1959 if ($this->addScriptaculous) {
1960 $mods = array();
1961 foreach ($this->addScriptaculousModules as $key => $value) {
1962 if ($this->addScriptaculousModules[$key]) {
1963 $mods[] = $key;
1964 }
1965 }
1966 // Resolve dependencies
1967 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
1968 $mods = array_merge(array('effects'), $mods);
1969 }
1970
1971 if (count($mods)) {
1972 foreach ($mods as $module) {
1973 $out .= '<script src="' . $this->processJsFile($this->backPath .
1974 $this->scriptaculousPath . $module . '.js') . '" type="text/javascript"></script>' . LF;
1975 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . $module . '.js']);
1976 }
1977 }
1978 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->scriptaculousPath .
1979 'scriptaculous.js') . '" type="text/javascript"></script>' . LF;
1980 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . 'scriptaculous.js']);
1981 }
1982
1983 // Include extCore, but only if ExtJS is not included
1984 if ($this->addExtCore && !$this->addExtJS) {
1985 $out .= '<script src="' . $this->processJsFile($this->backPath .
1986 $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
1987 '" type="text/javascript"></script>' . LF;
1988 unset($this->jsFiles[$this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
1989 }
1990
1991 // Include extJS
1992 if ($this->addExtJS) {
1993 // Use the base adapter all the time
1994 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
1995 'adapter/' . ($this->enableExtJsDebug ?
1996 str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
1997 '" type="text/javascript"></script>' . LF;
1998 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
1999 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
2000 '" type="text/javascript"></script>' . LF;
2001
2002 // Add extJS localization
2003 // Load standard ISO mapping and modify for use with ExtJS
2004 $localeMap = $this->locales->getIsoMapping();
2005 $localeMap[''] = 'en';
2006 $localeMap['default'] = 'en';
2007 // Greek
2008 $localeMap['gr'] = 'el_GR';
2009 // Norwegian Bokmaal
2010 $localeMap['no'] = 'no_BO';
2011 // Swedish
2012 $localeMap['se'] = 'se_SV';
2013
2014
2015 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
2016 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
2017 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
2018 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
2019 $out .= '<script src="' . $this->processJsFile($this->backPath .
2020 $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
2021 }
2022
2023 // Remove extjs from JScodeLibArray
2024 unset(
2025 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'],
2026 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']
2027 );
2028 }
2029
2030 if (count($this->inlineLanguageLabelFiles)) {
2031 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
2032 $this->includeLanguageFileForInline(
2033 $languageLabelFile['fileRef'],
2034 $languageLabelFile['selectionPrefix'],
2035 $languageLabelFile['stripFromSelectionName'],
2036 $languageLabelFile['$errorMode']
2037 );
2038 }
2039 }
2040 unset($this->inlineLanguageLabelFiles);
2041
2042 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
2043 if ($this->getCharSet() !== 'utf-8') {
2044 if ($this->inlineLanguageLabels) {
2045 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
2046 }
2047 if ($this->inlineSettings) {
2048 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
2049 }
2050 }
2051
2052 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
2053 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
2054
2055 if ($this->addExtCore || $this->addExtJS) {
2056 // Set clear.gif, move it on top, add handler code
2057 $code = '';
2058 if (count($this->extOnReadyCode)) {
2059 foreach ($this->extOnReadyCode as $block) {
2060 $code .= $block;
2061 }
2062 }
2063
2064 $out .= $this->inlineJavascriptWrap[0] . '
2065 Ext.ns("TYPO3");
2066 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . LF .
2067 $inlineSettings .
2068 'Ext.onReady(function() {' .
2069 ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '') . $code .
2070 ' });' . $this->inlineJavascriptWrap[1];
2071 unset ($this->extOnReadyCode);
2072
2073 // Include TYPO3.l10n object
2074 if (TYPO3_MODE === 'BE') {
2075 $out .= '<script src="' . $this->processJsFile($this->backPath . 'sysext/lang/res/js/be/typo3lang.js') . '" type="text/javascript" charset="utf-8"></script>' . LF;
2076 }
2077
2078 if ($this->extJStheme) {
2079 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
2080 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
2081 } else {
2082 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
2083 }
2084 }
2085 if ($this->extJScss) {
2086 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
2087 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
2088 } else {
2089 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
2090 }
2091 }
2092 } else {
2093 if ($inlineSettings) {
2094 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
2095 }
2096 }
2097
2098 return $out;
2099 }
2100
2101 /**
2102 * Include language file for inline usage
2103 *
2104 * @param string $fileRef
2105 * @param string $selectionPrefix
2106 * @param string $stripFromSelectionName
2107 * @param integer $errorMode
2108 * @return void
2109 * @throws RuntimeException
2110 */
2111 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
2112 if (!isset($this->lang) || !isset($this->charSet)) {
2113 throw new RuntimeException('Language and character encoding are not set.', 1284906026);
2114 }
2115
2116 $labelsFromFile = array();
2117 $allLabels = t3lib_div::readLLfile($fileRef, $this->lang, $this->charSet, $errorMode);
2118
2119 // Regular expression to strip the selection prefix and possibly something from the label name:
2120 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
2121
2122 if ($allLabels !== FALSE) {
2123 // Merge language specific translations:
2124 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
2125 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
2126 } else {
2127 $labels = $allLabels['default'];
2128 }
2129
2130 // Iterate through all locallang labels:
2131 foreach ($labels as $label => $value) {
2132 if ($selectionPrefix === '') {
2133 $labelsFromFile[$label] = $value;
2134 } elseif (strpos($label, $selectionPrefix) === 0) {
2135 $key = preg_replace($labelPattern, '', $label);
2136 $labelsFromFile[$label] = $value;
2137 }
2138 }
2139
2140 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
2141 }
2142 }
2143
2144 /*****************************************************/
2145 /* */
2146 /* Tools */
2147 /* */
2148 /* */
2149 /*****************************************************/
2150
2151 /**
2152 * Concatenate files into one file
2153 * registered handler
2154 *
2155 * @return void
2156 */
2157 protected function doConcatenate() {
2158 $this->doConcatenateCss();
2159 $this->doConcatenateJavaScript();
2160 }
2161
2162 /**
2163 * Concatenate JavaScript files according to the configuration.
2164 *
2165 * @return void
2166 */
2167 protected function doConcatenateJavaScript() {
2168 if ($this->concatenateFiles || $this->concatenateJavascript) {
2169 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'])) {
2170 // use external concatenation routine
2171 $params = array(
2172 'jsLibs' => &$this->jsLibs,
2173 'jsFiles' => &$this->jsFiles,
2174 'jsFooterFiles' => &$this->jsFooterFiles,
2175 'headerData' => &$this->headerData,
2176 'footerData' => &$this->footerData,
2177 );
2178 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'], $params, $this);
2179 } else {
2180 $this->jsLibs = $this->getCompressor()->concatenateJsFiles($this->jsLibs);
2181 $this->jsFiles = $this->getCompressor()->concatenateJsFiles($this->jsFiles);
2182 $this->jsFooterFiles = $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles);
2183 }
2184 }
2185 }
2186
2187 /**
2188 * Concatenate CSS files according to configuration.
2189 *
2190 * @return void
2191 */
2192 protected function doConcatenateCss() {
2193 if ($this->concatenateFiles || $this->concatenateCss) {
2194 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'])) {
2195 // use external concatenation routine
2196 $params = array(
2197 'cssFiles' => &$this->cssFiles,
2198 'headerData' => &$this->headerData,
2199 'footerData' => &$this->footerData,
2200 );
2201 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this);
2202 } else {
2203 $cssOptions = array();
2204 if (TYPO3_MODE === 'BE') {
2205 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
2206 }
2207 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
2208 }
2209 }
2210 }
2211
2212 /**
2213 * Compresses inline code
2214 *
2215 * @return void
2216 */
2217 protected function doCompress() {
2218 $this->doCompressJavaScript();
2219 $this->doCompressCss();
2220 }
2221
2222 /**
2223 * Compresses CSS according to configuration.
2224 *
2225 * @return void
2226 */
2227 protected function doCompressCss() {
2228 if ($this->compressCss) {
2229 // Use external compression routine
2230 $params = array(
2231 'cssInline' => &$this->cssInline,
2232 'cssFiles' => &$this->cssFiles,
2233 'headerData' => &$this->headerData,
2234 'footerData' => &$this->footerData,
2235 );
2236
2237 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'])) {
2238 // use external concatenation routine
2239 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
2240 } else {
2241 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
2242 }
2243 }
2244 }
2245
2246 /**
2247 * Compresses JavaScript according to configuration.
2248 *
2249 * @return void
2250 */
2251 protected function doCompressJavaScript() {
2252 if ($this->compressJavascript) {
2253 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'])) {
2254 // Use external compression routine
2255 $params = array(
2256 'jsInline' => &$this->jsInline,
2257 'jsFooterInline' => &$this->jsFooterInline,
2258 'jsLibs' => &$this->jsLibs,
2259 'jsFiles' => &$this->jsFiles,
2260 'jsFooterFiles' => &$this->jsFooterFiles,
2261 'headerData' => &$this->headerData,
2262 'footerData' => &$this->footerData,
2263 );
2264 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
2265 } else {
2266 // Traverse the arrays, compress files
2267 if (count($this->jsInline)) {
2268 foreach ($this->jsInline as $name => $properties) {
2269 if ($properties['compress']) {
2270 $error = '';
2271 $this->jsInline[$name]['code'] = t3lib_div::minifyJavaScript($properties['code'], $error);
2272 if ($error) {
2273 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
2274 }
2275 }
2276 }
2277 }
2278 $this->jsLibs = $this->getCompressor()->compressJsFiles($this->jsLibs);
2279 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
2280 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
2281 }
2282 }
2283 }
2284
2285 /**
2286 * Returns instance of t3lib_Compressor
2287 *
2288 * @return t3lib_Compressor Instance of t3lib_Compressor
2289 */
2290 protected function getCompressor() {
2291 if ($this->compressor === NULL) {
2292 $this->compressor = t3lib_div::makeInstance('t3lib_Compressor');
2293 }
2294 return $this->compressor;
2295 }
2296
2297 /**
2298 * Processes a Javascript file dependent on the current context
2299 *
2300 * Adds the version number for Frontend, compresses the file for Backend
2301 *
2302 * @param string $filename Filename
2303 * @return string New filename
2304 */
2305 protected function processJsFile($filename) {
2306 switch (TYPO3_MODE) {
2307 case 'FE':
2308 if ($this->compressJavascript) {
2309 $filename = $this->getCompressor()->compressJsFile($filename);
2310 } else {
2311 $filename = t3lib_div::createVersionNumberedFilename($filename);
2312 }
2313 break;
2314 case 'BE':
2315 if ($this->compressJavascript) {
2316 $filename = $this->getCompressor()->compressJsFile($filename);
2317 }
2318 break;
2319 }
2320 return $filename;
2321 }
2322 }
2323
2324 ?>