2 /***************************************************************
5 * (c) 2009-2010 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 /* @var t3lib_Compressor Instance of t3lib_Compressor */
51 protected $compressor;
53 // static array containing associative array for the included files
54 protected static $jsFiles = array ();
55 protected static $jsFooterFiles = array ();
56 protected static $jsLibs = array ();
57 protected static $jsFooterLibs = array ();
58 protected static $cssFiles = array ();
65 protected $renderXhtml = TRUE;
67 // static header blocks
68 protected $xmlPrologAndDocType = '';
69 protected $metaTags = array ();
70 protected $inlineComments = array ();
71 protected $headerData = array ();
72 protected $footerData = array ();
73 protected $titleTag = '<title>|</title>';
74 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
75 protected $htmlTag = '<html>';
76 protected $headTag = '<head>';
77 protected $baseUrlTag = '<base href="|" />';
78 protected $iconMimeType = '';
79 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />
80 <link rel="icon" href="%1$s"%2$s />';
82 // static inline code blocks
83 protected $jsInline = array ();
84 protected $extOnReadyCode = array ();
85 protected $cssInline = array ();
87 protected $bodyContent;
89 protected $templateFile;
91 protected $jsLibraryNames = array ('prototype', 'scriptaculous', 'extjs');
93 const PART_COMPLETE
= 0;
94 const PART_HEADER
= 1;
95 const PART_FOOTER
= 2;
97 // paths to contibuted libraries
98 protected $prototypePath = 'contrib/prototype/';
99 protected $scriptaculousPath = 'contrib/scriptaculous/';
100 protected $extCorePath = 'contrib/extjs/';
101 protected $extJsPath = 'contrib/extjs/';
104 // internal flags for JS-libraries
105 protected $addPrototype = FALSE;
106 protected $addScriptaculous = FALSE;
107 protected $addScriptaculousModules = array ('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
108 protected $addExtJS = FALSE;
109 protected $addExtCore = FALSE;
110 protected $extJSadapter = 'ext/ext-base.js';
112 protected $enableExtJsDebug = FALSE;
113 protected $enableExtCoreDebug = FALSE;
115 // available adapters for extJs
116 const EXTJS_ADAPTER_JQUERY
= 'jquery';
117 const EXTJS_ADAPTER_PROTOTYPE
= 'prototype';
118 const EXTJS_ADAPTER_YUI
= 'yui';
120 protected $extJStheme = TRUE;
121 protected $extJScss = TRUE;
123 protected $enableExtJSQuickTips = false;
125 protected $inlineLanguageLabels = array ();
126 protected $inlineSettings = array ();
128 protected $inlineJavascriptWrap = array ();
130 // used by BE modules
136 * @param string $templateFile declare the used template file. Omit this parameter will use default template
137 * @param string $backPath relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
140 public function __construct($templateFile = '', $backPath = NULL) {
143 $this->csConvObj
= t3lib_div
::makeInstance('t3lib_cs');
145 if (strlen($templateFile)) {
146 $this->templateFile
= $templateFile;
148 $this->backPath
= isset($backPath) ?
$backPath : $GLOBALS['BACK_PATH'];
150 $this->inlineJavascriptWrap
= array(
151 '<script type="text/javascript">' . LF
. '/*<![CDATA[*/' . LF
. '<!-- ' . LF
,
152 '// -->' . LF
. '/*]]>*/' . LF
. '</script>' . LF
154 $this->inlineCssWrap
= array(
155 '<style type="text/css">' . LF
. '/*<![CDATA[*/' . LF
. '<!-- ' . LF
,
156 '-->' . LF
. '/*]]>*/' . LF
. '</style>' . LF
162 * reset all vars to initial values
166 protected function reset() {
167 $this->templateFile
= TYPO3_mainDir
. 'templates/template_page_backend.html';
168 $this->jsFiles
= array ();
169 $this->jsFooterFiles
= array ();
170 $this->jsInline
= array ();
171 $this->jsFooterInline
= array ();
172 $this->jsLibs
= array ();
173 $this->cssFiles
= array ();
174 $this->cssInline
= array ();
175 $this->metaTags
= array ();
176 $this->inlineComments
= array ();
177 $this->headerData
= array ();
178 $this->footerData
= array ();
179 $this->extOnReadyCode
= array ();
181 /*****************************************************/
186 /*****************************************************/
191 * @param string $title title of webpage
194 public function setTitle($title) {
195 $this->title
= $title;
200 * Enables/disables rendering of XHTML code
202 * @param boolean $enable Enable XHTML
205 public function setRenderXhtml($enable) {
206 $this->renderXhtml
= $enable;
210 * Sets xml prolog and docType
212 * @param string $xmlPrologAndDocType complete tags for xml prolog and docType
215 public function setXmlPrologAndDocType($xmlPrologAndDocType) {
216 $this->xmlPrologAndDocType
= $xmlPrologAndDocType;
222 * @param string $charSet used charset
225 public function setCharSet($charSet) {
226 $this->charSet
= $charSet;
232 * @param string $lang used language
235 public function setLanguage($lang) {
242 * @param string $htmlTag html tag
245 public function setHtmlTag($htmlTag) {
246 $this->htmlTag
= $htmlTag;
252 * @param string $tag head tag
255 public function setHeadTag($headTag) {
256 $this->headTag
= $headTag;
262 * @param string $favIcon
265 public function setFavIcon($favIcon) {
266 $this->favIcon
= $favIcon;
270 * Sets icon mime type
272 * @param string $iconMimeType
275 public function setIconMimeType($iconMimeType) {
276 $this->iconMimeType
= $iconMimeType;
285 public function setBaseUrl($baseUrl) {
286 $this->baseUrl
= $baseUrl;
292 * @param string $file
295 public function setTemplateFile($file) {
296 $this->templateFile
= $file;
302 * @param string $backPath
305 public function setBackPath($backPath) {
306 $this->backPath
= $backPath;
310 * Sets Content for Body
312 * @param string $content
315 public function setBodyContent($content) {
316 $this->bodyContent
= $content;
320 * Sets Path for prototype library (relative to typo3 directory)
325 public function setPrototypePath($path) {
326 $this->prototypePath
= $path;
330 * Sets Path for scriptaculous library (relative to typo3 directory)
332 * @param string $path
335 public function setScriptaculousPath($path) {
336 $this->scriptaculousPath
= $path;
340 * Sets Path for Ext Core library (relative to typo3 directory)
342 * @param string $path
345 public function setExtCorePath($path) {
346 $this->extCorePath
= $path;
350 * Sets Path for ExtJs library (relative to typo3 directory)
352 * @param string $path
355 public function setExtJsPath($path) {
356 $this->extJsPath
= $path;
359 /*****************************************************/
361 /* Public Enablers / Disablers */
364 /*****************************************************/
367 * Enables MoveJsFromHeaderToFooter
372 public function enableMoveJsFromHeaderToFooter() {
373 $this->moveJsFromHeaderToFooter
= TRUE;
377 * Disables MoveJsFromHeaderToFooter
382 public function disableMoveJsFromHeaderToFooter() {
383 $this->moveJsFromHeaderToFooter
= FALSE;
387 * Enables compression of javascript
392 public function enableCompressJavascript() {
393 $this->compressJavascript
= TRUE;
397 * Disables compression of javascript
402 public function disableCompressJavascript() {
403 $this->compressJavascript
= FALSE;
407 * Enables compression of css
412 public function enableCompressCss() {
413 $this->compressCss
= TRUE;
417 * Disables compression of css
422 public function disableCompressCss() {
423 $this->compressCss
= FALSE;
427 * Enables concatenation of js/css files
432 public function enableConcatenateFiles() {
433 $this->concatenateFiles
= TRUE;
437 * Disables concatenation of js/css files
442 public function disableConcatenateFiles() {
443 $this->concatenateFiles
= FALSE;
447 * Sets removal of all line breaks in template
452 public function enableRemoveLineBreaksFromTemplate() {
453 $this->removeLineBreaksFromTemplate
= TRUE;
457 * Unsets removal of all line breaks in template
462 public function disableRemoveLineBreaksFromTemplate() {
463 $this->removeLineBreaksFromTemplate
= FALSE;
468 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
473 public function enableDebugMode() {
474 $this->compressJavascript
= FALSE;
475 $this->compressCss
= FALSE;
476 $this->concatenateFiles
= FALSE;
477 $this->removeLineBreaksFromTemplate
= FALSE;
480 /*****************************************************/
485 /*****************************************************/
490 * @return string $title title of webpage
492 public function getTitle() {
499 * @return string $charSet
501 public function getCharSet() {
502 return $this->charSet
;
508 * @return string $lang
510 public function getLanguage() {
515 * Returns rendering mode XHTML or HTML
517 * @return boolean TRUE if XHTML, FALSE if HTML
519 public function getRenderXhtml() {
520 return $this->renderXhtml
;
526 * @return string $htmlTag html tag
528 public function getHtmlTag() {
529 return $this->htmlTag
;
535 * @return string $tag head tag
537 public function getHeadTag() {
538 return $this->headTag
;
544 * @return string $favIcon
546 public function getFavIcon() {
547 return $this->favIcon
;
551 * Gets icon mime type
553 * @return string $iconMimeType
555 public function getIconMimeType() {
556 return $this->iconMimeType
;
562 * @return string $url
564 public function getBaseUrl() {
565 return $this->baseUrl
;
571 * @return string $file
573 public function getTemplateFile($file) {
574 return $this->templateFile
;
578 * Gets MoveJsFromHeaderToFooter
582 public function getMoveJsFromHeaderToFooter() {
583 return $this->moveJsFromHeaderToFooter
;
587 * Gets compress of javascript
591 public function getCompressJavascript() {
592 return $this->compressJavascript
;
596 * Gets compress of css
600 public function getCompressCss() {
601 return $this->compressCss
;
605 * Gets concatenate of files
609 public function getConcatenateFiles() {
610 return $this->concatenateFiles
;
614 * Gets remove of empty lines from template
618 public function getRemoveLineBreaksFromTemplate() {
619 return $this->removeLineBreaksFromTemplate
;
623 * Gets content for body
627 public function getBodyContent() {
628 return $this->bodyContent
;
632 * Gets Path for prototype library (relative to typo3 directory)
636 public function getPrototypePath() {
637 return $this->prototypePath
;
641 * Gets Path for scriptaculous library (relative to typo3 directory)
645 public function getScriptaculousPath() {
646 return $this->scriptaculousPath
;
650 * Gets Path for Ext Core library (relative to typo3 directory)
654 public function getExtCorePath() {
655 return $this->extCorePath
;
659 * Gets Path for ExtJs library (relative to typo3 directory)
663 public function getExtJsPath() {
664 return $this->extJsPath
;
667 /*****************************************************/
669 /* Public Function to add Data */
672 /*****************************************************/
677 * @param string $meta meta data (complete metatag)
680 public function addMetaTag($meta) {
681 if (!in_array($meta, $this->metaTags
)) {
682 $this->metaTags
[] = $meta;
687 * Adds inline HTML comment
689 * @param string $comment
692 public function addInlineComment($comment) {
693 if (!in_array($comment, $this->inlineComments
)) {
694 $this->inlineComments
[] = $comment;
701 * @param string $data free header data for HTML header
704 public function addHeaderData($data) {
705 if (!in_array($data, $this->headerData
)) {
706 $this->headerData
[] = $data;
713 * @param string $data free header data for HTML header
716 public function addFooterData($data) {
717 if (!in_array($data, $this->footerData
)) {
718 $this->footerData
[] = $data;
722 /* Javascript Files */
725 * Adds JS Library. JS Library block is rendered on top of the JS files.
727 * @param string $name
728 * @param string $file
729 * @param string $type
730 * @param boolean $compress flag if library should be compressed
731 * @param boolean $forceOnTop flag if added library should be inserted at begin of this block
732 * @param string $allWrap
735 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '') {
736 if (!in_array(strtolower($name), $this->jsLibs
)) {
737 $this->jsLibs
[strtolower($name)] = array (
740 'section' => self
::PART_HEADER
,
741 'compress' => $compress,
742 'forceOnTop' => $forceOnTop,
743 'allWrap' => $allWrap
750 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
752 * @param string $name
753 * @param string $file
754 * @param string $type
755 * @param boolean $compress flag if library should be compressed
756 * @param boolean $forceOnTop flag if added library should be inserted at begin of this block
757 * @param string $allWrap
760 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '') {
761 if (!in_array(strtolower($name), $this->jsLibs
)) {
762 $this->jsLibs
[strtolower($name)] = array (
765 'section' => self
::PART_FOOTER
,
766 'compress' => $compress,
767 'forceOnTop' => $forceOnTop,
768 'allWrap' => $allWrap
777 * @param string $file
778 * @param string $type
779 * @param boolean $compress
780 * @param boolean $forceOnTop
781 * @param string $allWrap
784 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
785 if (!isset($this->jsFiles
[$file])) {
786 $this->jsFiles
[$file] = array (
788 'section' => self
::PART_HEADER
,
789 'compress' => $compress,
790 'forceOnTop' => $forceOnTop,
791 'allWrap' => $allWrap
797 * Adds JS file to footer
799 * @param string $file
800 * @param string $type
801 * @param boolean $compress
802 * @param boolean $forceOnTop
805 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
806 if (!isset($this->jsFiles
[$file])) {
807 $this->jsFiles
[$file] = array (
809 'section' => self
::PART_FOOTER
,
810 'compress' => $compress,
811 'forceOnTop' => $forceOnTop,
812 'allWrap' => $allWrap
817 /*Javascript Inline Blocks */
820 * Adds JS inline code
822 * @param string $name
823 * @param string $block
824 * @param boolean $compress
825 * @param boolean $forceOnTop
828 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
829 if (!isset($this->jsInline
[$name]) && !empty($block)) {
830 $this->jsInline
[$name] = array (
831 'code' => $block . LF
,
832 'section' => self
::PART_HEADER
,
833 'compress' => $compress,
834 'forceOnTop' => $forceOnTop
840 * Adds JS inline code to footer
842 * @param string $name
843 * @param string $block
844 * @param boolean $compress
845 * @param boolean $forceOnTop
848 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
849 if (!isset($this->jsInline
[$name]) && !empty($block)) {
850 $this->jsInline
[$name] = array (
851 'code' => $block . LF
,
852 'section' => self
::PART_FOOTER
,
853 'compress' => $compress,
854 'forceOnTop' => $forceOnTop
860 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
862 * @param string $block javascript code
863 * @param boolean $forceOnTop position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
866 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
867 if (!in_array($block, $this->extOnReadyCode
)) {
869 array_unshift($this->extOnReadyCode
, $block);
871 $this->extOnReadyCode
[] = $block;
881 * @param string $file
883 * @param string $media
884 * @param string $title
885 * @param boolean $compress
886 * @param boolean $forceOnTop
889 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
890 if (!isset($this->cssFiles
[$file])) {
891 $this->cssFiles
[$file] = array (
895 'compress' => $compress,
896 'forceOnTop' => $forceOnTop,
897 'allWrap' => $allWrap
902 /*CSS Inline Blocks */
905 * Adds CSS inline code
907 * @param string $name
908 * @param string $block
909 * @param boolean $compress
910 * @param boolean $forceOnTop
913 public function addCssInlineBlock($name, $block, $compressed = FALSE, $forceOnTop = FALSE) {
914 if (!isset($this->cssInline
[$name]) && !empty($block)) {
915 $this->cssInline
[$name] = array (
917 'compress' => $compress,
918 'forceOnTop' => $forceOnTop
926 * call function if you need the prototype library
930 public function loadPrototype() {
931 $this->addPrototype
= TRUE;
935 * call function if you need the Scriptaculous library
937 * @param string $modules add modules you need. use "all" if you need complete modules
940 public function loadScriptaculous($modules = 'all') {
941 // Scriptaculous require prototype, so load prototype too.
942 $this->addPrototype
= TRUE;
943 $this->addScriptaculous
= TRUE;
945 if ($modules == 'all') {
946 foreach ($this->addScriptaculousModules
as $key => $value) {
947 $this->addScriptaculousModules
[$key] = TRUE;
950 $mods = t3lib_div
::trimExplode(',', $modules);
951 foreach ($mods as $mod) {
952 if (isset($this->addScriptaculousModules
[strtolower($mod)])) {
953 $this->addScriptaculousModules
[strtolower($mod)] = TRUE;
961 * call this function if you need the extJS library
963 * @param boolean $css flag, if set the ext-css will be loaded
964 * @param boolean $theme flag, if set the ext-theme "grey" will be loaded
965 * @param string $adapter choose alternative adapter, possible values: yui, prototype, jquery
968 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
970 // empty $adapter will always load the ext adapter
971 switch (t3lib_div
::strtolower(trim($adapter))) {
972 case self
::EXTJS_ADAPTER_YUI
:
973 $this->extJSadapter
= 'yui/ext-yui-adapter.js';
975 case self
::EXTJS_ADAPTER_PROTOTYPE
:
976 $this->extJSadapter
= 'prototype/ext-prototype-adapter.js';
978 case self
::EXTJS_ADAPTER_JQUERY
:
979 $this->extJSadapter
= 'jquery/ext-jquery-adapter.js';
983 $this->addExtJS
= TRUE;
984 $this->extJStheme
= $theme;
985 $this->extJScss
= $css;
990 * Enables ExtJs QuickTips
996 public function enableExtJSQuickTips() {
997 $this->enableExtJSQuickTips
= TRUE;
1002 * call function if you need the ExtCore library
1006 public function loadExtCore() {
1007 $this->addExtCore
= TRUE;
1011 * call this function to load debug version of ExtJS. Use this for development only
1014 public function enableExtJsDebug() {
1015 $this->enableExtJsDebug
= TRUE;
1019 * call this function to load debug version of ExtCore. Use this for development only
1023 public function enableExtCoreDebug() {
1024 $this->enableExtCoreDebug
= TRUE;
1028 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1029 * The label can be used in scripts with TYPO3.lang.<key>
1032 * @param string $key
1033 * @param string $value
1036 public function addInlineLanguageLabel($key, $value) {
1037 $this->inlineLanguageLabels
[$key] = $value;
1041 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1042 * The label can be used in scripts with TYPO3.lang.<key>
1043 * Array will be merged with existing array.
1046 * @param array $array
1049 public function addInlineLanguageLabelArray(array $array) {
1050 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $array);
1054 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1055 * The label can be used in scripts with TYPO3.setting.<key>
1058 * @param string $namespace
1059 * @param string $key
1060 * @param string $value
1063 public function addInlineSetting($namespace, $key, $value) {
1065 if (strpos($namespace, '.')) {
1066 $parts = explode('.', $namespace);
1067 $a = &$this->inlineSettings
;
1068 foreach ($parts as $part) {
1073 $this->inlineSettings
[$namespace][$key] = $value;
1076 $this->inlineSettings
[$key] = $value;
1081 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1082 * The label can be used in scripts with TYPO3.setting.<key>
1083 * Array will be merged with existing array.
1086 * @param string $namespace
1087 * @param array $array
1090 public function addInlineSettingArray($namespace, array $array) {
1092 if (strpos($namespace, '.')) {
1093 $parts = explode('.', $namespace);
1094 $a = &$this->inlineSettings
;
1095 foreach ($parts as $part) {
1098 $a = array_merge((array) $a, $array);
1100 $this->inlineSettings
[$namespace] = array_merge((array) $this->inlineSettings
[$namespace], $array);
1103 $this->inlineSettings
= array_merge($this->inlineSettings
, $array);
1108 * Adds content to body content
1110 * @param string $content
1113 public function addBodyContent($content) {
1114 $this->bodyContent
.= $content;
1117 /*****************************************************/
1119 /* Render Functions */
1122 /*****************************************************/
1125 * render the section (Header or Footer)
1127 * @param int $part section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1128 * @return string content of rendered section
1130 public function render($part = self
::PART_COMPLETE
) {
1136 $jsFooterInline = '';
1138 $jsFooterFiles = '';
1141 // preRenderHook for possible manuipulation
1142 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
1144 'jsLibs' => &$this->jsLibs
,
1145 'jsFiles' => &$this->jsFiles
,
1146 'jsFooterFiles' => &$this->jsFooterFiles
,
1147 'cssFiles' => &$this->cssFiles
,
1148 'headerData' => &$this->headerData
,
1149 'footerData' => &$this->footerData
,
1150 'jsInline' => &$this->jsInline
,
1151 'cssInline' => &$this->cssInline
,
1153 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
1154 t3lib_div
::callUserFunction($hook, $params, $this);
1158 $jsLibs = $this->renderJsLibraries();
1160 if ($this->concatenateFiles
) {
1161 // do the file concatenation
1162 $this->doConcatenate();
1164 if ($this->compressCss ||
$this->compressJavascript
) {
1165 // do the file compression
1166 $this->doCompress();
1169 $metaTags = implode(LF
, $this->metaTags
);
1171 // remove ending slashes from static header block
1172 // if the page is beeing rendered as html (not xhtml)
1173 // and define variable $endingSlash for further use
1174 if ($this->getRenderXhtml()) {
1175 $endingSlash = ' /';
1177 $this->metaCharsetTag
= str_replace(' />', '>', $this->metaCharsetTag
);
1178 $this->baseUrlTag
= str_replace(' />', '>', $this->baseUrlTag
);
1179 $this->shortcutTag
= str_replace(' />', '>', $this->shortcutTag
);
1183 if (count($this->cssFiles
)) {
1184 foreach ($this->cssFiles
as $file => $properties) {
1185 $file = t3lib_div
::resolveBackPath($file);
1186 $file = t3lib_div
::createVersionNumberedFilename($file);
1187 $tag = '<link rel="' . $properties['rel'] . '" type="text/css" href="' .
1188 htmlspecialchars($file) . '" media="' . $properties['media'] . '"' .
1189 ($properties['title'] ?
' title="' . $properties['title'] . '"' : '') .
1191 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1192 $tag = str_replace('|', $tag, $properties['allWrap']);
1194 if ($properties['forceOnTop']) {
1195 $cssFiles = $tag . LF
. $cssFiles;
1197 $cssFiles .= LF
. $tag;
1202 if (count($this->cssInline
)) {
1203 foreach ($this->cssInline
as $name => $properties) {
1204 if ($properties['forceOnTop']) {
1205 $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
. $cssInline;
1207 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
1210 $cssInline = $this->inlineCssWrap
[0] . $cssInline . $this->inlineCssWrap
[1];
1213 if (count($this->jsLibs
)) {
1214 foreach ($this->jsLibs
as $name => $properties) {
1215 $properties['file'] = t3lib_div
::resolveBackPath($properties['file']);
1216 $properties['file'] = t3lib_div
::createVersionNumberedFilename($properties['file']);
1217 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . $properties['type'] . '"></script>';
1218 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1219 $tag = str_replace('|', $tag, $properties['allWrap']);
1221 if ($properties['forceOnTop']) {
1222 if ($properties['section'] === self
::PART_HEADER
) {
1223 $jsLibs = $tag . LF
. $jsLibs;
1225 $jsFooterLibs = $tag . LF
. $jsFooterLibs;
1228 if ($properties['section'] === self
::PART_HEADER
) {
1229 $jsLibs .= LF
. $tag;
1231 $jsFooterLibs .= LF
. $tag;
1237 if (count($this->jsFiles
)) {
1238 foreach ($this->jsFiles
as $file => $properties) {
1239 $file = t3lib_div
::resolveBackPath($file);
1240 $file = t3lib_div
::createVersionNumberedFilename($file);
1241 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . $properties['type'] . '"></script>';
1242 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1243 $tag = str_replace('|', $tag, $properties['allWrap']);
1245 if ($properties['forceOnTop']) {
1246 if ($properties['section'] === self
::PART_HEADER
) {
1247 $jsFiles = $tag . LF
. $jsFiles;
1249 $jsFooterFiles = $tag . LF
. $jsFooterFiles;
1252 if ($properties['section'] === self
::PART_HEADER
) {
1253 $jsFiles .= LF
. $tag;
1255 $jsFooterFiles .= LF
. $tag;
1261 if (count($this->jsInline
)) {
1262 foreach ($this->jsInline
as $name => $properties) {
1263 if ($properties['forceOnTop']) {
1264 if ($properties['section'] === self
::PART_HEADER
) {
1265 $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
. $jsInline;
1267 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
. $jsFooterInline;
1270 if ($properties['section'] === self
::PART_HEADER
) {
1271 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
1273 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
1281 $jsInline = $this->inlineJavascriptWrap
[0] . $jsInline . $this->inlineJavascriptWrap
[1];
1284 if ($jsFooterInline) {
1285 $jsFooterInline = $this->inlineJavascriptWrap
[0] . $jsFooterInline . $this->inlineJavascriptWrap
[1];
1290 $templateFile = t3lib_div
::getFileAbsFileName($this->templateFile
, TRUE);
1291 $template = t3lib_div
::getURL($templateFile);
1293 if ($this->removeEmptyLinesFromTemplate
) {
1294 $template = strtr($template, array(LF
=> '', CR
=> ''));
1296 if ($part != self
::PART_COMPLETE
) {
1297 $templatePart = explode('###BODY###', $template);
1298 $template = $templatePart[$part - 1];
1301 if ($this->moveJsFromHeaderToFooter
) {
1302 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
1304 $jsFooterFiles = $jsFiles . LF
. $jsFooterFiles;
1306 $jsFooterInline = $jsInline . LF
. $jsFooterInline;
1310 $markerArray = array(
1311 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1312 'HTMLTAG' => $this->htmlTag
,
1313 'HEADTAG' => $this->headTag
,
1314 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1315 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
1316 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1317 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1318 'CSS_INCLUDE' => $cssFiles,
1319 'CSS_INLINE' => $cssInline,
1320 'JS_INLINE' => $jsInline,
1321 'JS_INCLUDE' => $jsFiles,
1322 'JS_LIBS' => $jsLibs,
1323 'TITLE' => $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '',
1324 'META' => $metaTags,
1325 'HEADERDATA' => $this->headerData ?
implode(LF
, $this->headerData
) : '',
1326 'FOOTERDATA' => $this->footerData ?
implode(LF
, $this->footerData
) : '',
1327 'JS_LIBS_FOOTER' => $jsFooterLibs,
1328 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1329 'JS_INLINE_FOOTER' => $jsFooterInline,
1330 'BODY' => $this->bodyContent
,
1333 $markerArray = array_map('trim', $markerArray);
1336 return trim(t3lib_parsehtml
::substituteMarkerArray($template, $markerArray, '###|###'));
1340 * helper function for render the javascript libraries
1342 * @return string content with javascript libraries
1344 protected function renderJsLibraries() {
1347 if ($this->addPrototype
) {
1348 $out .= '<script src="' . $this->processJsFile($this->backPath
. $this->prototypePath
. 'prototype.js') .
1349 '" type="text/javascript"></script>' . LF
;
1350 unset($this->jsFiles
[$this->backPath
. $this->prototypePath
.'prototype.js']);
1353 if ($this->addScriptaculous
) {
1355 foreach ($this->addScriptaculousModules
as $key => $value) {
1356 if ($this->addScriptaculousModules
[$key]) {
1360 // resolve dependencies
1361 if (in_array('dragdrop', $mods) ||
in_array('controls', $mods)) {
1362 $mods = array_merge(array('effects'), $mods);
1366 foreach ($mods as $module) {
1367 $out .= '<script src="' . $this->processJsFile($this->backPath
.
1368 $this->scriptaculousPath
. $module . '.js') . '" type="text/javascript"></script>' . LF
;
1369 unset($this->jsFiles
[$this->backPath
. $this->scriptaculousPath
. $module . '.js']);
1372 $out .= '<script src="' . $this->processJsFile($this->backPath
. $this->scriptaculousPath
.
1373 'scriptaculous.js') . '" type="text/javascript"></script>' . LF
;
1374 unset($this->jsFiles
[$this->backPath
. $this->scriptaculousPath
. 'scriptaculous.js']);
1378 if ($this->addExtCore
) {
1379 $out .= '<script src="' . $this->processJsFile($this->backPath
.
1380 $this->extCorePath
. 'ext-core' . ($this->enableExtCoreDebug ?
'-debug' : '') . '.js') .
1381 '" type="text/javascript"></script>' . LF
;
1382 unset($this->jsFiles
[$this->backPath
. $this->extCorePath
. 'ext-core' . ($this->enableExtCoreDebug ?
'-debug' : '') . '.js']);
1386 if ($this->addExtJS
) {
1387 // use the base adapter all the time
1388 $out .= '<script src="' . $this->processJsFile($this->backPath
. $this->extJsPath
.
1389 'adapter/' . ($this->enableExtJsDebug ?
1390 str_replace('.js', '-debug.js', $this->extJSadapter
) : $this->extJSadapter
)) .
1391 '" type="text/javascript"></script>' . LF
;
1392 $out .= '<script src="' . $this->processJsFile($this->backPath
. $this->extJsPath
.
1393 'ext-all' . ($this->enableExtJsDebug ?
'-debug' : '') . '.js') .
1394 '" type="text/javascript"></script>' . LF
;
1396 // add extJS localization
1397 $localeMap = $this->csConvObj
->isoArray
; // load standard ISO mapping and modify for use with ExtJS
1398 $localeMap[''] = 'en';
1399 $localeMap['default'] = 'en';
1400 $localeMap['gr'] = 'el_GR'; // Greek
1401 $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
1402 $localeMap['se'] = 'se_SV'; // Swedish
1405 $extJsLang = isset($localeMap[$this->lang
]) ?
$localeMap[$this->lang
] : $this->lang
;
1406 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1407 $extJsLocaleFile = $this->extJsPath
. 'locale/ext-lang-' . $extJsLang . '.js';
1408 if (file_exists(PATH_typo3
. $extJsLocaleFile)) {
1409 $out .= '<script src="' . $this->processJsFile($this->backPath
.
1410 $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF
;
1414 // remove extjs from JScodeLibArray
1416 $this->jsFiles
[$this->backPath
. $this->extJsPath
. 'ext-all.js'],
1417 $this->jsFiles
[$this->backPath
. $this->extJsPath
. 'ext-all-debug.js']
1421 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
1422 if ($this->getCharSet() !== 'utf-8') {
1423 if ($this->inlineLanguageLabels
) {
1424 $this->csConvObj
->convArray($this->inlineLanguageLabels
, $this->getCharSet(), 'utf-8');
1426 if ($this->inlineSettings
) {
1427 $this->csConvObj
->convArray($this->inlineSettings
, $this->getCharSet(), 'utf-8');
1431 $inlineSettings = $this->inlineLanguageLabels ?
'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels
) . ';' : '';
1432 $inlineSettings .= $this->inlineSettings ?
'TYPO3.settings = ' . json_encode($this->inlineSettings
) . ';' : '';
1434 if ($this->addExtCore ||
$this->addExtJS
) {
1435 // set clear.gif, move it on top, add handler code
1437 if (count($this->extOnReadyCode
)) {
1438 foreach ($this->extOnReadyCode
as $block) {
1443 $out .= $this->inlineJavascriptWrap
[0] . '
1445 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div
::locationHeaderUrl($this->backPath
. 'gfx/clear.gif')) . '";' . LF
.
1447 'Ext.onReady(function() {' .
1448 ($this->enableExtJSQuickTips ?
'Ext.QuickTips.init();' . LF
: '') . $code .
1449 ' });' . $this->inlineJavascriptWrap
[1];
1450 unset ($this->extOnReadyCode
);
1452 if ($this->extJStheme
) {
1453 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1454 $this->addCssFile($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
1456 $this->addCssFile($this->backPath
. $this->extJsPath
. 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
1459 if ($this->extJScss
) {
1460 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1461 $this->addCssFile($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
1463 $this->addCssFile($this->backPath
. $this->extJsPath
. 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
1467 if ($inlineSettings) {
1468 $out .= $this->inlineJavascriptWrap
[0] . $inlineSettings . $this->inlineJavascriptWrap
[1];
1475 /*****************************************************/
1480 /*****************************************************/
1483 * concatenate files into one file
1484 * registered handler
1488 protected function doConcatenate() {
1489 // traverse the arrays, concatenate in one file
1490 // then remove concatenated files from array and add the concatenated file
1492 if ($this->concatenateFiles
) {
1494 'jsLibs' => &$this->jsLibs
,
1495 'jsFiles' => &$this->jsFiles
,
1496 'jsFooterFiles' => &$this->jsFooterFiles
,
1497 'cssFiles' => &$this->cssFiles
,
1498 'headerData' => &$this->headerData
,
1499 'footerData' => &$this->footerData
,
1502 if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['concatenateHandler']) {
1503 // use extern concatenate routine
1504 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['concatenateHandler'], $params, $this);
1505 } elseif (TYPO3_MODE
=== 'BE') {
1506 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
1507 $this->cssFiles
= $this->getCompressor()->concatenateCssFiles($this->cssFiles
, $cssOptions);
1513 * compress inline code
1517 protected function doCompress() {
1519 if ($this->compressJavascript
&& $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler']) {
1520 // use extern compress routine
1522 'jsInline' => &$this->jsInline
,
1523 'jsFooterInline' => &$this->jsFooterInline
,
1524 'jsLibs' => &$this->jsLibs
,
1525 'jsFiles' => &$this->jsFiles
,
1526 'jsFooterFiles' => &$this->jsFooterFiles
,
1527 'headerData' => &$this->headerData
,
1528 'footerData' => &$this->footerData
,
1530 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'], $params, $this);
1532 // traverse the arrays, compress files
1533 $this->compressError
= '';
1535 if ($this->compressJavascript
) {
1536 if (count($this->jsInline
)) {
1537 foreach ($this->jsInline
as $name => $properties) {
1538 if ($properties['compress']) {
1540 $this->jsInline
[$name]['code'] = t3lib_div
::minifyJavaScript($properties['code'], $error);
1542 $this->compressError
.= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF
;
1547 if (TYPO3_MODE
=== 'BE') {
1548 $this->jsFiles
= $this->getCompressor()->compressJsFiles($this->jsFiles
);
1549 $this->jsFooterFiles
= $this->getCompressor()->compressJsFiles($this->jsFooterFiles
);
1553 if ($this->compressCss
) {
1554 // use extern compress routine
1556 'cssInline' => &$this->cssInline
,
1557 'cssFiles' => &$this->cssFiles
,
1558 'headerData' => &$this->headerData
,
1559 'footerData' => &$this->footerData
,
1562 if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler']) {
1563 // use extern concatenate routine
1564 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'], $params, $this);
1565 } elseif (TYPO3_MODE
=== 'BE') {
1566 $this->cssFiles
= $this->getCompressor()->compressCssFiles($this->cssFiles
);
1572 * Returns instance of t3lib_Compressor
1574 * @return t3lib_Compressor Instance of t3lib_Compressor
1576 protected function getCompressor() {
1577 if ($this->compressor
=== NULL) {
1578 $this->compressor
= t3lib_div
::makeInstance('t3lib_Compressor');
1580 return $this->compressor
;
1584 * Processes a Javascript file dependent on the current context
1586 * Adds the version number for Frontend, compresses the file for Backend
1588 * @param string $filename Filename
1589 * @return string new filename
1591 protected function processJsFile($filename) {
1592 switch (TYPO3_MODE
) {
1594 $filename = t3lib_div
::createVersionNumberedFilename($filename);
1597 if ($this->compressJavascript
) {
1598 $filename = $this->getCompressor()->compressJsFile($filename);
1606 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
1607 include_once ($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);