Fixed issue #17284: Formprotection persistToken method is called too often, causing...
[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 $token = '';
949 if (TYPO3_MODE === 'BE') {
950 $formprotection = t3lib_formprotection_Factory::get('t3lib_formprotection_BackendFormProtection');
951 $token = $formprotection->generateToken('extDirect');
952 }
953
954 // Note: we need to iterate thru the object, because the addProvider method
955 // does this only with multiple arguments
956 $this->addExtOnReadyCode('
957 (function() {
958 TYPO3.ExtDirectToken = "' . $token . '";
959 for (var api in Ext.app.ExtDirectAPI) {
960 var provider = Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
961 provider.on("beforecall", function(provider, transaction, meta) {
962 if (transaction.data) {
963 transaction.data[transaction.data.length] = TYPO3.ExtDirectToken;
964 } else {
965 transaction.data = [TYPO3.ExtDirectToken];
966 }
967 });
968
969 provider.on("call", function(provider, transaction, meta) {
970 if (transaction.isForm) {
971 transaction.params.securityToken = TYPO3.ExtDirectToken;
972 }
973 });
974 }
975 })();
976
977 var extDirectDebug = function(message, header, group) {
978 var TYPO3ViewportInstance = null;
979
980 if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
981 TYPO3ViewportInstance = top.TYPO3.Backend;
982 } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
983 TYPO3ViewportInstance = TYPO3.Backend;
984 }
985
986 if (TYPO3ViewportInstance !== null) {
987 TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
988 } else if (typeof console === "object") {
989 console.log(message);
990 } else {
991 document.write(message);
992 }
993 };
994
995 Ext.Direct.on("exception", function(event) {
996 if (event.code === Ext.Direct.exceptions.TRANSPORT && !event.where) {
997 TYPO3.Flashmessage.display(
998 TYPO3.Severity.error,
999 TYPO3.LLL.extDirect.timeoutHeader,
1000 TYPO3.LLL.extDirect.timeoutMessage,
1001 30
1002 );
1003 } else {
1004 var backtrace = "";
1005 if (event.where) {
1006 backtrace = "<p style=\"margin-top: 20px;\">" +
1007 "<strong>Backtrace:<\/strong><br \/>" +
1008 event.where.replace(/#/g, "<br \/>#") +
1009 "<\/p>";
1010 }
1011
1012 extDirectDebug(
1013 "<p>" + event.message + "<\/p>" + backtrace,
1014 event.method,
1015 "ExtDirect - Exception"
1016 );
1017 }
1018 });
1019
1020 Ext.Direct.on("event", function(event, provider) {
1021 if (typeof event.debug !== "undefined" && event.debug !== "") {
1022 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
1023 }
1024 });
1025 ',
1026 TRUE
1027 );
1028 }
1029
1030 /* CSS Files */
1031
1032 /**
1033 * Adds CSS file
1034 *
1035 * @param string $file
1036 * @param string $rel
1037 * @param string $media
1038 * @param string $title
1039 * @param boolean $compress
1040 * @param boolean $forceOnTop
1041 * @return void
1042 */
1043 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
1044 if (!isset($this->cssFiles[$file])) {
1045 $this->cssFiles[$file] = array(
1046 'rel' => $rel,
1047 'media' => $media,
1048 'title' => $title,
1049 'compress' => $compress,
1050 'forceOnTop' => $forceOnTop,
1051 'allWrap' => $allWrap
1052 );
1053 }
1054 }
1055
1056 /*CSS Inline Blocks */
1057
1058 /**
1059 * Adds CSS inline code
1060 *
1061 * @param string $name
1062 * @param string $block
1063 * @param boolean $compress
1064 * @param boolean $forceOnTop
1065 * @return void
1066 */
1067 public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
1068 if (!isset($this->cssInline[$name]) && !empty($block)) {
1069 $this->cssInline[$name] = array(
1070 'code' => $block,
1071 'compress' => $compress,
1072 'forceOnTop' => $forceOnTop
1073 );
1074 }
1075 }
1076
1077 /* JS Libraries */
1078
1079 /**
1080 * call function if you need the prototype library
1081 *
1082 * @return void
1083 */
1084 public function loadPrototype() {
1085 $this->addPrototype = TRUE;
1086 }
1087
1088 /**
1089 * call function if you need the Scriptaculous library
1090 *
1091 * @param string $modules add modules you need. use "all" if you need complete modules
1092 * @return void
1093 */
1094 public function loadScriptaculous($modules = 'all') {
1095 // Scriptaculous require prototype, so load prototype too.
1096 $this->addPrototype = TRUE;
1097 $this->addScriptaculous = TRUE;
1098 if ($modules) {
1099 if ($modules == 'all') {
1100 foreach ($this->addScriptaculousModules as $key => $value) {
1101 $this->addScriptaculousModules[$key] = TRUE;
1102 }
1103 } else {
1104 $mods = t3lib_div::trimExplode(',', $modules);
1105 foreach ($mods as $mod) {
1106 if (isset($this->addScriptaculousModules[strtolower($mod)])) {
1107 $this->addScriptaculousModules[strtolower($mod)] = TRUE;
1108 }
1109 }
1110 }
1111 }
1112 }
1113
1114 /**
1115 * call this function if you need the extJS library
1116 *
1117 * @param boolean $css flag, if set the ext-css will be loaded
1118 * @param boolean $theme flag, if set the ext-theme "grey" will be loaded
1119 * @param string $adapter choose alternative adapter, possible values: yui, prototype, jquery
1120 * @return void
1121 */
1122 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
1123 if ($adapter) {
1124 // empty $adapter will always load the ext adapter
1125 switch (t3lib_div::strtolower(trim($adapter))) {
1126 case self::EXTJS_ADAPTER_YUI :
1127 $this->extJSadapter = 'yui/ext-yui-adapter.js';
1128 break;
1129 case self::EXTJS_ADAPTER_PROTOTYPE :
1130 $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
1131 break;
1132 case self::EXTJS_ADAPTER_JQUERY :
1133 $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
1134 break;
1135 }
1136 }
1137 $this->addExtJS = TRUE;
1138 $this->extJStheme = $theme;
1139 $this->extJScss = $css;
1140
1141 }
1142
1143 /**
1144 * Enables ExtJs QuickTips
1145 * Need extJs loaded
1146 *
1147 * @return void
1148 *
1149 */
1150 public function enableExtJSQuickTips() {
1151 $this->enableExtJSQuickTips = TRUE;
1152 }
1153
1154
1155 /**
1156 * call function if you need the ExtCore library
1157 *
1158 * @return void
1159 */
1160 public function loadExtCore() {
1161 $this->addExtCore = TRUE;
1162 }
1163
1164 /**
1165 * call function if you need the SVG library
1166 *
1167 * @return void
1168 */
1169 public function loadSvg() {
1170 $this->addSvg = TRUE;
1171 }
1172
1173 /**
1174 * call this function to load debug version of ExtJS. Use this for development only
1175 *
1176 */
1177 public function enableSvgDebug() {
1178 $this->enableSvgDebug = TRUE;
1179 }
1180
1181 /**
1182 * call this function to force flash usage with SVG library
1183 *
1184 */
1185 public function svgForceFlash() {
1186 $this->addMetaTag('<meta name="svg.render.forceflash" content="true" />');
1187 }
1188
1189 /**
1190 * call this function to load debug version of ExtJS. Use this for development only
1191 *
1192 */
1193 public function enableExtJsDebug() {
1194 $this->enableExtJsDebug = TRUE;
1195 }
1196
1197 /**
1198 * call this function to load debug version of ExtCore. Use this for development only
1199 *
1200 * @return void
1201 */
1202 public function enableExtCoreDebug() {
1203 $this->enableExtCoreDebug = TRUE;
1204 }
1205
1206 /**
1207 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1208 * The label can be used in scripts with TYPO3.lang.<key>
1209 * Need extJs loaded
1210 *
1211 * @param string $key
1212 * @param string $value
1213 * @return void
1214 */
1215 public function addInlineLanguageLabel($key, $value) {
1216 $this->inlineLanguageLabels[$key] = $value;
1217 }
1218
1219 /**
1220 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1221 * The label can be used in scripts with TYPO3.lang.<key>
1222 * Array will be merged with existing array.
1223 * Need extJs loaded
1224 *
1225 * @param array $array
1226 * @return void
1227 */
1228 public function addInlineLanguageLabelArray(array $array) {
1229 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
1230 }
1231
1232 /**
1233 * Gets labels to be used in JavaScript fetched from a locallang file.
1234 *
1235 * @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.
1236 * @param string $selectionPrefix: Prefix to select the correct labels (default: '')
1237 * @param string $stripFromSelectionName: Sub-prefix to be removed from label names in the result (default: '')
1238 * @param integer Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1239 * @return void
1240 */
1241 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1242 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1243 if ($fileRef && !isset($this->inlineLanguageLabelFiles[$index])) {
1244 $this->inlineLanguageLabelFiles[$index] = array(
1245 'fileRef' => $fileRef,
1246 'selectionPrefix' => $selectionPrefix,
1247 'stripFromSelectionName' => $stripFromSelectionName,
1248 'errorMode' => $errorMode
1249 );
1250 }
1251 }
1252
1253
1254 /**
1255 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1256 * The label can be used in scripts with TYPO3.setting.<key>
1257 * Need extJs loaded
1258 *
1259 * @param string $namespace
1260 * @param string $key
1261 * @param string $value
1262 * @return void
1263 */
1264 public function addInlineSetting($namespace, $key, $value) {
1265 if ($namespace) {
1266 if (strpos($namespace, '.')) {
1267 $parts = explode('.', $namespace);
1268 $a = &$this->inlineSettings;
1269 foreach ($parts as $part) {
1270 $a = &$a[$part];
1271 }
1272 $a[$key] = $value;
1273 } else {
1274 $this->inlineSettings[$namespace][$key] = $value;
1275 }
1276 } else {
1277 $this->inlineSettings[$key] = $value;
1278 }
1279 }
1280
1281 /**
1282 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1283 * The label can be used in scripts with TYPO3.setting.<key>
1284 * Array will be merged with existing array.
1285 * Need extJs loaded
1286 *
1287 * @param string $namespace
1288 * @param array $array
1289 * @return void
1290 */
1291 public function addInlineSettingArray($namespace, array $array) {
1292 if ($namespace) {
1293 if (strpos($namespace, '.')) {
1294 $parts = explode('.', $namespace);
1295 $a = &$this->inlineSettings;
1296 foreach ($parts as $part) {
1297 $a = &$a[$part];
1298 }
1299 $a = array_merge((array) $a, $array);
1300 } else {
1301 $this->inlineSettings[$namespace] = array_merge((array) $this->inlineSettings[$namespace], $array);
1302 }
1303 } else {
1304 $this->inlineSettings = array_merge($this->inlineSettings, $array);
1305 }
1306 }
1307
1308 /**
1309 * Adds content to body content
1310 *
1311 * @param string $content
1312 * @return void
1313 */
1314 public function addBodyContent($content) {
1315 $this->bodyContent .= $content;
1316 }
1317
1318 /*****************************************************/
1319 /* */
1320 /* Render Functions */
1321 /* */
1322 /* */
1323 /*****************************************************/
1324
1325 /**
1326 * render the section (Header or Footer)
1327 *
1328 * @param int $part section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1329 * @return string content of rendered section
1330 */
1331 public function render($part = self::PART_COMPLETE) {
1332
1333 $jsFiles = '';
1334 $cssFiles = '';
1335 $cssInline = '';
1336 $jsInline = '';
1337 $jsFooterInline = '';
1338 $jsFooterLibs = '';
1339 $jsFooterFiles = '';
1340
1341 // preRenderHook for possible manuipulation
1342 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
1343 $params = array(
1344 'jsLibs' => &$this->jsLibs,
1345 'jsFooterLibs' => &$this->jsFooterLibs,
1346 'jsFiles' => &$this->jsFiles,
1347 'jsFooterFiles' => &$this->jsFooterFiles,
1348 'cssFiles' => &$this->cssFiles,
1349 'headerData' => &$this->headerData,
1350 'footerData' => &$this->footerData,
1351 'jsInline' => &$this->jsInline,
1352 'jsFooterInline' => &$this->jsFooterInline,
1353 'cssInline' => &$this->cssInline,
1354 );
1355 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
1356 t3lib_div::callUserFunction($hook, $params, $this);
1357 }
1358 }
1359
1360 $jsLibs = $this->renderJsLibraries();
1361
1362 if ($this->concatenateFiles) {
1363 // do the file concatenation
1364 $this->doConcatenate();
1365 }
1366 if ($this->compressCss || $this->compressJavascript) {
1367 // do the file compression
1368 $this->doCompress();
1369 }
1370
1371 $metaTags = implode(LF, $this->metaTags);
1372
1373 // remove ending slashes from static header block
1374 // if the page is beeing rendered as html (not xhtml)
1375 // and define variable $endingSlash for further use
1376 if ($this->getRenderXhtml()) {
1377 $endingSlash = ' /';
1378 } else {
1379 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
1380 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
1381 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
1382 $endingSlash = '';
1383 }
1384
1385 if (count($this->cssFiles)) {
1386 foreach ($this->cssFiles as $file => $properties) {
1387 $file = t3lib_div::resolveBackPath($file);
1388 $file = t3lib_div::createVersionNumberedFilename($file);
1389 $tag = '<link rel="' . htmlspecialchars($properties['rel']) . '" type="text/css" href="' .
1390 htmlspecialchars($file) . '" media="' . htmlspecialchars($properties['media']) . '"' .
1391 ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '') .
1392 $endingSlash . '>';
1393 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1394 $tag = str_replace('|', $tag, $properties['allWrap']);
1395 }
1396 if ($properties['forceOnTop']) {
1397 $cssFiles = $tag . LF . $cssFiles;
1398 } else {
1399 $cssFiles .= LF . $tag;
1400 }
1401 }
1402 }
1403
1404 if (count($this->cssInline)) {
1405 foreach ($this->cssInline as $name => $properties) {
1406 if ($properties['forceOnTop']) {
1407 $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $cssInline;
1408 } else {
1409 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1410 }
1411 }
1412 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
1413 }
1414
1415 if (count($this->jsLibs)) {
1416 foreach ($this->jsLibs as $name => $properties) {
1417 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
1418 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
1419 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
1420 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1421 $tag = str_replace('|', $tag, $properties['allWrap']);
1422 }
1423 if ($properties['forceOnTop']) {
1424 if ($properties['section'] === self::PART_HEADER) {
1425 $jsLibs = $tag . LF . $jsLibs;
1426 } else {
1427 $jsFooterLibs = $tag . LF . $jsFooterLibs;
1428 }
1429 } else {
1430 if ($properties['section'] === self::PART_HEADER) {
1431 $jsLibs .= LF . $tag;
1432 } else {
1433 $jsFooterLibs .= LF . $tag;
1434 }
1435 }
1436 }
1437 }
1438
1439 if (count($this->jsFiles)) {
1440 foreach ($this->jsFiles as $file => $properties) {
1441 $file = t3lib_div::resolveBackPath($file);
1442 $file = t3lib_div::createVersionNumberedFilename($file);
1443 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
1444 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1445 $tag = str_replace('|', $tag, $properties['allWrap']);
1446 }
1447 if ($properties['forceOnTop']) {
1448 if ($properties['section'] === self::PART_HEADER) {
1449 $jsFiles = $tag . LF . $jsFiles;
1450 } else {
1451 $jsFooterFiles = $tag . LF . $jsFooterFiles;
1452 }
1453 } else {
1454 if ($properties['section'] === self::PART_HEADER) {
1455 $jsFiles .= LF . $tag;
1456 } else {
1457 $jsFooterFiles .= LF . $tag;
1458 }
1459 }
1460 }
1461 }
1462
1463 if (count($this->jsInline)) {
1464 foreach ($this->jsInline as $name => $properties) {
1465 if ($properties['forceOnTop']) {
1466 if ($properties['section'] === self::PART_HEADER) {
1467 $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsInline;
1468 } else {
1469 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsFooterInline;
1470 }
1471 } else {
1472 if ($properties['section'] === self::PART_HEADER) {
1473 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1474 } else {
1475 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1476 }
1477 }
1478 }
1479 }
1480
1481
1482 if ($jsInline) {
1483 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
1484 }
1485
1486 if ($jsFooterInline) {
1487 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
1488 }
1489
1490
1491 // get template
1492 $templateFile = t3lib_div::getFileAbsFileName($this->templateFile, TRUE);
1493 $template = t3lib_div::getURL($templateFile);
1494
1495 if ($this->removeLineBreaksFromTemplate) {
1496 $template = strtr($template, array(LF => '', CR => ''));
1497 }
1498 if ($part != self::PART_COMPLETE) {
1499 $templatePart = explode('###BODY###', $template);
1500 $template = $templatePart[$part - 1];
1501 }
1502
1503 if ($this->moveJsFromHeaderToFooter) {
1504 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
1505 $jsLibs = '';
1506 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
1507 $jsFiles = '';
1508 $jsFooterInline = $jsInline . LF . $jsFooterInline;
1509 $jsInline = '';
1510 }
1511
1512 // postRenderHook for possible manipulation
1513 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
1514 $params = array (
1515 'jsLibs' => &$jsLibs,
1516 'jsFiles' => &$jsFiles,
1517 'jsFooterFiles' => &$jsFooterFiles,
1518 'cssFiles' => &$cssFiles,
1519 'headerData' => &$this->headerData,
1520 'footerData' => &$this->footerData,
1521 'jsInline' => &$jsInline,
1522 'cssInline' => &$cssInline,
1523 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType,
1524 'htmlTag' => &$this->htmlTag,
1525 'headTag' => &$this->headTag,
1526 'charSet' => &$this->charSet,
1527 'metaCharsetTag' => &$this->metaCharsetTag,
1528 'shortcutTag' => &$this->shortcutTag,
1529 'inlineComments' => &$this->inlineComments,
1530 'baseUrl' => &$this->baseUrl,
1531 'baseUrlTag' => &$this->baseUrlTag,
1532 'favIcon' => &$this->favIcon,
1533 'iconMimeType' => &$this->iconMimeType,
1534 'titleTag' => &$this->titleTag,
1535 'title' => &$this->title,
1536 'metaTags' => &$metaTags,
1537 'jsFooterInline' => &$jsFooterInline,
1538 'jsFooterLibs' => &$jsFooterLibs,
1539 'bodyContent' => &$this->bodyContent,
1540 );
1541 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
1542 t3lib_div::callUserFunction($hook, $params, $this);
1543 }
1544 }
1545
1546 $markerArray = array(
1547 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1548 'HTMLTAG' => $this->htmlTag,
1549 'HEADTAG' => $this->headTag,
1550 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1551 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1552 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1553 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1554 'CSS_INCLUDE' => $cssFiles,
1555 'CSS_INLINE' => $cssInline,
1556 'JS_INLINE' => $jsInline,
1557 'JS_INCLUDE' => $jsFiles,
1558 'JS_LIBS' => $jsLibs,
1559 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1560 'META' => $metaTags,
1561 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
1562 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
1563 'JS_LIBS_FOOTER' => $jsFooterLibs,
1564 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1565 'JS_INLINE_FOOTER' => $jsFooterInline,
1566 'BODY' => $this->bodyContent,
1567 );
1568
1569 $markerArray = array_map('trim', $markerArray);
1570
1571 $this->reset();
1572 return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
1573 }
1574
1575 /**
1576 * helper function for render the javascript libraries
1577 *
1578 * @return string content with javascript libraries
1579 */
1580 protected function renderJsLibraries() {
1581 $out = '';
1582
1583 if ($this->addSvg) {
1584 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->svgPath . 'svg.js') .
1585 '" data-path="' . $this->backPath . $this->svgPath .
1586 '"' . ($this->enableSvgDebug ? ' data-debug="true"' : '') . '></script>';
1587 }
1588
1589 if ($this->addPrototype) {
1590 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->prototypePath . 'prototype.js') .
1591 '" type="text/javascript"></script>' . LF;
1592 unset($this->jsFiles[$this->backPath . $this->prototypePath . 'prototype.js']);
1593 }
1594
1595 if ($this->addScriptaculous) {
1596 $mods = array();
1597 foreach ($this->addScriptaculousModules as $key => $value) {
1598 if ($this->addScriptaculousModules[$key]) {
1599 $mods[] = $key;
1600 }
1601 }
1602 // resolve dependencies
1603 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
1604 $mods = array_merge(array('effects'), $mods);
1605 }
1606
1607 if (count($mods)) {
1608 foreach ($mods as $module) {
1609 $out .= '<script src="' . $this->processJsFile($this->backPath .
1610 $this->scriptaculousPath . $module . '.js') . '" type="text/javascript"></script>' . LF;
1611 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . $module . '.js']);
1612 }
1613 }
1614 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->scriptaculousPath .
1615 'scriptaculous.js') . '" type="text/javascript"></script>' . LF;
1616 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . 'scriptaculous.js']);
1617 }
1618
1619 // include extCore
1620 if ($this->addExtCore) {
1621 $out .= '<script src="' . $this->processJsFile($this->backPath .
1622 $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
1623 '" type="text/javascript"></script>' . LF;
1624 unset($this->jsFiles[$this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
1625 }
1626
1627 // include extJS
1628 if ($this->addExtJS) {
1629 // use the base adapter all the time
1630 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
1631 'adapter/' . ($this->enableExtJsDebug ?
1632 str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
1633 '" type="text/javascript"></script>' . LF;
1634 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
1635 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
1636 '" type="text/javascript"></script>' . LF;
1637
1638 // add extJS localization
1639 $localeMap = $this->csConvObj->isoArray; // load standard ISO mapping and modify for use with ExtJS
1640 $localeMap[''] = 'en';
1641 $localeMap['default'] = 'en';
1642 $localeMap['gr'] = 'el_GR'; // Greek
1643 $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
1644 $localeMap['se'] = 'se_SV'; // Swedish
1645
1646
1647 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
1648 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1649 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
1650 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
1651 $out .= '<script src="' . $this->processJsFile($this->backPath .
1652 $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
1653 }
1654
1655
1656 // remove extjs from JScodeLibArray
1657 unset(
1658 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'],
1659 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']
1660 );
1661 }
1662
1663 if (count($this->inlineLanguageLabelFiles)) {
1664 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
1665 $this->includeLanguageFileForInline(
1666 $languageLabelFile['fileRef'],
1667 $languageLabelFile['selectionPrefix'],
1668 $languageLabelFile['stripFromSelectionName'],
1669 $languageLabelFile['$errorMode']
1670 );
1671 }
1672 }
1673 unset($this->inlineLanguageLabelFiles);
1674
1675 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
1676 if ($this->getCharSet() !== 'utf-8') {
1677 if ($this->inlineLanguageLabels) {
1678 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
1679 }
1680 if ($this->inlineSettings) {
1681 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
1682 }
1683 }
1684
1685 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
1686 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
1687
1688 if ($this->addExtCore || $this->addExtJS) {
1689 // set clear.gif, move it on top, add handler code
1690 $code = '';
1691 if (count($this->extOnReadyCode)) {
1692 foreach ($this->extOnReadyCode as $block) {
1693 $code .= $block;
1694 }
1695 }
1696
1697 $out .= $this->inlineJavascriptWrap[0] . '
1698 Ext.ns("TYPO3");
1699 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . LF .
1700 $inlineSettings .
1701 'Ext.onReady(function() {' .
1702 ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '') . $code .
1703 ' });' . $this->inlineJavascriptWrap[1];
1704 unset ($this->extOnReadyCode);
1705
1706 if ($this->extJStheme) {
1707 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1708 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
1709 } else {
1710 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
1711 }
1712 }
1713 if ($this->extJScss) {
1714 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1715 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
1716 } else {
1717 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
1718 }
1719 }
1720 } else {
1721 if ($inlineSettings) {
1722 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
1723 }
1724 }
1725
1726 return $out;
1727 }
1728
1729 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1730 if (!isset($this->lang) || !isset($this->charSet)) {
1731 throw new RuntimeException('Language and character encoding are not set.', 1284906026);
1732 }
1733
1734 $labelsFromFile = array();
1735 $allLabels = t3lib_div::readLLfile($fileRef, $this->lang, $this->charSet, $errorMode);
1736
1737 // Regular expression to strip the selection prefix and possibly something from the label name:
1738 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
1739
1740 if ($allLabels !== FALSE) {
1741 // Merge language specific translations:
1742 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
1743 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
1744 } else {
1745 $labels = $allLabels['default'];
1746 }
1747
1748 // Iterate through all locallang labels:
1749 foreach ($labels as $label => $value) {
1750 if ($selectionPrefix === '') {
1751 $labelsFromFile[$label] = $value;
1752 } elseif (strpos($label, $selectionPrefix) === 0) {
1753 $key = preg_replace($labelPattern, '', $label);
1754 $labelsFromFile[$label] = $value;
1755 }
1756 }
1757
1758 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
1759 }
1760 }
1761
1762 /*****************************************************/
1763 /* */
1764 /* Tools */
1765 /* */
1766 /* */
1767 /*****************************************************/
1768
1769 /**
1770 * concatenate files into one file
1771 * registered handler
1772 *
1773 * @return void
1774 */
1775 protected function doConcatenate() {
1776 // traverse the arrays, concatenate in one file
1777 // then remove concatenated files from array and add the concatenated file
1778
1779 if ($this->concatenateFiles) {
1780 $params = array(
1781 'jsLibs' => &$this->jsLibs,
1782 'jsFiles' => &$this->jsFiles,
1783 'jsFooterFiles' => &$this->jsFooterFiles,
1784 'cssFiles' => &$this->cssFiles,
1785 'headerData' => &$this->headerData,
1786 'footerData' => &$this->footerData,
1787 );
1788
1789 if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler']) {
1790 // use extern concatenate routine
1791 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler'], $params, $this);
1792 } elseif (TYPO3_MODE === 'BE') {
1793 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
1794 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
1795 }
1796 }
1797 }
1798
1799 /**
1800 * compress inline code
1801 *
1802 * @return void
1803 */
1804 protected function doCompress() {
1805
1806 if ($this->compressJavascript && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler']) {
1807 // use extern compress routine
1808 $params = array(
1809 'jsInline' => &$this->jsInline,
1810 'jsFooterInline' => &$this->jsFooterInline,
1811 'jsLibs' => &$this->jsLibs,
1812 'jsFiles' => &$this->jsFiles,
1813 'jsFooterFiles' => &$this->jsFooterFiles,
1814 'headerData' => &$this->headerData,
1815 'footerData' => &$this->footerData,
1816 );
1817 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
1818 } else {
1819 // traverse the arrays, compress files
1820
1821 if ($this->compressJavascript) {
1822 if (count($this->jsInline)) {
1823 foreach ($this->jsInline as $name => $properties) {
1824 if ($properties['compress']) {
1825 $error = '';
1826 $this->jsInline[$name]['code'] = t3lib_div::minifyJavaScript($properties['code'], $error);
1827 if ($error) {
1828 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
1829 }
1830 }
1831 }
1832 }
1833 if (TYPO3_MODE === 'BE') {
1834 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
1835 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
1836 }
1837 }
1838 }
1839 if ($this->compressCss) {
1840 // use extern compress routine
1841 $params = array(
1842 'cssInline' => &$this->cssInline,
1843 'cssFiles' => &$this->cssFiles,
1844 'headerData' => &$this->headerData,
1845 'footerData' => &$this->footerData,
1846 );
1847
1848 if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler']) {
1849 // use extern concatenate routine
1850 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
1851 } elseif (TYPO3_MODE === 'BE') {
1852 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
1853 }
1854 }
1855 }
1856
1857 /**
1858 * Returns instance of t3lib_Compressor
1859 *
1860 * @return t3lib_Compressor Instance of t3lib_Compressor
1861 */
1862 protected function getCompressor() {
1863 if ($this->compressor === NULL) {
1864 $this->compressor = t3lib_div::makeInstance('t3lib_Compressor');
1865 }
1866 return $this->compressor;
1867 }
1868
1869 /**
1870 * Processes a Javascript file dependent on the current context
1871 *
1872 * Adds the version number for Frontend, compresses the file for Backend
1873 *
1874 * @param string $filename Filename
1875 * @return string new filename
1876 */
1877 protected function processJsFile($filename) {
1878 switch (TYPO3_MODE) {
1879 case 'FE':
1880 $filename = t3lib_div::createVersionNumberedFilename($filename);
1881 break;
1882 case 'BE':
1883 if ($this->compressJavascript) {
1884 $filename = $this->getCompressor()->compressJsFile($filename);
1885 }
1886 break;
1887 }
1888 return $filename;
1889 }
1890
1891 }
1892
1893 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php'])) {
1894 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);
1895 }
1896 ?>