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