Follow-up to bug #11985: Move ExtJs CSS-assignment to renderJsKibraries
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_pagerenderer.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 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 // static array containing associative array for the included files
51 protected static $jsFiles = array ();
52 protected static $jsFooterFiles = array ();
53 protected static $jsLibs = array ();
54 protected static $jsFooterLibs = array ();
55 protected static $cssFiles = array ();
56
57 protected $title;
58 protected $charSet;
59 protected $favIcon;
60 protected $baseUrl;
61
62 // static header blocks
63 protected $xmlPrologAndDocType = '';
64 protected $metaTags = array ();
65 protected $inlineComments = array ();
66 protected $headerData = array ();
67 protected $footerData = array ();
68 protected $titleTag = '<title>|</title>';
69 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
70 protected $htmlTag = '<html>';
71 protected $headTag = '<head>';
72 protected $baseUrlTag = '<base href="|" />';
73 protected $iconMimeType = '';
74 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />
75 <link rel="icon" href="%1$s"%2$s />';
76
77 // static inline code blocks
78 protected $jsInline = array ();
79 protected $extOnReadyCode = array ();
80 protected $cssInline = array ();
81
82 protected $bodyContent;
83
84 protected $templateFile;
85
86 protected $jsLibraryNames = array ('prototype', 'scriptaculous', 'extjs');
87
88 const PART_COMPLETE = 0;
89 const PART_HEADER = 1;
90 const PART_FOOTER = 2;
91
92 // internal flags for JS-libraries
93 protected $addPrototype = FALSE;
94 protected $addScriptaculous = FALSE;
95 protected $addScriptaculousModules = array ('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
96 protected $addExtJS = FALSE;
97 protected $addExtCore = FALSE;
98 protected $extJSadapter = 'ext/ext-base.js';
99
100 protected $enableExtJsDebug = FALSE;
101 protected $enableExtCoreDebug = FALSE;
102
103 // available adapters for extJs
104 const EXTJS_ADAPTER_JQUERY = 'jquery';
105 const EXTJS_ADAPTER_PROTOTYPE = 'prototype';
106 const EXTJS_ADAPTER_YUI = 'yui';
107
108 protected $extJStheme = TRUE;
109 protected $extJScss = TRUE;
110
111 protected $enableExtJSQuickTips = false;
112
113 protected $inlineLanguageLabels = array ();
114 protected $inlineSettings = array ();
115
116 protected $inlineJavascriptWrap = array ();
117
118 // used by BE modules
119 public $backPath;
120
121 /**
122 * Constructor
123 *
124 * @param string $templateFile declare the used template file. Omit this parameter will use default template
125 * @param string $backPath relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
126 * @return void
127 */
128 public function __construct($templateFile = '', $backPath = '') {
129
130 $this->reset();
131
132 if (strlen($templateFile)) {
133 $this->templateFile = $templateFile;
134 }
135 $this->backPath = $backPath;
136
137 $this->inlineJavascriptWrap = array(
138 '<script type="text/javascript">' . chr(10) . '/*<![CDATA[*/' . chr(10) . '<!-- ' . chr(10),
139 '// -->' . chr(10) . '/*]]>*/' . chr(10) . '</script>' . chr(10)
140 );
141 $this->inlineCssWrap = array(
142 '<style type="text/css">' . chr(10) . '/*<![CDATA[*/' . chr(10) . '<!-- ' . chr(10),
143 '-->' . chr(10) . '/*]]>*/' . chr(10) . '</style>' . chr(10)
144 );
145
146 }
147
148 /**
149 * reset all vars to initial values
150 *
151 * @return void
152 */
153 protected function reset() {
154 $this->templateFile = TYPO3_mainDir . 'templates/template_page_backend.html';
155 $this->jsFiles = array ();
156 $this->jsFooterFiles = array ();
157 $this->jsInline = array ();
158 $this->jsFooterInline = array ();
159 $this->jsLibs = array ();
160 $this->cssFiles = array ();
161 $this->cssInline = array ();
162 $this->metaTags = array ();
163 $this->inlineComments = array ();
164 $this->headerData = array ();
165 $this->footerData = array ();
166 $this->extOnReadyCode = array ();
167 }
168 /*****************************************************/
169 /* */
170 /* Public Setters */
171 /* */
172 /* */
173 /*****************************************************/
174
175 /**
176 * Sets the title
177 *
178 * @param string $title title of webpage
179 * @return void
180 */
181 public function setTitle($title) {
182 $this->title = $title;
183 }
184
185 /**
186 * Sets xml prolog and docType
187 *
188 * @param string $xmlPrologAndDocType complete tags for xml prolog and docType
189 * @return void
190 */
191 public function setXmlPrologAndDocType($xmlPrologAndDocType) {
192 $this->xmlPrologAndDocType = $xmlPrologAndDocType;
193 }
194
195 /**
196 * Sets meta charset
197 * @return void
198 *
199 * @param string $charSet used charset
200 */
201 public function setCharSet($charSet) {
202 $this->charSet = $charSet;
203 }
204
205 /**
206 * Sets html tag
207 *
208 * @param string $htmlTag html tag
209 * @return void
210 */
211 public function setHtmlTag($htmlTag) {
212 $this->htmlTag = $htmlTag;
213 }
214
215 /**
216 * Sets head tag
217 *
218 * @param string $tag head tag
219 * @return void
220 */
221 public function setHeadTag($headTag) {
222 $this->headTag = $headTag;
223 }
224
225 /**
226 * Sets favicon
227 *
228 * @param string $favIcon
229 * @return void
230 */
231 public function setFavIcon($favIcon) {
232 $this->favIcon = $favIcon;
233 }
234
235 /**
236 * Sets icon mime type
237 *
238 * @param string $iconMimeType
239 * @return void
240 */
241 public function setIconMimeType($iconMimeType) {
242 $this->iconMimeType = $iconMimeType;
243 }
244
245 /**
246 * Sets base url
247 *
248 * @param string $url
249 * @return void
250 */
251 public function setBaseUrl($baseUrl) {
252 $this->baseUrl = $baseUrl;
253 }
254
255 /**
256 * Sets template file
257 *
258 * @param string $file
259 * @return void
260 */
261 public function setTemplateFile($file) {
262 $this->templateFile = $file;
263 }
264
265 /**
266 * Sets back path
267 *
268 * @param string $backPath
269 * @return void
270 */
271 public function setBackPath($backPath) {
272 $this->backPath = $backPath;
273 }
274
275 /**
276 * Sets Content for Body
277 *
278 * @param string $content
279 * @return void
280 */
281 public function setBodyContent($content) {
282 $this->bodyContent = $content;
283 }
284
285 /*****************************************************/
286 /* */
287 /* Public Enablers */
288 /* */
289 /* */
290 /*****************************************************/
291 /**
292 * Enables MoveJsFromHeaderToFooter
293 *
294 * @param void
295 * @return void
296 */
297 public function enableMoveJsFromHeaderToFooter() {
298 $this->moveJsFromHeaderToFooter = TRUE;
299 }
300
301 /**
302 * Enables compression of javascript
303 *
304 * @param void
305 * @return void
306 */
307 public function enableCompressJavascript() {
308 $this->compressJavascript = TRUE;
309 }
310
311 /**
312 * Enables compression of css
313 *
314 * @param void
315 * @return void
316 */
317 public function enableCompressCss() {
318 $this->compressCss = TRUE;
319 }
320
321 /**
322 /**
323 * Enables concatenation of js/css files
324 *
325 * @param void
326 * @return void
327 */
328 public function enableConcatenateFiles() {
329 $this->concatenateFiles = TRUE;
330 }
331
332 /**
333 * Sets removal of all line breaks in template
334 *
335 * @param void
336 * @return void
337 */
338 public function enableRemoveLineBreaksFromTemplate() {
339 $this->removeLineBreaksFromTemplate = TRUE;
340 }
341
342 /*****************************************************/
343 /* */
344 /* Public Getters */
345 /* */
346 /* */
347 /*****************************************************/
348
349 /**
350 * Gets the title
351 *
352 * @return string $title title of webpage
353 */
354 public function getTitle() {
355 return $this->title;
356 }
357
358 /**
359 * Gets the charSet
360 *
361 * @return string $charSet
362 */
363 public function getCharSet() {
364 return $this->charSet;
365 }
366
367 /**
368 * Gets html tag
369 *
370 * @return string $htmlTag html tag
371 */
372 public function getHtmlTag() {
373 return $this->htmlTag;
374 }
375
376 /**
377 * Gets head tag
378 *
379 * @return string $tag head tag
380 */
381 public function getHeadTag() {
382 return $this->headTag;
383 }
384
385 /**
386 * Gets favicon
387 *
388 * @return string $favIcon
389 */
390 public function getFavIcon() {
391 return $this->favIcon;
392 }
393
394 /**
395 * Gets icon mime type
396 *
397 * @return string $iconMimeType
398 */
399 public function getIconMimeType() {
400 return $this->iconMimeType;
401 }
402
403 /**
404 * Gets base url
405 *
406 * @return string $url
407 */
408 public function getBaseUrl() {
409 return $this->baseUrl;
410 }
411
412 /**
413 * Gets template file
414 *
415 * @return string $file
416 */
417 public function getTemplateFile($file) {
418 return $this->templateFile;
419 }
420
421 /**
422 * Gets MoveJsFromHeaderToFooter
423 *
424 * @return boolean
425 */
426 public function getMoveJsFromHeaderToFooter() {
427 return $this->moveJsFromHeaderToFooter;
428 }
429
430 /**
431 * Gets compress of javascript
432 *
433 * @return boolean
434 */
435 public function getCompressJavascript() {
436 return $this->compressJavascript;
437 }
438
439 /**
440 * Gets compress of css
441 *
442 * @return boolean
443 */
444 public function getCompressCss() {
445 return $this->compressCss;
446 }
447
448 /**
449 * Gets concatenate of files
450 *
451 * @return boolean
452 */
453 public function getConcatenateFiles() {
454 return $this->concatenateFiles;
455 }
456
457 /**
458 * Gets remove of empty lines from template
459 *
460 * @return boolean
461 */
462 public function getRemoveLineBreaksFromTemplate() {
463 return $this->removeLineBreaksFromTemplate;
464 }
465
466 /**
467 * Gets content for body
468 *
469 * @return string
470 */
471 public function getBodyContent() {
472 return $this->bodyContent;
473 }
474
475 /*****************************************************/
476 /* */
477 /* Public Function to add Data */
478 /* */
479 /* */
480 /*****************************************************/
481
482 /**
483 * Adds meta data
484 *
485 * @param string $meta meta data (complete metatag)
486 * @return void
487 */
488 public function addMetaTag($meta) {
489 if (!in_array($meta, $this->metaTags)) {
490 $this->metaTags[] = $meta;
491 }
492 }
493
494 /**
495 * Adds inline HTML comment
496 *
497 * @param string $comment
498 * @return void
499 */
500 public function addInlineComment($comment) {
501 if (!in_array($comment, $this->inlineComments)) {
502 $this->inlineComments[] = $comment;
503 }
504 }
505
506 /**
507 * Adds header data
508 *
509 * @param string $data free header data for HTML header
510 * @return void
511 */
512 public function addHeaderData($data) {
513 if (!in_array($data, $this->headerData)) {
514 $this->headerData[] = $data;
515 }
516 }
517
518 /**
519 * Adds footer data
520 *
521 * @param string $data free header data for HTML header
522 * @return void
523 */
524 public function addFooterData($data) {
525 if (!in_array($data, $this->footerData)) {
526 $this->footerData[] = $data;
527 }
528 }
529
530 /* Javascript Files */
531
532 /**
533 * Adds JS Library. JS Library block is rendered on top of the JS files.
534 *
535 * @param string $name
536 * @param string $file
537 * @param string $type
538 * @param boolean $compressed flag if library is compressed
539 * @param boolean $forceOnTop flag if added library should be inserted at begin of this block
540 * @param string $allWrap
541 * @return void
542 */
543 public function addJsLibrary($name, $file, $type = 'text/javascript', $compressed = TRUE, $forceOnTop = FALSE, $allWrap = '') {
544 if (!in_array(strtolower($name), $this->jsLibs)) {
545 $this->jsLibs[strtolower($name)] = array (
546 'file' => $file,
547 'type' => $type,
548 'section' => self::PART_HEADER,
549 'compressed' => $compressed,
550 'forceOnTop' => $forceOnTop,
551 'allWrap' => $allWrap
552 );
553 }
554
555 }
556
557 /**
558 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
559 *
560 * @param string $name
561 * @param string $file
562 * @param string $type
563 * @param boolean $compressed flag if library is compressed
564 * @param boolean $forceOnTop flag if added library should be inserted at begin of this block
565 * @param string $allWrap
566 * @return void
567 */
568 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compressed = TRUE, $forceOnTop = FALSE, $allWrap = '') {
569 if (!in_array(strtolower($name), $this->jsLibs)) {
570 $this->jsLibs[strtolower($name)] = array (
571 'file' => $file,
572 'type' => $type,
573 'section' => self::PART_FOOTER,
574 'compressed' => $compressed,
575 'forceOnTop' => $forceOnTop,
576 'allWrap' => $allWrap
577 );
578 }
579
580 }
581
582 /**
583 * Adds JS file
584 *
585 * @param string $file
586 * @param string $type
587 * @param boolean $compressed
588 * @param boolean $forceOnTop
589 * @param string $allWrap
590 * @return void
591 */
592 public function addJsFile($file, $type = 'text/javascript', $compressed = FALSE, $forceOnTop = FALSE, $allWrap = '') {
593 if (!isset($this->jsFiles[$file])) {
594 $this->jsFiles[$file] = array (
595 'type' => $type,
596 'section' => self::PART_HEADER,
597 'compressed' => $compressed,
598 'forceOnTop' => $forceOnTop,
599 'allWrap' => $allWrap
600 );
601 }
602 }
603
604 /**
605 * Adds JS file to footer
606 *
607 * @param string $file
608 * @param string $type
609 * @param boolean $compressed
610 * @param boolean $forceOnTop
611 * @return void
612 */
613 public function addJsFooterFile($file, $type = 'text/javascript', $compressed = FALSE, $forceOnTop = FALSE, $allWrap = '') {
614 if (!isset($this->jsFiles[$file])) {
615 $this->jsFiles[$file] = array (
616 'type' => $type,
617 'section' => self::PART_FOOTER,
618 'compressed' => $compressed,
619 'forceOnTop' => $forceOnTop,
620 'allWrap' => $allWrap
621 );
622 }
623 }
624
625 /*Javascript Inline Blocks */
626
627 /**
628 * Adds JS inline code
629 *
630 * @param string $name
631 * @param string $block
632 * @param boolean $compressed
633 * @param boolean $forceOnTop
634 * @return void
635 */
636 public function addJsInlineCode($name, $block, $compressed = FALSE, $forceOnTop = FALSE) {
637 if (!isset($this->jsInline[$name])) {
638 $this->jsInline[$name] = array (
639 'code' => $block . chr(10),
640 'section' => self::PART_HEADER,
641 'compressed' => $compressed,
642 'forceOnTop' => $forceOnTop
643 );
644 }
645 }
646
647 /**
648 * Adds JS inline code to footer
649 *
650 * @param string $name
651 * @param string $block
652 * @param boolean $compressed
653 * @param boolean $forceOnTop
654 * @return void
655 */
656 public function addJsFooterInlineCode($name, $block, $compressed = FALSE, $forceOnTop = FALSE) {
657 if (!isset($this->jsInline[$name])) {
658 $this->jsInline[$name] = array (
659 'code' => $block . chr(10),
660 'section' => self::PART_FOOTER,
661 'compressed' => $compressed,
662 'forceOnTop' => $forceOnTop
663 );
664 }
665 }
666
667 /**
668 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
669 *
670 * @param string $block
671 * @return void
672 */
673 public function addExtOnReadyCode($block) {
674 if (!in_array($block, $this->extOnReadyCode)) {
675 $this->extOnReadyCode[] = $block;
676 }
677 }
678
679 /* CSS Files */
680
681 /**
682 * Adds CSS file
683 *
684 * @param string $file
685 * @param string $rel
686 * @param string $media
687 * @param string $title
688 * @param boolean $compressed
689 * @param boolean $forceOnTop
690 * @return void
691 */
692 public function addCssFile($file, $rel = 'stylesheet', $media = 'screen', $title = '', $compressed = FALSE, $forceOnTop = FALSE, $allWrap = '') {
693 if (!isset($this->cssFiles[$file])) {
694 $this->cssFiles[$file] = array ('rel' => $rel, 'media' => $media, 'title' => $title, 'compressed' => $compressed, 'forceOnTop' => $forceOnTop, 'allWrap' => $allWrap);
695 }
696 }
697
698 /*CSS Inline Blocks */
699
700 /**
701 * Adds CSS inline code
702 *
703 * @param string $name
704 * @param string $block
705 * @param boolean $compressed
706 * @param boolean $forceOnTop
707 * @return void
708 */
709 public function addCssInlineBlock($name, $block, $compressed = FALSE, $forceOnTop = FALSE) {
710 if (!isset($this->cssInline[$name])) {
711 $this->cssInline[$name] = array ('code' => $block, 'compressed' => $compressed, 'forceOnTop' => $forceOnTop);
712 }
713 }
714
715 /* JS Libraries */
716
717 /**
718 * call function if you need the prototype library
719 *
720 * @return void
721 */
722 public function loadPrototype() {
723 $this->addPrototype = TRUE;
724 }
725
726 /**
727 * call function if you need the Scriptaculous library
728 *
729 * @param string $modules add modules you need. use "all" if you need complete modules
730 * @return void
731 */
732 public function loadScriptaculous($modules = '') {
733 // Scriptaculous require prototype, so load prototype too.
734 $this->addPrototype = TRUE;
735 $this->addScriptaculous = TRUE;
736 if ($modules) {
737 if ($modules == 'all') {
738 foreach ($this->addScriptaculousModules as $key => $value) {
739 $this->addScriptaculousModules[$key] = TRUE;
740 }
741 } else {
742 $mods = t3lib_div::trimExplode(',', $modules);
743 foreach ($mods as $mod) {
744 if (isset($this->addScriptaculousModules[strtolower($mod)])) {
745 $this->addScriptaculousModules[strtolower($mod)] = TRUE;
746 }
747 }
748 }
749 }
750 }
751
752 /**
753 * call this function if you need the extJS library
754 *
755 * @param boolean $css flag, if set the ext-css will be loaded
756 * @param boolean $theme flag, if set the ext-theme "grey" will be loaded
757 * @param string $adapter choose alternative adapter, possible values: yui, prototype, jquery
758 * @return void
759 */
760 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
761 if ($adapter) {
762 // empty $adapter will always load the ext adapter
763 switch (t3lib_div::strtolower(trim($adapter))) {
764 case self::EXTJS_ADAPTER_YUI :
765 $this->extJSadapter = 'yui/ext-yui-adapter.js';
766 break;
767 case self::EXTJS_ADAPTER_PROTOTYPE :
768 $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
769 break;
770 case self::EXTJS_ADAPTER_JQUERY :
771 $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
772 break;
773 }
774 }
775 $this->addExtJS = TRUE;
776 $this->extJStheme = $theme;
777 $this->extJScss = $css;
778
779 }
780
781 /**
782 * Enables ExtJs QuickTips
783 * Need extJs loaded
784 *
785 * @return void
786 *
787 */
788 public function enableExtJSQuickTips() {
789 $this->enableExtJSQuickTips = TRUE;
790 }
791
792
793 /**
794 * call function if you need the ExtCore library
795 *
796 * @return void
797 */
798 public function loadExtCore() {
799 $this->addExtCore = TRUE;
800 }
801
802 /**
803 * call this function to load debug version of ExtJS. Use this for development only
804 *
805 */
806 public function enableExtJsDebug() {
807 $this->enableExtJsDebug = TRUE;
808 }
809
810 /**
811 * call this function to load debug version of ExtCore. Use this for development only
812 *
813 * @return void
814 */
815 public function enableExtCoreDebug() {
816 $this->enableExtCoreDebug = TRUE;
817 }
818
819 /**
820 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
821 * The label can be used in scripts with TYPO3.lang.<key>
822 * Need extJs loaded
823 *
824 * @param string $key
825 * @param string $value
826 * @return void
827 */
828 public function addInlineLanguageLabel($key, $value) {
829 $this->inlineLanguageLabels[$key] = $value;
830 }
831
832 /**
833 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
834 * The label can be used in scripts with TYPO3.lang.<key>
835 * Array will be merged with existing array.
836 * Need extJs loaded
837 *
838 * @param array $array
839 * @return void
840 */
841 public function addInlineLanguageLabelArray(array $array) {
842 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
843 }
844
845 /**
846 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
847 * The label can be used in scripts with TYPO3.setting.<key>
848 * Need extJs loaded
849 *
850 * @param string $namespace
851 * @param string $key
852 * @param string $value
853 * @return void
854 */
855 public function addInlineSetting($namespace, $key, $value) {
856 if ($namespace) {
857 if (strpos($namespace, '.')) {
858 $parts = explode('.', $namespace);
859 $a = &$this->inlineSettings;
860 foreach ($parts as $part) {
861 $a = &$a[$part];
862 }
863 $a[$key] = $value;
864 } else {
865 $this->inlineSettings[$namespace][$key] = $value;
866 }
867 } else {
868 $this->inlineSettings[$key] = $value;
869 }
870 }
871
872 /**
873 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
874 * The label can be used in scripts with TYPO3.setting.<key>
875 * Array will be merged with existing array.
876 * Need extJs loaded
877 *
878 * @param string $namespace
879 * @param array $array
880 * @return void
881 */
882 public function addInlineSettingArray($namespace, array $array) {
883 if ($namespace) {
884 if (strpos($namespace, '.')) {
885 $parts = explode('.', $namespace);
886 $a = &$this->inlineSettings;
887 foreach ($parts as $part) {
888 $a = &$a[$part];
889 }
890 $a = array_merge((array) $a, $array);
891 } else {
892 $this->inlineSettings[$namespace] = array_merge((array) $this->inlineSettings[$namespace], $array);
893 }
894 } else {
895 $this->inlineSettings = array_merge($this->inlineSettings, $array);
896 }
897 }
898
899 /**
900 * Adds content to body content
901 *
902 * @param string $content
903 * @return void
904 */
905 public function addBodyContent($content) {
906 $this->bodyContent .= $content;
907 }
908
909 /*****************************************************/
910 /* */
911 /* Render Functions */
912 /* */
913 /* */
914 /*****************************************************/
915
916 /**
917 * render the section (Header or Footer)
918 *
919 * @param int $part section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
920 * @return string content of rendered section
921 */
922 public function render($part = self::PART_COMPLETE) {
923
924 $jsFiles = '';
925 $cssFiles = '';
926 $cssInline = '';
927 $jsInline = '';
928 $jsFooterInline = '';
929 $jsFooterLibs = '';
930 $jsFooterFiles = '';
931 $noJS = FALSE;
932
933 $jsLibs = $this->renderJsLibraries();
934
935 if ($this->compressCss || $this->compressJavascript) {
936 // do the file compression
937 $this->doCompress();
938 }
939 if ($this->concatenateFiles) {
940 // do the file concatenation
941 $this->doConcatenate();
942 }
943
944 $metaTags = implode(chr(10), $this->metaTags);
945
946 if (count($this->cssFiles)) {
947 foreach ($this->cssFiles as $file => $properties) {
948 $tag = '<link rel="' . $properties['rel'] . '" type="text/css" href="' . $file . '" media="' . $properties['media'] . '"' . ($properties['title'] ? ' title="' . $properties['title'] . '"' : '') . ' />';
949 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
950 $tag = str_replace('|', $tag, $properties['allWrap']);
951 }
952 if ($properties['forceOnTop']) {
953 $cssFiles = $tag . chr(10) . $cssFiles;
954 } else {
955 $cssFiles .= chr(10) . $tag;
956 }
957 }
958 }
959
960 if (count($this->cssInline)) {
961
962 foreach ($this->cssInline as $name => $properties) {
963 if ($properties['forceOnTop']) {
964 $cssInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $cssInline;
965 } else {
966 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
967 }
968 }
969 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
970
971 }
972
973 if (count($this->jsLibs)) {
974 foreach ($this->jsLibs as $name => $properties) {
975 $tag = '<script src="' . $properties['file'] . '" type="' . $properties['type'] . '"></script>';
976 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
977 $tag = str_replace('|', $tag, $properties['allWrap']);
978 }
979 if ($properties['forceOnTop']) {
980 if ($properties['section'] === self::PART_HEADER) {
981 $jsLibs = $tag . chr(10) . $jsLibs;
982 } else {
983 $jsFooterLibs = $tag . chr(10) . $jsFooterLibs;
984 }
985 } else {
986 if ($properties['section'] === self::PART_HEADER) {
987 $jsLibs .= chr(10) . $tag;
988 } else {
989 $jsFooterLibs .= chr(10) . $tag;
990 }
991 }
992
993 }
994 }
995
996 if (count($this->jsFiles)) {
997 foreach ($this->jsFiles as $file => $properties) {
998 $tag = '<script src="' . $file . '" type="' . $properties['type'] . '"></script>';
999 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1000 $tag = str_replace('|', $tag, $properties['allWrap']);
1001 }
1002 if ($properties['forceOnTop']) {
1003 if ($properties['section'] === self::PART_HEADER) {
1004 $jsFiles = $tag . chr(10) . $jsFiles;
1005 } else {
1006 $jsFooterFiles = $tag . chr(10) . $jsFooterFiles;
1007 }
1008 } else {
1009 if ($properties['section'] === self::PART_HEADER) {
1010 $jsFiles .= chr(10) . $tag;
1011 } else {
1012 $jsFooterFiles .= chr(10) . $tag;
1013 }
1014 }
1015 }
1016 }
1017
1018 if (count($this->jsInline)) {
1019 foreach ($this->jsInline as $name => $properties) {
1020 if ($properties['forceOnTop']) {
1021 if ($properties['section'] === self::PART_HEADER) {
1022 $jsInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $jsInline;
1023 } else {
1024 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $jsFooterInline;
1025 }
1026 } else {
1027 if ($properties['section'] === self::PART_HEADER) {
1028 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1029 } else {
1030 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1031 }
1032 }
1033 }
1034 }
1035
1036
1037 if ($jsInline) {
1038 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
1039 }
1040
1041 if ($jsFooterInline) {
1042 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
1043 }
1044
1045
1046 // get template
1047 $templateFile = t3lib_div::getFileAbsFileName($this->templateFile, TRUE);
1048 $template = t3lib_div::getURL($templateFile);
1049
1050 if ($this->removeEmptyLinesFromTemplate) {
1051 $template = strtr($template, array(chr(10) => '', chr(13) => ''));
1052 }
1053 if ($part != self::PART_COMPLETE) {
1054 $templatePart = explode('###BODY###', $template);
1055 $template = $templatePart[$part - 1];
1056 }
1057
1058 if ($this->moveJsFromHeaderToFooter) {
1059 $jsFooterLibs = $jsLibs . chr(10) . $jsFooterLibs;
1060 $jsLibs = '';
1061 $jsFooterFiles = $jsFiles . chr(10) . $jsFooterFiles;
1062 $jsFiles = '';
1063 $jsFooterInline = $jsInline . chr(10) . $jsFooterInline;
1064 $jsInline = '';
1065 }
1066
1067 $markerArray = array(
1068 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1069 'HTMLTAG' => $this->htmlTag,
1070 'HEADTAG' => $this->headTag,
1071 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1072 'INLINECOMMENT' => $this->inlineComments ? chr(10) . chr(10) . '<!-- ' . chr(10) . implode(chr(10), $this->inlineComments) . '-->' . chr(10) . chr(10) : '',
1073 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1074 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1075 'CSS_INCLUDE' => $cssFiles,
1076 'CSS_INLINE' => $cssInline,
1077 'JS_INLINE' => $jsInline,
1078 'JS_INCLUDE' => $jsFiles,
1079 'JS_LIBS' => $jsLibs,
1080 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1081 'META' => $metaTags,
1082 'HEADERDATA' => $this->headerData ? implode(chr(10), $this->headerData) : '',
1083 'FOOTERDATA' => $this->footerData ? implode(chr(10), $this->footerData) : '',
1084 'JS_LIBS_FOOTER' => $jsFooterLibs,
1085 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1086 'JS_INLINE_FOOTER' => $jsFooterInline,
1087 'BODY' => $this->bodyContent,
1088 );
1089
1090 $markerArray = array_map('trim', $markerArray);
1091
1092 $this->reset();
1093 return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
1094 }
1095
1096 /**
1097 * helper function for render the javascript libraries
1098 *
1099 * @return string content with javascript libraries
1100 */
1101 protected function renderJsLibraries() {
1102 $out = '';
1103
1104 if ($this->addPrototype) {
1105 $out .= '<script src="' . $this->backPath . 'contrib/prototype/prototype.js" type="text/javascript"></script>' . chr(10);
1106 unset($this->jsFiles[$this->backPath . 'contrib/prototype/prototype.js']);
1107 }
1108
1109 if ($this->addScriptaculous) {
1110 $mods = array ();
1111 foreach ($this->addScriptaculousModules as $key => $value) {
1112 if ($this->addScriptaculousModules[$key]) {
1113 $mods[] = $key;
1114 }
1115 }
1116 // resolve dependencies
1117 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
1118 $mods = array_merge(array('effects'), $mods);
1119 }
1120
1121 if (count($mods)) {
1122 $moduleLoadString = '?load=' . implode(',', $mods);
1123 }
1124
1125 $out .= '<script src="' . $this->backPath . 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString . '" type="text/javascript"></script>' . chr(10);
1126 unset($this->jsFiles[$this->backPath . 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString]);
1127 }
1128
1129 // include extCore
1130 if ($this->addExtCore) {
1131 $out .= '<script src="' . $this->backPath . 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js" type="text/javascript"></script>' . chr(10);
1132 unset($this->jsFiles[$this->backPath . 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
1133 }
1134
1135 // include extJS
1136 if ($this->addExtJS) {
1137 // use the base adapter all the time
1138 $out .= '<script src="' . $this->backPath . 'contrib/extjs/adapter/' . $this->extJSadapter . '" type="text/javascript"></script>' . chr(10);
1139 $out .= '<script src="' . $this->backPath . 'contrib/extjs/ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js" type="text/javascript"></script>' . chr(10);
1140
1141 // add extJS localization
1142 $localeMap = $this->csConvObj->isoArray; // load standard ISO mapping and modify for use with ExtJS
1143 $localeMap[''] = 'en';
1144 $localeMap['default'] = 'en';
1145 $localeMap['gr'] = 'el_GR'; // Greek
1146 $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
1147 $localeMap['se'] = 'se_SV'; // Swedish
1148
1149
1150 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
1151 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1152 $extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '-min.js';
1153 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
1154 $out .= '<script src="' . $this->backPath . $extJsLocaleFile . '" type="text/javascript"></script>' . chr(10);
1155 }
1156
1157
1158 // remove extjs from JScodeLibArray
1159 unset(
1160 $this->jsFiles[$this->backPath . 'contrib/extjs/ext-all.js'], $this->jsFiles[$this->backPath . 'contrib/extjs/ext-all-debug.js']
1161 );
1162 }
1163 if ($this->addExtCore || $this->addExtJS) {
1164 // set clear.gif, move it on top, add handler code
1165 $code = '';
1166 if (count($this->extOnReadyCode)) {
1167 foreach ($this->extOnReadyCode as $block) {
1168 $code .= $block;
1169 }
1170 }
1171
1172 $out .= $this->inlineJavascriptWrap[0] . '
1173 Ext.ns("TYPO3");
1174 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . chr(10) .
1175 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' . 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' .
1176 'Ext.onReady(function() {' .
1177 ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . chr(10) : '') . $code .
1178 ' });' . $this->inlineJavascriptWrap[1];
1179 unset ($this->extOnReadyCode);
1180
1181 if ($this->extJStheme) {
1182 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1183 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'screen', '', FALSE, TRUE);
1184 } else {
1185 $this->addCssFile($this->backPath . 'contrib/extjs/resources/css/xtheme-blue.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1186 }
1187 }
1188 if ($this->extJScss) {
1189 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1190 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'screen', '', FALSE, TRUE);
1191 } else {
1192 $this->addCssFile($this->backPath . 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1193 }
1194 }
1195
1196 }
1197
1198 return $out;
1199 }
1200
1201 /*****************************************************/
1202 /* */
1203 /* Tools */
1204 /* */
1205 /* */
1206 /*****************************************************/
1207
1208 /**
1209 * concatenate files into one file
1210 * registered handler
1211 * TODO: implement own method
1212 *
1213 * @return void
1214 */
1215 protected function doConcatenate() {
1216 // traverse the arrays, concatenate in one file
1217 // then remove concatenated files from array and add the concatenated file
1218
1219
1220 // extern concatination
1221 if ($this->concatenateFiles && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler']) {
1222 // use extern concatenate routine
1223 $params = array (
1224 'jsLibs' => &$this->jsLibs,
1225 'jsFiles' => &$this->jsFiles,
1226 'jsFooterFiles' => &$this->jsFiles,
1227 'cssFiles' => &$this->cssFiles,
1228 );
1229 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler'], $params, $this);
1230 } else {
1231 // own method, nothing implemented atm
1232
1233
1234 }
1235 }
1236
1237 /**
1238 * compress inline code
1239 *
1240 */
1241 protected function doCompress() {
1242
1243 if ($this->compressJavascript && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler']) {
1244 // use extern compress routine
1245 $params = array (
1246 'jsInline' => &$this->jsInline,
1247 'jsFooterInline' => &$this->jsFooterInline
1248 );
1249 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
1250 } else {
1251 // traverse the arrays, compress files
1252 $this->compressError = '';
1253
1254 if ($this->compressJavascript) {
1255 if (count($this->jsInline)) {
1256 foreach ($this->jsInline as $name => $properties) {
1257 if (!$properties['compressed']) {
1258 $error = '';
1259 $this->jsInline[$name]['code'] = t3lib_div::minifyJavaScript($properties['code'], $error);
1260 if ($error) {
1261 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . chr(10);
1262 }
1263 }
1264 }
1265 }
1266 }
1267 }
1268
1269 if ($this->compressCss && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler']) {
1270 // use extern compress routine
1271 $params = array (
1272 'cssInline' => &$this->cssInline
1273 );
1274 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
1275 } else {
1276 if ($this->compressCss) {
1277 // own method, nothing implemented atm
1278 }
1279 }
1280 }
1281
1282 }
1283
1284 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
1285 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);
1286 }
1287 ?>