Added feature #15900: [Feature] Add SVG support for all browsers
[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 }
502
503 /*****************************************************/
504 /* */
505 /* Public Getters */
506 /* */
507 /* */
508 /*****************************************************/
509
510 /**
511 * Gets the title
512 *
513 * @return string $title title of webpage
514 */
515 public function getTitle() {
516 return $this->title;
517 }
518
519 /**
520 * Gets the charSet
521 *
522 * @return string $charSet
523 */
524 public function getCharSet() {
525 return $this->charSet;
526 }
527
528 /**
529 * Gets the language
530 *
531 * @return string $lang
532 */
533 public function getLanguage() {
534 return $this->lang;
535 }
536
537 /**
538 * Returns rendering mode XHTML or HTML
539 *
540 * @return boolean TRUE if XHTML, FALSE if HTML
541 */
542 public function getRenderXhtml() {
543 return $this->renderXhtml;
544 }
545
546 /**
547 * Gets html tag
548 *
549 * @return string $htmlTag html tag
550 */
551 public function getHtmlTag() {
552 return $this->htmlTag;
553 }
554
555 /**
556 * Gets head tag
557 *
558 * @return string $tag head tag
559 */
560 public function getHeadTag() {
561 return $this->headTag;
562 }
563
564 /**
565 * Gets favicon
566 *
567 * @return string $favIcon
568 */
569 public function getFavIcon() {
570 return $this->favIcon;
571 }
572
573 /**
574 * Gets icon mime type
575 *
576 * @return string $iconMimeType
577 */
578 public function getIconMimeType() {
579 return $this->iconMimeType;
580 }
581
582 /**
583 * Gets base url
584 *
585 * @return string $url
586 */
587 public function getBaseUrl() {
588 return $this->baseUrl;
589 }
590
591 /**
592 * Gets template file
593 *
594 * @return string $file
595 */
596 public function getTemplateFile($file) {
597 return $this->templateFile;
598 }
599
600 /**
601 * Gets MoveJsFromHeaderToFooter
602 *
603 * @return boolean
604 */
605 public function getMoveJsFromHeaderToFooter() {
606 return $this->moveJsFromHeaderToFooter;
607 }
608
609 /**
610 * Gets compress of javascript
611 *
612 * @return boolean
613 */
614 public function getCompressJavascript() {
615 return $this->compressJavascript;
616 }
617
618 /**
619 * Gets compress of css
620 *
621 * @return boolean
622 */
623 public function getCompressCss() {
624 return $this->compressCss;
625 }
626
627 /**
628 * Gets concatenate of files
629 *
630 * @return boolean
631 */
632 public function getConcatenateFiles() {
633 return $this->concatenateFiles;
634 }
635
636 /**
637 * Gets remove of empty lines from template
638 *
639 * @return boolean
640 */
641 public function getRemoveLineBreaksFromTemplate() {
642 return $this->removeLineBreaksFromTemplate;
643 }
644
645 /**
646 * Gets content for body
647 *
648 * @return string
649 */
650 public function getBodyContent() {
651 return $this->bodyContent;
652 }
653
654 /**
655 * Gets Path for prototype library (relative to typo3 directory)
656 *
657 * @return string
658 */
659 public function getPrototypePath() {
660 return $this->prototypePath;
661 }
662
663 /**
664 * Gets Path for scriptaculous library (relative to typo3 directory)
665 *
666 * @return string
667 */
668 public function getScriptaculousPath() {
669 return $this->scriptaculousPath;
670 }
671
672 /**
673 * Gets Path for Ext Core library (relative to typo3 directory)
674 *
675 * @return string
676 */
677 public function getExtCorePath() {
678 return $this->extCorePath;
679 }
680
681 /**
682 * Gets Path for ExtJs library (relative to typo3 directory)
683 *
684 * @return string
685 */
686 public function getExtJsPath() {
687 return $this->extJsPath;
688 }
689
690 /**
691 * Gets Path for SVG library (relative to typo3 directory)
692 *
693 * @return string
694 */
695 public function getSvgPath() {
696 return $this->svgPath;
697 }
698
699 /**
700 * Gets the inline language labels.
701 *
702 * @return array The inline language labels
703 */
704 public function getInlineLanguageLabels() {
705 return $this->inlineLanguageLabels;
706 }
707
708 /**
709 * Gets the inline language files
710 *
711 * @return array
712 */
713 public function getInlineLanguageLabelFiles() {
714 return $this->inlineLanguageLabelFiles;
715 }
716
717 /*****************************************************/
718 /* */
719 /* Public Function to add Data */
720 /* */
721 /* */
722 /*****************************************************/
723
724 /**
725 * Adds meta data
726 *
727 * @param string $meta meta data (complete metatag)
728 * @return void
729 */
730 public function addMetaTag($meta) {
731 if (!in_array($meta, $this->metaTags)) {
732 $this->metaTags[] = $meta;
733 }
734 }
735
736 /**
737 * Adds inline HTML comment
738 *
739 * @param string $comment
740 * @return void
741 */
742 public function addInlineComment($comment) {
743 if (!in_array($comment, $this->inlineComments)) {
744 $this->inlineComments[] = $comment;
745 }
746 }
747
748 /**
749 * Adds header data
750 *
751 * @param string $data free header data for HTML header
752 * @return void
753 */
754 public function addHeaderData($data) {
755 if (!in_array($data, $this->headerData)) {
756 $this->headerData[] = $data;
757 }
758 }
759
760 /**
761 * Adds footer data
762 *
763 * @param string $data free header data for HTML header
764 * @return void
765 */
766 public function addFooterData($data) {
767 if (!in_array($data, $this->footerData)) {
768 $this->footerData[] = $data;
769 }
770 }
771
772 /* Javascript Files */
773
774 /**
775 * Adds JS Library. JS Library block is rendered on top of the JS files.
776 *
777 * @param string $name
778 * @param string $file
779 * @param string $type
780 * @param boolean $compress flag if library should be compressed
781 * @param boolean $forceOnTop flag if added library should be inserted at begin of this block
782 * @param string $allWrap
783 * @return void
784 */
785 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '') {
786 if (!in_array(strtolower($name), $this->jsLibs)) {
787 $this->jsLibs[strtolower($name)] = array (
788 'file' => $file,
789 'type' => $type,
790 'section' => self::PART_HEADER,
791 'compress' => $compress,
792 'forceOnTop' => $forceOnTop,
793 'allWrap' => $allWrap
794 );
795 }
796
797 }
798
799 /**
800 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
801 *
802 * @param string $name
803 * @param string $file
804 * @param string $type
805 * @param boolean $compress flag if library should be compressed
806 * @param boolean $forceOnTop flag if added library should be inserted at begin of this block
807 * @param string $allWrap
808 * @return void
809 */
810 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '') {
811 if (!in_array(strtolower($name), $this->jsLibs)) {
812 $this->jsLibs[strtolower($name)] = array (
813 'file' => $file,
814 'type' => $type,
815 'section' => self::PART_FOOTER,
816 'compress' => $compress,
817 'forceOnTop' => $forceOnTop,
818 'allWrap' => $allWrap
819 );
820 }
821
822 }
823
824 /**
825 * Adds JS file
826 *
827 * @param string $file
828 * @param string $type
829 * @param boolean $compress
830 * @param boolean $forceOnTop
831 * @param string $allWrap
832 * @return void
833 */
834 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
835 if (!isset($this->jsFiles[$file])) {
836 $this->jsFiles[$file] = array (
837 'type' => $type,
838 'section' => self::PART_HEADER,
839 'compress' => $compress,
840 'forceOnTop' => $forceOnTop,
841 'allWrap' => $allWrap
842 );
843 }
844 }
845
846 /**
847 * Adds JS file to footer
848 *
849 * @param string $file
850 * @param string $type
851 * @param boolean $compress
852 * @param boolean $forceOnTop
853 * @return void
854 */
855 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
856 if (!isset($this->jsFiles[$file])) {
857 $this->jsFiles[$file] = array (
858 'type' => $type,
859 'section' => self::PART_FOOTER,
860 'compress' => $compress,
861 'forceOnTop' => $forceOnTop,
862 'allWrap' => $allWrap
863 );
864 }
865 }
866
867 /*Javascript Inline Blocks */
868
869 /**
870 * Adds JS inline code
871 *
872 * @param string $name
873 * @param string $block
874 * @param boolean $compress
875 * @param boolean $forceOnTop
876 * @return void
877 */
878 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
879 if (!isset($this->jsInline[$name]) && !empty($block)) {
880 $this->jsInline[$name] = array (
881 'code' => $block . LF,
882 'section' => self::PART_HEADER,
883 'compress' => $compress,
884 'forceOnTop' => $forceOnTop
885 );
886 }
887 }
888
889 /**
890 * Adds JS inline code to footer
891 *
892 * @param string $name
893 * @param string $block
894 * @param boolean $compress
895 * @param boolean $forceOnTop
896 * @return void
897 */
898 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
899 if (!isset($this->jsInline[$name]) && !empty($block)) {
900 $this->jsInline[$name] = array (
901 'code' => $block . LF,
902 'section' => self::PART_FOOTER,
903 'compress' => $compress,
904 'forceOnTop' => $forceOnTop
905 );
906 }
907 }
908
909 /**
910 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
911 *
912 * @param string $block javascript code
913 * @param boolean $forceOnTop position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
914 * @return void
915 */
916 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
917 if (!in_array($block, $this->extOnReadyCode)) {
918 if ($forceOnTop) {
919 array_unshift($this->extOnReadyCode, $block);
920 } else {
921 $this->extOnReadyCode[] = $block;
922 }
923 }
924 }
925
926 /**
927 * Adds the ExtDirect code
928 *
929 * @return void
930 */
931 public function addExtDirectCode() {
932 // Note: we need to iterate thru the object, because the addProvider method
933 // does this only with multiple arguments
934 $this->addExtOnReadyCode(
935 'for (var api in Ext.app.ExtDirectAPI) {
936 Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
937 }
938
939 var extDirectDebug = function(message, header, group) {
940 var TYPO3ViewportInstance = null;
941
942 if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
943 TYPO3ViewportInstance = top.TYPO3.Backend;
944 } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
945 TYPO3ViewportInstance = TYPO3.Backend;
946 }
947
948 if (TYPO3ViewportInstance !== null) {
949 TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
950 } else if (typeof console === "object") {
951 console.log(message);
952 } else {
953 document.write(message);
954 }
955 };
956
957 Ext.Direct.on("exception", function(event) {
958 var backtrace = "";
959 if (event.where) {
960 backtrace = "<p style=\"margin-top: 20px;\">" +
961 "<strong>Backtrace:<\/strong><br \/>" +
962 event.where.replace(/#/g, "<br \/>#") +
963 "<\/p>";
964 }
965
966 extDirectDebug(
967 "<p>" + event.message + "<\/p>" + backtrace,
968 event.method,
969 "ExtDirect - Exception"
970 );
971 });
972
973 Ext.Direct.on("event", function(event, provider) {
974 if (typeof event.debug !== "undefined" && event.debug !== "") {
975 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
976 }
977 });
978 ',
979 TRUE
980 );
981 }
982
983 /* CSS Files */
984
985 /**
986 * Adds CSS file
987 *
988 * @param string $file
989 * @param string $rel
990 * @param string $media
991 * @param string $title
992 * @param boolean $compress
993 * @param boolean $forceOnTop
994 * @return void
995 */
996 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
997 if (!isset($this->cssFiles[$file])) {
998 $this->cssFiles[$file] = array (
999 'rel' => $rel,
1000 'media' => $media,
1001 'title' => $title,
1002 'compress' => $compress,
1003 'forceOnTop' => $forceOnTop,
1004 'allWrap' => $allWrap
1005 );
1006 }
1007 }
1008
1009 /*CSS Inline Blocks */
1010
1011 /**
1012 * Adds CSS inline code
1013 *
1014 * @param string $name
1015 * @param string $block
1016 * @param boolean $compress
1017 * @param boolean $forceOnTop
1018 * @return void
1019 */
1020 public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
1021 if (!isset($this->cssInline[$name]) && !empty($block)) {
1022 $this->cssInline[$name] = array (
1023 'code' => $block,
1024 'compress' => $compress,
1025 'forceOnTop' => $forceOnTop
1026 );
1027 }
1028 }
1029
1030 /* JS Libraries */
1031
1032 /**
1033 * call function if you need the prototype library
1034 *
1035 * @return void
1036 */
1037 public function loadPrototype() {
1038 $this->addPrototype = TRUE;
1039 }
1040
1041 /**
1042 * call function if you need the Scriptaculous library
1043 *
1044 * @param string $modules add modules you need. use "all" if you need complete modules
1045 * @return void
1046 */
1047 public function loadScriptaculous($modules = 'all') {
1048 // Scriptaculous require prototype, so load prototype too.
1049 $this->addPrototype = TRUE;
1050 $this->addScriptaculous = TRUE;
1051 if ($modules) {
1052 if ($modules == 'all') {
1053 foreach ($this->addScriptaculousModules as $key => $value) {
1054 $this->addScriptaculousModules[$key] = TRUE;
1055 }
1056 } else {
1057 $mods = t3lib_div::trimExplode(',', $modules);
1058 foreach ($mods as $mod) {
1059 if (isset($this->addScriptaculousModules[strtolower($mod)])) {
1060 $this->addScriptaculousModules[strtolower($mod)] = TRUE;
1061 }
1062 }
1063 }
1064 }
1065 }
1066
1067 /**
1068 * call this function if you need the extJS library
1069 *
1070 * @param boolean $css flag, if set the ext-css will be loaded
1071 * @param boolean $theme flag, if set the ext-theme "grey" will be loaded
1072 * @param string $adapter choose alternative adapter, possible values: yui, prototype, jquery
1073 * @return void
1074 */
1075 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
1076 if ($adapter) {
1077 // empty $adapter will always load the ext adapter
1078 switch (t3lib_div::strtolower(trim($adapter))) {
1079 case self::EXTJS_ADAPTER_YUI :
1080 $this->extJSadapter = 'yui/ext-yui-adapter.js';
1081 break;
1082 case self::EXTJS_ADAPTER_PROTOTYPE :
1083 $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
1084 break;
1085 case self::EXTJS_ADAPTER_JQUERY :
1086 $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
1087 break;
1088 }
1089 }
1090 $this->addExtJS = TRUE;
1091 $this->extJStheme = $theme;
1092 $this->extJScss = $css;
1093
1094 }
1095
1096 /**
1097 * Enables ExtJs QuickTips
1098 * Need extJs loaded
1099 *
1100 * @return void
1101 *
1102 */
1103 public function enableExtJSQuickTips() {
1104 $this->enableExtJSQuickTips = TRUE;
1105 }
1106
1107
1108 /**
1109 * call function if you need the ExtCore library
1110 *
1111 * @return void
1112 */
1113 public function loadExtCore() {
1114 $this->addExtCore = TRUE;
1115 }
1116
1117 /**
1118 * call function if you need the SVG library
1119 *
1120 * @return void
1121 */
1122 public function loadSvg() {
1123 $this->addSvg = TRUE;
1124 }
1125
1126 /**
1127 * call this function to load debug version of ExtJS. Use this for development only
1128 *
1129 */
1130 public function enableSvgDebug() {
1131 $this->enableSvgDebug = TRUE;
1132 }
1133
1134 /**
1135 * call this function to force flash usage with SVG library
1136 *
1137 */
1138 public function svgForceFlash() {
1139 $this->addMetaTag('<meta name="svg.render.forceflash" content="true" />');
1140 }
1141
1142 /**
1143 * call this function to load debug version of ExtJS. Use this for development only
1144 *
1145 */
1146 public function enableExtJsDebug() {
1147 $this->enableExtJsDebug = TRUE;
1148 }
1149
1150 /**
1151 * call this function to load debug version of ExtCore. Use this for development only
1152 *
1153 * @return void
1154 */
1155 public function enableExtCoreDebug() {
1156 $this->enableExtCoreDebug = TRUE;
1157 }
1158
1159 /**
1160 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1161 * The label can be used in scripts with TYPO3.lang.<key>
1162 * Need extJs loaded
1163 *
1164 * @param string $key
1165 * @param string $value
1166 * @return void
1167 */
1168 public function addInlineLanguageLabel($key, $value) {
1169 $this->inlineLanguageLabels[$key] = $value;
1170 }
1171
1172 /**
1173 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1174 * The label can be used in scripts with TYPO3.lang.<key>
1175 * Array will be merged with existing array.
1176 * Need extJs loaded
1177 *
1178 * @param array $array
1179 * @return void
1180 */
1181 public function addInlineLanguageLabelArray(array $array) {
1182 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
1183 }
1184
1185 /**
1186 * Gets labels to be used in JavaScript fetched from a locallang file.
1187 *
1188 * @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.
1189 * @param string $selectionPrefix: Prefix to select the correct labels (default: '')
1190 * @param string $stripFromSelectionName: Sub-prefix to be removed from label names in the result (default: '')
1191 * @param integer Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1192 * @return void
1193 */
1194 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1195 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1196 if ($fileRef && !isset($this->inlineLanguageLabelFiles[$index])) {
1197 $this->inlineLanguageLabelFiles[$index] = array(
1198 'fileRef' => $fileRef,
1199 'selectionPrefix' => $selectionPrefix,
1200 'stripFromSelectionName' => $stripFromSelectionName,
1201 'errorMode' => $errorMode
1202 );
1203 }
1204 }
1205
1206
1207 /**
1208 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1209 * The label can be used in scripts with TYPO3.setting.<key>
1210 * Need extJs loaded
1211 *
1212 * @param string $namespace
1213 * @param string $key
1214 * @param string $value
1215 * @return void
1216 */
1217 public function addInlineSetting($namespace, $key, $value) {
1218 if ($namespace) {
1219 if (strpos($namespace, '.')) {
1220 $parts = explode('.', $namespace);
1221 $a = &$this->inlineSettings;
1222 foreach ($parts as $part) {
1223 $a = &$a[$part];
1224 }
1225 $a[$key] = $value;
1226 } else {
1227 $this->inlineSettings[$namespace][$key] = $value;
1228 }
1229 } else {
1230 $this->inlineSettings[$key] = $value;
1231 }
1232 }
1233
1234 /**
1235 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1236 * The label can be used in scripts with TYPO3.setting.<key>
1237 * Array will be merged with existing array.
1238 * Need extJs loaded
1239 *
1240 * @param string $namespace
1241 * @param array $array
1242 * @return void
1243 */
1244 public function addInlineSettingArray($namespace, array $array) {
1245 if ($namespace) {
1246 if (strpos($namespace, '.')) {
1247 $parts = explode('.', $namespace);
1248 $a = &$this->inlineSettings;
1249 foreach ($parts as $part) {
1250 $a = &$a[$part];
1251 }
1252 $a = array_merge((array) $a, $array);
1253 } else {
1254 $this->inlineSettings[$namespace] = array_merge((array) $this->inlineSettings[$namespace], $array);
1255 }
1256 } else {
1257 $this->inlineSettings = array_merge($this->inlineSettings, $array);
1258 }
1259 }
1260
1261 /**
1262 * Adds content to body content
1263 *
1264 * @param string $content
1265 * @return void
1266 */
1267 public function addBodyContent($content) {
1268 $this->bodyContent .= $content;
1269 }
1270
1271 /*****************************************************/
1272 /* */
1273 /* Render Functions */
1274 /* */
1275 /* */
1276 /*****************************************************/
1277
1278 /**
1279 * render the section (Header or Footer)
1280 *
1281 * @param int $part section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1282 * @return string content of rendered section
1283 */
1284 public function render($part = self::PART_COMPLETE) {
1285
1286 $jsFiles = '';
1287 $cssFiles = '';
1288 $cssInline = '';
1289 $jsInline = '';
1290 $jsFooterInline = '';
1291 $jsFooterLibs = '';
1292 $jsFooterFiles = '';
1293
1294 // preRenderHook for possible manuipulation
1295 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
1296 $params = array (
1297 'jsLibs' => &$this->jsLibs,
1298 'jsFiles' => &$this->jsFiles,
1299 'jsFooterFiles' => &$this->jsFooterFiles,
1300 'cssFiles' => &$this->cssFiles,
1301 'headerData' => &$this->headerData,
1302 'footerData' => &$this->footerData,
1303 'jsInline' => &$this->jsInline,
1304 'cssInline' => &$this->cssInline,
1305 );
1306 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
1307 t3lib_div::callUserFunction($hook, $params, $this);
1308 }
1309 }
1310
1311 $jsLibs = $this->renderJsLibraries();
1312
1313 if ($this->concatenateFiles) {
1314 // do the file concatenation
1315 $this->doConcatenate();
1316 }
1317 if ($this->compressCss || $this->compressJavascript) {
1318 // do the file compression
1319 $this->doCompress();
1320 }
1321
1322 $metaTags = implode(LF, $this->metaTags);
1323
1324 // remove ending slashes from static header block
1325 // if the page is beeing rendered as html (not xhtml)
1326 // and define variable $endingSlash for further use
1327 if ($this->getRenderXhtml()) {
1328 $endingSlash = ' /';
1329 } else {
1330 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
1331 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
1332 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
1333 $endingSlash = '';
1334 }
1335
1336 if (count($this->cssFiles)) {
1337 foreach ($this->cssFiles as $file => $properties) {
1338 $file = t3lib_div::resolveBackPath($file);
1339 $file = t3lib_div::createVersionNumberedFilename($file);
1340 $tag = '<link rel="' . $properties['rel'] . '" type="text/css" href="' .
1341 htmlspecialchars($file) . '" media="' . $properties['media'] . '"' .
1342 ($properties['title'] ? ' title="' . $properties['title'] . '"' : '') .
1343 $endingSlash . '>';
1344 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1345 $tag = str_replace('|', $tag, $properties['allWrap']);
1346 }
1347 if ($properties['forceOnTop']) {
1348 $cssFiles = $tag . LF . $cssFiles;
1349 } else {
1350 $cssFiles .= LF . $tag;
1351 }
1352 }
1353 }
1354
1355 if (count($this->cssInline)) {
1356 foreach ($this->cssInline as $name => $properties) {
1357 if ($properties['forceOnTop']) {
1358 $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $cssInline;
1359 } else {
1360 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1361 }
1362 }
1363 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
1364 }
1365
1366 if (count($this->jsLibs)) {
1367 foreach ($this->jsLibs as $name => $properties) {
1368 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
1369 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
1370 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . $properties['type'] . '"></script>';
1371 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1372 $tag = str_replace('|', $tag, $properties['allWrap']);
1373 }
1374 if ($properties['forceOnTop']) {
1375 if ($properties['section'] === self::PART_HEADER) {
1376 $jsLibs = $tag . LF . $jsLibs;
1377 } else {
1378 $jsFooterLibs = $tag . LF . $jsFooterLibs;
1379 }
1380 } else {
1381 if ($properties['section'] === self::PART_HEADER) {
1382 $jsLibs .= LF . $tag;
1383 } else {
1384 $jsFooterLibs .= LF . $tag;
1385 }
1386 }
1387 }
1388 }
1389
1390 if (count($this->jsFiles)) {
1391 foreach ($this->jsFiles as $file => $properties) {
1392 $file = t3lib_div::resolveBackPath($file);
1393 $file = t3lib_div::createVersionNumberedFilename($file);
1394 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . $properties['type'] . '"></script>';
1395 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1396 $tag = str_replace('|', $tag, $properties['allWrap']);
1397 }
1398 if ($properties['forceOnTop']) {
1399 if ($properties['section'] === self::PART_HEADER) {
1400 $jsFiles = $tag . LF . $jsFiles;
1401 } else {
1402 $jsFooterFiles = $tag . LF . $jsFooterFiles;
1403 }
1404 } else {
1405 if ($properties['section'] === self::PART_HEADER) {
1406 $jsFiles .= LF . $tag;
1407 } else {
1408 $jsFooterFiles .= LF . $tag;
1409 }
1410 }
1411 }
1412 }
1413
1414 if (count($this->jsInline)) {
1415 foreach ($this->jsInline as $name => $properties) {
1416 if ($properties['forceOnTop']) {
1417 if ($properties['section'] === self::PART_HEADER) {
1418 $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsInline;
1419 } else {
1420 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsFooterInline;
1421 }
1422 } else {
1423 if ($properties['section'] === self::PART_HEADER) {
1424 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1425 } else {
1426 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1427 }
1428 }
1429 }
1430 }
1431
1432
1433 if ($jsInline) {
1434 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
1435 }
1436
1437 if ($jsFooterInline) {
1438 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
1439 }
1440
1441
1442 // get template
1443 $templateFile = t3lib_div::getFileAbsFileName($this->templateFile, TRUE);
1444 $template = t3lib_div::getURL($templateFile);
1445
1446 if ($this->removeLineBreaksFromTemplate) {
1447 $template = strtr($template, array(LF => '', CR => ''));
1448 }
1449 if ($part != self::PART_COMPLETE) {
1450 $templatePart = explode('###BODY###', $template);
1451 $template = $templatePart[$part - 1];
1452 }
1453
1454 if ($this->moveJsFromHeaderToFooter) {
1455 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
1456 $jsLibs = '';
1457 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
1458 $jsFiles = '';
1459 $jsFooterInline = $jsInline . LF . $jsFooterInline;
1460 $jsInline = '';
1461 }
1462
1463 $markerArray = array(
1464 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1465 'HTMLTAG' => $this->htmlTag,
1466 'HEADTAG' => $this->headTag,
1467 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1468 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1469 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1470 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1471 'CSS_INCLUDE' => $cssFiles,
1472 'CSS_INLINE' => $cssInline,
1473 'JS_INLINE' => $jsInline,
1474 'JS_INCLUDE' => $jsFiles,
1475 'JS_LIBS' => $jsLibs,
1476 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1477 'META' => $metaTags,
1478 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
1479 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
1480 'JS_LIBS_FOOTER' => $jsFooterLibs,
1481 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1482 'JS_INLINE_FOOTER' => $jsFooterInline,
1483 'BODY' => $this->bodyContent,
1484 );
1485
1486 $markerArray = array_map('trim', $markerArray);
1487
1488 $this->reset();
1489 return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
1490 }
1491
1492 /**
1493 * helper function for render the javascript libraries
1494 *
1495 * @return string content with javascript libraries
1496 */
1497 protected function renderJsLibraries() {
1498 $out = '';
1499
1500 if ($this->addSvg) {
1501 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->svgPath . 'svg.js') .
1502 '" data-path="' . $this->backPath . $this->svgPath .
1503 '"' . ($this->enableSvgDebug ? ' data-debug="true"' : '') . '></script>';
1504 }
1505
1506 if ($this->addPrototype) {
1507 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->prototypePath . 'prototype.js') .
1508 '" type="text/javascript"></script>' . LF;
1509 unset($this->jsFiles[$this->backPath . $this->prototypePath .'prototype.js']);
1510 }
1511
1512 if ($this->addScriptaculous) {
1513 $mods = array ();
1514 foreach ($this->addScriptaculousModules as $key => $value) {
1515 if ($this->addScriptaculousModules[$key]) {
1516 $mods[] = $key;
1517 }
1518 }
1519 // resolve dependencies
1520 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
1521 $mods = array_merge(array('effects'), $mods);
1522 }
1523
1524 if (count($mods)) {
1525 foreach ($mods as $module) {
1526 $out .= '<script src="' . $this->processJsFile($this->backPath .
1527 $this->scriptaculousPath . $module . '.js') . '" type="text/javascript"></script>' . LF;
1528 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . $module . '.js']);
1529 }
1530 }
1531 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->scriptaculousPath .
1532 'scriptaculous.js') . '" type="text/javascript"></script>' . LF;
1533 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . 'scriptaculous.js']);
1534 }
1535
1536 // include extCore
1537 if ($this->addExtCore) {
1538 $out .= '<script src="' . $this->processJsFile($this->backPath .
1539 $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
1540 '" type="text/javascript"></script>' . LF;
1541 unset($this->jsFiles[$this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
1542 }
1543
1544 // include extJS
1545 if ($this->addExtJS) {
1546 // use the base adapter all the time
1547 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
1548 'adapter/' . ($this->enableExtJsDebug ?
1549 str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
1550 '" type="text/javascript"></script>' . LF;
1551 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
1552 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
1553 '" type="text/javascript"></script>' . LF;
1554
1555 // add extJS localization
1556 $localeMap = $this->csConvObj->isoArray; // load standard ISO mapping and modify for use with ExtJS
1557 $localeMap[''] = 'en';
1558 $localeMap['default'] = 'en';
1559 $localeMap['gr'] = 'el_GR'; // Greek
1560 $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
1561 $localeMap['se'] = 'se_SV'; // Swedish
1562
1563
1564 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
1565 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1566 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
1567 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
1568 $out .= '<script src="' . $this->processJsFile($this->backPath .
1569 $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
1570 }
1571
1572
1573
1574 // remove extjs from JScodeLibArray
1575 unset(
1576 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'],
1577 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']
1578 );
1579 }
1580
1581 if (count($this->inlineLanguageLabelFiles)) {
1582 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
1583 $this->includeLanguageFileForInline(
1584 $languageLabelFile['fileRef'],
1585 $languageLabelFile['selectionPrefix'],
1586 $languageLabelFile['stripFromSelectionName'],
1587 $languageLabelFile['$errorMode']
1588 );
1589 }
1590 }
1591 unset($this->inlineLanguageLabelFiles);
1592
1593 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
1594 if ($this->getCharSet() !== 'utf-8') {
1595 if ($this->inlineLanguageLabels) {
1596 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
1597 }
1598 if ($this->inlineSettings) {
1599 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
1600 }
1601 }
1602
1603 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
1604 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
1605
1606 if ($this->addExtCore || $this->addExtJS) {
1607 // set clear.gif, move it on top, add handler code
1608 $code = '';
1609 if (count($this->extOnReadyCode)) {
1610 foreach ($this->extOnReadyCode as $block) {
1611 $code .= $block;
1612 }
1613 }
1614
1615 $out .= $this->inlineJavascriptWrap[0] . '
1616 Ext.ns("TYPO3");
1617 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . LF .
1618 $inlineSettings .
1619 'Ext.onReady(function() {' .
1620 ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '') . $code .
1621 ' });' . $this->inlineJavascriptWrap[1];
1622 unset ($this->extOnReadyCode);
1623
1624 if ($this->extJStheme) {
1625 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1626 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
1627 } else {
1628 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
1629 }
1630 }
1631 if ($this->extJScss) {
1632 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1633 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
1634 } else {
1635 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
1636 }
1637 }
1638 } else {
1639 if ($inlineSettings) {
1640 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
1641 }
1642 }
1643
1644 return $out;
1645 }
1646
1647 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1648 if (!isset($this->lang) || !isset($this->charSet)) {
1649 throw new RuntimeException('Language and character encoding are not set.', 1284906026);
1650 }
1651
1652 $labelsFromFile = array();
1653 $allLabels = t3lib_div::readLLfile($fileRef, $this->lang, $this->charSet, $errorMode);
1654
1655 // Regular expression to strip the selection prefix and possibly something from the label name:
1656 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
1657
1658 if ($allLabels !== FALSE) {
1659 // Merge language specific translations:
1660 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
1661 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
1662 } else {
1663 $labels = $allLabels['default'];
1664 }
1665
1666 // Iterate through all locallang labels:
1667 foreach ($labels as $label => $value) {
1668 if ($selectionPrefix === '') {
1669 $labelsFromFile[$label] = $value;
1670 } elseif (strpos($label, $selectionPrefix) === 0) {
1671 $key = preg_replace($labelPattern, '', $label);
1672 $labelsFromFile[$label] = $value;
1673 }
1674 }
1675
1676 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
1677 }
1678 }
1679 /*****************************************************/
1680 /* */
1681 /* Tools */
1682 /* */
1683 /* */
1684 /*****************************************************/
1685
1686 /**
1687 * concatenate files into one file
1688 * registered handler
1689 *
1690 * @return void
1691 */
1692 protected function doConcatenate() {
1693 // traverse the arrays, concatenate in one file
1694 // then remove concatenated files from array and add the concatenated file
1695
1696 if ($this->concatenateFiles) {
1697 $params = array (
1698 'jsLibs' => &$this->jsLibs,
1699 'jsFiles' => &$this->jsFiles,
1700 'jsFooterFiles' => &$this->jsFooterFiles,
1701 'cssFiles' => &$this->cssFiles,
1702 'headerData' => &$this->headerData,
1703 'footerData' => &$this->footerData,
1704 );
1705
1706 if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler']) {
1707 // use extern concatenate routine
1708 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler'], $params, $this);
1709 } elseif (TYPO3_MODE === 'BE') {
1710 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
1711 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
1712 }
1713 }
1714 }
1715
1716 /**
1717 * compress inline code
1718 *
1719 * @return void
1720 */
1721 protected function doCompress() {
1722
1723 if ($this->compressJavascript && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler']) {
1724 // use extern compress routine
1725 $params = array (
1726 'jsInline' => &$this->jsInline,
1727 'jsFooterInline' => &$this->jsFooterInline,
1728 'jsLibs' => &$this->jsLibs,
1729 'jsFiles' => &$this->jsFiles,
1730 'jsFooterFiles' => &$this->jsFooterFiles,
1731 'headerData' => &$this->headerData,
1732 'footerData' => &$this->footerData,
1733 );
1734 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
1735 } else {
1736 // traverse the arrays, compress files
1737
1738 if ($this->compressJavascript) {
1739 if (count($this->jsInline)) {
1740 foreach ($this->jsInline as $name => $properties) {
1741 if ($properties['compress']) {
1742 $error = '';
1743 $this->jsInline[$name]['code'] = t3lib_div::minifyJavaScript($properties['code'], $error);
1744 if ($error) {
1745 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
1746 }
1747 }
1748 }
1749 }
1750 if (TYPO3_MODE === 'BE') {
1751 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
1752 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
1753 }
1754 }
1755 }
1756 if ($this->compressCss) {
1757 // use extern compress routine
1758 $params = array (
1759 'cssInline' => &$this->cssInline,
1760 'cssFiles' => &$this->cssFiles,
1761 'headerData' => &$this->headerData,
1762 'footerData' => &$this->footerData,
1763 );
1764
1765 if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler']) {
1766 // use extern concatenate routine
1767 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
1768 } elseif (TYPO3_MODE === 'BE') {
1769 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
1770 }
1771 }
1772 }
1773
1774 /**
1775 * Returns instance of t3lib_Compressor
1776 *
1777 * @return t3lib_Compressor Instance of t3lib_Compressor
1778 */
1779 protected function getCompressor() {
1780 if ($this->compressor === NULL) {
1781 $this->compressor = t3lib_div::makeInstance('t3lib_Compressor');
1782 }
1783 return $this->compressor;
1784 }
1785
1786 /**
1787 * Processes a Javascript file dependent on the current context
1788 *
1789 * Adds the version number for Frontend, compresses the file for Backend
1790 *
1791 * @param string $filename Filename
1792 * @return string new filename
1793 */
1794 protected function processJsFile($filename) {
1795 switch (TYPO3_MODE) {
1796 case 'FE':
1797 $filename = t3lib_div::createVersionNumberedFilename($filename);
1798 break;
1799 case 'BE':
1800 if ($this->compressJavascript) {
1801 $filename = $this->getCompressor()->compressJsFile($filename);
1802 }
1803 break;
1804 }
1805 return $filename;
1806 }
1807
1808 }
1809
1810 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
1811 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);
1812 }
1813 ?>