Fixed bug #14050: CleanUp - CGL format of t3lib files - t3lib_scbase
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_pagerenderer.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2010 Steffen Kamper (info@sk-typo3.de)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * TYPO3 pageRender class (new in TYPO3 4.3.0)
30 * This class render the HTML of a webpage, usable for BE and FE
31 *
32 * @author Steffen Kamper <info@sk-typo3.de>
33 * @package TYPO3
34 * @subpackage t3lib
35 * $Id$
36 */
37 class t3lib_PageRenderer implements t3lib_Singleton {
38
39 protected $compressJavascript = FALSE;
40 protected $compressCss = FALSE;
41 protected $removeLineBreaksFromTemplate = FALSE;
42
43 protected $concatenateFiles = FALSE;
44
45 protected $moveJsFromHeaderToFooter = FALSE;
46
47 /* @var t3lib_cs Instance of t3lib_cs */
48 protected $csConvObj;
49 protected $lang;
50
51 /* @var t3lib_Compressor Instance of t3lib_Compressor */
52 protected $compressor;
53
54 // static array containing associative array for the included files
55 protected static $jsFiles = array();
56 protected static $jsFooterFiles = array();
57 protected static $jsLibs = array();
58 protected static $jsFooterLibs = array();
59 protected static $cssFiles = array();
60
61 protected $title;
62 protected $charSet;
63 protected $favIcon;
64 protected $baseUrl;
65
66 protected $renderXhtml = TRUE;
67
68 // static header blocks
69 protected $xmlPrologAndDocType = '';
70 protected $metaTags = array();
71 protected $inlineComments = array();
72 protected $headerData = array();
73 protected $footerData = array();
74 protected $titleTag = '<title>|</title>';
75 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
76 protected $htmlTag = '<html>';
77 protected $headTag = '<head>';
78 protected $baseUrlTag = '<base href="|" />';
79 protected $iconMimeType = '';
80 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />
81 <link rel="icon" href="%1$s"%2$s />';
82
83 // static inline code blocks
84 protected $jsInline = array();
85 protected $jsFooterInline = array();
86 protected $extOnReadyCode = array();
87 protected $cssInline = array();
88
89 protected $bodyContent;
90
91 protected $templateFile;
92
93 protected $jsLibraryNames = array('prototype', 'scriptaculous', 'extjs');
94
95 const PART_COMPLETE = 0;
96 const PART_HEADER = 1;
97 const PART_FOOTER = 2;
98
99 // paths to contibuted libraries
100 protected $prototypePath = 'contrib/prototype/';
101 protected $scriptaculousPath = 'contrib/scriptaculous/';
102 protected $extCorePath = 'contrib/extjs/';
103 protected $extJsPath = 'contrib/extjs/';
104 protected $svgPath = 'contrib/websvg/';
105
106
107 // internal flags for JS-libraries
108 protected $addPrototype = FALSE;
109 protected $addScriptaculous = FALSE;
110 protected $addScriptaculousModules = array('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
111 protected $addExtJS = FALSE;
112 protected $addExtCore = FALSE;
113 protected $extJSadapter = 'ext/ext-base.js';
114
115
116 protected $enableExtJsDebug = FALSE;
117 protected $enableExtCoreDebug = FALSE;
118
119 // available adapters for extJs
120 const EXTJS_ADAPTER_JQUERY = 'jquery';
121 const EXTJS_ADAPTER_PROTOTYPE = 'prototype';
122 const EXTJS_ADAPTER_YUI = 'yui';
123
124 protected $extJStheme = TRUE;
125 protected $extJScss = TRUE;
126
127 protected $enableExtJSQuickTips = FALSE;
128
129 protected $inlineLanguageLabels = array();
130 protected $inlineLanguageLabelFiles = array();
131 protected $inlineSettings = array();
132
133 protected $inlineJavascriptWrap = array();
134
135 // saves error messages generated during compression
136 protected $compressError = '';
137
138 // SVG library
139 protected $addSvg = FALSE;
140 protected $enableSvgDebug = FALSE;
141
142
143 // used by BE modules
144 public $backPath;
145
146 /**
147 * Constructor
148 *
149 * @param string $templateFile declare the used template file. Omit this parameter will use default template
150 * @param string $backPath relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
151 * @return void
152 */
153 public function __construct($templateFile = '', $backPath = NULL) {
154
155 $this->reset();
156 $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
157
158 if (strlen($templateFile)) {
159 $this->templateFile = $templateFile;
160 }
161 $this->backPath = isset($backPath) ? $backPath : $GLOBALS['BACK_PATH'];
162
163 $this->inlineJavascriptWrap = array(
164 '<script type="text/javascript">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
165 '// -->' . LF . '/*]]>*/' . LF . '</script>' . LF
166 );
167 $this->inlineCssWrap = array(
168 '<style type="text/css">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
169 '-->' . LF . '/*]]>*/' . LF . '</style>' . LF
170 );
171
172 }
173
174 /**
175 * reset all vars to initial values
176 *
177 * @return void
178 */
179 protected function reset() {
180 $this->templateFile = TYPO3_mainDir . 'templates/template_page_backend.html';
181 $this->jsFiles = array();
182 $this->jsFooterFiles = array();
183 $this->jsInline = array();
184 $this->jsFooterInline = array();
185 $this->jsLibs = array();
186 $this->cssFiles = array();
187 $this->cssInline = array();
188 $this->metaTags = array();
189 $this->inlineComments = array();
190 $this->headerData = array();
191 $this->footerData = array();
192 $this->extOnReadyCode = array();
193 }
194
195 /*****************************************************/
196 /* */
197 /* Public Setters */
198 /* */
199 /* */
200 /*****************************************************/
201
202 /**
203 * Sets the title
204 *
205 * @param string $title title of webpage
206 * @return void
207 */
208 public function setTitle($title) {
209 $this->title = $title;
210 }
211
212
213 /**
214 * Enables/disables rendering of XHTML code
215 *
216 * @param boolean $enable Enable XHTML
217 * @return void
218 */
219 public function setRenderXhtml($enable) {
220 $this->renderXhtml = $enable;
221 }
222
223 /**
224 * Sets xml prolog and docType
225 *
226 * @param string $xmlPrologAndDocType complete tags for xml prolog and docType
227 * @return void
228 */
229 public function setXmlPrologAndDocType($xmlPrologAndDocType) {
230 $this->xmlPrologAndDocType = $xmlPrologAndDocType;
231 }
232
233 /**
234 * Sets meta charset
235 *
236 * @param string $charSet used charset
237 * @return void
238 */
239 public function setCharSet($charSet) {
240 $this->charSet = $charSet;
241 }
242
243 /**
244 * Sets language
245 *
246 * @param string $lang used language
247 * @return void
248 */
249 public function setLanguage($lang) {
250 $this->lang = $lang;
251 }
252
253 /**
254 * Sets html tag
255 *
256 * @param string $htmlTag html tag
257 * @return void
258 */
259 public function setHtmlTag($htmlTag) {
260 $this->htmlTag = $htmlTag;
261 }
262
263 /**
264 * Sets head tag
265 *
266 * @param string $tag head tag
267 * @return void
268 */
269 public function setHeadTag($headTag) {
270 $this->headTag = $headTag;
271 }
272
273 /**
274 * Sets favicon
275 *
276 * @param string $favIcon
277 * @return void
278 */
279 public function setFavIcon($favIcon) {
280 $this->favIcon = $favIcon;
281 }
282
283 /**
284 * Sets icon mime type
285 *
286 * @param string $iconMimeType
287 * @return void
288 */
289 public function setIconMimeType($iconMimeType) {
290 $this->iconMimeType = $iconMimeType;
291 }
292
293 /**
294 * Sets base url
295 *
296 * @param string $url
297 * @return void
298 */
299 public function setBaseUrl($baseUrl) {
300 $this->baseUrl = $baseUrl;
301 }
302
303 /**
304 * Sets template file
305 *
306 * @param string $file
307 * @return void
308 */
309 public function setTemplateFile($file) {
310 $this->templateFile = $file;
311 }
312
313 /**
314 * Sets back path
315 *
316 * @param string $backPath
317 * @return void
318 */
319 public function setBackPath($backPath) {
320 $this->backPath = $backPath;
321 }
322
323 /**
324 * Sets Content for Body
325 *
326 * @param string $content
327 * @return void
328 */
329 public function setBodyContent($content) {
330 $this->bodyContent = $content;
331 }
332
333 /**
334 * Sets Path for prototype library (relative to typo3 directory)
335 *
336 * @param string path
337 * @return void
338 */
339 public function setPrototypePath($path) {
340 $this->prototypePath = $path;
341 }
342
343 /**
344 * Sets Path for scriptaculous library (relative to typo3 directory)
345 *
346 * @param string $path
347 * @return void
348 */
349 public function setScriptaculousPath($path) {
350 $this->scriptaculousPath = $path;
351 }
352
353 /**
354 * Sets Path for Ext Core library (relative to typo3 directory)
355 *
356 * @param string $path
357 * @return void
358 */
359 public function setExtCorePath($path) {
360 $this->extCorePath = $path;
361 }
362
363 /**
364 * Sets Path for ExtJs library (relative to typo3 directory)
365 *
366 * @param string $path
367 * @return void
368 */
369 public function setExtJsPath($path) {
370 $this->extJsPath = $path;
371 }
372
373 /**
374 * Sets Path for SVG library (websvg)
375 *
376 * @param string $path
377 * @return void
378 */
379 public function setSvgPath($path) {
380 $this->svgPath = $path;
381 }
382
383 /*****************************************************/
384 /* */
385 /* Public Enablers / Disablers */
386 /* */
387 /* */
388 /*****************************************************/
389
390 /**
391 * Enables MoveJsFromHeaderToFooter
392 *
393 * @param void
394 * @return void
395 */
396 public function enableMoveJsFromHeaderToFooter() {
397 $this->moveJsFromHeaderToFooter = TRUE;
398 }
399
400 /**
401 * Disables MoveJsFromHeaderToFooter
402 *
403 * @param void
404 * @return void
405 */
406 public function disableMoveJsFromHeaderToFooter() {
407 $this->moveJsFromHeaderToFooter = FALSE;
408 }
409
410 /**
411 * Enables compression of javascript
412 *
413 * @param void
414 * @return void
415 */
416 public function enableCompressJavascript() {
417 $this->compressJavascript = TRUE;
418 }
419
420 /**
421 * Disables compression of javascript
422 *
423 * @param void
424 * @return void
425 */
426 public function disableCompressJavascript() {
427 $this->compressJavascript = FALSE;
428 }
429
430 /**
431 * Enables compression of css
432 *
433 * @param void
434 * @return void
435 */
436 public function enableCompressCss() {
437 $this->compressCss = TRUE;
438 }
439
440 /**
441 * Disables compression of css
442 *
443 * @param void
444 * @return void
445 */
446 public function disableCompressCss() {
447 $this->compressCss = FALSE;
448 }
449
450 /**
451 * Enables concatenation of js/css files
452 *
453 * @param void
454 * @return void
455 */
456 public function enableConcatenateFiles() {
457 $this->concatenateFiles = TRUE;
458 }
459
460 /**
461 * Disables concatenation of js/css files
462 *
463 * @param void
464 * @return void
465 */
466 public function disableConcatenateFiles() {
467 $this->concatenateFiles = FALSE;
468 }
469
470 /**
471 * Sets removal of all line breaks in template
472 *
473 * @param void
474 * @return void
475 */
476 public function enableRemoveLineBreaksFromTemplate() {
477 $this->removeLineBreaksFromTemplate = TRUE;
478 }
479
480 /**
481 * Unsets removal of all line breaks in template
482 *
483 * @param void
484 * @return void
485 */
486 public function disableRemoveLineBreaksFromTemplate() {
487 $this->removeLineBreaksFromTemplate = FALSE;
488 }
489
490 /**
491 * Enables Debug Mode
492 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
493 *
494 * @param void
495 * @return void
496 */
497 public function enableDebugMode() {
498 $this->compressJavascript = FALSE;
499 $this->compressCss = FALSE;
500 $this->concatenateFiles = FALSE;
501 $this->removeLineBreaksFromTemplate = FALSE;
502 $this->enableExtCoreDebug = TRUE;
503 $this->enableExtJsDebug = TRUE;
504 $this->enableSvgDebug = TRUE;
505 }
506
507 /*****************************************************/
508 /* */
509 /* Public Getters */
510 /* */
511 /* */
512 /*****************************************************/
513
514 /**
515 * Gets the title
516 *
517 * @return string $title title of webpage
518 */
519 public function getTitle() {
520 return $this->title;
521 }
522
523 /**
524 * Gets the charSet
525 *
526 * @return string $charSet
527 */
528 public function getCharSet() {
529 return $this->charSet;
530 }
531
532 /**
533 * Gets the language
534 *
535 * @return string $lang
536 */
537 public function getLanguage() {
538 return $this->lang;
539 }
540
541 /**
542 * Returns rendering mode XHTML or HTML
543 *
544 * @return boolean TRUE if XHTML, FALSE if HTML
545 */
546 public function getRenderXhtml() {
547 return $this->renderXhtml;
548 }
549
550 /**
551 * Gets html tag
552 *
553 * @return string $htmlTag html tag
554 */
555 public function getHtmlTag() {
556 return $this->htmlTag;
557 }
558
559 /**
560 * Gets head tag
561 *
562 * @return string $tag head tag
563 */
564 public function getHeadTag() {
565 return $this->headTag;
566 }
567
568 /**
569 * Gets favicon
570 *
571 * @return string $favIcon
572 */
573 public function getFavIcon() {
574 return $this->favIcon;
575 }
576
577 /**
578 * Gets icon mime type
579 *
580 * @return string $iconMimeType
581 */
582 public function getIconMimeType() {
583 return $this->iconMimeType;
584 }
585
586 /**
587 * Gets base url
588 *
589 * @return string $url
590 */
591 public function getBaseUrl() {
592 return $this->baseUrl;
593 }
594
595 /**
596 * Gets template file
597 *
598 * @return string $file
599 */
600 public function getTemplateFile($file) {
601 return $this->templateFile;
602 }
603
604 /**
605 * Gets MoveJsFromHeaderToFooter
606 *
607 * @return boolean
608 */
609 public function getMoveJsFromHeaderToFooter() {
610 return $this->moveJsFromHeaderToFooter;
611 }
612
613 /**
614 * Gets compress of javascript
615 *
616 * @return boolean
617 */
618 public function getCompressJavascript() {
619 return $this->compressJavascript;
620 }
621
622 /**
623 * Gets compress of css
624 *
625 * @return boolean
626 */
627 public function getCompressCss() {
628 return $this->compressCss;
629 }
630
631 /**
632 * Gets concatenate of files
633 *
634 * @return boolean
635 */
636 public function getConcatenateFiles() {
637 return $this->concatenateFiles;
638 }
639
640 /**
641 * Gets remove of empty lines from template
642 *
643 * @return boolean
644 */
645 public function getRemoveLineBreaksFromTemplate() {
646 return $this->removeLineBreaksFromTemplate;
647 }
648
649 /**
650 * Gets content for body
651 *
652 * @return string
653 */
654 public function getBodyContent() {
655 return $this->bodyContent;
656 }
657
658 /**
659 * Gets Path for prototype library (relative to typo3 directory)
660 *
661 * @return string
662 */
663 public function getPrototypePath() {
664 return $this->prototypePath;
665 }
666
667 /**
668 * Gets Path for scriptaculous library (relative to typo3 directory)
669 *
670 * @return string
671 */
672 public function getScriptaculousPath() {
673 return $this->scriptaculousPath;
674 }
675
676 /**
677 * Gets Path for Ext Core library (relative to typo3 directory)
678 *
679 * @return string
680 */
681 public function getExtCorePath() {
682 return $this->extCorePath;
683 }
684
685 /**
686 * Gets Path for ExtJs library (relative to typo3 directory)
687 *
688 * @return string
689 */
690 public function getExtJsPath() {
691 return $this->extJsPath;
692 }
693
694 /**
695 * Gets Path for SVG library (relative to typo3 directory)
696 *
697 * @return string
698 */
699 public function getSvgPath() {
700 return $this->svgPath;
701 }
702
703 /**
704 * Gets the inline language labels.
705 *
706 * @return array The inline language labels
707 */
708 public function getInlineLanguageLabels() {
709 return $this->inlineLanguageLabels;
710 }
711
712 /**
713 * Gets the inline language files
714 *
715 * @return array
716 */
717 public function getInlineLanguageLabelFiles() {
718 return $this->inlineLanguageLabelFiles;
719 }
720
721 /*****************************************************/
722 /* */
723 /* Public Function to add Data */
724 /* */
725 /* */
726 /*****************************************************/
727
728 /**
729 * Adds meta data
730 *
731 * @param string $meta meta data (complete metatag)
732 * @return void
733 */
734 public function addMetaTag($meta) {
735 if (!in_array($meta, $this->metaTags)) {
736 $this->metaTags[] = $meta;
737 }
738 }
739
740 /**
741 * Adds inline HTML comment
742 *
743 * @param string $comment
744 * @return void
745 */
746 public function addInlineComment($comment) {
747 if (!in_array($comment, $this->inlineComments)) {
748 $this->inlineComments[] = $comment;
749 }
750 }
751
752 /**
753 * Adds header data
754 *
755 * @param string $data free header data for HTML header
756 * @return void
757 */
758 public function addHeaderData($data) {
759 if (!in_array($data, $this->headerData)) {
760 $this->headerData[] = $data;
761 }
762 }
763
764 /**
765 * Adds footer data
766 *
767 * @param string $data free header data for HTML header
768 * @return void
769 */
770 public function addFooterData($data) {
771 if (!in_array($data, $this->footerData)) {
772 $this->footerData[] = $data;
773 }
774 }
775
776 /* Javascript Files */
777
778 /**
779 * Adds JS Library. JS Library block is rendered on top of the JS files.
780 *
781 * @param string $name
782 * @param string $file
783 * @param string $type
784 * @param boolean $compress flag if library should be compressed
785 * @param boolean $forceOnTop flag if added library should be inserted at begin of this block
786 * @param string $allWrap
787 * @return void
788 */
789 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '') {
790 if (!$type) {
791 $type = 'text/javascript';
792 }
793 if (!in_array(strtolower($name), $this->jsLibs)) {
794 $this->jsLibs[strtolower($name)] = array(
795 'file' => $file,
796 'type' => $type,
797 'section' => self::PART_HEADER,
798 'compress' => $compress,
799 'forceOnTop' => $forceOnTop,
800 'allWrap' => $allWrap
801 );
802 }
803
804 }
805
806 /**
807 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
808 *
809 * @param string $name
810 * @param string $file
811 * @param string $type
812 * @param boolean $compress flag if library should be compressed
813 * @param boolean $forceOnTop flag if added library should be inserted at begin of this block
814 * @param string $allWrap
815 * @return void
816 */
817 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '') {
818 if (!$type) {
819 $type = 'text/javascript';
820 }
821 if (!in_array(strtolower($name), $this->jsLibs)) {
822 $this->jsLibs[strtolower($name)] = array(
823 'file' => $file,
824 'type' => $type,
825 'section' => self::PART_FOOTER,
826 'compress' => $compress,
827 'forceOnTop' => $forceOnTop,
828 'allWrap' => $allWrap
829 );
830 }
831
832 }
833
834 /**
835 * Adds JS file
836 *
837 * @param string $file
838 * @param string $type
839 * @param boolean $compress
840 * @param boolean $forceOnTop
841 * @param string $allWrap
842 * @return void
843 */
844 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
845 if (!$type) {
846 $type = 'text/javascript';
847 }
848 if (!isset($this->jsFiles[$file])) {
849 $this->jsFiles[$file] = array(
850 'type' => $type,
851 'section' => self::PART_HEADER,
852 'compress' => $compress,
853 'forceOnTop' => $forceOnTop,
854 'allWrap' => $allWrap
855 );
856 }
857 }
858
859 /**
860 * Adds JS file to footer
861 *
862 * @param string $file
863 * @param string $type
864 * @param boolean $compress
865 * @param boolean $forceOnTop
866 * @return void
867 */
868 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
869 if (!$type) {
870 $type = 'text/javascript';
871 }
872 if (!isset($this->jsFiles[$file])) {
873 $this->jsFiles[$file] = array(
874 'type' => $type,
875 'section' => self::PART_FOOTER,
876 'compress' => $compress,
877 'forceOnTop' => $forceOnTop,
878 'allWrap' => $allWrap
879 );
880 }
881 }
882
883 /*Javascript Inline Blocks */
884
885 /**
886 * Adds JS inline code
887 *
888 * @param string $name
889 * @param string $block
890 * @param boolean $compress
891 * @param boolean $forceOnTop
892 * @return void
893 */
894 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
895 if (!isset($this->jsInline[$name]) && !empty($block)) {
896 $this->jsInline[$name] = array(
897 'code' => $block . LF,
898 'section' => self::PART_HEADER,
899 'compress' => $compress,
900 'forceOnTop' => $forceOnTop
901 );
902 }
903 }
904
905 /**
906 * Adds JS inline code to footer
907 *
908 * @param string $name
909 * @param string $block
910 * @param boolean $compress
911 * @param boolean $forceOnTop
912 * @return void
913 */
914 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
915 if (!isset($this->jsInline[$name]) && !empty($block)) {
916 $this->jsInline[$name] = array(
917 'code' => $block . LF,
918 'section' => self::PART_FOOTER,
919 'compress' => $compress,
920 'forceOnTop' => $forceOnTop
921 );
922 }
923 }
924
925 /**
926 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
927 *
928 * @param string $block javascript code
929 * @param boolean $forceOnTop position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
930 * @return void
931 */
932 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
933 if (!in_array($block, $this->extOnReadyCode)) {
934 if ($forceOnTop) {
935 array_unshift($this->extOnReadyCode, $block);
936 } else {
937 $this->extOnReadyCode[] = $block;
938 }
939 }
940 }
941
942 /**
943 * Adds the ExtDirect code
944 *
945 * @return void
946 */
947 public function addExtDirectCode() {
948 // Note: we need to iterate thru the object, because the addProvider method
949 // does this only with multiple arguments
950 $this->addExtOnReadyCode(
951 'for (var api in Ext.app.ExtDirectAPI) {
952 Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
953 }
954
955 var extDirectDebug = function(message, header, group) {
956 var TYPO3ViewportInstance = null;
957
958 if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
959 TYPO3ViewportInstance = top.TYPO3.Backend;
960 } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
961 TYPO3ViewportInstance = TYPO3.Backend;
962 }
963
964 if (TYPO3ViewportInstance !== null) {
965 TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
966 } else if (typeof console === "object") {
967 console.log(message);
968 } else {
969 document.write(message);
970 }
971 };
972
973 Ext.Direct.on("exception", function(event) {
974 var backtrace = "";
975 if (event.where) {
976 backtrace = "<p style=\"margin-top: 20px;\">" +
977 "<strong>Backtrace:<\/strong><br \/>" +
978 event.where.replace(/#/g, "<br \/>#") +
979 "<\/p>";
980 }
981
982 extDirectDebug(
983 "<p>" + event.message + "<\/p>" + backtrace,
984 event.method,
985 "ExtDirect - Exception"
986 );
987 });
988
989 Ext.Direct.on("event", function(event, provider) {
990 if (typeof event.debug !== "undefined" && event.debug !== "") {
991 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
992 }
993 });
994 ',
995 TRUE
996 );
997 }
998
999 /* CSS Files */
1000
1001 /**
1002 * Adds CSS file
1003 *
1004 * @param string $file
1005 * @param string $rel
1006 * @param string $media
1007 * @param string $title
1008 * @param boolean $compress
1009 * @param boolean $forceOnTop
1010 * @return void
1011 */
1012 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
1013 if (!isset($this->cssFiles[$file])) {
1014 $this->cssFiles[$file] = array(
1015 'rel' => $rel,
1016 'media' => $media,
1017 'title' => $title,
1018 'compress' => $compress,
1019 'forceOnTop' => $forceOnTop,
1020 'allWrap' => $allWrap
1021 );
1022 }
1023 }
1024
1025 /*CSS Inline Blocks */
1026
1027 /**
1028 * Adds CSS inline code
1029 *
1030 * @param string $name
1031 * @param string $block
1032 * @param boolean $compress
1033 * @param boolean $forceOnTop
1034 * @return void
1035 */
1036 public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
1037 if (!isset($this->cssInline[$name]) && !empty($block)) {
1038 $this->cssInline[$name] = array(
1039 'code' => $block,
1040 'compress' => $compress,
1041 'forceOnTop' => $forceOnTop
1042 );
1043 }
1044 }
1045
1046 /* JS Libraries */
1047
1048 /**
1049 * call function if you need the prototype library
1050 *
1051 * @return void
1052 */
1053 public function loadPrototype() {
1054 $this->addPrototype = TRUE;
1055 }
1056
1057 /**
1058 * call function if you need the Scriptaculous library
1059 *
1060 * @param string $modules add modules you need. use "all" if you need complete modules
1061 * @return void
1062 */
1063 public function loadScriptaculous($modules = 'all') {
1064 // Scriptaculous require prototype, so load prototype too.
1065 $this->addPrototype = TRUE;
1066 $this->addScriptaculous = TRUE;
1067 if ($modules) {
1068 if ($modules == 'all') {
1069 foreach ($this->addScriptaculousModules as $key => $value) {
1070 $this->addScriptaculousModules[$key] = TRUE;
1071 }
1072 } else {
1073 $mods = t3lib_div::trimExplode(',', $modules);
1074 foreach ($mods as $mod) {
1075 if (isset($this->addScriptaculousModules[strtolower($mod)])) {
1076 $this->addScriptaculousModules[strtolower($mod)] = TRUE;
1077 }
1078 }
1079 }
1080 }
1081 }
1082
1083 /**
1084 * call this function if you need the extJS library
1085 *
1086 * @param boolean $css flag, if set the ext-css will be loaded
1087 * @param boolean $theme flag, if set the ext-theme "grey" will be loaded
1088 * @param string $adapter choose alternative adapter, possible values: yui, prototype, jquery
1089 * @return void
1090 */
1091 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
1092 if ($adapter) {
1093 // empty $adapter will always load the ext adapter
1094 switch (t3lib_div::strtolower(trim($adapter))) {
1095 case self::EXTJS_ADAPTER_YUI :
1096 $this->extJSadapter = 'yui/ext-yui-adapter.js';
1097 break;
1098 case self::EXTJS_ADAPTER_PROTOTYPE :
1099 $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
1100 break;
1101 case self::EXTJS_ADAPTER_JQUERY :
1102 $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
1103 break;
1104 }
1105 }
1106 $this->addExtJS = TRUE;
1107 $this->extJStheme = $theme;
1108 $this->extJScss = $css;
1109
1110 }
1111
1112 /**
1113 * Enables ExtJs QuickTips
1114 * Need extJs loaded
1115 *
1116 * @return void
1117 *
1118 */
1119 public function enableExtJSQuickTips() {
1120 $this->enableExtJSQuickTips = TRUE;
1121 }
1122
1123
1124 /**
1125 * call function if you need the ExtCore library
1126 *
1127 * @return void
1128 */
1129 public function loadExtCore() {
1130 $this->addExtCore = TRUE;
1131 }
1132
1133 /**
1134 * call function if you need the SVG library
1135 *
1136 * @return void
1137 */
1138 public function loadSvg() {
1139 $this->addSvg = TRUE;
1140 }
1141
1142 /**
1143 * call this function to load debug version of ExtJS. Use this for development only
1144 *
1145 */
1146 public function enableSvgDebug() {
1147 $this->enableSvgDebug = TRUE;
1148 }
1149
1150 /**
1151 * call this function to force flash usage with SVG library
1152 *
1153 */
1154 public function svgForceFlash() {
1155 $this->addMetaTag('<meta name="svg.render.forceflash" content="true" />');
1156 }
1157
1158 /**
1159 * call this function to load debug version of ExtJS. Use this for development only
1160 *
1161 */
1162 public function enableExtJsDebug() {
1163 $this->enableExtJsDebug = TRUE;
1164 }
1165
1166 /**
1167 * call this function to load debug version of ExtCore. Use this for development only
1168 *
1169 * @return void
1170 */
1171 public function enableExtCoreDebug() {
1172 $this->enableExtCoreDebug = TRUE;
1173 }
1174
1175 /**
1176 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1177 * The label can be used in scripts with TYPO3.lang.<key>
1178 * Need extJs loaded
1179 *
1180 * @param string $key
1181 * @param string $value
1182 * @return void
1183 */
1184 public function addInlineLanguageLabel($key, $value) {
1185 $this->inlineLanguageLabels[$key] = $value;
1186 }
1187
1188 /**
1189 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1190 * The label can be used in scripts with TYPO3.lang.<key>
1191 * Array will be merged with existing array.
1192 * Need extJs loaded
1193 *
1194 * @param array $array
1195 * @return void
1196 */
1197 public function addInlineLanguageLabelArray(array $array) {
1198 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
1199 }
1200
1201 /**
1202 * Gets labels to be used in JavaScript fetched from a locallang file.
1203 *
1204 * @param string 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.
1205 * @param string $selectionPrefix: Prefix to select the correct labels (default: '')
1206 * @param string $stripFromSelectionName: Sub-prefix to be removed from label names in the result (default: '')
1207 * @param integer Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1208 * @return void
1209 */
1210 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1211 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1212 if ($fileRef && !isset($this->inlineLanguageLabelFiles[$index])) {
1213 $this->inlineLanguageLabelFiles[$index] = array(
1214 'fileRef' => $fileRef,
1215 'selectionPrefix' => $selectionPrefix,
1216 'stripFromSelectionName' => $stripFromSelectionName,
1217 'errorMode' => $errorMode
1218 );
1219 }
1220 }
1221
1222
1223 /**
1224 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1225 * The label can be used in scripts with TYPO3.setting.<key>
1226 * Need extJs loaded
1227 *
1228 * @param string $namespace
1229 * @param string $key
1230 * @param string $value
1231 * @return void
1232 */
1233 public function addInlineSetting($namespace, $key, $value) {
1234 if ($namespace) {
1235 if (strpos($namespace, '.')) {
1236 $parts = explode('.', $namespace);
1237 $a = &$this->inlineSettings;
1238 foreach ($parts as $part) {
1239 $a = &$a[$part];
1240 }
1241 $a[$key] = $value;
1242 } else {
1243 $this->inlineSettings[$namespace][$key] = $value;
1244 }
1245 } else {
1246 $this->inlineSettings[$key] = $value;
1247 }
1248 }
1249
1250 /**
1251 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1252 * The label can be used in scripts with TYPO3.setting.<key>
1253 * Array will be merged with existing array.
1254 * Need extJs loaded
1255 *
1256 * @param string $namespace
1257 * @param array $array
1258 * @return void
1259 */
1260 public function addInlineSettingArray($namespace, array $array) {
1261 if ($namespace) {
1262 if (strpos($namespace, '.')) {
1263 $parts = explode('.', $namespace);
1264 $a = &$this->inlineSettings;
1265 foreach ($parts as $part) {
1266 $a = &$a[$part];
1267 }
1268 $a = array_merge((array) $a, $array);
1269 } else {
1270 $this->inlineSettings[$namespace] = array_merge((array) $this->inlineSettings[$namespace], $array);
1271 }
1272 } else {
1273 $this->inlineSettings = array_merge($this->inlineSettings, $array);
1274 }
1275 }
1276
1277 /**
1278 * Adds content to body content
1279 *
1280 * @param string $content
1281 * @return void
1282 */
1283 public function addBodyContent($content) {
1284 $this->bodyContent .= $content;
1285 }
1286
1287 /*****************************************************/
1288 /* */
1289 /* Render Functions */
1290 /* */
1291 /* */
1292 /*****************************************************/
1293
1294 /**
1295 * render the section (Header or Footer)
1296 *
1297 * @param int $part section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1298 * @return string content of rendered section
1299 */
1300 public function render($part = self::PART_COMPLETE) {
1301
1302 $jsFiles = '';
1303 $cssFiles = '';
1304 $cssInline = '';
1305 $jsInline = '';
1306 $jsFooterInline = '';
1307 $jsFooterLibs = '';
1308 $jsFooterFiles = '';
1309
1310 // preRenderHook for possible manuipulation
1311 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
1312 $params = array(
1313 'jsLibs' => &$this->jsLibs,
1314 'jsFiles' => &$this->jsFiles,
1315 'jsFooterFiles' => &$this->jsFooterFiles,
1316 'cssFiles' => &$this->cssFiles,
1317 'headerData' => &$this->headerData,
1318 'footerData' => &$this->footerData,
1319 'jsInline' => &$this->jsInline,
1320 'cssInline' => &$this->cssInline,
1321 );
1322 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
1323 t3lib_div::callUserFunction($hook, $params, $this);
1324 }
1325 }
1326
1327 $jsLibs = $this->renderJsLibraries();
1328
1329 if ($this->concatenateFiles) {
1330 // do the file concatenation
1331 $this->doConcatenate();
1332 }
1333 if ($this->compressCss || $this->compressJavascript) {
1334 // do the file compression
1335 $this->doCompress();
1336 }
1337
1338 $metaTags = implode(LF, $this->metaTags);
1339
1340 // remove ending slashes from static header block
1341 // if the page is beeing rendered as html (not xhtml)
1342 // and define variable $endingSlash for further use
1343 if ($this->getRenderXhtml()) {
1344 $endingSlash = ' /';
1345 } else {
1346 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
1347 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
1348 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
1349 $endingSlash = '';
1350 }
1351
1352 if (count($this->cssFiles)) {
1353 foreach ($this->cssFiles as $file => $properties) {
1354 $file = t3lib_div::resolveBackPath($file);
1355 $file = t3lib_div::createVersionNumberedFilename($file);
1356 $tag = '<link rel="' . htmlspecialchars($properties['rel']) . '" type="text/css" href="' .
1357 htmlspecialchars($file) . '" media="' . htmlspecialchars($properties['media']) . '"' .
1358 ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '') .
1359 $endingSlash . '>';
1360 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1361 $tag = str_replace('|', $tag, $properties['allWrap']);
1362 }
1363 if ($properties['forceOnTop']) {
1364 $cssFiles = $tag . LF . $cssFiles;
1365 } else {
1366 $cssFiles .= LF . $tag;
1367 }
1368 }
1369 }
1370
1371 if (count($this->cssInline)) {
1372 foreach ($this->cssInline as $name => $properties) {
1373 if ($properties['forceOnTop']) {
1374 $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $cssInline;
1375 } else {
1376 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1377 }
1378 }
1379 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
1380 }
1381
1382 if (count($this->jsLibs)) {
1383 foreach ($this->jsLibs as $name => $properties) {
1384 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
1385 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
1386 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
1387 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1388 $tag = str_replace('|', $tag, $properties['allWrap']);
1389 }
1390 if ($properties['forceOnTop']) {
1391 if ($properties['section'] === self::PART_HEADER) {
1392 $jsLibs = $tag . LF . $jsLibs;
1393 } else {
1394 $jsFooterLibs = $tag . LF . $jsFooterLibs;
1395 }
1396 } else {
1397 if ($properties['section'] === self::PART_HEADER) {
1398 $jsLibs .= LF . $tag;
1399 } else {
1400 $jsFooterLibs .= LF . $tag;
1401 }
1402 }
1403 }
1404 }
1405
1406 if (count($this->jsFiles)) {
1407 foreach ($this->jsFiles as $file => $properties) {
1408 $file = t3lib_div::resolveBackPath($file);
1409 $file = t3lib_div::createVersionNumberedFilename($file);
1410 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
1411 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1412 $tag = str_replace('|', $tag, $properties['allWrap']);
1413 }
1414 if ($properties['forceOnTop']) {
1415 if ($properties['section'] === self::PART_HEADER) {
1416 $jsFiles = $tag . LF . $jsFiles;
1417 } else {
1418 $jsFooterFiles = $tag . LF . $jsFooterFiles;
1419 }
1420 } else {
1421 if ($properties['section'] === self::PART_HEADER) {
1422 $jsFiles .= LF . $tag;
1423 } else {
1424 $jsFooterFiles .= LF . $tag;
1425 }
1426 }
1427 }
1428 }
1429
1430 if (count($this->jsInline)) {
1431 foreach ($this->jsInline as $name => $properties) {
1432 if ($properties['forceOnTop']) {
1433 if ($properties['section'] === self::PART_HEADER) {
1434 $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsInline;
1435 } else {
1436 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsFooterInline;
1437 }
1438 } else {
1439 if ($properties['section'] === self::PART_HEADER) {
1440 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1441 } else {
1442 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1443 }
1444 }
1445 }
1446 }
1447
1448
1449 if ($jsInline) {
1450 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
1451 }
1452
1453 if ($jsFooterInline) {
1454 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
1455 }
1456
1457
1458 // get template
1459 $templateFile = t3lib_div::getFileAbsFileName($this->templateFile, TRUE);
1460 $template = t3lib_div::getURL($templateFile);
1461
1462 if ($this->removeLineBreaksFromTemplate) {
1463 $template = strtr($template, array(LF => '', CR => ''));
1464 }
1465 if ($part != self::PART_COMPLETE) {
1466 $templatePart = explode('###BODY###', $template);
1467 $template = $templatePart[$part - 1];
1468 }
1469
1470 if ($this->moveJsFromHeaderToFooter) {
1471 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
1472 $jsLibs = '';
1473 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
1474 $jsFiles = '';
1475 $jsFooterInline = $jsInline . LF . $jsFooterInline;
1476 $jsInline = '';
1477 }
1478
1479 $markerArray = array(
1480 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1481 'HTMLTAG' => $this->htmlTag,
1482 'HEADTAG' => $this->headTag,
1483 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1484 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1485 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1486 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1487 'CSS_INCLUDE' => $cssFiles,
1488 'CSS_INLINE' => $cssInline,
1489 'JS_INLINE' => $jsInline,
1490 'JS_INCLUDE' => $jsFiles,
1491 'JS_LIBS' => $jsLibs,
1492 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1493 'META' => $metaTags,
1494 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
1495 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
1496 'JS_LIBS_FOOTER' => $jsFooterLibs,
1497 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1498 'JS_INLINE_FOOTER' => $jsFooterInline,
1499 'BODY' => $this->bodyContent,
1500 );
1501
1502 $markerArray = array_map('trim', $markerArray);
1503
1504 $this->reset();
1505 return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
1506 }
1507
1508 /**
1509 * helper function for render the javascript libraries
1510 *
1511 * @return string content with javascript libraries
1512 */
1513 protected function renderJsLibraries() {
1514 $out = '';
1515
1516 if ($this->addSvg) {
1517 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->svgPath . 'svg.js') .
1518 '" data-path="' . $this->backPath . $this->svgPath .
1519 '"' . ($this->enableSvgDebug ? ' data-debug="true"' : '') . '></script>';
1520 }
1521
1522 if ($this->addPrototype) {
1523 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->prototypePath . 'prototype.js') .
1524 '" type="text/javascript"></script>' . LF;
1525 unset($this->jsFiles[$this->backPath . $this->prototypePath . 'prototype.js']);
1526 }
1527
1528 if ($this->addScriptaculous) {
1529 $mods = array();
1530 foreach ($this->addScriptaculousModules as $key => $value) {
1531 if ($this->addScriptaculousModules[$key]) {
1532 $mods[] = $key;
1533 }
1534 }
1535 // resolve dependencies
1536 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
1537 $mods = array_merge(array('effects'), $mods);
1538 }
1539
1540 if (count($mods)) {
1541 foreach ($mods as $module) {
1542 $out .= '<script src="' . $this->processJsFile($this->backPath .
1543 $this->scriptaculousPath . $module . '.js') . '" type="text/javascript"></script>' . LF;
1544 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . $module . '.js']);
1545 }
1546 }
1547 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->scriptaculousPath .
1548 'scriptaculous.js') . '" type="text/javascript"></script>' . LF;
1549 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . 'scriptaculous.js']);
1550 }
1551
1552 // include extCore
1553 if ($this->addExtCore) {
1554 $out .= '<script src="' . $this->processJsFile($this->backPath .
1555 $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
1556 '" type="text/javascript"></script>' . LF;
1557 unset($this->jsFiles[$this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
1558 }
1559
1560 // include extJS
1561 if ($this->addExtJS) {
1562 // use the base adapter all the time
1563 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
1564 'adapter/' . ($this->enableExtJsDebug ?
1565 str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
1566 '" type="text/javascript"></script>' . LF;
1567 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
1568 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
1569 '" type="text/javascript"></script>' . LF;
1570
1571 // add extJS localization
1572 $localeMap = $this->csConvObj->isoArray; // load standard ISO mapping and modify for use with ExtJS
1573 $localeMap[''] = 'en';
1574 $localeMap['default'] = 'en';
1575 $localeMap['gr'] = 'el_GR'; // Greek
1576 $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
1577 $localeMap['se'] = 'se_SV'; // Swedish
1578
1579
1580 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
1581 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1582 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
1583 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
1584 $out .= '<script src="' . $this->processJsFile($this->backPath .
1585 $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
1586 }
1587
1588
1589 // remove extjs from JScodeLibArray
1590 unset(
1591 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'],
1592 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']
1593 );
1594 }
1595
1596 if (count($this->inlineLanguageLabelFiles)) {
1597 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
1598 $this->includeLanguageFileForInline(
1599 $languageLabelFile['fileRef'],
1600 $languageLabelFile['selectionPrefix'],
1601 $languageLabelFile['stripFromSelectionName'],
1602 $languageLabelFile['$errorMode']
1603 );
1604 }
1605 }
1606 unset($this->inlineLanguageLabelFiles);
1607
1608 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
1609 if ($this->getCharSet() !== 'utf-8') {
1610 if ($this->inlineLanguageLabels) {
1611 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
1612 }
1613 if ($this->inlineSettings) {
1614 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
1615 }
1616 }
1617
1618 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
1619 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
1620
1621 if ($this->addExtCore || $this->addExtJS) {
1622 // set clear.gif, move it on top, add handler code
1623 $code = '';
1624 if (count($this->extOnReadyCode)) {
1625 foreach ($this->extOnReadyCode as $block) {
1626 $code .= $block;
1627 }
1628 }
1629
1630 $out .= $this->inlineJavascriptWrap[0] . '
1631 Ext.ns("TYPO3");
1632 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . LF .
1633 $inlineSettings .
1634 'Ext.onReady(function() {' .
1635 ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '') . $code .
1636 ' });' . $this->inlineJavascriptWrap[1];
1637 unset ($this->extOnReadyCode);
1638
1639 if ($this->extJStheme) {
1640 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1641 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
1642 } else {
1643 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
1644 }
1645 }
1646 if ($this->extJScss) {
1647 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1648 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
1649 } else {
1650 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
1651 }
1652 }
1653 } else {
1654 if ($inlineSettings) {
1655 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
1656 }
1657 }
1658
1659 return $out;
1660 }
1661
1662 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1663 if (!isset($this->lang) || !isset($this->charSet)) {
1664 throw new RuntimeException('Language and character encoding are not set.', 1284906026);
1665 }
1666
1667 $labelsFromFile = array();
1668 $allLabels = t3lib_div::readLLfile($fileRef, $this->lang, $this->charSet, $errorMode);
1669
1670 // Regular expression to strip the selection prefix and possibly something from the label name:
1671 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
1672
1673 if ($allLabels !== FALSE) {
1674 // Merge language specific translations:
1675 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
1676 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
1677 } else {
1678 $labels = $allLabels['default'];
1679 }
1680
1681 // Iterate through all locallang labels:
1682 foreach ($labels as $label => $value) {
1683 if ($selectionPrefix === '') {
1684 $labelsFromFile[$label] = $value;
1685 } elseif (strpos($label, $selectionPrefix) === 0) {
1686 $key = preg_replace($labelPattern, '', $label);
1687 $labelsFromFile[$label] = $value;
1688 }
1689 }
1690
1691 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
1692 }
1693 }
1694
1695 /*****************************************************/
1696 /* */
1697 /* Tools */
1698 /* */
1699 /* */
1700 /*****************************************************/
1701
1702 /**
1703 * concatenate files into one file
1704 * registered handler
1705 *
1706 * @return void
1707 */
1708 protected function doConcatenate() {
1709 // traverse the arrays, concatenate in one file
1710 // then remove concatenated files from array and add the concatenated file
1711
1712 if ($this->concatenateFiles) {
1713 $params = array(
1714 'jsLibs' => &$this->jsLibs,
1715 'jsFiles' => &$this->jsFiles,
1716 'jsFooterFiles' => &$this->jsFooterFiles,
1717 'cssFiles' => &$this->cssFiles,
1718 'headerData' => &$this->headerData,
1719 'footerData' => &$this->footerData,
1720 );
1721
1722 if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler']) {
1723 // use extern concatenate routine
1724 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler'], $params, $this);
1725 } elseif (TYPO3_MODE === 'BE') {
1726 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
1727 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
1728 }
1729 }
1730 }
1731
1732 /**
1733 * compress inline code
1734 *
1735 * @return void
1736 */
1737 protected function doCompress() {
1738
1739 if ($this->compressJavascript && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler']) {
1740 // use extern compress routine
1741 $params = array(
1742 'jsInline' => &$this->jsInline,
1743 'jsFooterInline' => &$this->jsFooterInline,
1744 'jsLibs' => &$this->jsLibs,
1745 'jsFiles' => &$this->jsFiles,
1746 'jsFooterFiles' => &$this->jsFooterFiles,
1747 'headerData' => &$this->headerData,
1748 'footerData' => &$this->footerData,
1749 );
1750 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
1751 } else {
1752 // traverse the arrays, compress files
1753
1754 if ($this->compressJavascript) {
1755 if (count($this->jsInline)) {
1756 foreach ($this->jsInline as $name => $properties) {
1757 if ($properties['compress']) {
1758 $error = '';
1759 $this->jsInline[$name]['code'] = t3lib_div::minifyJavaScript($properties['code'], $error);
1760 if ($error) {
1761 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
1762 }
1763 }
1764 }
1765 }
1766 if (TYPO3_MODE === 'BE') {
1767 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
1768 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
1769 }
1770 }
1771 }
1772 if ($this->compressCss) {
1773 // use extern compress routine
1774 $params = array(
1775 'cssInline' => &$this->cssInline,
1776 'cssFiles' => &$this->cssFiles,
1777 'headerData' => &$this->headerData,
1778 'footerData' => &$this->footerData,
1779 );
1780
1781 if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler']) {
1782 // use extern concatenate routine
1783 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
1784 } elseif (TYPO3_MODE === 'BE') {
1785 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
1786 }
1787 }
1788 }
1789
1790 /**
1791 * Returns instance of t3lib_Compressor
1792 *
1793 * @return t3lib_Compressor Instance of t3lib_Compressor
1794 */
1795 protected function getCompressor() {
1796 if ($this->compressor === NULL) {
1797 $this->compressor = t3lib_div::makeInstance('t3lib_Compressor');
1798 }
1799 return $this->compressor;
1800 }
1801
1802 /**
1803 * Processes a Javascript file dependent on the current context
1804 *
1805 * Adds the version number for Frontend, compresses the file for Backend
1806 *
1807 * @param string $filename Filename
1808 * @return string new filename
1809 */
1810 protected function processJsFile($filename) {
1811 switch (TYPO3_MODE) {
1812 case 'FE':
1813 $filename = t3lib_div::createVersionNumberedFilename($filename);
1814 break;
1815 case 'BE':
1816 if ($this->compressJavascript) {
1817 $filename = $this->getCompressor()->compressJsFile($filename);
1818 }
1819 break;
1820 }
1821 return $filename;
1822 }
1823
1824 }
1825
1826 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
1827 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);
1828 }
1829 ?>