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