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