2 /***************************************************************
5 * (c) 2009 Steffen Kamper (info@sk-typo3.de)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * TYPO3 pageRender class (new in TYPO3 4.3.0)
30 * This class render the HTML of a webpage, usable for BE and FE
32 * @author Steffen Kamper <info@sk-typo3.de>
37 class t3lib_PageRenderer
implements t3lib_Singleton
{
39 protected $compressJavascript = FALSE;
40 protected $compressCss = FALSE;
41 protected $removeLineBreaksFromTemplate = FALSE;
43 protected $concatenateFiles = FALSE;
45 protected $moveJsFromHeaderToFooter = FALSE;
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 ();
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 />';
77 // static inline code blocks
78 protected $jsInline = array ();
79 protected $extOnReadyCode = array ();
80 protected $cssInline = array ();
82 protected $bodyContent;
84 protected $templateFile;
86 protected $jsLibraryNames = array ('prototype', 'scriptaculous', 'extjs');
88 const PART_COMPLETE
= 0;
89 const PART_HEADER
= 1;
90 const PART_FOOTER
= 2;
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';
100 protected $enableExtJsDebug = FALSE;
101 protected $enableExtCoreDebug = FALSE;
103 // available adapters for extJs
104 const EXTJS_ADAPTER_JQUERY
= 'jquery';
105 const EXTJS_ADAPTER_PROTOTYPE
= 'prototype';
106 const EXTJS_ADAPTER_YUI
= 'yui';
108 protected $extJStheme = TRUE;
109 protected $extJScss = TRUE;
111 protected $enableExtJSQuickTips = false;
113 protected $inlineLanguageLabels = array ();
114 protected $inlineSettings = array ();
116 protected $inlineJavascriptWrap = array ();
118 // used by BE modules
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/
128 public function __construct($templateFile = '', $backPath = NULL) {
131 $this->csConvObj
= t3lib_div
::makeInstance('t3lib_cs');
133 if (strlen($templateFile)) {
134 $this->templateFile
= $templateFile;
136 $this->backPath
= isset($backPath) ?
$backPath : $GLOBALS['BACK_PATH'];
138 $this->inlineJavascriptWrap
= array(
139 '<script type="text/javascript">' . LF
. '/*<![CDATA[*/' . LF
. '<!-- ' . LF
,
140 '// -->' . LF
. '/*]]>*/' . LF
. '</script>' . LF
142 $this->inlineCssWrap
= array(
143 '<style type="text/css">' . LF
. '/*<![CDATA[*/' . LF
. '<!-- ' . LF
,
144 '-->' . LF
. '/*]]>*/' . LF
. '</style>' . LF
150 * reset all vars to initial values
154 protected function reset() {
155 $this->templateFile
= TYPO3_mainDir
. 'templates/template_page_backend.html';
156 $this->jsFiles
= array ();
157 $this->jsFooterFiles
= array ();
158 $this->jsInline
= array ();
159 $this->jsFooterInline
= array ();
160 $this->jsLibs
= array ();
161 $this->cssFiles
= array ();
162 $this->cssInline
= array ();
163 $this->metaTags
= array ();
164 $this->inlineComments
= array ();
165 $this->headerData
= array ();
166 $this->footerData
= array ();
167 $this->extOnReadyCode
= array ();
169 /*****************************************************/
174 /*****************************************************/
179 * @param string $title title of webpage
182 public function setTitle($title) {
183 $this->title
= $title;
187 * Sets xml prolog and docType
189 * @param string $xmlPrologAndDocType complete tags for xml prolog and docType
192 public function setXmlPrologAndDocType($xmlPrologAndDocType) {
193 $this->xmlPrologAndDocType
= $xmlPrologAndDocType;
199 * @param string $charSet used charset
202 public function setCharSet($charSet) {
203 $this->charSet
= $charSet;
209 * @param string $lang used language
212 public function setLanguage($lang) {
219 * @param string $htmlTag html tag
222 public function setHtmlTag($htmlTag) {
223 $this->htmlTag
= $htmlTag;
229 * @param string $tag head tag
232 public function setHeadTag($headTag) {
233 $this->headTag
= $headTag;
239 * @param string $favIcon
242 public function setFavIcon($favIcon) {
243 $this->favIcon
= $favIcon;
247 * Sets icon mime type
249 * @param string $iconMimeType
252 public function setIconMimeType($iconMimeType) {
253 $this->iconMimeType
= $iconMimeType;
262 public function setBaseUrl($baseUrl) {
263 $this->baseUrl
= $baseUrl;
269 * @param string $file
272 public function setTemplateFile($file) {
273 $this->templateFile
= $file;
279 * @param string $backPath
282 public function setBackPath($backPath) {
283 $this->backPath
= $backPath;
287 * Sets Content for Body
289 * @param string $content
292 public function setBodyContent($content) {
293 $this->bodyContent
= $content;
296 /*****************************************************/
298 /* Public Enablers */
301 /*****************************************************/
303 * Enables MoveJsFromHeaderToFooter
308 public function enableMoveJsFromHeaderToFooter() {
309 $this->moveJsFromHeaderToFooter
= TRUE;
313 * Enables compression of javascript
318 public function enableCompressJavascript() {
319 $this->compressJavascript
= TRUE;
323 * Enables compression of css
328 public function enableCompressCss() {
329 $this->compressCss
= TRUE;
334 * Enables concatenation of js/css files
339 public function enableConcatenateFiles() {
340 $this->concatenateFiles
= TRUE;
344 * Sets removal of all line breaks in template
349 public function enableRemoveLineBreaksFromTemplate() {
350 $this->removeLineBreaksFromTemplate
= TRUE;
353 /*****************************************************/
358 /*****************************************************/
363 * @return string $title title of webpage
365 public function getTitle() {
372 * @return string $charSet
374 public function getCharSet() {
375 return $this->charSet
;
381 * @return string $lang
383 public function getLanguage() {
390 * @return string $htmlTag html tag
392 public function getHtmlTag() {
393 return $this->htmlTag
;
399 * @return string $tag head tag
401 public function getHeadTag() {
402 return $this->headTag
;
408 * @return string $favIcon
410 public function getFavIcon() {
411 return $this->favIcon
;
415 * Gets icon mime type
417 * @return string $iconMimeType
419 public function getIconMimeType() {
420 return $this->iconMimeType
;
426 * @return string $url
428 public function getBaseUrl() {
429 return $this->baseUrl
;
435 * @return string $file
437 public function getTemplateFile($file) {
438 return $this->templateFile
;
442 * Gets MoveJsFromHeaderToFooter
446 public function getMoveJsFromHeaderToFooter() {
447 return $this->moveJsFromHeaderToFooter
;
451 * Gets compress of javascript
455 public function getCompressJavascript() {
456 return $this->compressJavascript
;
460 * Gets compress of css
464 public function getCompressCss() {
465 return $this->compressCss
;
469 * Gets concatenate of files
473 public function getConcatenateFiles() {
474 return $this->concatenateFiles
;
478 * Gets remove of empty lines from template
482 public function getRemoveLineBreaksFromTemplate() {
483 return $this->removeLineBreaksFromTemplate
;
487 * Gets content for body
491 public function getBodyContent() {
492 return $this->bodyContent
;
495 /*****************************************************/
497 /* Public Function to add Data */
500 /*****************************************************/
505 * @param string $meta meta data (complete metatag)
508 public function addMetaTag($meta) {
509 if (!in_array($meta, $this->metaTags
)) {
510 $this->metaTags
[] = $meta;
515 * Adds inline HTML comment
517 * @param string $comment
520 public function addInlineComment($comment) {
521 if (!in_array($comment, $this->inlineComments
)) {
522 $this->inlineComments
[] = $comment;
529 * @param string $data free header data for HTML header
532 public function addHeaderData($data) {
533 if (!in_array($data, $this->headerData
)) {
534 $this->headerData
[] = $data;
541 * @param string $data free header data for HTML header
544 public function addFooterData($data) {
545 if (!in_array($data, $this->footerData
)) {
546 $this->footerData
[] = $data;
550 /* Javascript Files */
553 * Adds JS Library. JS Library block is rendered on top of the JS files.
555 * @param string $name
556 * @param string $file
557 * @param string $type
558 * @param boolean $compress flag if library should be compressed
559 * @param boolean $forceOnTop flag if added library should be inserted at begin of this block
560 * @param string $allWrap
563 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '') {
564 if (!in_array(strtolower($name), $this->jsLibs
)) {
565 $this->jsLibs
[strtolower($name)] = array (
568 'section' => self
::PART_HEADER
,
569 'compress' => $compress,
570 'forceOnTop' => $forceOnTop,
571 'allWrap' => $allWrap
578 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
580 * @param string $name
581 * @param string $file
582 * @param string $type
583 * @param boolean $compress flag if library should be compressed
584 * @param boolean $forceOnTop flag if added library should be inserted at begin of this block
585 * @param string $allWrap
588 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '') {
589 if (!in_array(strtolower($name), $this->jsLibs
)) {
590 $this->jsLibs
[strtolower($name)] = array (
593 'section' => self
::PART_FOOTER
,
594 'compress' => $compress,
595 'forceOnTop' => $forceOnTop,
596 'allWrap' => $allWrap
605 * @param string $file
606 * @param string $type
607 * @param boolean $compress
608 * @param boolean $forceOnTop
609 * @param string $allWrap
612 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
613 if (!isset($this->jsFiles
[$file])) {
614 $this->jsFiles
[$file] = array (
616 'section' => self
::PART_HEADER
,
617 'compress' => $compress,
618 'forceOnTop' => $forceOnTop,
619 'allWrap' => $allWrap
625 * Adds JS file to footer
627 * @param string $file
628 * @param string $type
629 * @param boolean $compress
630 * @param boolean $forceOnTop
633 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
634 if (!isset($this->jsFiles
[$file])) {
635 $this->jsFiles
[$file] = array (
637 'section' => self
::PART_FOOTER
,
638 'compress' => $compress,
639 'forceOnTop' => $forceOnTop,
640 'allWrap' => $allWrap
645 /*Javascript Inline Blocks */
648 * Adds JS inline code
650 * @param string $name
651 * @param string $block
652 * @param boolean $compress
653 * @param boolean $forceOnTop
656 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
657 if (!isset($this->jsInline
[$name])) {
658 $this->jsInline
[$name] = array (
659 'code' => $block . LF
,
660 'section' => self
::PART_HEADER
,
661 'compress' => $compress,
662 'forceOnTop' => $forceOnTop
668 * Adds JS inline code to footer
670 * @param string $name
671 * @param string $block
672 * @param boolean $compress
673 * @param boolean $forceOnTop
676 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
677 if (!isset($this->jsInline
[$name])) {
678 $this->jsInline
[$name] = array (
679 'code' => $block . LF
,
680 'section' => self
::PART_FOOTER
,
681 'compress' => $compress,
682 'forceOnTop' => $forceOnTop
688 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
690 * @param string $block javascript code
691 * @param boolean $forceOnTop position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
694 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
695 if (!in_array($block, $this->extOnReadyCode
)) {
697 array_unshift($this->extOnReadyCode
, $block);
699 $this->extOnReadyCode
[] = $block;
709 * @param string $file
711 * @param string $media
712 * @param string $title
713 * @param boolean $compress
714 * @param boolean $forceOnTop
717 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
718 if (!isset($this->cssFiles
[$file])) {
719 $this->cssFiles
[$file] = array (
723 'compress' => $compress,
724 'forceOnTop' => $forceOnTop,
725 'allWrap' => $allWrap
730 /*CSS Inline Blocks */
733 * Adds CSS inline code
735 * @param string $name
736 * @param string $block
737 * @param boolean $compress
738 * @param boolean $forceOnTop
741 public function addCssInlineBlock($name, $block, $compressed = FALSE, $forceOnTop = FALSE) {
742 if (!isset($this->cssInline
[$name])) {
743 $this->cssInline
[$name] = array (
745 'compress' => $compress,
746 'forceOnTop' => $forceOnTop
754 * call function if you need the prototype library
758 public function loadPrototype() {
759 $this->addPrototype
= TRUE;
763 * call function if you need the Scriptaculous library
765 * @param string $modules add modules you need. use "all" if you need complete modules
768 public function loadScriptaculous($modules = '') {
769 // Scriptaculous require prototype, so load prototype too.
770 $this->addPrototype
= TRUE;
771 $this->addScriptaculous
= TRUE;
773 if ($modules == 'all') {
774 foreach ($this->addScriptaculousModules
as $key => $value) {
775 $this->addScriptaculousModules
[$key] = TRUE;
778 $mods = t3lib_div
::trimExplode(',', $modules);
779 foreach ($mods as $mod) {
780 if (isset($this->addScriptaculousModules
[strtolower($mod)])) {
781 $this->addScriptaculousModules
[strtolower($mod)] = TRUE;
789 * call this function if you need the extJS library
791 * @param boolean $css flag, if set the ext-css will be loaded
792 * @param boolean $theme flag, if set the ext-theme "grey" will be loaded
793 * @param string $adapter choose alternative adapter, possible values: yui, prototype, jquery
796 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
798 // empty $adapter will always load the ext adapter
799 switch (t3lib_div
::strtolower(trim($adapter))) {
800 case self
::EXTJS_ADAPTER_YUI
:
801 $this->extJSadapter
= 'yui/ext-yui-adapter.js';
803 case self
::EXTJS_ADAPTER_PROTOTYPE
:
804 $this->extJSadapter
= 'prototype/ext-prototype-adapter.js';
806 case self
::EXTJS_ADAPTER_JQUERY
:
807 $this->extJSadapter
= 'jquery/ext-jquery-adapter.js';
811 $this->addExtJS
= TRUE;
812 $this->extJStheme
= $theme;
813 $this->extJScss
= $css;
818 * Enables ExtJs QuickTips
824 public function enableExtJSQuickTips() {
825 $this->enableExtJSQuickTips
= TRUE;
830 * call function if you need the ExtCore library
834 public function loadExtCore() {
835 $this->addExtCore
= TRUE;
839 * call this function to load debug version of ExtJS. Use this for development only
842 public function enableExtJsDebug() {
843 $this->enableExtJsDebug
= TRUE;
847 * call this function to load debug version of ExtCore. Use this for development only
851 public function enableExtCoreDebug() {
852 $this->enableExtCoreDebug
= TRUE;
856 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
857 * The label can be used in scripts with TYPO3.lang.<key>
861 * @param string $value
864 public function addInlineLanguageLabel($key, $value) {
865 $this->inlineLanguageLabels
[$key] = $value;
869 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
870 * The label can be used in scripts with TYPO3.lang.<key>
871 * Array will be merged with existing array.
874 * @param array $array
877 public function addInlineLanguageLabelArray(array $array) {
878 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $array);
882 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
883 * The label can be used in scripts with TYPO3.setting.<key>
886 * @param string $namespace
888 * @param string $value
891 public function addInlineSetting($namespace, $key, $value) {
893 if (strpos($namespace, '.')) {
894 $parts = explode('.', $namespace);
895 $a = &$this->inlineSettings
;
896 foreach ($parts as $part) {
901 $this->inlineSettings
[$namespace][$key] = $value;
904 $this->inlineSettings
[$key] = $value;
909 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
910 * The label can be used in scripts with TYPO3.setting.<key>
911 * Array will be merged with existing array.
914 * @param string $namespace
915 * @param array $array
918 public function addInlineSettingArray($namespace, array $array) {
920 if (strpos($namespace, '.')) {
921 $parts = explode('.', $namespace);
922 $a = &$this->inlineSettings
;
923 foreach ($parts as $part) {
926 $a = array_merge((array) $a, $array);
928 $this->inlineSettings
[$namespace] = array_merge((array) $this->inlineSettings
[$namespace], $array);
931 $this->inlineSettings
= array_merge($this->inlineSettings
, $array);
936 * Adds content to body content
938 * @param string $content
941 public function addBodyContent($content) {
942 $this->bodyContent
.= $content;
945 /*****************************************************/
947 /* Render Functions */
950 /*****************************************************/
953 * render the section (Header or Footer)
955 * @param int $part section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
956 * @return string content of rendered section
958 public function render($part = self
::PART_COMPLETE
) {
964 $jsFooterInline = '';
971 // preRenderHook for possible manuipulation
972 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
974 'jsLibs' => &$this->jsLibs
,
975 'jsFiles' => &$this->jsFiles
,
976 'jsFooterFiles' => &$this->jsFiles
,
977 'cssFiles' => &$this->cssFiles
,
978 'headerData' => &$this->headerData
,
979 'footerData' => &$this->footerData
,
980 'jsInline' => &$this->jsInline
,
981 'cssInline' => &$this->cssInline
,
983 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
984 t3lib_div
::callUserFunction($hook, $params, $this);
988 $jsLibs = $this->renderJsLibraries();
990 if ($this->compressCss ||
$this->compressJavascript
) {
991 // do the file compression
994 if ($this->concatenateFiles
) {
995 // do the file concatenation
996 $this->doConcatenate();
999 $metaTags = implode(LF
, $this->metaTags
);
1001 // remove ending slashes from static header block
1002 // if the page is beeing rendered as html (not xhtml)
1003 // and define variable $endingSlash for further use
1004 if ($GLOBALS['TSFE']->xhtmlVersion
) {
1005 $endingSlash = ' /';
1007 $this->metaCharsetTag
= str_replace(' />', '>', $this->metaCharsetTag
);
1008 $this->baseUrlTag
= str_replace(' />', '>', $this->baseUrlTag
);
1009 $this->shortcutTag
= str_replace(' />', '>', $this->shortcutTag
);
1013 if (count($this->cssFiles
)) {
1014 foreach ($this->cssFiles
as $file => $properties) {
1015 $file = t3lib_div
::resolveBackPath($file);
1016 $file = t3lib_div
::createVersionNumberedFilename($file);
1017 $tag = '<link rel="' . $properties['rel'] . '" type="text/css" href="' .
1018 htmlspecialchars($file) . '" media="' . $properties['media'] . '"' .
1019 ($properties['title'] ?
' title="' . $properties['title'] . '"' : '') .
1021 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1022 $tag = str_replace('|', $tag, $properties['allWrap']);
1024 if ($properties['forceOnTop']) {
1025 $cssFiles = $tag . LF
. $cssFiles;
1027 $cssFiles .= LF
. $tag;
1032 if (count($this->cssInline
)) {
1034 foreach ($this->cssInline
as $name => $properties) {
1035 if ($properties['forceOnTop']) {
1036 $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
. $cssInline;
1038 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
1041 $cssInline = $this->inlineCssWrap
[0] . $cssInline . $this->inlineCssWrap
[1];
1045 if (count($this->jsLibs
)) {
1046 foreach ($this->jsLibs
as $name => $properties) {
1047 $properties['file'] = t3lib_div
::resolveBackPath($properties['file']);
1048 $properties['file'] = t3lib_div
::createVersionNumberedFilename($properties['file']);
1049 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . $properties['type'] . '"></script>';
1050 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1051 $tag = str_replace('|', $tag, $properties['allWrap']);
1053 if ($properties['forceOnTop']) {
1054 if ($properties['section'] === self
::PART_HEADER
) {
1055 $jsLibs = $tag . LF
. $jsLibs;
1057 $jsFooterLibs = $tag . LF
. $jsFooterLibs;
1060 if ($properties['section'] === self
::PART_HEADER
) {
1061 $jsLibs .= LF
. $tag;
1063 $jsFooterLibs .= LF
. $tag;
1070 if (count($this->jsFiles
)) {
1071 foreach ($this->jsFiles
as $file => $properties) {
1072 $file = t3lib_div
::resolveBackPath($file);
1073 $file = t3lib_div
::createVersionNumberedFilename($file);
1074 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . $properties['type'] . '"></script>';
1075 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1076 $tag = str_replace('|', $tag, $properties['allWrap']);
1078 if ($properties['forceOnTop']) {
1079 if ($properties['section'] === self
::PART_HEADER
) {
1080 $jsFiles = $tag . LF
. $jsFiles;
1082 $jsFooterFiles = $tag . LF
. $jsFooterFiles;
1085 if ($properties['section'] === self
::PART_HEADER
) {
1086 $jsFiles .= LF
. $tag;
1088 $jsFooterFiles .= LF
. $tag;
1094 if (count($this->jsInline
)) {
1095 foreach ($this->jsInline
as $name => $properties) {
1096 if ($properties['forceOnTop']) {
1097 if ($properties['section'] === self
::PART_HEADER
) {
1098 $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
. $jsInline;
1100 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
. $jsFooterInline;
1103 if ($properties['section'] === self
::PART_HEADER
) {
1104 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
1106 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
1114 $jsInline = $this->inlineJavascriptWrap
[0] . $jsInline . $this->inlineJavascriptWrap
[1];
1117 if ($jsFooterInline) {
1118 $jsFooterInline = $this->inlineJavascriptWrap
[0] . $jsFooterInline . $this->inlineJavascriptWrap
[1];
1123 $templateFile = t3lib_div
::getFileAbsFileName($this->templateFile
, TRUE);
1124 $template = t3lib_div
::getURL($templateFile);
1126 if ($this->removeEmptyLinesFromTemplate
) {
1127 $template = strtr($template, array(LF
=> '', CR
=> ''));
1129 if ($part != self
::PART_COMPLETE
) {
1130 $templatePart = explode('###BODY###', $template);
1131 $template = $templatePart[$part - 1];
1134 if ($this->moveJsFromHeaderToFooter
) {
1135 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
1137 $jsFooterFiles = $jsFiles . LF
. $jsFooterFiles;
1139 $jsFooterInline = $jsInline . LF
. $jsFooterInline;
1143 $markerArray = array(
1144 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1145 'HTMLTAG' => $this->htmlTag
,
1146 'HEADTAG' => $this->headTag
,
1147 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1148 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
1149 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1150 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1151 'CSS_INCLUDE' => $cssFiles,
1152 'CSS_INLINE' => $cssInline,
1153 'JS_INLINE' => $jsInline,
1154 'JS_INCLUDE' => $jsFiles,
1155 'JS_LIBS' => $jsLibs,
1156 'TITLE' => $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '',
1157 'META' => $metaTags,
1158 'HEADERDATA' => $this->headerData ?
implode(LF
, $this->headerData
) : '',
1159 'FOOTERDATA' => $this->footerData ?
implode(LF
, $this->footerData
) : '',
1160 'JS_LIBS_FOOTER' => $jsFooterLibs,
1161 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1162 'JS_INLINE_FOOTER' => $jsFooterInline,
1163 'BODY' => $this->bodyContent
,
1166 $markerArray = array_map('trim', $markerArray);
1169 return trim(t3lib_parsehtml
::substituteMarkerArray($template, $markerArray, '###|###'));
1173 * helper function for render the javascript libraries
1175 * @return string content with javascript libraries
1177 protected function renderJsLibraries() {
1180 if ($this->addPrototype
) {
1181 $out .= '<script src="' . t3lib_div
::createVersionNumberedFilename($this->backPath
.
1182 'contrib/prototype/prototype.js') . '" type="text/javascript"></script>' . LF
;
1183 unset($this->jsFiles
[$this->backPath
. 'contrib/prototype/prototype.js']);
1186 if ($this->addScriptaculous
) {
1188 foreach ($this->addScriptaculousModules
as $key => $value) {
1189 if ($this->addScriptaculousModules
[$key]) {
1193 // resolve dependencies
1194 if (in_array('dragdrop', $mods) ||
in_array('controls', $mods)) {
1195 $mods = array_merge(array('effects'), $mods);
1199 $moduleLoadString = '?load=' . implode(',', $mods);
1201 $out .= '<script src="' . t3lib_div
::createVersionNumberedFilename($this->backPath
.
1202 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString, TRUE) .
1203 '" type="text/javascript"></script>' . LF
;
1204 unset($this->jsFiles
[$this->backPath
. 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString]);
1208 if ($this->addExtCore
) {
1209 $out .= '<script src="' . t3lib_div
::createVersionNumberedFilename($this->backPath
.
1210 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ?
'-debug' : '') . '.js') .
1211 '" type="text/javascript"></script>' . LF
;
1212 unset($this->jsFiles
[$this->backPath
. 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ?
'-debug' : '') . '.js']);
1216 if ($this->addExtJS
) {
1217 // use the base adapter all the time
1218 $out .= '<script src="' . t3lib_div
::createVersionNumberedFilename($this->backPath
.
1219 'contrib/extjs/adapter/' . ($this->enableExtJsDebug ?
1220 str_replace('.js', '-debug.js', $this->extJSadapter
) : $this->extJSadapter
)) .
1221 '" type="text/javascript"></script>' . LF
;
1222 $out .= '<script src="' . t3lib_div
::createVersionNumberedFilename($this->backPath
.
1223 'contrib/extjs/ext-all' . ($this->enableExtJsDebug ?
'-debug' : '') . '.js') .
1224 '" type="text/javascript"></script>' . LF
;
1226 // add extJS localization
1227 $localeMap = $this->csConvObj
->isoArray
; // load standard ISO mapping and modify for use with ExtJS
1228 $localeMap[''] = 'en';
1229 $localeMap['default'] = 'en';
1230 $localeMap['gr'] = 'el_GR'; // Greek
1231 $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
1232 $localeMap['se'] = 'se_SV'; // Swedish
1235 $extJsLang = isset($localeMap[$this->lang
]) ?
$localeMap[$this->lang
] : $this->lang
;
1236 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1237 $extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '.js';
1238 if (file_exists(PATH_typo3
. $extJsLocaleFile)) {
1239 $out .= '<script src="' . t3lib_div
::createVersionNumberedFilename($this->backPath
.
1240 $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF
;
1244 // remove extjs from JScodeLibArray
1246 $this->jsFiles
[$this->backPath
. 'contrib/extjs/ext-all.js'], $this->jsFiles
[$this->backPath
. 'contrib/extjs/ext-all-debug.js']
1250 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
1251 if ($this->getCharSet() !== 'utf-8') {
1252 if ($this->inlineLanguageLabels
) {
1253 $this->csConvObj
->convArray($this->inlineLanguageLabels
, $this->getCharSet(), 'utf-8');
1255 if ($this->inlineSettings
) {
1256 $this->csConvObj
->convArray($this->inlineSettings
, $this->getCharSet(), 'utf-8');
1260 $inlineSettings = $this->inlineLanguageLabels ?
'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels
) . ';' : '';
1261 $inlineSettings .= $this->inlineSettings ?
'TYPO3.settings = ' . json_encode($this->inlineSettings
) . ';' : '';
1263 if ($this->addExtCore ||
$this->addExtJS
) {
1264 // set clear.gif, move it on top, add handler code
1266 if (count($this->extOnReadyCode
)) {
1267 foreach ($this->extOnReadyCode
as $block) {
1272 $out .= $this->inlineJavascriptWrap
[0] . '
1274 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div
::locationHeaderUrl($this->backPath
. 'gfx/clear.gif')) . '";' . LF
.
1276 'Ext.onReady(function() {' .
1277 ($this->enableExtJSQuickTips ?
'Ext.QuickTips.init();' . LF
: '') . $code .
1278 ' });' . $this->inlineJavascriptWrap
[1];
1279 unset ($this->extOnReadyCode
);
1281 if ($this->extJStheme
) {
1282 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1283 $this->addCssFile($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'screen', '', FALSE, TRUE);
1285 $this->addCssFile($this->backPath
. 'contrib/extjs/resources/css/xtheme-blue.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1288 if ($this->extJScss
) {
1289 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1290 $this->addCssFile($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'screen', '', FALSE, TRUE);
1292 $this->addCssFile($this->backPath
. 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1296 if ($inlineSettings) {
1297 $out .= $this->inlineJavascriptWrap
[0] . $inlineSettings . $this->inlineJavascriptWrap
[1];
1304 /*****************************************************/
1309 /*****************************************************/
1312 * concatenate files into one file
1313 * registered handler
1314 * TODO: implement own method
1318 protected function doConcatenate() {
1319 // traverse the arrays, concatenate in one file
1320 // then remove concatenated files from array and add the concatenated file
1323 if ($this->concatenateFiles
) {
1325 'jsLibs' => &$this->jsLibs
,
1326 'jsFiles' => &$this->jsFiles
,
1327 'jsFooterFiles' => &$this->jsFiles
,
1328 'cssFiles' => &$this->cssFiles
,
1329 'headerData' => &$this->headerData
,
1330 'footerData' => &$this->footerData
,
1333 if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['concatenateHandler']) {
1334 // use extern concatenate routine
1335 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['concatenateHandler'], $params, $this);
1336 } elseif (TYPO3_MODE
=== 'BE') {
1337 $compressor = t3lib_div
::makeInstance('t3lib_compressor');
1338 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
1339 $this->cssFiles
= $compressor->concatenateCssFiles($this->cssFiles
, $cssOptions);
1345 * compress inline code
1348 protected function doCompress() {
1350 if ($this->compressJavascript
&& $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler']) {
1351 // use extern compress routine
1353 'jsInline' => &$this->jsInline
,
1354 'jsFooterInline' => &$this->jsFooterInline
,
1355 'jsLibs' => &$this->jsLibs
,
1356 'jsFiles' => &$this->jsFiles
,
1357 'jsFooterFiles' => &$this->jsFiles
,
1358 'headerData' => &$this->headerData
,
1359 'footerData' => &$this->footerData
,
1361 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'], $params, $this);
1363 // traverse the arrays, compress files
1364 $this->compressError
= '';
1366 if ($this->compressJavascript
) {
1367 if (count($this->jsInline
)) {
1368 foreach ($this->jsInline
as $name => $properties) {
1369 if ($properties['compress']) {
1371 $this->jsInline
[$name]['code'] = t3lib_div
::minifyJavaScript($properties['code'], $error);
1373 $this->compressError
.= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF
;
1381 if ($this->compressCss
&& $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler']) {
1382 // use extern compress routine
1384 'cssInline' => &$this->cssInline
,
1385 'cssFiles' => &$this->cssFiles
,
1386 'headerData' => &$this->headerData
,
1387 'footerData' => &$this->footerData
,
1389 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'], $params, $this);
1391 if ($this->compressCss
) {
1392 // own method, nothing implemented atm
1399 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
1400 include_once ($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);