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