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