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