Fixed bug #12611: Add preRenderHook in pageRenderer
[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 // preRenderHook for possible manuipulation
947 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
948 $params = array (
949 'jsLibsCore' => &$jsLibs,
950 'jsLibs' => &$this->jsLibs,
951 'jsFiles' => &$this->jsFiles,
952 'jsFooterFiles' => &$this->jsFiles,
953 'cssFiles' => &$this->cssFiles,
954 'headerData' => &$this->headerData,
955 'footerData' => &$this->footerData,
956 'jsInline' => &$this->jsInline,
957 'cssInline' => &$this->cssInline,
958 );
959 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
960 t3lib_div::callUserFunction($hook, $params, $this);
961 }
962 }
963
964 if ($this->compressCss || $this->compressJavascript) {
965 // do the file compression
966 $this->doCompress();
967 }
968 if ($this->concatenateFiles) {
969 // do the file concatenation
970 $this->doConcatenate();
971 }
972
973 $metaTags = implode(chr(10), $this->metaTags);
974
975 if (count($this->cssFiles)) {
976 foreach ($this->cssFiles as $file => $properties) {
977 $file = t3lib_div::resolveBackPath($file);
978 $tag = '<link rel="' . $properties['rel'] . '" type="text/css" href="' . $file . '" media="' . $properties['media'] . '"' . ($properties['title'] ? ' title="' . $properties['title'] . '"' : '') . ' />';
979 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
980 $tag = str_replace('|', $tag, $properties['allWrap']);
981 }
982 if ($properties['forceOnTop']) {
983 $cssFiles = $tag . chr(10) . $cssFiles;
984 } else {
985 $cssFiles .= chr(10) . $tag;
986 }
987 }
988 }
989
990 if (count($this->cssInline)) {
991
992 foreach ($this->cssInline as $name => $properties) {
993 if ($properties['forceOnTop']) {
994 $cssInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $cssInline;
995 } else {
996 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
997 }
998 }
999 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
1000
1001 }
1002
1003 if (count($this->jsLibs)) {
1004 foreach ($this->jsLibs as $name => $properties) {
1005 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
1006 $tag = '<script src="' . $properties['file'] . '" type="' . $properties['type'] . '"></script>';
1007 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1008 $tag = str_replace('|', $tag, $properties['allWrap']);
1009 }
1010 if ($properties['forceOnTop']) {
1011 if ($properties['section'] === self::PART_HEADER) {
1012 $jsLibs = $tag . chr(10) . $jsLibs;
1013 } else {
1014 $jsFooterLibs = $tag . chr(10) . $jsFooterLibs;
1015 }
1016 } else {
1017 if ($properties['section'] === self::PART_HEADER) {
1018 $jsLibs .= chr(10) . $tag;
1019 } else {
1020 $jsFooterLibs .= chr(10) . $tag;
1021 }
1022 }
1023
1024 }
1025 }
1026
1027 if (count($this->jsFiles)) {
1028 foreach ($this->jsFiles as $file => $properties) {
1029 $file = t3lib_div::resolveBackPath($file);
1030 $tag = '<script src="' . $file . '" type="' . $properties['type'] . '"></script>';
1031 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1032 $tag = str_replace('|', $tag, $properties['allWrap']);
1033 }
1034 if ($properties['forceOnTop']) {
1035 if ($properties['section'] === self::PART_HEADER) {
1036 $jsFiles = $tag . chr(10) . $jsFiles;
1037 } else {
1038 $jsFooterFiles = $tag . chr(10) . $jsFooterFiles;
1039 }
1040 } else {
1041 if ($properties['section'] === self::PART_HEADER) {
1042 $jsFiles .= chr(10) . $tag;
1043 } else {
1044 $jsFooterFiles .= chr(10) . $tag;
1045 }
1046 }
1047 }
1048 }
1049
1050 if (count($this->jsInline)) {
1051 foreach ($this->jsInline as $name => $properties) {
1052 if ($properties['forceOnTop']) {
1053 if ($properties['section'] === self::PART_HEADER) {
1054 $jsInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $jsInline;
1055 } else {
1056 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $jsFooterInline;
1057 }
1058 } else {
1059 if ($properties['section'] === self::PART_HEADER) {
1060 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1061 } else {
1062 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1063 }
1064 }
1065 }
1066 }
1067
1068
1069 if ($jsInline) {
1070 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
1071 }
1072
1073 if ($jsFooterInline) {
1074 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
1075 }
1076
1077
1078 // get template
1079 $templateFile = t3lib_div::getFileAbsFileName($this->templateFile, TRUE);
1080 $template = t3lib_div::getURL($templateFile);
1081
1082 if ($this->removeEmptyLinesFromTemplate) {
1083 $template = strtr($template, array(chr(10) => '', chr(13) => ''));
1084 }
1085 if ($part != self::PART_COMPLETE) {
1086 $templatePart = explode('###BODY###', $template);
1087 $template = $templatePart[$part - 1];
1088 }
1089
1090 if ($this->moveJsFromHeaderToFooter) {
1091 $jsFooterLibs = $jsLibs . chr(10) . $jsFooterLibs;
1092 $jsLibs = '';
1093 $jsFooterFiles = $jsFiles . chr(10) . $jsFooterFiles;
1094 $jsFiles = '';
1095 $jsFooterInline = $jsInline . chr(10) . $jsFooterInline;
1096 $jsInline = '';
1097 }
1098
1099 $markerArray = array(
1100 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1101 'HTMLTAG' => $this->htmlTag,
1102 'HEADTAG' => $this->headTag,
1103 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1104 'INLINECOMMENT' => $this->inlineComments ? chr(10) . chr(10) . '<!-- ' . chr(10) . implode(chr(10), $this->inlineComments) . '-->' . chr(10) . chr(10) : '',
1105 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1106 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1107 'CSS_INCLUDE' => $cssFiles,
1108 'CSS_INLINE' => $cssInline,
1109 'JS_INLINE' => $jsInline,
1110 'JS_INCLUDE' => $jsFiles,
1111 'JS_LIBS' => $jsLibs,
1112 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1113 'META' => $metaTags,
1114 'HEADERDATA' => $this->headerData ? implode(chr(10), $this->headerData) : '',
1115 'FOOTERDATA' => $this->footerData ? implode(chr(10), $this->footerData) : '',
1116 'JS_LIBS_FOOTER' => $jsFooterLibs,
1117 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1118 'JS_INLINE_FOOTER' => $jsFooterInline,
1119 'BODY' => $this->bodyContent,
1120 );
1121
1122 $markerArray = array_map('trim', $markerArray);
1123
1124 $this->reset();
1125 return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
1126 }
1127
1128 /**
1129 * helper function for render the javascript libraries
1130 *
1131 * @return string content with javascript libraries
1132 */
1133 protected function renderJsLibraries() {
1134 $out = '';
1135
1136 if ($this->addPrototype) {
1137 $out .= '<script src="' . $this->backPath . 'contrib/prototype/prototype.js" type="text/javascript"></script>' . chr(10);
1138 unset($this->jsFiles[$this->backPath . 'contrib/prototype/prototype.js']);
1139 }
1140
1141 if ($this->addScriptaculous) {
1142 $mods = array ();
1143 foreach ($this->addScriptaculousModules as $key => $value) {
1144 if ($this->addScriptaculousModules[$key]) {
1145 $mods[] = $key;
1146 }
1147 }
1148 // resolve dependencies
1149 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
1150 $mods = array_merge(array('effects'), $mods);
1151 }
1152
1153 if (count($mods)) {
1154 $moduleLoadString = '?load=' . implode(',', $mods);
1155 }
1156
1157 $out .= '<script src="' . $this->backPath . 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString . '" type="text/javascript"></script>' . chr(10);
1158 unset($this->jsFiles[$this->backPath . 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString]);
1159 }
1160
1161 // include extCore
1162 if ($this->addExtCore) {
1163 $out .= '<script src="' . $this->backPath . 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js" type="text/javascript"></script>' . chr(10);
1164 unset($this->jsFiles[$this->backPath . 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
1165 }
1166
1167 // include extJS
1168 if ($this->addExtJS) {
1169 // use the base adapter all the time
1170 $out .= '<script src="' . $this->backPath . 'contrib/extjs/adapter/' . $this->extJSadapter . '" type="text/javascript"></script>' . chr(10);
1171 $out .= '<script src="' . $this->backPath . 'contrib/extjs/ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js" type="text/javascript"></script>' . chr(10);
1172
1173 // add extJS localization
1174 $localeMap = $this->csConvObj->isoArray; // load standard ISO mapping and modify for use with ExtJS
1175 $localeMap[''] = 'en';
1176 $localeMap['default'] = 'en';
1177 $localeMap['gr'] = 'el_GR'; // Greek
1178 $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
1179 $localeMap['se'] = 'se_SV'; // Swedish
1180
1181
1182 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
1183 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1184 $extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '-min.js';
1185 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
1186 $out .= '<script src="' . $this->backPath . $extJsLocaleFile . '" type="text/javascript"></script>' . chr(10);
1187 }
1188
1189
1190 // remove extjs from JScodeLibArray
1191 unset(
1192 $this->jsFiles[$this->backPath . 'contrib/extjs/ext-all.js'], $this->jsFiles[$this->backPath . 'contrib/extjs/ext-all-debug.js']
1193 );
1194 }
1195
1196 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
1197 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
1198
1199 if ($this->addExtCore || $this->addExtJS) {
1200 // set clear.gif, move it on top, add handler code
1201 $code = '';
1202 if (count($this->extOnReadyCode)) {
1203 foreach ($this->extOnReadyCode as $block) {
1204 $code .= $block;
1205 }
1206 }
1207
1208 $out .= $this->inlineJavascriptWrap[0] . '
1209 Ext.ns("TYPO3");
1210 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . chr(10) .
1211 $inlineSettings .
1212 'Ext.onReady(function() {' .
1213 ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . chr(10) : '') . $code .
1214 ' });' . $this->inlineJavascriptWrap[1];
1215 unset ($this->extOnReadyCode);
1216
1217 if ($this->extJStheme) {
1218 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1219 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'screen', '', FALSE, TRUE);
1220 } else {
1221 $this->addCssFile($this->backPath . 'contrib/extjs/resources/css/xtheme-blue.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1222 }
1223 }
1224 if ($this->extJScss) {
1225 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1226 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'screen', '', FALSE, TRUE);
1227 } else {
1228 $this->addCssFile($this->backPath . 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1229 }
1230 }
1231 } else {
1232 if ($inlineSettings) {
1233 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
1234 }
1235 }
1236
1237 return $out;
1238 }
1239
1240 /*****************************************************/
1241 /* */
1242 /* Tools */
1243 /* */
1244 /* */
1245 /*****************************************************/
1246
1247 /**
1248 * concatenate files into one file
1249 * registered handler
1250 * TODO: implement own method
1251 *
1252 * @return void
1253 */
1254 protected function doConcatenate() {
1255 // traverse the arrays, concatenate in one file
1256 // then remove concatenated files from array and add the concatenated file
1257
1258
1259 // extern concatination
1260 if ($this->concatenateFiles && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler']) {
1261 // use extern concatenate routine
1262 $params = array (
1263 'jsLibs' => &$this->jsLibs,
1264 'jsFiles' => &$this->jsFiles,
1265 'jsFooterFiles' => &$this->jsFiles,
1266 'cssFiles' => &$this->cssFiles,
1267 'headerData' => &$this->headerData,
1268 'footerData' => &$this->footerData,
1269 );
1270 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler'], $params, $this);
1271 } else {
1272 // own method, nothing implemented atm
1273
1274
1275 }
1276 }
1277
1278 /**
1279 * compress inline code
1280 *
1281 */
1282 protected function doCompress() {
1283
1284 if ($this->compressJavascript && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler']) {
1285 // use extern compress routine
1286 $params = array (
1287 'jsInline' => &$this->jsInline,
1288 'jsFooterInline' => &$this->jsFooterInline,
1289 'jsLibs' => &$this->jsLibs,
1290 'jsFiles' => &$this->jsFiles,
1291 'jsFooterFiles' => &$this->jsFiles,
1292 'headerData' => &$this->headerData,
1293 'footerData' => &$this->footerData,
1294 );
1295 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
1296 } else {
1297 // traverse the arrays, compress files
1298 $this->compressError = '';
1299
1300 if ($this->compressJavascript) {
1301 if (count($this->jsInline)) {
1302 foreach ($this->jsInline as $name => $properties) {
1303 if ($properties['compress']) {
1304 $error = '';
1305 $this->jsInline[$name]['code'] = t3lib_div::minifyJavaScript($properties['code'], $error);
1306 if ($error) {
1307 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . chr(10);
1308 }
1309 }
1310 }
1311 }
1312 }
1313 }
1314
1315 if ($this->compressCss && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler']) {
1316 // use extern compress routine
1317 $params = array (
1318 'cssInline' => &$this->cssInline,
1319 'cssFiles' => &$this->cssFiles,
1320 'headerData' => &$this->headerData,
1321 'footerData' => &$this->footerData,
1322 );
1323 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
1324 } else {
1325 if ($this->compressCss) {
1326 // own method, nothing implemented atm
1327 }
1328 }
1329 }
1330
1331 }
1332
1333 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
1334 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);
1335 }
1336 ?>