Fixed bug #12017: Wrong Inclusion in tceforms and tceforms_fe
[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 = NULL) {
129
130 $this->reset();
131
132 if (strlen($templateFile)) {
133 $this->templateFile = $templateFile;
134 }
135 $this->backPath = isset($backPath) ? $backPath : $GLOBALS['BACK_PATH'];
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 $compress flag if library should be 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', $compress = FALSE, $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 'compress' => $compress,
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 $compress flag if library should be 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', $compress = FALSE, $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 'compress' => $compress,
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 $compress
588 * @param boolean $forceOnTop
589 * @param string $allWrap
590 * @return void
591 */
592 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
593 if (!isset($this->jsFiles[$file])) {
594 $this->jsFiles[$file] = array (
595 'type' => $type,
596 'section' => self::PART_HEADER,
597 'compress' => $compress,
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 $compress
610 * @param boolean $forceOnTop
611 * @return void
612 */
613 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
614 if (!isset($this->jsFiles[$file])) {
615 $this->jsFiles[$file] = array (
616 'type' => $type,
617 'section' => self::PART_FOOTER,
618 'compress' => $compress,
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 $compress
633 * @param boolean $forceOnTop
634 * @return void
635 */
636 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
637 if (!isset($this->jsInline[$name])) {
638 $this->jsInline[$name] = array (
639 'code' => $block . chr(10),
640 'section' => self::PART_HEADER,
641 'compress' => $compress,
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 $compress
653 * @param boolean $forceOnTop
654 * @return void
655 */
656 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
657 if (!isset($this->jsInline[$name])) {
658 $this->jsInline[$name] = array (
659 'code' => $block . chr(10),
660 'section' => self::PART_FOOTER,
661 'compress' => $compress,
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 $compress
689 * @param boolean $forceOnTop
690 * @return void
691 */
692 public function addCssFile($file, $rel = 'stylesheet', $media = 'screen', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
693 if (!isset($this->cssFiles[$file])) {
694 $this->cssFiles[$file] = array (
695 'rel' => $rel,
696 'media' => $media,
697 'title' => $title,
698 'compress' => $compress,
699 'forceOnTop' => $forceOnTop,
700 'allWrap' => $allWrap
701 );
702 }
703 }
704
705 /*CSS Inline Blocks */
706
707 /**
708 * Adds CSS inline code
709 *
710 * @param string $name
711 * @param string $block
712 * @param boolean $compress
713 * @param boolean $forceOnTop
714 * @return void
715 */
716 public function addCssInlineBlock($name, $block, $compressed = FALSE, $forceOnTop = FALSE) {
717 if (!isset($this->cssInline[$name])) {
718 $this->cssInline[$name] = array (
719 'code' => $block,
720 'compress' => $compress,
721 'forceOnTop' => $forceOnTop
722 );
723 }
724 }
725
726 /* JS Libraries */
727
728 /**
729 * call function if you need the prototype library
730 *
731 * @return void
732 */
733 public function loadPrototype() {
734 $this->addPrototype = TRUE;
735 }
736
737 /**
738 * call function if you need the Scriptaculous library
739 *
740 * @param string $modules add modules you need. use "all" if you need complete modules
741 * @return void
742 */
743 public function loadScriptaculous($modules = '') {
744 // Scriptaculous require prototype, so load prototype too.
745 $this->addPrototype = TRUE;
746 $this->addScriptaculous = TRUE;
747 if ($modules) {
748 if ($modules == 'all') {
749 foreach ($this->addScriptaculousModules as $key => $value) {
750 $this->addScriptaculousModules[$key] = TRUE;
751 }
752 } else {
753 $mods = t3lib_div::trimExplode(',', $modules);
754 foreach ($mods as $mod) {
755 if (isset($this->addScriptaculousModules[strtolower($mod)])) {
756 $this->addScriptaculousModules[strtolower($mod)] = TRUE;
757 }
758 }
759 }
760 }
761 }
762
763 /**
764 * call this function if you need the extJS library
765 *
766 * @param boolean $css flag, if set the ext-css will be loaded
767 * @param boolean $theme flag, if set the ext-theme "grey" will be loaded
768 * @param string $adapter choose alternative adapter, possible values: yui, prototype, jquery
769 * @return void
770 */
771 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
772 if ($adapter) {
773 // empty $adapter will always load the ext adapter
774 switch (t3lib_div::strtolower(trim($adapter))) {
775 case self::EXTJS_ADAPTER_YUI :
776 $this->extJSadapter = 'yui/ext-yui-adapter.js';
777 break;
778 case self::EXTJS_ADAPTER_PROTOTYPE :
779 $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
780 break;
781 case self::EXTJS_ADAPTER_JQUERY :
782 $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
783 break;
784 }
785 }
786 $this->addExtJS = TRUE;
787 $this->extJStheme = $theme;
788 $this->extJScss = $css;
789
790 }
791
792 /**
793 * Enables ExtJs QuickTips
794 * Need extJs loaded
795 *
796 * @return void
797 *
798 */
799 public function enableExtJSQuickTips() {
800 $this->enableExtJSQuickTips = TRUE;
801 }
802
803
804 /**
805 * call function if you need the ExtCore library
806 *
807 * @return void
808 */
809 public function loadExtCore() {
810 $this->addExtCore = TRUE;
811 }
812
813 /**
814 * call this function to load debug version of ExtJS. Use this for development only
815 *
816 */
817 public function enableExtJsDebug() {
818 $this->enableExtJsDebug = TRUE;
819 }
820
821 /**
822 * call this function to load debug version of ExtCore. Use this for development only
823 *
824 * @return void
825 */
826 public function enableExtCoreDebug() {
827 $this->enableExtCoreDebug = TRUE;
828 }
829
830 /**
831 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
832 * The label can be used in scripts with TYPO3.lang.<key>
833 * Need extJs loaded
834 *
835 * @param string $key
836 * @param string $value
837 * @return void
838 */
839 public function addInlineLanguageLabel($key, $value) {
840 $this->inlineLanguageLabels[$key] = $value;
841 }
842
843 /**
844 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
845 * The label can be used in scripts with TYPO3.lang.<key>
846 * Array will be merged with existing array.
847 * Need extJs loaded
848 *
849 * @param array $array
850 * @return void
851 */
852 public function addInlineLanguageLabelArray(array $array) {
853 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
854 }
855
856 /**
857 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
858 * The label can be used in scripts with TYPO3.setting.<key>
859 * Need extJs loaded
860 *
861 * @param string $namespace
862 * @param string $key
863 * @param string $value
864 * @return void
865 */
866 public function addInlineSetting($namespace, $key, $value) {
867 if ($namespace) {
868 if (strpos($namespace, '.')) {
869 $parts = explode('.', $namespace);
870 $a = &$this->inlineSettings;
871 foreach ($parts as $part) {
872 $a = &$a[$part];
873 }
874 $a[$key] = $value;
875 } else {
876 $this->inlineSettings[$namespace][$key] = $value;
877 }
878 } else {
879 $this->inlineSettings[$key] = $value;
880 }
881 }
882
883 /**
884 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
885 * The label can be used in scripts with TYPO3.setting.<key>
886 * Array will be merged with existing array.
887 * Need extJs loaded
888 *
889 * @param string $namespace
890 * @param array $array
891 * @return void
892 */
893 public function addInlineSettingArray($namespace, array $array) {
894 if ($namespace) {
895 if (strpos($namespace, '.')) {
896 $parts = explode('.', $namespace);
897 $a = &$this->inlineSettings;
898 foreach ($parts as $part) {
899 $a = &$a[$part];
900 }
901 $a = array_merge((array) $a, $array);
902 } else {
903 $this->inlineSettings[$namespace] = array_merge((array) $this->inlineSettings[$namespace], $array);
904 }
905 } else {
906 $this->inlineSettings = array_merge($this->inlineSettings, $array);
907 }
908 }
909
910 /**
911 * Adds content to body content
912 *
913 * @param string $content
914 * @return void
915 */
916 public function addBodyContent($content) {
917 $this->bodyContent .= $content;
918 }
919
920 /*****************************************************/
921 /* */
922 /* Render Functions */
923 /* */
924 /* */
925 /*****************************************************/
926
927 /**
928 * render the section (Header or Footer)
929 *
930 * @param int $part section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
931 * @return string content of rendered section
932 */
933 public function render($part = self::PART_COMPLETE) {
934
935 $jsFiles = '';
936 $cssFiles = '';
937 $cssInline = '';
938 $jsInline = '';
939 $jsFooterInline = '';
940 $jsFooterLibs = '';
941 $jsFooterFiles = '';
942 $noJS = FALSE;
943
944 $jsLibs = $this->renderJsLibraries();
945
946 if ($this->compressCss || $this->compressJavascript) {
947 // do the file compression
948 $this->doCompress();
949 }
950 if ($this->concatenateFiles) {
951 // do the file concatenation
952 $this->doConcatenate();
953 }
954
955 $metaTags = implode(chr(10), $this->metaTags);
956
957 if (count($this->cssFiles)) {
958 foreach ($this->cssFiles as $file => $properties) {
959 $file = t3lib_div::resolveBackPath($file);
960 $tag = '<link rel="' . $properties['rel'] . '" type="text/css" href="' . $file . '" media="' . $properties['media'] . '"' . ($properties['title'] ? ' title="' . $properties['title'] . '"' : '') . ' />';
961 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
962 $tag = str_replace('|', $tag, $properties['allWrap']);
963 }
964 if ($properties['forceOnTop']) {
965 $cssFiles = $tag . chr(10) . $cssFiles;
966 } else {
967 $cssFiles .= chr(10) . $tag;
968 }
969 }
970 }
971
972 if (count($this->cssInline)) {
973
974 foreach ($this->cssInline as $name => $properties) {
975 if ($properties['forceOnTop']) {
976 $cssInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $cssInline;
977 } else {
978 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
979 }
980 }
981 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
982
983 }
984
985 if (count($this->jsLibs)) {
986 foreach ($this->jsLibs as $name => $properties) {
987 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
988 $tag = '<script src="' . $properties['file'] . '" type="' . $properties['type'] . '"></script>';
989 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
990 $tag = str_replace('|', $tag, $properties['allWrap']);
991 }
992 if ($properties['forceOnTop']) {
993 if ($properties['section'] === self::PART_HEADER) {
994 $jsLibs = $tag . chr(10) . $jsLibs;
995 } else {
996 $jsFooterLibs = $tag . chr(10) . $jsFooterLibs;
997 }
998 } else {
999 if ($properties['section'] === self::PART_HEADER) {
1000 $jsLibs .= chr(10) . $tag;
1001 } else {
1002 $jsFooterLibs .= chr(10) . $tag;
1003 }
1004 }
1005
1006 }
1007 }
1008
1009 if (count($this->jsFiles)) {
1010 foreach ($this->jsFiles as $file => $properties) {
1011 $file = t3lib_div::resolveBackPath($file);
1012 $tag = '<script src="' . $file . '" type="' . $properties['type'] . '"></script>';
1013 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1014 $tag = str_replace('|', $tag, $properties['allWrap']);
1015 }
1016 if ($properties['forceOnTop']) {
1017 if ($properties['section'] === self::PART_HEADER) {
1018 $jsFiles = $tag . chr(10) . $jsFiles;
1019 } else {
1020 $jsFooterFiles = $tag . chr(10) . $jsFooterFiles;
1021 }
1022 } else {
1023 if ($properties['section'] === self::PART_HEADER) {
1024 $jsFiles .= chr(10) . $tag;
1025 } else {
1026 $jsFooterFiles .= chr(10) . $tag;
1027 }
1028 }
1029 }
1030 }
1031
1032 if (count($this->jsInline)) {
1033 foreach ($this->jsInline as $name => $properties) {
1034 if ($properties['forceOnTop']) {
1035 if ($properties['section'] === self::PART_HEADER) {
1036 $jsInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $jsInline;
1037 } else {
1038 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $jsFooterInline;
1039 }
1040 } else {
1041 if ($properties['section'] === self::PART_HEADER) {
1042 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1043 } else {
1044 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1045 }
1046 }
1047 }
1048 }
1049
1050
1051 if ($jsInline) {
1052 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
1053 }
1054
1055 if ($jsFooterInline) {
1056 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
1057 }
1058
1059
1060 // get template
1061 $templateFile = t3lib_div::getFileAbsFileName($this->templateFile, TRUE);
1062 $template = t3lib_div::getURL($templateFile);
1063
1064 if ($this->removeEmptyLinesFromTemplate) {
1065 $template = strtr($template, array(chr(10) => '', chr(13) => ''));
1066 }
1067 if ($part != self::PART_COMPLETE) {
1068 $templatePart = explode('###BODY###', $template);
1069 $template = $templatePart[$part - 1];
1070 }
1071
1072 if ($this->moveJsFromHeaderToFooter) {
1073 $jsFooterLibs = $jsLibs . chr(10) . $jsFooterLibs;
1074 $jsLibs = '';
1075 $jsFooterFiles = $jsFiles . chr(10) . $jsFooterFiles;
1076 $jsFiles = '';
1077 $jsFooterInline = $jsInline . chr(10) . $jsFooterInline;
1078 $jsInline = '';
1079 }
1080
1081 $markerArray = array(
1082 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1083 'HTMLTAG' => $this->htmlTag,
1084 'HEADTAG' => $this->headTag,
1085 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1086 'INLINECOMMENT' => $this->inlineComments ? chr(10) . chr(10) . '<!-- ' . chr(10) . implode(chr(10), $this->inlineComments) . '-->' . chr(10) . chr(10) : '',
1087 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1088 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1089 'CSS_INCLUDE' => $cssFiles,
1090 'CSS_INLINE' => $cssInline,
1091 'JS_INLINE' => $jsInline,
1092 'JS_INCLUDE' => $jsFiles,
1093 'JS_LIBS' => $jsLibs,
1094 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1095 'META' => $metaTags,
1096 'HEADERDATA' => $this->headerData ? implode(chr(10), $this->headerData) : '',
1097 'FOOTERDATA' => $this->footerData ? implode(chr(10), $this->footerData) : '',
1098 'JS_LIBS_FOOTER' => $jsFooterLibs,
1099 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1100 'JS_INLINE_FOOTER' => $jsFooterInline,
1101 'BODY' => $this->bodyContent,
1102 );
1103
1104 $markerArray = array_map('trim', $markerArray);
1105
1106 $this->reset();
1107 return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
1108 }
1109
1110 /**
1111 * helper function for render the javascript libraries
1112 *
1113 * @return string content with javascript libraries
1114 */
1115 protected function renderJsLibraries() {
1116 $out = '';
1117
1118 if ($this->addPrototype) {
1119 $out .= '<script src="' . $this->backPath . 'contrib/prototype/prototype.js" type="text/javascript"></script>' . chr(10);
1120 unset($this->jsFiles[$this->backPath . 'contrib/prototype/prototype.js']);
1121 }
1122
1123 if ($this->addScriptaculous) {
1124 $mods = array ();
1125 foreach ($this->addScriptaculousModules as $key => $value) {
1126 if ($this->addScriptaculousModules[$key]) {
1127 $mods[] = $key;
1128 }
1129 }
1130 // resolve dependencies
1131 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
1132 $mods = array_merge(array('effects'), $mods);
1133 }
1134
1135 if (count($mods)) {
1136 $moduleLoadString = '?load=' . implode(',', $mods);
1137 }
1138
1139 $out .= '<script src="' . $this->backPath . 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString . '" type="text/javascript"></script>' . chr(10);
1140 unset($this->jsFiles[$this->backPath . 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString]);
1141 }
1142
1143 // include extCore
1144 if ($this->addExtCore) {
1145 $out .= '<script src="' . $this->backPath . 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js" type="text/javascript"></script>' . chr(10);
1146 unset($this->jsFiles[$this->backPath . 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
1147 }
1148
1149 // include extJS
1150 if ($this->addExtJS) {
1151 // use the base adapter all the time
1152 $out .= '<script src="' . $this->backPath . 'contrib/extjs/adapter/' . $this->extJSadapter . '" type="text/javascript"></script>' . chr(10);
1153 $out .= '<script src="' . $this->backPath . 'contrib/extjs/ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js" type="text/javascript"></script>' . chr(10);
1154
1155 // add extJS localization
1156 $localeMap = $this->csConvObj->isoArray; // load standard ISO mapping and modify for use with ExtJS
1157 $localeMap[''] = 'en';
1158 $localeMap['default'] = 'en';
1159 $localeMap['gr'] = 'el_GR'; // Greek
1160 $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
1161 $localeMap['se'] = 'se_SV'; // Swedish
1162
1163
1164 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
1165 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1166 $extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '-min.js';
1167 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
1168 $out .= '<script src="' . $this->backPath . $extJsLocaleFile . '" type="text/javascript"></script>' . chr(10);
1169 }
1170
1171
1172 // remove extjs from JScodeLibArray
1173 unset(
1174 $this->jsFiles[$this->backPath . 'contrib/extjs/ext-all.js'], $this->jsFiles[$this->backPath . 'contrib/extjs/ext-all-debug.js']
1175 );
1176 }
1177 if ($this->addExtCore || $this->addExtJS) {
1178 // set clear.gif, move it on top, add handler code
1179 $code = '';
1180 if (count($this->extOnReadyCode)) {
1181 foreach ($this->extOnReadyCode as $block) {
1182 $code .= $block;
1183 }
1184 }
1185
1186 $out .= $this->inlineJavascriptWrap[0] . '
1187 Ext.ns("TYPO3");
1188 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . chr(10) .
1189 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' . 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' .
1190 'Ext.onReady(function() {' .
1191 ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . chr(10) : '') . $code .
1192 ' });' . $this->inlineJavascriptWrap[1];
1193 unset ($this->extOnReadyCode);
1194
1195 if ($this->extJStheme) {
1196 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1197 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'screen', '', FALSE, TRUE);
1198 } else {
1199 $this->addCssFile($this->backPath . 'contrib/extjs/resources/css/xtheme-blue.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1200 }
1201 }
1202 if ($this->extJScss) {
1203 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1204 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'screen', '', FALSE, TRUE);
1205 } else {
1206 $this->addCssFile($this->backPath . 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1207 }
1208 }
1209
1210 }
1211
1212 return $out;
1213 }
1214
1215 /*****************************************************/
1216 /* */
1217 /* Tools */
1218 /* */
1219 /* */
1220 /*****************************************************/
1221
1222 /**
1223 * concatenate files into one file
1224 * registered handler
1225 * TODO: implement own method
1226 *
1227 * @return void
1228 */
1229 protected function doConcatenate() {
1230 // traverse the arrays, concatenate in one file
1231 // then remove concatenated files from array and add the concatenated file
1232
1233
1234 // extern concatination
1235 if ($this->concatenateFiles && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler']) {
1236 // use extern concatenate routine
1237 $params = array (
1238 'jsLibs' => &$this->jsLibs,
1239 'jsFiles' => &$this->jsFiles,
1240 'jsFooterFiles' => &$this->jsFiles,
1241 'cssFiles' => &$this->cssFiles,
1242 );
1243 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler'], $params, $this);
1244 } else {
1245 // own method, nothing implemented atm
1246
1247
1248 }
1249 }
1250
1251 /**
1252 * compress inline code
1253 *
1254 */
1255 protected function doCompress() {
1256
1257 if ($this->compressJavascript && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler']) {
1258 // use extern compress routine
1259 $params = array (
1260 'jsInline' => &$this->jsInline,
1261 'jsFooterInline' => &$this->jsFooterInline
1262 );
1263 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
1264 } else {
1265 // traverse the arrays, compress files
1266 $this->compressError = '';
1267
1268 if ($this->compressJavascript) {
1269 if (count($this->jsInline)) {
1270 foreach ($this->jsInline as $name => $properties) {
1271 if ($properties['compress']) {
1272 $error = '';
1273 $this->jsInline[$name]['code'] = t3lib_div::minifyJavaScript($properties['code'], $error);
1274 if ($error) {
1275 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . chr(10);
1276 }
1277 }
1278 }
1279 }
1280 }
1281 }
1282
1283 if ($this->compressCss && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler']) {
1284 // use extern compress routine
1285 $params = array (
1286 'cssInline' => &$this->cssInline
1287 );
1288 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
1289 } else {
1290 if ($this->compressCss) {
1291 // own method, nothing implemented atm
1292 }
1293 }
1294 }
1295
1296 }
1297
1298 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
1299 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);
1300 }
1301 ?>