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 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 = 'screen', $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 = '';
969 $jsLibs = $this->renderJsLibraries();
971 // preRenderHook for possible manuipulation
972 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
974 'jsLibsCore' => &$jsLibs,
975 'jsLibs' => &$this->jsLibs
,
976 'jsFiles' => &$this->jsFiles
,
977 'jsFooterFiles' => &$this->jsFiles
,
978 'cssFiles' => &$this->cssFiles
,
979 'headerData' => &$this->headerData
,
980 'footerData' => &$this->footerData
,
981 'jsInline' => &$this->jsInline
,
982 'cssInline' => &$this->cssInline
,
984 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
985 t3lib_div
::callUserFunction($hook, $params, $this);
989 if ($this->compressCss ||
$this->compressJavascript
) {
990 // do the file compression
993 if ($this->concatenateFiles
) {
994 // do the file concatenation
995 $this->doConcatenate();
998 $metaTags = implode(chr(10), $this->metaTags
);
1000 if (count($this->cssFiles
)) {
1001 foreach ($this->cssFiles
as $file => $properties) {
1002 $file = t3lib_div
::resolveBackPath($file);
1003 $tag = '<link rel="' . $properties['rel'] . '" type="text/css" href="' . $file . '" media="' . $properties['media'] . '"' . ($properties['title'] ?
' title="' . $properties['title'] . '"' : '') . ' />';
1004 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1005 $tag = str_replace('|', $tag, $properties['allWrap']);
1007 if ($properties['forceOnTop']) {
1008 $cssFiles = $tag . chr(10) . $cssFiles;
1010 $cssFiles .= chr(10) . $tag;
1015 if (count($this->cssInline
)) {
1017 foreach ($this->cssInline
as $name => $properties) {
1018 if ($properties['forceOnTop']) {
1019 $cssInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $cssInline;
1021 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1024 $cssInline = $this->inlineCssWrap
[0] . $cssInline . $this->inlineCssWrap
[1];
1028 if (count($this->jsLibs
)) {
1029 foreach ($this->jsLibs
as $name => $properties) {
1030 $properties['file'] = t3lib_div
::resolveBackPath($properties['file']);
1031 $tag = '<script src="' . $properties['file'] . '" type="' . $properties['type'] . '"></script>';
1032 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1033 $tag = str_replace('|', $tag, $properties['allWrap']);
1035 if ($properties['forceOnTop']) {
1036 if ($properties['section'] === self
::PART_HEADER
) {
1037 $jsLibs = $tag . chr(10) . $jsLibs;
1039 $jsFooterLibs = $tag . chr(10) . $jsFooterLibs;
1042 if ($properties['section'] === self
::PART_HEADER
) {
1043 $jsLibs .= chr(10) . $tag;
1045 $jsFooterLibs .= chr(10) . $tag;
1052 if (count($this->jsFiles
)) {
1053 foreach ($this->jsFiles
as $file => $properties) {
1054 $file = t3lib_div
::resolveBackPath($file);
1055 $tag = '<script src="' . $file . '" type="' . $properties['type'] . '"></script>';
1056 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1057 $tag = str_replace('|', $tag, $properties['allWrap']);
1059 if ($properties['forceOnTop']) {
1060 if ($properties['section'] === self
::PART_HEADER
) {
1061 $jsFiles = $tag . chr(10) . $jsFiles;
1063 $jsFooterFiles = $tag . chr(10) . $jsFooterFiles;
1066 if ($properties['section'] === self
::PART_HEADER
) {
1067 $jsFiles .= chr(10) . $tag;
1069 $jsFooterFiles .= chr(10) . $tag;
1075 if (count($this->jsInline
)) {
1076 foreach ($this->jsInline
as $name => $properties) {
1077 if ($properties['forceOnTop']) {
1078 if ($properties['section'] === self
::PART_HEADER
) {
1079 $jsInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $jsInline;
1081 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10) . $jsFooterInline;
1084 if ($properties['section'] === self
::PART_HEADER
) {
1085 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1087 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . chr(10) . $properties['code'] . chr(10);
1095 $jsInline = $this->inlineJavascriptWrap
[0] . $jsInline . $this->inlineJavascriptWrap
[1];
1098 if ($jsFooterInline) {
1099 $jsFooterInline = $this->inlineJavascriptWrap
[0] . $jsFooterInline . $this->inlineJavascriptWrap
[1];
1104 $templateFile = t3lib_div
::getFileAbsFileName($this->templateFile
, TRUE);
1105 $template = t3lib_div
::getURL($templateFile);
1107 if ($this->removeEmptyLinesFromTemplate
) {
1108 $template = strtr($template, array(chr(10) => '', chr(13) => ''));
1110 if ($part != self
::PART_COMPLETE
) {
1111 $templatePart = explode('###BODY###', $template);
1112 $template = $templatePart[$part - 1];
1115 if ($this->moveJsFromHeaderToFooter
) {
1116 $jsFooterLibs = $jsLibs . chr(10) . $jsFooterLibs;
1118 $jsFooterFiles = $jsFiles . chr(10) . $jsFooterFiles;
1120 $jsFooterInline = $jsInline . chr(10) . $jsFooterInline;
1124 $markerArray = array(
1125 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1126 'HTMLTAG' => $this->htmlTag
,
1127 'HEADTAG' => $this->headTag
,
1128 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1129 'INLINECOMMENT' => $this->inlineComments ?
chr(10) . chr(10) . '<!-- ' . chr(10) . implode(chr(10), $this->inlineComments
) . '-->' . chr(10) . chr(10) : '',
1130 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1131 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1132 'CSS_INCLUDE' => $cssFiles,
1133 'CSS_INLINE' => $cssInline,
1134 'JS_INLINE' => $jsInline,
1135 'JS_INCLUDE' => $jsFiles,
1136 'JS_LIBS' => $jsLibs,
1137 'TITLE' => $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '',
1138 'META' => $metaTags,
1139 'HEADERDATA' => $this->headerData ?
implode(chr(10), $this->headerData
) : '',
1140 'FOOTERDATA' => $this->footerData ?
implode(chr(10), $this->footerData
) : '',
1141 'JS_LIBS_FOOTER' => $jsFooterLibs,
1142 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1143 'JS_INLINE_FOOTER' => $jsFooterInline,
1144 'BODY' => $this->bodyContent
,
1147 $markerArray = array_map('trim', $markerArray);
1150 return trim(t3lib_parsehtml
::substituteMarkerArray($template, $markerArray, '###|###'));
1154 * helper function for render the javascript libraries
1156 * @return string content with javascript libraries
1158 protected function renderJsLibraries() {
1161 if ($this->addPrototype
) {
1162 $out .= '<script src="' . $this->backPath
. 'contrib/prototype/prototype.js" type="text/javascript"></script>' . chr(10);
1163 unset($this->jsFiles
[$this->backPath
. 'contrib/prototype/prototype.js']);
1166 if ($this->addScriptaculous
) {
1168 foreach ($this->addScriptaculousModules
as $key => $value) {
1169 if ($this->addScriptaculousModules
[$key]) {
1173 // resolve dependencies
1174 if (in_array('dragdrop', $mods) ||
in_array('controls', $mods)) {
1175 $mods = array_merge(array('effects'), $mods);
1179 $moduleLoadString = '?load=' . implode(',', $mods);
1182 $out .= '<script src="' . $this->backPath
. 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString . '" type="text/javascript"></script>' . chr(10);
1183 unset($this->jsFiles
[$this->backPath
. 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString]);
1187 if ($this->addExtCore
) {
1188 $out .= '<script src="' . $this->backPath
. 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ?
'-debug' : '') . '.js" type="text/javascript"></script>' . chr(10);
1189 unset($this->jsFiles
[$this->backPath
. 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ?
'-debug' : '') . '.js']);
1193 if ($this->addExtJS
) {
1194 // use the base adapter all the time
1195 $out .= '<script src="' . $this->backPath
. 'contrib/extjs/adapter/' . $this->extJSadapter
. '" type="text/javascript"></script>' . chr(10);
1196 $out .= '<script src="' . $this->backPath
. 'contrib/extjs/ext-all' . ($this->enableExtJsDebug ?
'-debug' : '') . '.js" type="text/javascript"></script>' . chr(10);
1198 // add extJS localization
1199 $localeMap = $this->csConvObj
->isoArray
; // load standard ISO mapping and modify for use with ExtJS
1200 $localeMap[''] = 'en';
1201 $localeMap['default'] = 'en';
1202 $localeMap['gr'] = 'el_GR'; // Greek
1203 $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
1204 $localeMap['se'] = 'se_SV'; // Swedish
1207 $extJsLang = isset($localeMap[$this->lang
]) ?
$localeMap[$this->lang
] : $this->lang
;
1208 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1209 $extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '.js';
1210 if (file_exists(PATH_typo3
. $extJsLocaleFile)) {
1211 $out .= '<script src="' . $this->backPath
. $extJsLocaleFile . '" type="text/javascript" charset="utf-8"></script>' . chr(10);
1215 // remove extjs from JScodeLibArray
1217 $this->jsFiles
[$this->backPath
. 'contrib/extjs/ext-all.js'], $this->jsFiles
[$this->backPath
. 'contrib/extjs/ext-all-debug.js']
1221 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
1222 if ($this->getCharSet() !== 'utf-8') {
1223 if ($this->inlineLanguageLabels
) {
1224 $this->csConvObj
->convArray($this->inlineLanguageLabels
, $this->getCharSet(), 'utf-8');
1226 if ($this->inlineSettings
) {
1227 $this->csConvObj
->convArray($this->inlineSettings
, $this->getCharSet(), 'utf-8');
1231 $inlineSettings = $this->inlineLanguageLabels ?
'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels
) . ';' : '';
1232 $inlineSettings .= $this->inlineSettings ?
'TYPO3.settings = ' . json_encode($this->inlineSettings
) . ';' : '';
1234 if ($this->addExtCore ||
$this->addExtJS
) {
1235 // set clear.gif, move it on top, add handler code
1237 if (count($this->extOnReadyCode
)) {
1238 foreach ($this->extOnReadyCode
as $block) {
1243 $out .= $this->inlineJavascriptWrap
[0] . '
1245 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div
::locationHeaderUrl($this->backPath
. 'gfx/clear.gif')) . '";' . chr(10) .
1247 'Ext.onReady(function() {' .
1248 ($this->enableExtJSQuickTips ?
'Ext.QuickTips.init();' . chr(10) : '') . $code .
1249 ' });' . $this->inlineJavascriptWrap
[1];
1250 unset ($this->extOnReadyCode
);
1252 if ($this->extJStheme
) {
1253 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1254 $this->addCssFile($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'screen', '', FALSE, TRUE);
1256 $this->addCssFile($this->backPath
. 'contrib/extjs/resources/css/xtheme-blue.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1259 if ($this->extJScss
) {
1260 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1261 $this->addCssFile($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'screen', '', FALSE, TRUE);
1263 $this->addCssFile($this->backPath
. 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1267 if ($inlineSettings) {
1268 $out .= $this->inlineJavascriptWrap
[0] . $inlineSettings . $this->inlineJavascriptWrap
[1];
1275 /*****************************************************/
1280 /*****************************************************/
1283 * concatenate files into one file
1284 * registered handler
1285 * TODO: implement own method
1289 protected function doConcatenate() {
1290 // traverse the arrays, concatenate in one file
1291 // then remove concatenated files from array and add the concatenated file
1294 // extern concatination
1295 if ($this->concatenateFiles
&& $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['concatenateHandler']) {
1296 // use extern concatenate routine
1298 'jsLibs' => &$this->jsLibs
,
1299 'jsFiles' => &$this->jsFiles
,
1300 'jsFooterFiles' => &$this->jsFiles
,
1301 'cssFiles' => &$this->cssFiles
,
1302 'headerData' => &$this->headerData
,
1303 'footerData' => &$this->footerData
,
1305 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['concatenateHandler'], $params, $this);
1307 // own method, nothing implemented atm
1314 * compress inline code
1317 protected function doCompress() {
1319 if ($this->compressJavascript
&& $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler']) {
1320 // use extern compress routine
1322 'jsInline' => &$this->jsInline
,
1323 'jsFooterInline' => &$this->jsFooterInline
,
1324 'jsLibs' => &$this->jsLibs
,
1325 'jsFiles' => &$this->jsFiles
,
1326 'jsFooterFiles' => &$this->jsFiles
,
1327 'headerData' => &$this->headerData
,
1328 'footerData' => &$this->footerData
,
1330 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'], $params, $this);
1332 // traverse the arrays, compress files
1333 $this->compressError
= '';
1335 if ($this->compressJavascript
) {
1336 if (count($this->jsInline
)) {
1337 foreach ($this->jsInline
as $name => $properties) {
1338 if ($properties['compress']) {
1340 $this->jsInline
[$name]['code'] = t3lib_div
::minifyJavaScript($properties['code'], $error);
1342 $this->compressError
.= 'Error with minify JS Inline Block "' . $name . '": ' . $error . chr(10);
1350 if ($this->compressCss
&& $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler']) {
1351 // use extern compress routine
1353 'cssInline' => &$this->cssInline
,
1354 'cssFiles' => &$this->cssFiles
,
1355 'headerData' => &$this->headerData
,
1356 'footerData' => &$this->footerData
,
1358 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'], $params, $this);
1360 if ($this->compressCss
) {
1361 // own method, nothing implemented atm
1368 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
1369 include_once ($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);