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