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">' . chr(10) . '/*<![CDATA[*/' . chr(10) . '<!-- ' . chr(10),
140 '// -->' . chr(10) . '/*]]>*/' . chr(10) . '</script>' . chr(10)
142 $this->inlineCssWrap
= array(
143 '<style type="text/css">' . chr(10) . '/*<![CDATA[*/' . chr(10) . '<!-- ' . chr(10),
144 '-->' . chr(10) . '/*]]>*/' . chr(10) . '</style>' . chr(10)
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 . chr(10),
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 . chr(10),
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
693 public function addExtOnReadyCode($block) {
694 if (!in_array($block, $this->extOnReadyCode
)) {
695 $this->extOnReadyCode
[] = $block;
704 * @param string $file
706 * @param string $media
707 * @param string $title
708 * @param boolean $compress
709 * @param boolean $forceOnTop
712 public function addCssFile($file, $rel = 'stylesheet', $media = 'screen', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
713 if (!isset($this->cssFiles
[$file])) {
714 $this->cssFiles
[$file] = array (
718 'compress' => $compress,
719 'forceOnTop' => $forceOnTop,
720 'allWrap' => $allWrap
725 /*CSS Inline Blocks */
728 * Adds CSS inline code
730 * @param string $name
731 * @param string $block
732 * @param boolean $compress
733 * @param boolean $forceOnTop
736 public function addCssInlineBlock($name, $block, $compressed = FALSE, $forceOnTop = FALSE) {
737 if (!isset($this->cssInline
[$name])) {
738 $this->cssInline
[$name] = array (
740 'compress' => $compress,
741 'forceOnTop' => $forceOnTop
749 * call function if you need the prototype library
753 public function loadPrototype() {
754 $this->addPrototype
= TRUE;
758 * call function if you need the Scriptaculous library
760 * @param string $modules add modules you need. use "all" if you need complete modules
763 public function loadScriptaculous($modules = '') {
764 // Scriptaculous require prototype, so load prototype too.
765 $this->addPrototype
= TRUE;
766 $this->addScriptaculous
= TRUE;
768 if ($modules == 'all') {
769 foreach ($this->addScriptaculousModules
as $key => $value) {
770 $this->addScriptaculousModules
[$key] = TRUE;
773 $mods = t3lib_div
::trimExplode(',', $modules);
774 foreach ($mods as $mod) {
775 if (isset($this->addScriptaculousModules
[strtolower($mod)])) {
776 $this->addScriptaculousModules
[strtolower($mod)] = TRUE;
784 * call this function if you need the extJS library
786 * @param boolean $css flag, if set the ext-css will be loaded
787 * @param boolean $theme flag, if set the ext-theme "grey" will be loaded
788 * @param string $adapter choose alternative adapter, possible values: yui, prototype, jquery
791 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
793 // empty $adapter will always load the ext adapter
794 switch (t3lib_div
::strtolower(trim($adapter))) {
795 case self
::EXTJS_ADAPTER_YUI
:
796 $this->extJSadapter
= 'yui/ext-yui-adapter.js';
798 case self
::EXTJS_ADAPTER_PROTOTYPE
:
799 $this->extJSadapter
= 'prototype/ext-prototype-adapter.js';
801 case self
::EXTJS_ADAPTER_JQUERY
:
802 $this->extJSadapter
= 'jquery/ext-jquery-adapter.js';
806 $this->addExtJS
= TRUE;
807 $this->extJStheme
= $theme;
808 $this->extJScss
= $css;
813 * Enables ExtJs QuickTips
819 public function enableExtJSQuickTips() {
820 $this->enableExtJSQuickTips
= TRUE;
825 * call function if you need the ExtCore library
829 public function loadExtCore() {
830 $this->addExtCore
= TRUE;
834 * call this function to load debug version of ExtJS. Use this for development only
837 public function enableExtJsDebug() {
838 $this->enableExtJsDebug
= TRUE;
842 * call this function to load debug version of ExtCore. Use this for development only
846 public function enableExtCoreDebug() {
847 $this->enableExtCoreDebug
= TRUE;
851 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
852 * The label can be used in scripts with TYPO3.lang.<key>
856 * @param string $value
859 public function addInlineLanguageLabel($key, $value) {
860 $this->inlineLanguageLabels
[$key] = $value;
864 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
865 * The label can be used in scripts with TYPO3.lang.<key>
866 * Array will be merged with existing array.
869 * @param array $array
872 public function addInlineLanguageLabelArray(array $array) {
873 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $array);
877 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
878 * The label can be used in scripts with TYPO3.setting.<key>
881 * @param string $namespace
883 * @param string $value
886 public function addInlineSetting($namespace, $key, $value) {
888 if (strpos($namespace, '.')) {
889 $parts = explode('.', $namespace);
890 $a = &$this->inlineSettings
;
891 foreach ($parts as $part) {
896 $this->inlineSettings
[$namespace][$key] = $value;
899 $this->inlineSettings
[$key] = $value;
904 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
905 * The label can be used in scripts with TYPO3.setting.<key>
906 * Array will be merged with existing array.
909 * @param string $namespace
910 * @param array $array
913 public function addInlineSettingArray($namespace, array $array) {
915 if (strpos($namespace, '.')) {
916 $parts = explode('.', $namespace);
917 $a = &$this->inlineSettings
;
918 foreach ($parts as $part) {
921 $a = array_merge((array) $a, $array);
923 $this->inlineSettings
[$namespace] = array_merge((array) $this->inlineSettings
[$namespace], $array);
926 $this->inlineSettings
= array_merge($this->inlineSettings
, $array);
931 * Adds content to body content
933 * @param string $content
936 public function addBodyContent($content) {
937 $this->bodyContent
.= $content;
940 /*****************************************************/
942 /* Render Functions */
945 /*****************************************************/
948 * render the section (Header or Footer)
950 * @param int $part section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
951 * @return string content of rendered section
953 public function render($part = self
::PART_COMPLETE
) {
959 $jsFooterInline = '';
964 $jsLibs = $this->renderJsLibraries();
966 // preRenderHook for possible manuipulation
967 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
969 'jsLibsCore' => &$jsLibs,
970 'jsLibs' => &$this->jsLibs
,
971 'jsFiles' => &$this->jsFiles
,
972 'jsFooterFiles' => &$this->jsFiles
,
973 'cssFiles' => &$this->cssFiles
,
974 'headerData' => &$this->headerData
,
975 'footerData' => &$this->footerData
,
976 'jsInline' => &$this->jsInline
,
977 'cssInline' => &$this->cssInline
,
979 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
980 t3lib_div
::callUserFunction($hook, $params, $this);
984 if ($this->compressCss ||
$this->compressJavascript
) {
985 // do the file compression
988 if ($this->concatenateFiles
) {
989 // do the file concatenation
990 $this->doConcatenate();
993 $metaTags = implode(chr(10), $this->metaTags
);
995 if (count($this->cssFiles
)) {
996 foreach ($this->cssFiles
as $file => $properties) {
997 $file = t3lib_div
::resolveBackPath($file);
998 $tag = '<link rel="' . $properties['rel'] . '" type="text/css" href="' . $file . '" media="' . $properties['media'] . '"' . ($properties['title'] ?
' title="' . $properties['title'] . '"' : '') . ' />';
999 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1000 $tag = str_replace('|', $tag, $properties['allWrap']);
1002 if ($properties['forceOnTop']) {
1003 $cssFiles = $tag . chr(10) . $cssFiles;
1005 $cssFiles .= chr(10) . $tag;
1010 if (count($this->cssInline
)) {
1012 foreach ($this->cssInline
as $name => $properties) {
1013 if ($properties['forceOnTop']) {
1014 $cssInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $cssInline;
1016 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1019 $cssInline = $this->inlineCssWrap
[0] . $cssInline . $this->inlineCssWrap
[1];
1023 if (count($this->jsLibs
)) {
1024 foreach ($this->jsLibs
as $name => $properties) {
1025 $properties['file'] = t3lib_div
::resolveBackPath($properties['file']);
1026 $tag = '<script src="' . $properties['file'] . '" type="' . $properties['type'] . '"></script>';
1027 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1028 $tag = str_replace('|', $tag, $properties['allWrap']);
1030 if ($properties['forceOnTop']) {
1031 if ($properties['section'] === self
::PART_HEADER
) {
1032 $jsLibs = $tag . chr(10) . $jsLibs;
1034 $jsFooterLibs = $tag . chr(10) . $jsFooterLibs;
1037 if ($properties['section'] === self
::PART_HEADER
) {
1038 $jsLibs .= chr(10) . $tag;
1040 $jsFooterLibs .= chr(10) . $tag;
1047 if (count($this->jsFiles
)) {
1048 foreach ($this->jsFiles
as $file => $properties) {
1049 $file = t3lib_div
::resolveBackPath($file);
1050 $tag = '<script src="' . $file . '" type="' . $properties['type'] . '"></script>';
1051 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1052 $tag = str_replace('|', $tag, $properties['allWrap']);
1054 if ($properties['forceOnTop']) {
1055 if ($properties['section'] === self
::PART_HEADER
) {
1056 $jsFiles = $tag . chr(10) . $jsFiles;
1058 $jsFooterFiles = $tag . chr(10) . $jsFooterFiles;
1061 if ($properties['section'] === self
::PART_HEADER
) {
1062 $jsFiles .= chr(10) . $tag;
1064 $jsFooterFiles .= chr(10) . $tag;
1070 if (count($this->jsInline
)) {
1071 foreach ($this->jsInline
as $name => $properties) {
1072 if ($properties['forceOnTop']) {
1073 if ($properties['section'] === self
::PART_HEADER
) {
1074 $jsInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $jsInline;
1076 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $jsFooterInline;
1079 if ($properties['section'] === self
::PART_HEADER
) {
1080 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1082 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1090 $jsInline = $this->inlineJavascriptWrap
[0] . $jsInline . $this->inlineJavascriptWrap
[1];
1093 if ($jsFooterInline) {
1094 $jsFooterInline = $this->inlineJavascriptWrap
[0] . $jsFooterInline . $this->inlineJavascriptWrap
[1];
1099 $templateFile = t3lib_div
::getFileAbsFileName($this->templateFile
, TRUE);
1100 $template = t3lib_div
::getURL($templateFile);
1102 if ($this->removeEmptyLinesFromTemplate
) {
1103 $template = strtr($template, array(chr(10) => '', chr(13) => ''));
1105 if ($part != self
::PART_COMPLETE
) {
1106 $templatePart = explode('###BODY###', $template);
1107 $template = $templatePart[$part - 1];
1110 if ($this->moveJsFromHeaderToFooter
) {
1111 $jsFooterLibs = $jsLibs . chr(10) . $jsFooterLibs;
1113 $jsFooterFiles = $jsFiles . chr(10) . $jsFooterFiles;
1115 $jsFooterInline = $jsInline . chr(10) . $jsFooterInline;
1119 $markerArray = array(
1120 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1121 'HTMLTAG' => $this->htmlTag
,
1122 'HEADTAG' => $this->headTag
,
1123 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1124 'INLINECOMMENT' => $this->inlineComments ?
chr(10) . chr(10) . '<!-- ' . chr(10) . implode(chr(10), $this->inlineComments
) . '-->' . chr(10) . chr(10) : '',
1125 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1126 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1127 'CSS_INCLUDE' => $cssFiles,
1128 'CSS_INLINE' => $cssInline,
1129 'JS_INLINE' => $jsInline,
1130 'JS_INCLUDE' => $jsFiles,
1131 'JS_LIBS' => $jsLibs,
1132 'TITLE' => $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '',
1133 'META' => $metaTags,
1134 'HEADERDATA' => $this->headerData ?
implode(chr(10), $this->headerData
) : '',
1135 'FOOTERDATA' => $this->footerData ?
implode(chr(10), $this->footerData
) : '',
1136 'JS_LIBS_FOOTER' => $jsFooterLibs,
1137 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1138 'JS_INLINE_FOOTER' => $jsFooterInline,
1139 'BODY' => $this->bodyContent
,
1142 $markerArray = array_map('trim', $markerArray);
1145 return trim(t3lib_parsehtml
::substituteMarkerArray($template, $markerArray, '###|###'));
1149 * helper function for render the javascript libraries
1151 * @return string content with javascript libraries
1153 protected function renderJsLibraries() {
1156 if ($this->addPrototype
) {
1157 $out .= '<script src="' . $this->backPath
. 'contrib/prototype/prototype.js" type="text/javascript"></script>' . chr(10);
1158 unset($this->jsFiles
[$this->backPath
. 'contrib/prototype/prototype.js']);
1161 if ($this->addScriptaculous
) {
1163 foreach ($this->addScriptaculousModules
as $key => $value) {
1164 if ($this->addScriptaculousModules
[$key]) {
1168 // resolve dependencies
1169 if (in_array('dragdrop', $mods) ||
in_array('controls', $mods)) {
1170 $mods = array_merge(array('effects'), $mods);
1174 $moduleLoadString = '?load=' . implode(',', $mods);
1177 $out .= '<script src="' . $this->backPath
. 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString . '" type="text/javascript"></script>' . chr(10);
1178 unset($this->jsFiles
[$this->backPath
. 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString]);
1182 if ($this->addExtCore
) {
1183 $out .= '<script src="' . $this->backPath
. 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ?
'-debug' : '') . '.js" type="text/javascript"></script>' . chr(10);
1184 unset($this->jsFiles
[$this->backPath
. 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ?
'-debug' : '') . '.js']);
1188 if ($this->addExtJS
) {
1189 // use the base adapter all the time
1190 $out .= '<script src="' . $this->backPath
. 'contrib/extjs/adapter/' . $this->extJSadapter
. '" type="text/javascript"></script>' . chr(10);
1191 $out .= '<script src="' . $this->backPath
. 'contrib/extjs/ext-all' . ($this->enableExtJsDebug ?
'-debug' : '') . '.js" type="text/javascript"></script>' . chr(10);
1193 // add extJS localization
1194 $localeMap = $this->csConvObj
->isoArray
; // load standard ISO mapping and modify for use with ExtJS
1195 $localeMap[''] = 'en';
1196 $localeMap['default'] = 'en';
1197 $localeMap['gr'] = 'el_GR'; // Greek
1198 $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
1199 $localeMap['se'] = 'se_SV'; // Swedish
1202 $extJsLang = isset($localeMap[$this->lang
]) ?
$localeMap[$this->lang
] : $this->lang
;
1203 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1204 $extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '.js';
1205 if (file_exists(PATH_typo3
. $extJsLocaleFile)) {
1206 $out .= '<script src="' . $this->backPath
. $extJsLocaleFile . '" type="text/javascript" charset="utf-8"></script>' . chr(10);
1210 // remove extjs from JScodeLibArray
1212 $this->jsFiles
[$this->backPath
. 'contrib/extjs/ext-all.js'], $this->jsFiles
[$this->backPath
. 'contrib/extjs/ext-all-debug.js']
1216 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
1217 if ($this->getCharSet() !== 'utf-8') {
1218 if ($this->inlineLanguageLabels
) {
1219 $this->csConvObj
->convArray($this->inlineLanguageLabels
, $this->getCharSet(), 'utf-8');
1221 if ($this->inlineSettings
) {
1222 $this->csConvObj
->convArray($this->inlineSettings
, $this->getCharSet(), 'utf-8');
1226 $inlineSettings = $this->inlineLanguageLabels ?
'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels
) . ';' : '';
1227 $inlineSettings .= $this->inlineSettings ?
'TYPO3.settings = ' . json_encode($this->inlineSettings
) . ';' : '';
1229 if ($this->addExtCore ||
$this->addExtJS
) {
1230 // set clear.gif, move it on top, add handler code
1232 if (count($this->extOnReadyCode
)) {
1233 foreach ($this->extOnReadyCode
as $block) {
1238 $out .= $this->inlineJavascriptWrap
[0] . '
1240 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div
::locationHeaderUrl($this->backPath
. 'gfx/clear.gif')) . '";' . chr(10) .
1242 'Ext.onReady(function() {' .
1243 ($this->enableExtJSQuickTips ?
'Ext.QuickTips.init();' . chr(10) : '') . $code .
1244 ' });' . $this->inlineJavascriptWrap
[1];
1245 unset ($this->extOnReadyCode
);
1247 if ($this->extJStheme
) {
1248 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1249 $this->addCssFile($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'screen', '', FALSE, TRUE);
1251 $this->addCssFile($this->backPath
. 'contrib/extjs/resources/css/xtheme-blue.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1254 if ($this->extJScss
) {
1255 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1256 $this->addCssFile($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'screen', '', FALSE, TRUE);
1258 $this->addCssFile($this->backPath
. 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1262 if ($inlineSettings) {
1263 $out .= $this->inlineJavascriptWrap
[0] . $inlineSettings . $this->inlineJavascriptWrap
[1];
1270 /*****************************************************/
1275 /*****************************************************/
1278 * concatenate files into one file
1279 * registered handler
1280 * TODO: implement own method
1284 protected function doConcatenate() {
1285 // traverse the arrays, concatenate in one file
1286 // then remove concatenated files from array and add the concatenated file
1289 // extern concatination
1290 if ($this->concatenateFiles
&& $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['concatenateHandler']) {
1291 // use extern concatenate routine
1293 'jsLibs' => &$this->jsLibs
,
1294 'jsFiles' => &$this->jsFiles
,
1295 'jsFooterFiles' => &$this->jsFiles
,
1296 'cssFiles' => &$this->cssFiles
,
1297 'headerData' => &$this->headerData
,
1298 'footerData' => &$this->footerData
,
1300 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['concatenateHandler'], $params, $this);
1302 // own method, nothing implemented atm
1309 * compress inline code
1312 protected function doCompress() {
1314 if ($this->compressJavascript
&& $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler']) {
1315 // use extern compress routine
1317 'jsInline' => &$this->jsInline
,
1318 'jsFooterInline' => &$this->jsFooterInline
,
1319 'jsLibs' => &$this->jsLibs
,
1320 'jsFiles' => &$this->jsFiles
,
1321 'jsFooterFiles' => &$this->jsFiles
,
1322 'headerData' => &$this->headerData
,
1323 'footerData' => &$this->footerData
,
1325 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'], $params, $this);
1327 // traverse the arrays, compress files
1328 $this->compressError
= '';
1330 if ($this->compressJavascript
) {
1331 if (count($this->jsInline
)) {
1332 foreach ($this->jsInline
as $name => $properties) {
1333 if ($properties['compress']) {
1335 $this->jsInline
[$name]['code'] = t3lib_div
::minifyJavaScript($properties['code'], $error);
1337 $this->compressError
.= 'Error with minify JS Inline Block "' . $name . '": ' . $error . chr(10);
1345 if ($this->compressCss
&& $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler']) {
1346 // use extern compress routine
1348 'cssInline' => &$this->cssInline
,
1349 'cssFiles' => &$this->cssFiles
,
1350 'headerData' => &$this->headerData
,
1351 'footerData' => &$this->footerData
,
1353 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'], $params, $this);
1355 if ($this->compressCss
) {
1356 // own method, nothing implemented atm
1363 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
1364 include_once ($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);