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