2 /***************************************************************
5 * (c) 2009-2011 Steffen Kamper <info@sk-typo3.de>
6 * (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
30 * TYPO3 pageRender class (new in TYPO3 4.3.0)
31 * This class render the HTML of a webpage, usable for BE and FE
33 * @author Steffen Kamper <info@sk-typo3.de>
34 * @author Kai Vogel <kai.vogel@speedprogs.de>
38 class t3lib_PageRenderer
implements t3lib_Singleton
{
39 // Constants for the part to be rendered
40 const PART_COMPLETE
= 0;
41 const PART_HEADER
= 1;
42 const PART_FOOTER
= 2;
44 // Available adapters for extJs
45 const EXTJS_ADAPTER_JQUERY
= 'jquery';
46 const EXTJS_ADAPTER_PROTOTYPE
= 'prototype';
47 const EXTJS_ADAPTER_YUI
= 'yui';
49 // jQuery Core version that is shipped with TYPO3
50 const JQUERY_VERSION_LATEST
= '1.8.0';
52 // jQuery namespace options
53 const JQUERY_NAMESPACE_NONE
= 'none';
54 const JQUERY_NAMESPACE_DEFAULT
= 'jQuery';
55 const JQUERY_NAMESPACE_DEFAULT_NOCONFLICT
= 'defaultNoConflict';
60 protected $compressJavascript = FALSE;
65 protected $compressCss = FALSE;
70 protected $removeLineBreaksFromTemplate = FALSE;
75 protected $concatenateFiles = FALSE;
80 protected $concatenateJavascript = FALSE;
85 protected $concatenateCss = FALSE;
90 protected $moveJsFromHeaderToFooter = FALSE;
98 * @var t3lib_l10n_Locales
104 * Two character string or 'default'
111 * @var t3lib_Compressor
113 protected $compressor;
115 // Arrays containing associative array for the included files
120 protected $jsFiles = array();
125 protected $jsFooterFiles = array();
130 protected $jsLibs = array();
135 protected $jsFooterLibs = array();
140 protected $cssFiles = array();
143 * The title of the page
150 * Charset for the rendering
169 protected $renderXhtml = TRUE;
172 // Static header blocks
177 protected $xmlPrologAndDocType = '';
182 protected $metaTags = array();
187 protected $inlineComments = array();
192 protected $headerData = array();
197 protected $footerData = array();
202 protected $titleTag = '<title>|</title>';
207 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
212 protected $htmlTag = '<html>';
217 protected $headTag = '<head>';
222 protected $baseUrlTag = '<base href="|" />';
227 protected $iconMimeType = '';
232 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />
233 <link rel="icon" href="%1$s"%2$s />';
235 // Static inline code blocks
240 protected $jsInline = array();
245 protected $jsFooterInline = array();
250 protected $extOnReadyCode = array();
255 protected $cssInline = array();
260 protected $bodyContent;
265 protected $templateFile;
270 protected $jsLibraryNames = array('prototype', 'scriptaculous', 'extjs');
272 // Paths to contibuted libraries
277 protected $prototypePath = 'contrib/prototype/';
282 protected $scriptaculousPath = 'contrib/scriptaculous/';
287 protected $extCorePath = 'contrib/extjs/';
292 protected $extJsPath = 'contrib/extjs/';
297 protected $svgPath = 'contrib/websvg/';
300 * The local directory where one can find jQuery versions and plugins
304 protected $jQueryPath = 'contrib/jquery/';
306 // Internal flags for JS-libraries
309 * This array holds all jQuery versions that should be included in the
311 * Each version is described by "source", "version" and "namespace"
313 * The namespace of every particular version is the key
314 * of that array, because only one version per namespace can exist.
316 * The type "source" describes where the jQuery core should be included from
317 * currently, TYPO3 supports "local" (make use of jQuery path), "google",
318 * "jquery" and "msn".
319 * Currently there are downsides to "local" and "jquery", as "local" only
320 * supports the latest/shipped jQuery core out of the box, and
321 * "jquery" does not have SSL support.
325 protected $jQueryVersions = array();
328 * Array of jQuery version numbers shipped with the core
332 protected $availableLocalJqueryVersions = array(
333 self
::JQUERY_VERSION_LATEST
,
337 * Array of jQuery CDNs with placeholders
341 protected $jQueryCdnUrls = array(
342 'google' => '//ajax.googleapis.com/ajax/libs/jquery/%1$s/jquery%2$s.js',
343 'msn' => '//ajax.aspnetcdn.com/ajax/jQuery/jquery-%1$s%2$s.js',
344 'jquery' => 'http://code.jquery.com/jquery-%1$s%2$s.js',
350 protected $addPrototype = FALSE;
355 protected $addScriptaculous = FALSE;
360 protected $addScriptaculousModules = array('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
365 protected $addExtJS = FALSE;
370 protected $addExtCore = FALSE;
375 protected $extJSadapter = 'ext/ext-base.js';
380 protected $extDirectCodeAdded = FALSE;
385 protected $enableExtJsDebug = FALSE;
390 protected $enableExtCoreDebug = FALSE;
395 protected $enableJqueryDebug = FALSE;
400 protected $extJStheme = TRUE;
405 protected $extJScss = TRUE;
410 protected $enableExtJSQuickTips = FALSE;
415 protected $inlineLanguageLabels = array();
420 protected $inlineLanguageLabelFiles = array();
425 protected $inlineSettings = array();
430 protected $inlineJavascriptWrap = array();
433 * Saves error messages generated during compression
437 protected $compressError = '';
440 * Is empty string for HTML and ' /' for XHTML rendering
444 protected $endingSlash = '';
451 protected $addSvg = FALSE;
456 protected $enableSvgDebug = FALSE;
466 * @param string $templateFile Declare the used template file. Omit this parameter will use default template
467 * @param string $backPath Relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
469 public function __construct($templateFile = '', $backPath = NULL) {
472 $this->csConvObj
= t3lib_div
::makeInstance('t3lib_cs');
473 $this->locales
= t3lib_div
::makeInstance('t3lib_l10n_Locales');
475 if (strlen($templateFile)) {
476 $this->templateFile
= $templateFile;
478 $this->backPath
= isset($backPath) ?
$backPath : $GLOBALS['BACK_PATH'];
480 $this->inlineJavascriptWrap
= array(
481 '<script type="text/javascript">' . LF
. '/*<![CDATA[*/' . LF
. '<!-- ' . LF
,
482 '// -->' . LF
. '/*]]>*/' . LF
. '</script>' . LF
484 $this->inlineCssWrap
= array(
485 '<style type="text/css">' . LF
. '/*<![CDATA[*/' . LF
. '<!-- ' . LF
,
486 '-->' . LF
. '/*]]>*/' . LF
. '</style>' . LF
491 * Reset all vars to initial values
495 protected function reset() {
496 $this->templateFile
= TYPO3_mainDir
. 'templates/template_page_backend.html';
497 $this->jsFiles
= array();
498 $this->jsFooterFiles
= array();
499 $this->jsInline
= array();
500 $this->jsFooterInline
= array();
501 $this->jsLibs
= array();
502 $this->cssFiles
= array();
503 $this->cssInline
= array();
504 $this->metaTags
= array();
505 $this->inlineComments
= array();
506 $this->headerData
= array();
507 $this->footerData
= array();
508 $this->extOnReadyCode
= array();
509 $this->jQueryVersions
= array();
512 /*****************************************************/
517 /*****************************************************/
522 * @param string $title title of webpage
525 public function setTitle($title) {
526 $this->title
= $title;
530 * Enables/disables rendering of XHTML code
532 * @param boolean $enable Enable XHTML
535 public function setRenderXhtml($enable) {
536 $this->renderXhtml
= $enable;
540 * Sets xml prolog and docType
542 * @param string $xmlPrologAndDocType Complete tags for xml prolog and docType
545 public function setXmlPrologAndDocType($xmlPrologAndDocType) {
546 $this->xmlPrologAndDocType
= $xmlPrologAndDocType;
552 * @param string $charSet Used charset
555 public function setCharSet($charSet) {
556 $this->charSet
= $charSet;
562 * @param string $lang Used language
565 public function setLanguage($lang) {
570 * Set the meta charset tag
572 * @param string $metaCharsetTag
575 public function setMetaCharsetTag($metaCharsetTag) {
576 $this->metaCharsetTag
= $metaCharsetTag;
582 * @param string $htmlTag Html tag
585 public function setHtmlTag($htmlTag) {
586 $this->htmlTag
= $htmlTag;
592 * @param string $headTag HTML head tag
595 public function setHeadTag($headTag) {
596 $this->headTag
= $headTag;
602 * @param string $favIcon
605 public function setFavIcon($favIcon) {
606 $this->favIcon
= $favIcon;
610 * Sets icon mime type
612 * @param string $iconMimeType
615 public function setIconMimeType($iconMimeType) {
616 $this->iconMimeType
= $iconMimeType;
622 * @param string $baseUrl HTML base URL
625 public function setBaseUrl($baseUrl) {
626 $this->baseUrl
= $baseUrl;
632 * @param string $file
635 public function setTemplateFile($file) {
636 $this->templateFile
= $file;
642 * @param string $backPath
645 public function setBackPath($backPath) {
646 $this->backPath
= $backPath;
650 * Sets Content for Body
652 * @param string $content
655 public function setBodyContent($content) {
656 $this->bodyContent
= $content;
660 * Sets path to prototype library (relative to typo3 directory)
662 * @param string $path Path to prototype library
665 public function setPrototypePath($path) {
666 $this->prototypePath
= $path;
670 * Sets Path for scriptaculous library (relative to typo3 directory)
672 * @param string $path
675 public function setScriptaculousPath($path) {
676 $this->scriptaculousPath
= $path;
680 * Sets Path for Ext Core library (relative to typo3 directory)
682 * @param string $path
685 public function setExtCorePath($path) {
686 $this->extCorePath
= $path;
690 * Sets Path for ExtJs library (relative to typo3 directory)
692 * @param string $path
695 public function setExtJsPath($path) {
696 $this->extJsPath
= $path;
700 * Sets Path for SVG library (websvg)
702 * @param string $path
705 public function setSvgPath($path) {
706 $this->svgPath
= $path;
709 /*****************************************************/
711 /* Public Enablers / Disablers */
714 /*****************************************************/
717 * Enables MoveJsFromHeaderToFooter
720 public function enableMoveJsFromHeaderToFooter() {
721 $this->moveJsFromHeaderToFooter
= TRUE;
725 * Disables MoveJsFromHeaderToFooter
728 public function disableMoveJsFromHeaderToFooter() {
729 $this->moveJsFromHeaderToFooter
= FALSE;
733 * Enables compression of javascript
736 public function enableCompressJavascript() {
737 $this->compressJavascript
= TRUE;
741 * Disables compression of javascript
744 public function disableCompressJavascript() {
745 $this->compressJavascript
= FALSE;
749 * Enables compression of css
752 public function enableCompressCss() {
753 $this->compressCss
= TRUE;
757 * Disables compression of css
760 public function disableCompressCss() {
761 $this->compressCss
= FALSE;
765 * Enables concatenation of js and css files
768 public function enableConcatenateFiles() {
769 $this->concatenateFiles
= TRUE;
773 * Disables concatenation of js and css files
776 public function disableConcatenateFiles() {
777 $this->concatenateFiles
= FALSE;
781 * Enables concatenation of js files
784 public function enableConcatenateJavascript() {
785 $this->concatenateJavascript
= TRUE;
789 * Disables concatenation of js files
792 public function disableConcatenateJavascript() {
793 $this->concatenateJavascript
= FALSE;
797 * Enables concatenation of css files
800 public function enableConcatenateCss() {
801 $this->concatenateCss
= TRUE;
805 * Disables concatenation of css files
808 public function disableConcatenateCss() {
809 $this->concatenateCss
= FALSE;
813 * Sets removal of all line breaks in template
816 public function enableRemoveLineBreaksFromTemplate() {
817 $this->removeLineBreaksFromTemplate
= TRUE;
821 * Unsets removal of all line breaks in template
824 public function disableRemoveLineBreaksFromTemplate() {
825 $this->removeLineBreaksFromTemplate
= FALSE;
830 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
833 public function enableDebugMode() {
834 $this->compressJavascript
= FALSE;
835 $this->compressCss
= FALSE;
836 $this->concatenateFiles
= FALSE;
837 $this->removeLineBreaksFromTemplate
= FALSE;
838 $this->enableExtCoreDebug
= TRUE;
839 $this->enableExtJsDebug
= TRUE;
840 $this->enableJqueryDebug
= TRUE;
841 $this->enableSvgDebug
= TRUE;
844 /*****************************************************/
849 /*****************************************************/
854 * @return string $title Title of webpage
856 public function getTitle() {
863 * @return string $charSet
865 public function getCharSet() {
866 return $this->charSet
;
872 * @return string $lang
874 public function getLanguage() {
879 * Returns rendering mode XHTML or HTML
881 * @return boolean TRUE if XHTML, FALSE if HTML
883 public function getRenderXhtml() {
884 return $this->renderXhtml
;
890 * @return string $htmlTag Html tag
892 public function getHtmlTag() {
893 return $this->htmlTag
;
901 public function getMetaCharsetTag() {
902 return $this->metaCharsetTag
;
908 * @return string $tag Head tag
910 public function getHeadTag() {
911 return $this->headTag
;
917 * @return string $favIcon
919 public function getFavIcon() {
920 return $this->favIcon
;
924 * Gets icon mime type
926 * @return string $iconMimeType
928 public function getIconMimeType() {
929 return $this->iconMimeType
;
935 * @return string $url
937 public function getBaseUrl() {
938 return $this->baseUrl
;
946 public function getTemplateFile() {
947 return $this->templateFile
;
951 * Gets MoveJsFromHeaderToFooter
955 public function getMoveJsFromHeaderToFooter() {
956 return $this->moveJsFromHeaderToFooter
;
960 * Gets compress of javascript
964 public function getCompressJavascript() {
965 return $this->compressJavascript
;
969 * Gets compress of css
973 public function getCompressCss() {
974 return $this->compressCss
;
978 * Gets concatenate of js and css files
982 public function getConcatenateFiles() {
983 return $this->concatenateFiles
;
987 * Gets concatenate of js files
991 public function getConcatenateJavascript() {
992 return $this->concatenateJavascript
;
996 * Gets concatenate of css files
1000 public function getConcatenateCss() {
1001 return $this->concatenateCss
;
1005 * Gets remove of empty lines from template
1009 public function getRemoveLineBreaksFromTemplate() {
1010 return $this->removeLineBreaksFromTemplate
;
1014 * Gets content for body
1018 public function getBodyContent() {
1019 return $this->bodyContent
;
1023 * Gets Path for prototype library (relative to typo3 directory)
1027 public function getPrototypePath() {
1028 return $this->prototypePath
;
1032 * Gets Path for scriptaculous library (relative to typo3 directory)
1036 public function getScriptaculousPath() {
1037 return $this->scriptaculousPath
;
1041 * Gets Path for Ext Core library (relative to typo3 directory)
1045 public function getExtCorePath() {
1046 return $this->extCorePath
;
1050 * Gets Path for ExtJs library (relative to typo3 directory)
1054 public function getExtJsPath() {
1055 return $this->extJsPath
;
1059 * Gets Path for SVG library (relative to typo3 directory)
1063 public function getSvgPath() {
1064 return $this->svgPath
;
1068 * Gets the inline language labels.
1070 * @return array The inline language labels
1072 public function getInlineLanguageLabels() {
1073 return $this->inlineLanguageLabels
;
1077 * Gets the inline language files
1081 public function getInlineLanguageLabelFiles() {
1082 return $this->inlineLanguageLabelFiles
;
1085 /*****************************************************/
1087 /* Public Functions to add Data */
1090 /*****************************************************/
1095 * @param string $meta Meta data (complete metatag)
1098 public function addMetaTag($meta) {
1099 if (!in_array($meta, $this->metaTags
)) {
1100 $this->metaTags
[] = $meta;
1105 * Adds inline HTML comment
1107 * @param string $comment
1110 public function addInlineComment($comment) {
1111 if (!in_array($comment, $this->inlineComments
)) {
1112 $this->inlineComments
[] = $comment;
1119 * @param string $data Free header data for HTML header
1122 public function addHeaderData($data) {
1123 if (!in_array($data, $this->headerData
)) {
1124 $this->headerData
[] = $data;
1131 * @param string $data Free header data for HTML header
1134 public function addFooterData($data) {
1135 if (!in_array($data, $this->footerData
)) {
1136 $this->footerData
[] = $data;
1141 * Adds JS Library. JS Library block is rendered on top of the JS files.
1143 * @param string $name Arbitrary identifier
1144 * @param string $file File name
1145 * @param string $type Content Type
1146 * @param boolean $compress Flag if library should be compressed
1147 * @param boolean $forceOnTop Flag if added library should be inserted at begin of this block
1148 * @param string $allWrap
1149 * @param boolean $excludeFromConcatenation
1152 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1154 $type = 'text/javascript';
1156 if (!in_array(strtolower($name), $this->jsLibs
)) {
1157 $this->jsLibs
[strtolower($name)] = array(
1160 'section' => self
::PART_HEADER
,
1161 'compress' => $compress,
1162 'forceOnTop' => $forceOnTop,
1163 'allWrap' => $allWrap,
1164 'excludeFromConcatenation' => $excludeFromConcatenation,
1170 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
1172 * @param string $name Arbitrary identifier
1173 * @param string $file File name
1174 * @param string $type Content Type
1175 * @param boolean $compress Flag if library should be compressed
1176 * @param boolean $forceOnTop Flag if added library should be inserted at begin of this block
1177 * @param string $allWrap
1178 * @param boolean $excludeFromConcatenation
1181 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1183 $type = 'text/javascript';
1185 if (!in_array(strtolower($name), $this->jsLibs
)) {
1186 $this->jsLibs
[strtolower($name)] = array(
1189 'section' => self
::PART_FOOTER
,
1190 'compress' => $compress,
1191 'forceOnTop' => $forceOnTop,
1192 'allWrap' => $allWrap,
1193 'excludeFromConcatenation' => $excludeFromConcatenation,
1201 * @param string $file File name
1202 * @param string $type Content Type
1203 * @param boolean $compress
1204 * @param boolean $forceOnTop
1205 * @param string $allWrap
1206 * @param boolean $excludeFromConcatenation
1209 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1211 $type = 'text/javascript';
1213 if (!isset($this->jsFiles
[$file])) {
1214 if (strpos($file, 'ajax.php?') !== FALSE) {
1217 $this->jsFiles
[$file] = array(
1220 'section' => self
::PART_HEADER
,
1221 'compress' => $compress,
1222 'forceOnTop' => $forceOnTop,
1223 'allWrap' => $allWrap,
1224 'excludeFromConcatenation' => $excludeFromConcatenation,
1230 * Adds JS file to footer
1232 * @param string $file File name
1233 * @param string $type Content Type
1234 * @param boolean $compress
1235 * @param boolean $forceOnTop
1236 * @param string $allWrap
1237 * @param boolean $excludeFromConcatenation
1240 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1242 $type = 'text/javascript';
1244 if (!isset($this->jsFiles
[$file])) {
1245 if (strpos($file, 'ajax.php?') !== FALSE) {
1248 $this->jsFiles
[$file] = array(
1251 'section' => self
::PART_FOOTER
,
1252 'compress' => $compress,
1253 'forceOnTop' => $forceOnTop,
1254 'allWrap' => $allWrap,
1255 'excludeFromConcatenation' => $excludeFromConcatenation,
1261 * Adds JS inline code
1263 * @param string $name
1264 * @param string $block
1265 * @param boolean $compress
1266 * @param boolean $forceOnTop
1269 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1270 if (!isset($this->jsInline
[$name]) && !empty($block)) {
1271 $this->jsInline
[$name] = array(
1272 'code' => $block . LF
,
1273 'section' => self
::PART_HEADER
,
1274 'compress' => $compress,
1275 'forceOnTop' => $forceOnTop
1281 * Adds JS inline code to footer
1283 * @param string $name
1284 * @param string $block
1285 * @param boolean $compress
1286 * @param boolean $forceOnTop
1289 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1290 if (!isset($this->jsInline
[$name]) && !empty($block)) {
1291 $this->jsInline
[$name] = array(
1292 'code' => $block . LF
,
1293 'section' => self
::PART_FOOTER
,
1294 'compress' => $compress,
1295 'forceOnTop' => $forceOnTop
1301 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
1303 * @param string $block Javascript code
1304 * @param boolean $forceOnTop Position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
1307 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
1308 if (!in_array($block, $this->extOnReadyCode
)) {
1310 array_unshift($this->extOnReadyCode
, $block);
1312 $this->extOnReadyCode
[] = $block;
1318 * Adds the ExtDirect code
1320 * @param array $filterNamespaces Limit the output to defined namespaces. If empty, all namespaces are generated
1323 public function addExtDirectCode(array $filterNamespaces = array()) {
1324 if ($this->extDirectCodeAdded
) {
1327 $this->extDirectCodeAdded
= TRUE;
1329 if (count($filterNamespaces) === 0) {
1330 $filterNamespaces = array('TYPO3');
1333 // For ExtDirect we need flash message support
1334 $this->addJsFile(t3lib_div
::resolveBackPath($this->backPath
. '../t3lib/js/extjs/ux/flashmessages.js'));
1336 // Add language labels for ExtDirect
1337 if (TYPO3_MODE
=== 'FE') {
1338 $this->addInlineLanguageLabelArray(array(
1339 'extDirect_timeoutHeader' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutHeader'),
1340 'extDirect_timeoutMessage' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutMessage'),
1343 $this->addInlineLanguageLabelArray(array(
1344 'extDirect_timeoutHeader' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutHeader'),
1345 'extDirect_timeoutMessage' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutMessage'),
1350 if (TYPO3_MODE
=== 'BE') {
1351 $formprotection = t3lib_formprotection_Factory
::get();
1352 $token = $formprotection->generateToken('extDirect');
1355 /** @var $extDirect t3lib_extjs_ExtDirectApi */
1356 $extDirect = t3lib_div
::makeInstance('t3lib_extjs_ExtDirectApi');
1357 $api = $extDirect->getApiPhp($filterNamespaces);
1359 $this->addJsInlineCode('TYPO3ExtDirectAPI', $api, FALSE);
1361 // Note: we need to iterate thru the object, because the addProvider method
1362 // does this only with multiple arguments
1363 $this->addExtOnReadyCode('
1365 TYPO3.ExtDirectToken = "' . $token . '";
1366 for (var api in Ext.app.ExtDirectAPI) {
1367 var provider = Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
1368 provider.on("beforecall", function(provider, transaction, meta) {
1369 if (transaction.data) {
1370 transaction.data[transaction.data.length] = TYPO3.ExtDirectToken;
1372 transaction.data = [TYPO3.ExtDirectToken];
1376 provider.on("call", function(provider, transaction, meta) {
1377 if (transaction.isForm) {
1378 transaction.params.securityToken = TYPO3.ExtDirectToken;
1384 var extDirectDebug = function(message, header, group) {
1385 var TYPO3ViewportInstance = null;
1387 if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
1388 TYPO3ViewportInstance = top.TYPO3.Backend;
1389 } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
1390 TYPO3ViewportInstance = TYPO3.Backend;
1393 if (TYPO3ViewportInstance !== null) {
1394 TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
1395 } else if (typeof console === "object") {
1396 console.log(message);
1398 document.write(message);
1402 Ext.Direct.on("exception", function(event) {
1403 if (event.code === Ext.Direct.exceptions.TRANSPORT && !event.where) {
1404 TYPO3.Flashmessage.display(
1405 TYPO3.Severity.error,
1406 TYPO3.l10n.localize("extDirect_timeoutHeader"),
1407 TYPO3.l10n.localize("extDirect_timeoutMessage"),
1412 if (event.code === "parse") {
1414 "<p>" + event.xhr.responseText + "<\/p>",
1416 "ExtDirect - Exception"
1418 } else if (event.code === "router") {
1419 TYPO3.Flashmessage.display(
1420 TYPO3.Severity.error,
1425 } else if (event.where) {
1426 backtrace = "<p style=\"margin-top: 20px;\">" +
1427 "<strong>Backtrace:<\/strong><br \/>" +
1428 event.where.replace(/#/g, "<br \/>#") +
1431 "<p>" + event.message + "<\/p>" + backtrace,
1433 "ExtDirect - Exception"
1441 Ext.Direct.on("event", function(event, provider) {
1442 if (typeof event.debug !== "undefined" && event.debug !== "") {
1443 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
1454 * @param string $file
1455 * @param string $rel
1456 * @param string $media
1457 * @param string $title
1458 * @param boolean $compress
1459 * @param boolean $forceOnTop
1460 * @param string $allWrap
1461 * @param boolean $excludeFromConcatenation
1464 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1465 if (!isset($this->cssFiles
[$file])) {
1466 $this->cssFiles
[$file] = array(
1471 'compress' => $compress,
1472 'forceOnTop' => $forceOnTop,
1473 'allWrap' => $allWrap,
1474 'excludeFromConcatenation' => $excludeFromConcatenation,
1480 * Adds CSS inline code
1482 * @param string $name
1483 * @param string $block
1484 * @param boolean $compress
1485 * @param boolean $forceOnTop
1488 public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
1489 if (!isset($this->cssInline
[$name]) && !empty($block)) {
1490 $this->cssInline
[$name] = array(
1492 'compress' => $compress,
1493 'forceOnTop' => $forceOnTop
1499 * Call this function if you need to include the jQuery library
1501 * @param null|string $version The jQuery version that should be included, either "latest" or any available version
1502 * @param null|string $source The location of the jQuery source, can be "local", "google", "msn", "jquery" or just an URL to your jQuery lib
1503 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored.
1505 * @throws UnexpectedValueException
1507 public function loadJquery($version = NULL, $source = NULL, $namespace = self
::JQUERY_NAMESPACE_DEFAULT
) {
1508 // Set it to the version that is shipped with the TYPO3 core
1509 if ($version === NULL ||
$version === 'latest') {
1510 $version = self
::JQUERY_VERSION_LATEST
;
1513 // Check if the source is set, otherwise set it to "default"
1514 if ($source === NULL) {
1518 if ($source === 'local' && !in_array($version, $this->availableLocalJqueryVersions
)) {
1519 throw new UnexpectedValueException('The requested jQuery version is not available in the local filesystem.', 1341505305);
1522 if (!ctype_alnum($namespace)) {
1523 throw new UnexpectedValueException('The requested namespace contains non alphanumeric characters.', 1341571604);
1526 $this->jQueryVersions
[$namespace] = array(
1527 'version' => $version,
1528 'source' => $source,
1533 * Call function if you need the prototype library
1537 public function loadPrototype() {
1538 $this->addPrototype
= TRUE;
1542 * Call function if you need the Scriptaculous library
1544 * @param string $modules Add modules you need. use "all" if you need complete modules
1547 public function loadScriptaculous($modules = 'all') {
1548 // Scriptaculous require prototype, so load prototype too.
1549 $this->addPrototype
= TRUE;
1550 $this->addScriptaculous
= TRUE;
1552 if ($modules == 'all') {
1553 foreach ($this->addScriptaculousModules
as $key => $value) {
1554 $this->addScriptaculousModules
[$key] = TRUE;
1557 $mods = t3lib_div
::trimExplode(',', $modules);
1558 foreach ($mods as $mod) {
1559 if (isset($this->addScriptaculousModules
[strtolower($mod)])) {
1560 $this->addScriptaculousModules
[strtolower($mod)] = TRUE;
1568 * call this function if you need the extJS library
1570 * @param boolean $css Flag, if set the ext-css will be loaded
1571 * @param boolean $theme Flag, if set the ext-theme "grey" will be loaded
1572 * @param string $adapter Choose alternative adapter, possible values: yui, prototype, jquery
1575 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
1577 // Empty $adapter will always load the ext adapter
1578 switch (t3lib_div
::strtolower(trim($adapter))) {
1579 case self
::EXTJS_ADAPTER_YUI
:
1580 $this->extJSadapter
= 'yui/ext-yui-adapter.js';
1582 case self
::EXTJS_ADAPTER_PROTOTYPE
:
1583 $this->extJSadapter
= 'prototype/ext-prototype-adapter.js';
1585 case self
::EXTJS_ADAPTER_JQUERY
:
1586 $this->extJSadapter
= 'jquery/ext-jquery-adapter.js';
1590 $this->addExtJS
= TRUE;
1591 $this->extJStheme
= $theme;
1592 $this->extJScss
= $css;
1596 * Enables ExtJs QuickTips
1601 public function enableExtJSQuickTips() {
1602 $this->enableExtJSQuickTips
= TRUE;
1606 * Call function if you need the ExtCore library
1610 public function loadExtCore() {
1611 $this->addExtCore
= TRUE;
1615 * Call function if you need the SVG library
1619 public function loadSvg() {
1620 $this->addSvg
= TRUE;
1624 * Call this function to load debug version of ExtJS. Use this for development only
1627 public function enableSvgDebug() {
1628 $this->enableSvgDebug
= TRUE;
1632 * Call this function to force flash usage with SVG library
1635 public function svgForceFlash() {
1636 $this->addMetaTag('<meta name="svg.render.forceflash" content="true" />');
1640 * Call this function to load debug version of ExtJS. Use this for development only
1643 public function enableExtJsDebug() {
1644 $this->enableExtJsDebug
= TRUE;
1648 * Call this function to load debug version of ExtCore. Use this for development only
1651 public function enableExtCoreDebug() {
1652 $this->enableExtCoreDebug
= TRUE;
1656 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1657 * The label can be used in scripts with TYPO3.lang.<key>
1660 * @param string $key
1661 * @param string $value
1664 public function addInlineLanguageLabel($key, $value) {
1665 $this->inlineLanguageLabels
[$key] = $value;
1669 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1670 * The label can be used in scripts with TYPO3.lang.<key>
1671 * Array will be merged with existing array.
1674 * @param array $array
1677 public function addInlineLanguageLabelArray(array $array) {
1678 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $array);
1682 * Gets labels to be used in JavaScript fetched from a locallang file.
1684 * @param string $fileRef Input is a file-reference (see t3lib_div::getFileAbsFileName). That file is expected to be a 'locallang.xml' file containing a valid XML TYPO3 language structure.
1685 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1686 * @param string $stripFromSelectionName Sub-prefix to be removed from label names in the result (default: '')
1687 * @param integer $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1690 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1691 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1692 if ($fileRef && !isset($this->inlineLanguageLabelFiles
[$index])) {
1693 $this->inlineLanguageLabelFiles
[$index] = array(
1694 'fileRef' => $fileRef,
1695 'selectionPrefix' => $selectionPrefix,
1696 'stripFromSelectionName' => $stripFromSelectionName,
1697 'errorMode' => $errorMode
1704 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1705 * The label can be used in scripts with TYPO3.setting.<key>
1708 * @param string $namespace
1709 * @param string $key
1710 * @param string $value
1713 public function addInlineSetting($namespace, $key, $value) {
1715 if (strpos($namespace, '.')) {
1716 $parts = explode('.', $namespace);
1717 $a = &$this->inlineSettings
;
1718 foreach ($parts as $part) {
1723 $this->inlineSettings
[$namespace][$key] = $value;
1726 $this->inlineSettings
[$key] = $value;
1731 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1732 * The label can be used in scripts with TYPO3.setting.<key>
1733 * Array will be merged with existing array.
1736 * @param string $namespace
1737 * @param array $array
1740 public function addInlineSettingArray($namespace, array $array) {
1742 if (strpos($namespace, '.')) {
1743 $parts = explode('.', $namespace);
1744 $a = &$this->inlineSettings
;
1745 foreach ($parts as $part) {
1748 $a = array_merge((array) $a, $array);
1750 $this->inlineSettings
[$namespace] = array_merge((array) $this->inlineSettings
[$namespace], $array);
1753 $this->inlineSettings
= array_merge($this->inlineSettings
, $array);
1758 * Adds content to body content
1760 * @param string $content
1763 public function addBodyContent($content) {
1764 $this->bodyContent
.= $content;
1767 /*****************************************************/
1769 /* Render Functions */
1771 /*****************************************************/
1774 * Render the section (Header or Footer)
1776 * @param integer $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1777 * @return string Content of rendered section
1779 public function render($part = self
::PART_COMPLETE
) {
1780 $this->prepareRendering();
1791 ) = $this->renderJavaScriptAndCss();
1793 $metaTags = implode(LF
, $this->metaTags
);
1794 $markerArray = $this->getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags);
1795 $template = $this->getTemplateForPart($part);
1798 return trim(t3lib_parsehtml
::substituteMarkerArray($template, $markerArray, '###|###'));
1802 * Remove ending slashes from static header block
1803 * if the page is beeing rendered as html (not xhtml)
1804 * and define property $this->endingSlash for further use
1808 protected function prepareRendering() {
1809 if ($this->getRenderXhtml()) {
1810 $this->endingSlash
= ' /';
1812 $this->metaCharsetTag
= str_replace(' />', '>', $this->metaCharsetTag
);
1813 $this->baseUrlTag
= str_replace(' />', '>', $this->baseUrlTag
);
1814 $this->shortcutTag
= str_replace(' />', '>', $this->shortcutTag
);
1816 $this->endingSlash
= '';
1821 * Renders all JavaScript and CSS
1823 * @return array<string>
1825 protected function renderJavaScriptAndCss() {
1826 $this->executePreRenderHook();
1828 $mainJsLibs = $this->renderMainJavaScriptLibraries();
1830 if ($this->concatenateFiles ||
$this->concatenateJavascript ||
$this->concatenateCss
) {
1831 // Do the file concatenation
1832 $this->doConcatenate();
1834 if ($this->compressCss ||
$this->compressJavascript
) {
1835 // Do the file compression
1836 $this->doCompress();
1839 $this->executeRenderPostTransformHook();
1841 $cssFiles = $this->renderCssFiles();
1842 $cssInline = $this->renderCssInline();
1843 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
1844 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
1845 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
1847 $jsLibs = $mainJsLibs . $jsLibs;
1849 if ($this->moveJsFromHeaderToFooter
) {
1850 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
1852 $jsFooterFiles = $jsFiles . LF
. $jsFooterFiles;
1854 $jsFooterInline = $jsInline . LF
. $jsFooterInline;
1858 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1860 return array($jsLibs, $jsFiles, $jsFooterFiles, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1864 * Fills the marker array with the given strings and trims each value
1866 * @param $jsLibs string
1867 * @param $jsFiles string
1868 * @param $jsFooterFiles string
1869 * @param $cssFiles string
1870 * @param $jsInline string
1871 * @param $cssInline string
1872 * @param $jsFooterInline string
1873 * @param $jsFooterLibs string
1874 * @param $metaTags string
1875 * @return array Marker array
1877 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags) {
1878 $markerArray = array(
1879 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType
,
1880 'HTMLTAG' => $this->htmlTag
,
1881 'HEADTAG' => $this->headTag
,
1882 'METACHARSET' => $this->charSet ?
str_replace('|', htmlspecialchars($this->charSet
), $this->metaCharsetTag
) : '',
1883 'INLINECOMMENT' => $this->inlineComments ? LF
. LF
. '<!-- ' . LF
. implode(LF
, $this->inlineComments
) . '-->' . LF
. LF
: '',
1884 'BASEURL' => $this->baseUrl ?
str_replace('|', $this->baseUrl
, $this->baseUrlTag
) : '',
1885 'SHORTCUT' => $this->favIcon ?
sprintf($this->shortcutTag
, htmlspecialchars($this->favIcon
), $this->iconMimeType
) : '',
1886 'CSS_INCLUDE' => $cssFiles,
1887 'CSS_INLINE' => $cssInline,
1888 'JS_INLINE' => $jsInline,
1889 'JS_INCLUDE' => $jsFiles,
1890 'JS_LIBS' => $jsLibs,
1891 'TITLE' => $this->title ?
str_replace('|', htmlspecialchars($this->title
), $this->titleTag
) : '',
1892 'META' => $metaTags,
1893 'HEADERDATA' => $this->headerData ?
implode(LF
, $this->headerData
) : '',
1894 'FOOTERDATA' => $this->footerData ?
implode(LF
, $this->footerData
) : '',
1895 'JS_LIBS_FOOTER' => $jsFooterLibs,
1896 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1897 'JS_INLINE_FOOTER' => $jsFooterInline,
1898 'BODY' => $this->bodyContent
,
1900 $markerArray = array_map('trim', $markerArray);
1902 return $markerArray;
1906 * Reads the template file and returns the requested part as string
1908 * @param integer $part
1911 protected function getTemplateForPart($part) {
1912 $templateFile = t3lib_div
::getFileAbsFileName($this->templateFile
, TRUE);
1913 $template = t3lib_div
::getUrl($templateFile);
1915 if ($this->removeLineBreaksFromTemplate
) {
1916 $template = strtr($template, array(LF
=> '', CR
=> ''));
1918 if ($part != self
::PART_COMPLETE
) {
1919 $templatePart = explode('###BODY###', $template);
1920 $template = $templatePart[$part - 1];
1927 * Helper function for render the main JavaScript libraries,
1928 * currently: jQuery, prototype, SVG, ExtJs
1930 * @return string Content with JavaScript libraries
1932 protected function renderMainJavaScriptLibraries() {
1935 if ($this->addSvg
) {
1936 $out .= '<script src="' . $this->processJsFile($this->backPath
. $this->svgPath
. 'svg.js') .
1937 '" data-path="' . $this->backPath
. $this->svgPath
.
1938 '"' . ($this->enableSvgDebug ?
' data-debug="true"' : '') . '></script>';
1941 // Include jQuery Core for each namespace, depending on the version and source
1942 if (!empty($this->jQueryVersions
)) {
1943 foreach ($this->jQueryVersions
as $namespace => $jQueryVersion) {
1944 $out .= $this->renderJqueryScriptTag(
1945 $jQueryVersion['version'],
1946 $jQueryVersion['source'],
1952 if ($this->addPrototype
) {
1953 $out .= '<script src="' . $this->processJsFile($this->backPath
. $this->prototypePath
. 'prototype.js') .
1954 '" type="text/javascript"></script>' . LF
;
1955 unset($this->jsFiles
[$this->backPath
. $this->prototypePath
. 'prototype.js']);
1958 if ($this->addScriptaculous
) {
1960 foreach ($this->addScriptaculousModules
as $key => $value) {
1961 if ($this->addScriptaculousModules
[$key]) {
1965 // Resolve dependencies
1966 if (in_array('dragdrop', $mods) ||
in_array('controls', $mods)) {
1967 $mods = array_merge(array('effects'), $mods);
1971 foreach ($mods as $module) {
1972 $out .= '<script src="' . $this->processJsFile($this->backPath
.
1973 $this->scriptaculousPath
. $module . '.js') . '" type="text/javascript"></script>' . LF
;
1974 unset($this->jsFiles
[$this->backPath
. $this->scriptaculousPath
. $module . '.js']);
1977 $out .= '<script src="' . $this->processJsFile($this->backPath
. $this->scriptaculousPath
.
1978 'scriptaculous.js') . '" type="text/javascript"></script>' . LF
;
1979 unset($this->jsFiles
[$this->backPath
. $this->scriptaculousPath
. 'scriptaculous.js']);
1982 // Include extCore, but only if ExtJS is not included
1983 if ($this->addExtCore
&& !$this->addExtJS
) {
1984 $out .= '<script src="' . $this->processJsFile($this->backPath
.
1985 $this->extCorePath
. 'ext-core' . ($this->enableExtCoreDebug ?
'-debug' : '') . '.js') .
1986 '" type="text/javascript"></script>' . LF
;
1987 unset($this->jsFiles
[$this->backPath
. $this->extCorePath
. 'ext-core' . ($this->enableExtCoreDebug ?
'-debug' : '') . '.js']);
1991 if ($this->addExtJS
) {
1992 // Use the base adapter all the time
1993 $out .= '<script src="' . $this->processJsFile($this->backPath
. $this->extJsPath
.
1994 'adapter/' . ($this->enableExtJsDebug ?
1995 str_replace('.js', '-debug.js', $this->extJSadapter
) : $this->extJSadapter
)) .
1996 '" type="text/javascript"></script>' . LF
;
1997 $out .= '<script src="' . $this->processJsFile($this->backPath
. $this->extJsPath
.
1998 'ext-all' . ($this->enableExtJsDebug ?
'-debug' : '') . '.js') .
1999 '" type="text/javascript"></script>' . LF
;
2001 // Add extJS localization
2002 // Load standard ISO mapping and modify for use with ExtJS
2003 $localeMap = $this->locales
->getIsoMapping();
2004 $localeMap[''] = 'en';
2005 $localeMap['default'] = 'en';
2007 $localeMap['gr'] = 'el_GR';
2008 // Norwegian Bokmaal
2009 $localeMap['no'] = 'no_BO';
2011 $localeMap['se'] = 'se_SV';
2013 $extJsLang = isset($localeMap[$this->lang
]) ?
$localeMap[$this->lang
] : $this->lang
;
2014 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
2015 $extJsLocaleFile = $this->extJsPath
. 'locale/ext-lang-' . $extJsLang . '.js';
2016 if (file_exists(PATH_typo3
. $extJsLocaleFile)) {
2017 $out .= '<script src="' . $this->processJsFile($this->backPath
.
2018 $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF
;
2021 // Remove extjs from JScodeLibArray
2023 $this->jsFiles
[$this->backPath
. $this->extJsPath
. 'ext-all.js'],
2024 $this->jsFiles
[$this->backPath
. $this->extJsPath
. 'ext-all-debug.js']
2028 if (count($this->inlineLanguageLabelFiles
)) {
2029 foreach ($this->inlineLanguageLabelFiles
as $languageLabelFile) {
2030 $this->includeLanguageFileForInline(
2031 $languageLabelFile['fileRef'],
2032 $languageLabelFile['selectionPrefix'],
2033 $languageLabelFile['stripFromSelectionName'],
2034 $languageLabelFile['$errorMode']
2038 unset($this->inlineLanguageLabelFiles
);
2040 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
2041 if ($this->getCharSet() !== 'utf-8') {
2042 if ($this->inlineLanguageLabels
) {
2043 $this->csConvObj
->convArray($this->inlineLanguageLabels
, $this->getCharSet(), 'utf-8');
2045 if ($this->inlineSettings
) {
2046 $this->csConvObj
->convArray($this->inlineSettings
, $this->getCharSet(), 'utf-8');
2050 $inlineSettings = $this->inlineLanguageLabels ?
'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels
) . ';' : '';
2051 $inlineSettings .= $this->inlineSettings ?
'TYPO3.settings = ' . json_encode($this->inlineSettings
) . ';' : '';
2053 if ($this->addExtCore ||
$this->addExtJS
) {
2054 // Set clear.gif, move it on top, add handler code
2056 if (count($this->extOnReadyCode
)) {
2057 foreach ($this->extOnReadyCode
as $block) {
2062 $out .= $this->inlineJavascriptWrap
[0] . '
2064 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div
::locationHeaderUrl($this->backPath
. 'gfx/clear.gif')) . '";' . LF
.
2066 'Ext.onReady(function() {' .
2067 ($this->enableExtJSQuickTips ?
'Ext.QuickTips.init();' . LF
: '') . $code .
2068 ' });' . $this->inlineJavascriptWrap
[1];
2069 unset ($this->extOnReadyCode
);
2071 // Include TYPO3.l10n object
2072 if (TYPO3_MODE
=== 'BE') {
2073 $out .= '<script src="' . $this->processJsFile($this->backPath
. 'sysext/lang/res/js/be/typo3lang.js') . '" type="text/javascript" charset="utf-8"></script>' . LF
;
2076 if ($this->extJStheme
) {
2077 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
2078 $this->addCssFile($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
2080 $this->addCssFile($this->backPath
. $this->extJsPath
. 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
2083 if ($this->extJScss
) {
2084 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
2085 $this->addCssFile($this->backPath
. $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
2087 $this->addCssFile($this->backPath
. $this->extJsPath
. 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
2091 if ($inlineSettings) {
2092 $out .= $this->inlineJavascriptWrap
[0] . $inlineSettings . $this->inlineJavascriptWrap
[1];
2100 * Renders the HTML script tag for the given jQuery version.
2102 * @param string $version The jQuery version that should be included, either "latest" or any available version
2103 * @param string $source The location of the jQuery source, can be "local", "google", "msn" or "jquery"
2104 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored
2107 protected function renderJqueryScriptTag($version, $source, $namespace) {
2110 case isset($this->jQueryCdnUrls
[$source]):
2111 if ($this->enableJqueryDebug
) {
2114 $minifyPart = '.min';
2116 $jQueryFileName = sprintf($this->jQueryCdnUrls
[$source], $version, $minifyPart);
2119 // Local source - include the latest
2120 case $source === 'local':
2121 $jQueryFileName = $this->backPath
. $this->jQueryPath
. 'jquery-' . rawurlencode($version);
2123 if ($this->enableJqueryDebug
) {
2124 $jQueryFileName .= '.js';
2126 $jQueryFileName .= '.min.js';
2129 // No special key found, assume the source is a valid URL to a jQuery library
2131 $jQueryFileName = $source;
2134 // Include the jQuery Core
2135 $scriptTag = '<script src="' . htmlspecialchars($jQueryFileName) . '" type="text/javascript"></script>' . LF
;
2137 // Set the noConflict mode to be available via "TYPO3.jQuery" in all installations
2139 switch ($namespace) {
2140 case self
::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT
:
2141 $scriptTag .= t3lib_div
::wrapJS(
2142 'jQuery.noConflict();'
2145 case self
::JQUERY_NAMESPACE_NONE
:
2147 case self
::JQUERY_NAMESPACE_DEFAULT
:
2149 $scriptTag .= t3lib_div
::wrapJS(
2150 'var TYPO3 = TYPO3 || {}; TYPO3.' . $namespace . ' = jQuery.noConflict(true);'
2163 protected function renderCssFiles() {
2165 if (count($this->cssFiles
)) {
2166 foreach ($this->cssFiles
as $file => $properties) {
2167 $file = t3lib_div
::resolveBackPath($file);
2168 $file = t3lib_div
::createVersionNumberedFilename($file);
2169 $tag = '<link rel="' . htmlspecialchars($properties['rel']) .
2170 '" type="text/css" href="' . htmlspecialchars($file) .
2171 '" media="' . htmlspecialchars($properties['media']) .
2172 '"' . ($properties['title'] ?
' title="' . htmlspecialchars($properties['title']) . '"' : '') . $this->endingSlash
. '>';
2173 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
2174 $tag = str_replace('|', $tag, $properties['allWrap']);
2176 if ($properties['forceOnTop']) {
2177 $cssFiles = $tag . LF
. $cssFiles;
2179 $cssFiles .= LF
. $tag;
2192 protected function renderCssInline() {
2194 if (count($this->cssInline
)) {
2195 foreach ($this->cssInline
as $name => $properties) {
2196 if ($properties['forceOnTop']) {
2197 $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
. $cssInline;
2199 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2202 $cssInline = $this->inlineCssWrap
[0] . $cssInline . $this->inlineCssWrap
[1];
2209 * Render JavaScipt libraries
2211 * @return array<string> jsLibs and jsFooterLibs strings
2213 protected function renderAdditionalJavaScriptLibraries() {
2216 if (count($this->jsLibs
)) {
2217 foreach ($this->jsLibs
as $properties) {
2218 $properties['file'] = t3lib_div
::resolveBackPath($properties['file']);
2219 $properties['file'] = t3lib_div
::createVersionNumberedFilename($properties['file']);
2220 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
2221 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
2222 $tag = str_replace('|', $tag, $properties['allWrap']);
2224 if ($properties['forceOnTop']) {
2225 if ($properties['section'] === self
::PART_HEADER
) {
2226 $jsLibs = $tag . LF
. $jsLibs;
2228 $jsFooterLibs = $tag . LF
. $jsFooterLibs;
2231 if ($properties['section'] === self
::PART_HEADER
) {
2232 $jsLibs .= LF
. $tag;
2234 $jsFooterLibs .= LF
. $tag;
2239 if ($this->moveJsFromHeaderToFooter
) {
2240 $jsFooterLibs = $jsLibs . LF
. $jsFooterLibs;
2244 return array($jsLibs, $jsFooterLibs);
2248 * Render JavaScript files
2250 * @return array<string> jsFiles and jsFooterFiles strings
2252 protected function renderJavaScriptFiles() {
2254 $jsFooterFiles = '';
2255 if (count($this->jsFiles
)) {
2256 foreach ($this->jsFiles
as $file => $properties) {
2257 $file = t3lib_div
::resolveBackPath($file);
2258 $file = t3lib_div
::createVersionNumberedFilename($file);
2259 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
2260 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
2261 $tag = str_replace('|', $tag, $properties['allWrap']);
2263 if ($properties['forceOnTop']) {
2264 if ($properties['section'] === self
::PART_HEADER
) {
2265 $jsFiles = $tag . LF
. $jsFiles;
2267 $jsFooterFiles = $tag . LF
. $jsFooterFiles;
2270 if ($properties['section'] === self
::PART_HEADER
) {
2271 $jsFiles .= LF
. $tag;
2273 $jsFooterFiles .= LF
. $tag;
2278 if ($this->moveJsFromHeaderToFooter
) {
2279 $jsFooterFiles = $jsFiles . LF
. $jsFooterFiles;
2283 return array($jsFiles, $jsFooterFiles);
2287 * Render inline JavaScript
2289 * @return array<string> jsInline and jsFooterInline string
2291 protected function renderInlineJavaScript() {
2293 $jsFooterInline = '';
2294 if (count($this->jsInline
)) {
2295 foreach ($this->jsInline
as $name => $properties) {
2296 if ($properties['forceOnTop']) {
2297 if ($properties['section'] === self
::PART_HEADER
) {
2298 $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
. $jsInline;
2300 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
. $jsFooterInline;
2303 if ($properties['section'] === self
::PART_HEADER
) {
2304 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2306 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF
. $properties['code'] . LF
;
2312 $jsInline = $this->inlineJavascriptWrap
[0] . $jsInline . $this->inlineJavascriptWrap
[1];
2315 if ($jsFooterInline) {
2316 $jsFooterInline = $this->inlineJavascriptWrap
[0] . $jsFooterInline . $this->inlineJavascriptWrap
[1];
2318 if ($this->moveJsFromHeaderToFooter
) {
2319 $jsFooterInline = $jsInline . LF
. $jsFooterInline;
2323 return array($jsInline, $jsFooterInline);
2327 * Include language file for inline usage
2329 * @param string $fileRef
2330 * @param string $selectionPrefix
2331 * @param string $stripFromSelectionName
2332 * @param integer $errorMode
2334 * @throws RuntimeException
2336 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
2337 if (!isset($this->lang
) ||
!isset($this->charSet
)) {
2338 throw new RuntimeException('Language and character encoding are not set.', 1284906026);
2341 $labelsFromFile = array();
2342 $allLabels = t3lib_div
::readLLfile($fileRef, $this->lang
, $this->charSet
, $errorMode);
2344 // Regular expression to strip the selection prefix and possibly something from the label name:
2345 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
2347 if ($allLabels !== FALSE) {
2348 // Merge language specific translations:
2349 if ($this->lang
!== 'default' && isset($allLabels[$this->lang
])) {
2350 $labels = array_merge($allLabels['default'], $allLabels[$this->lang
]);
2352 $labels = $allLabels['default'];
2355 // Iterate through all locallang labels:
2356 foreach ($labels as $label => $value) {
2357 if ($selectionPrefix === '') {
2358 $labelsFromFile[$label] = $value;
2359 } elseif (strpos($label, $selectionPrefix) === 0) {
2360 $key = preg_replace($labelPattern, '', $label);
2361 $labelsFromFile[$label] = $value;
2365 $this->inlineLanguageLabels
= array_merge($this->inlineLanguageLabels
, $labelsFromFile);
2369 /*****************************************************/
2373 /*****************************************************/
2376 * Concatenate files into one file
2377 * registered handler
2381 protected function doConcatenate() {
2382 $this->doConcatenateCss();
2383 $this->doConcatenateJavaScript();
2387 * Concatenate JavaScript files according to the configuration.
2391 protected function doConcatenateJavaScript() {
2392 if ($this->concatenateFiles ||
$this->concatenateJavascript
) {
2393 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsConcatenateHandler'])) {
2394 // use external concatenation routine
2396 'jsLibs' => &$this->jsLibs
,
2397 'jsFiles' => &$this->jsFiles
,
2398 'jsFooterFiles' => &$this->jsFooterFiles
,
2399 'headerData' => &$this->headerData
,
2400 'footerData' => &$this->footerData
,
2402 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsConcatenateHandler'], $params, $this);
2404 $this->jsLibs
= $this->getCompressor()->concatenateJsFiles($this->jsLibs
);
2405 $this->jsFiles
= $this->getCompressor()->concatenateJsFiles($this->jsFiles
);
2406 $this->jsFooterFiles
= $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles
);
2412 * Concatenate CSS files according to configuration.
2416 protected function doConcatenateCss() {
2417 if ($this->concatenateFiles ||
$this->concatenateCss
) {
2418 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssConcatenateHandler'])) {
2419 // use external concatenation routine
2421 'cssFiles' => &$this->cssFiles
,
2422 'headerData' => &$this->headerData
,
2423 'footerData' => &$this->footerData
,
2425 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssConcatenateHandler'], $params, $this);
2427 $cssOptions = array();
2428 if (TYPO3_MODE
=== 'BE') {
2429 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
2431 $this->cssFiles
= $this->getCompressor()->concatenateCssFiles($this->cssFiles
, $cssOptions);
2437 * Compresses inline code
2441 protected function doCompress() {
2442 $this->doCompressJavaScript();
2443 $this->doCompressCss();
2447 * Compresses CSS according to configuration.
2451 protected function doCompressCss() {
2452 if ($this->compressCss
) {
2453 // Use external compression routine
2455 'cssInline' => &$this->cssInline
,
2456 'cssFiles' => &$this->cssFiles
,
2457 'headerData' => &$this->headerData
,
2458 'footerData' => &$this->footerData
,
2461 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'])) {
2462 // use external concatenation routine
2463 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['cssCompressHandler'], $params, $this);
2465 $this->cssFiles
= $this->getCompressor()->compressCssFiles($this->cssFiles
);
2471 * Compresses JavaScript according to configuration.
2475 protected function doCompressJavaScript() {
2476 if ($this->compressJavascript
) {
2477 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'])) {
2478 // Use external compression routine
2480 'jsInline' => &$this->jsInline
,
2481 'jsFooterInline' => &$this->jsFooterInline
,
2482 'jsLibs' => &$this->jsLibs
,
2483 'jsFiles' => &$this->jsFiles
,
2484 'jsFooterFiles' => &$this->jsFooterFiles
,
2485 'headerData' => &$this->headerData
,
2486 'footerData' => &$this->footerData
,
2488 t3lib_div
::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['jsCompressHandler'], $params, $this);
2490 // Traverse the arrays, compress files
2491 if (count($this->jsInline
)) {
2492 foreach ($this->jsInline
as $name => $properties) {
2493 if ($properties['compress']) {
2495 $this->jsInline
[$name]['code'] = t3lib_div
::minifyJavaScript($properties['code'], $error);
2497 $this->compressError
.= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF
;
2502 $this->jsLibs
= $this->getCompressor()->compressJsFiles($this->jsLibs
);
2503 $this->jsFiles
= $this->getCompressor()->compressJsFiles($this->jsFiles
);
2504 $this->jsFooterFiles
= $this->getCompressor()->compressJsFiles($this->jsFooterFiles
);
2510 * Returns instance of t3lib_Compressor
2512 * @return t3lib_Compressor Instance of t3lib_Compressor
2514 protected function getCompressor() {
2515 if ($this->compressor
=== NULL) {
2516 $this->compressor
= t3lib_div
::makeInstance('t3lib_Compressor');
2518 return $this->compressor
;
2522 * Processes a Javascript file dependent on the current context
2524 * Adds the version number for Frontend, compresses the file for Backend
2526 * @param string $filename Filename
2527 * @return string New filename
2529 protected function processJsFile($filename) {
2530 switch (TYPO3_MODE
) {
2532 if ($this->compressJavascript
) {
2533 $filename = $this->getCompressor()->compressJsFile($filename);
2535 $filename = t3lib_div
::createVersionNumberedFilename($filename);
2539 if ($this->compressJavascript
) {
2540 $filename = $this->getCompressor()->compressJsFile($filename);
2547 /*****************************************************/
2551 /*****************************************************/
2554 * Execute PreRenderHook for possible manuipulation
2558 protected function executePreRenderHook() {
2559 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
2561 'jsLibs' => &$this->jsLibs
,
2562 'jsFooterLibs' => &$this->jsFooterLibs
,
2563 'jsFiles' => &$this->jsFiles
,
2564 'jsFooterFiles' => &$this->jsFooterFiles
,
2565 'cssFiles' => &$this->cssFiles
,
2566 'headerData' => &$this->headerData
,
2567 'footerData' => &$this->footerData
,
2568 'jsInline' => &$this->jsInline
,
2569 'jsFooterInline' => &$this->jsFooterInline
,
2570 'cssInline' => &$this->cssInline
,
2572 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
2573 t3lib_div
::callUserFunction($hook, $params, $this);
2579 * PostTransform for possible manuipulation of concatenated and compressed files
2583 protected function executeRenderPostTransformHook() {
2584 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
2585 $params = array('jsLibs' => &$this->jsLibs
,
2586 'jsFooterLibs' => &$this->jsFooterLibs
,
2587 'jsFiles' => &$this->jsFiles
,
2588 'jsFooterFiles' => &$this->jsFooterFiles
,
2589 'cssFiles' => &$this->cssFiles
,
2590 'headerData' => &$this->headerData
,
2591 'footerData' => &$this->footerData
,
2592 'jsInline' => &$this->jsInline
,
2593 'jsFooterInline' => &$this->jsFooterInline
,
2594 'cssInline' => &$this->cssInline
,
2596 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
2597 t3lib_div
::callUserFunction($hook, $params, $this);
2603 * Execute postRenderHook for possible manipulation
2605 * @param $jsLibs string
2606 * @param $jsFiles string
2607 * @param $jsFooterFiles string
2608 * @param $cssFiles string
2609 * @param $jsInline string
2610 * @param $cssInline string
2611 * @param $jsFooterInline string
2612 * @param $jsFooterLibs string
2616 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs) {
2617 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
2619 'jsLibs' => &$jsLibs,
2620 'jsFiles' => &$jsFiles,
2621 'jsFooterFiles' => &$jsFooterFiles,
2622 'cssFiles' => &$cssFiles,
2623 'headerData' => &$this->headerData
,
2624 'footerData' => &$this->footerData
,
2625 'jsInline' => &$jsInline,
2626 'cssInline' => &$cssInline,
2627 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType
,
2628 'htmlTag' => &$this->htmlTag
,
2629 'headTag' => &$this->headTag
,
2630 'charSet' => &$this->charSet
,
2631 'metaCharsetTag' => &$this->metaCharsetTag
,
2632 'shortcutTag' => &$this->shortcutTag
,
2633 'inlineComments' => &$this->inlineComments
,
2634 'baseUrl' => &$this->baseUrl
,
2635 'baseUrlTag' => &$this->baseUrlTag
,
2636 'favIcon' => &$this->favIcon
,
2637 'iconMimeType' => &$this->iconMimeType
,
2638 'titleTag' => &$this->titleTag
,
2639 'title' => &$this->title
,
2640 'metaTags' => &$this->metaTags
,
2641 'jsFooterInline' => &$jsFooterInline,
2642 'jsFooterLibs' => &$jsFooterLibs,
2643 'bodyContent' => &$this->bodyContent
2645 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
2646 t3lib_div
::callUserFunction($hook, $params, $this);