1d922ca9700bdee66b8ec57b87f081e846da1a4b
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Page / PageGenerator.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Page;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * Class for starting TypoScript page generation
34 *
35 * The class is not instantiated as an objects but called directly with the "::" operator.
36 * eg: TSpagegen::pagegenInit()
37 *
38 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 */
40 class PageGenerator {
41
42 /**
43 * Setting some vars in TSFE, primarily based on TypoScript config settings.
44 *
45 * @return void
46 */
47 static public function pagegenInit() {
48 if ($GLOBALS['TSFE']->page['content_from_pid'] > 0) {
49 // make REAL copy of TSFE object - not reference!
50 $temp_copy_TSFE = clone $GLOBALS['TSFE'];
51 // Set ->id to the content_from_pid value - we are going to evaluate this pid as was it a given id for a page-display!
52 $temp_copy_TSFE->id = $GLOBALS['TSFE']->page['content_from_pid'];
53 $temp_copy_TSFE->MP = '';
54 $temp_copy_TSFE->getPageAndRootlineWithDomain($GLOBALS['TSFE']->config['config']['content_from_pid_allowOutsideDomain'] ? 0 : $GLOBALS['TSFE']->domainStartPage);
55 $GLOBALS['TSFE']->contentPid = intval($temp_copy_TSFE->id);
56 unset($temp_copy_TSFE);
57 }
58 if ($GLOBALS['TSFE']->config['config']['MP_defaults']) {
59 $temp_parts = GeneralUtility::trimExplode('|', $GLOBALS['TSFE']->config['config']['MP_defaults'], TRUE);
60 foreach ($temp_parts as $temp_p) {
61 list($temp_idP, $temp_MPp) = explode(':', $temp_p, 2);
62 $temp_ids = GeneralUtility::intExplode(',', $temp_idP);
63 foreach ($temp_ids as $temp_id) {
64 $GLOBALS['TSFE']->MP_defaults[$temp_id] = $temp_MPp;
65 }
66 }
67 }
68 // Global vars...
69 $GLOBALS['TSFE']->indexedDocTitle = $GLOBALS['TSFE']->page['title'];
70 $GLOBALS['TSFE']->debug = '' . $GLOBALS['TSFE']->config['config']['debug'];
71 // Base url:
72 if (isset($GLOBALS['TSFE']->config['config']['baseURL'])) {
73 $GLOBALS['TSFE']->baseUrl = $GLOBALS['TSFE']->config['config']['baseURL'];
74 $GLOBALS['TSFE']->anchorPrefix = substr(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), strlen(GeneralUtility::getIndpEnv('TYPO3_SITE_URL')));
75 }
76 // Internal and External target defaults
77 $GLOBALS['TSFE']->intTarget = '' . $GLOBALS['TSFE']->config['config']['intTarget'];
78 $GLOBALS['TSFE']->extTarget = '' . $GLOBALS['TSFE']->config['config']['extTarget'];
79 $GLOBALS['TSFE']->fileTarget = '' . $GLOBALS['TSFE']->config['config']['fileTarget'];
80 if ($GLOBALS['TSFE']->config['config']['spamProtectEmailAddresses'] === 'ascii') {
81 $GLOBALS['TSFE']->spamProtectEmailAddresses = 'ascii';
82 } else {
83 $GLOBALS['TSFE']->spamProtectEmailAddresses = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($GLOBALS['TSFE']->config['config']['spamProtectEmailAddresses'], -10, 10, 0);
84 }
85 $GLOBALS['TSFE']->absRefPrefix = $GLOBALS['TSFE']->config['config']['absRefPrefix'] ? trim($GLOBALS['TSFE']->config['config']['absRefPrefix']) : '';
86 if ($GLOBALS['TSFE']->type && $GLOBALS['TSFE']->config['config']['frameReloadIfNotInFrameset']) {
87 $tdlLD = $GLOBALS['TSFE']->tmpl->linkData($GLOBALS['TSFE']->page, '_top', $GLOBALS['TSFE']->no_cache, '');
88 $GLOBALS['TSFE']->additionalJavaScript['JSCode'] .= 'if(!parent.' . trim($GLOBALS['TSFE']->sPre) . ' && !parent.view_frame) top.location.href="' . $GLOBALS['TSFE']->baseUrlWrap($tdlLD['totalURL']) . '"';
89 }
90 $GLOBALS['TSFE']->compensateFieldWidth = '' . $GLOBALS['TSFE']->config['config']['compensateFieldWidth'];
91 $GLOBALS['TSFE']->lockFilePath = '' . $GLOBALS['TSFE']->config['config']['lockFilePath'];
92 $GLOBALS['TSFE']->lockFilePath = $GLOBALS['TSFE']->lockFilePath ? $GLOBALS['TSFE']->lockFilePath : $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'];
93 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_noScaleUp'] = isset($GLOBALS['TSFE']->config['config']['noScaleUp']) ? '' . $GLOBALS['TSFE']->config['config']['noScaleUp'] : $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_noScaleUp'];
94 $GLOBALS['TSFE']->TYPO3_CONF_VARS['GFX']['im_noScaleUp'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_noScaleUp'];
95 $GLOBALS['TSFE']->ATagParams = trim($GLOBALS['TSFE']->config['config']['ATagParams']) ? ' ' . trim($GLOBALS['TSFE']->config['config']['ATagParams']) : '';
96 if ($GLOBALS['TSFE']->config['config']['setJS_mouseOver']) {
97 $GLOBALS['TSFE']->setJS('mouseOver');
98 }
99 if ($GLOBALS['TSFE']->config['config']['setJS_openPic']) {
100 $GLOBALS['TSFE']->setJS('openPic');
101 }
102 $GLOBALS['TSFE']->sWordRegEx = '';
103 $GLOBALS['TSFE']->sWordList = GeneralUtility::_GP('sword_list');
104 if (is_array($GLOBALS['TSFE']->sWordList)) {
105 $space = !empty($GLOBALS['TSFE']->config['config']['sword_standAlone']) ? '[[:space:]]' : '';
106 foreach ($GLOBALS['TSFE']->sWordList as $val) {
107 if (strlen(trim($val)) > 0) {
108 $GLOBALS['TSFE']->sWordRegEx .= $space . quotemeta($val) . $space . '|';
109 }
110 }
111 $GLOBALS['TSFE']->sWordRegEx = preg_replace('/\\|$/', '', $GLOBALS['TSFE']->sWordRegEx);
112 }
113 // linkVars
114 $GLOBALS['TSFE']->calculateLinkVars();
115 // dtdAllowsFrames indicates whether to use the target attribute in links
116 $GLOBALS['TSFE']->dtdAllowsFrames = FALSE;
117 if ($GLOBALS['TSFE']->config['config']['doctype']) {
118 if (in_array(
119 (string) $GLOBALS['TSFE']->config['config']['doctype'],
120 array('xhtml_trans', 'xhtml_frames', 'xhtml_basic', 'xhtml_2', 'html5'),
121 TRUE)
122 ) {
123 $GLOBALS['TSFE']->dtdAllowsFrames = TRUE;
124 }
125 } else {
126 $GLOBALS['TSFE']->dtdAllowsFrames = TRUE;
127 }
128 // Setting XHTML-doctype from doctype
129 if (!$GLOBALS['TSFE']->config['config']['xhtmlDoctype']) {
130 $GLOBALS['TSFE']->config['config']['xhtmlDoctype'] = $GLOBALS['TSFE']->config['config']['doctype'];
131 }
132 if ($GLOBALS['TSFE']->config['config']['xhtmlDoctype']) {
133 $GLOBALS['TSFE']->xhtmlDoctype = $GLOBALS['TSFE']->config['config']['xhtmlDoctype'];
134 // Checking XHTML-docytpe
135 switch ((string) $GLOBALS['TSFE']->config['config']['xhtmlDoctype']) {
136 case 'xhtml_trans':
137
138 case 'xhtml_strict':
139
140 case 'xhtml_frames':
141 $GLOBALS['TSFE']->xhtmlVersion = 100;
142 break;
143 case 'xhtml_basic':
144 $GLOBALS['TSFE']->xhtmlVersion = 105;
145 break;
146 case 'xhtml_11':
147
148 case 'xhtml+rdfa_10':
149 $GLOBALS['TSFE']->xhtmlVersion = 110;
150 break;
151 case 'xhtml_2':
152 $GLOBALS['TSFE']->xhtmlVersion = 200;
153 break;
154 default:
155 $GLOBALS['TSFE']->getPageRenderer()->setRenderXhtml(FALSE);
156 $GLOBALS['TSFE']->xhtmlDoctype = '';
157 $GLOBALS['TSFE']->xhtmlVersion = 0;
158 }
159 } else {
160 $GLOBALS['TSFE']->getPageRenderer()->setRenderXhtml(FALSE);
161 }
162 }
163
164 /**
165 * Returns an array with files to include. These files are the ones set up in TypoScript config.
166 *
167 * @return array Files to include. Paths are relative to PATH_site.
168 */
169 static public function getIncFiles() {
170 $incFilesArray = array();
171 // Get files from config.includeLibrary
172 $includeLibrary = trim('' . $GLOBALS['TSFE']->config['config']['includeLibrary']);
173 if ($includeLibrary) {
174 $incFile = $GLOBALS['TSFE']->tmpl->getFileName($includeLibrary);
175 if ($incFile) {
176 $incFilesArray[] = $incFile;
177 }
178 }
179 if (is_array($GLOBALS['TSFE']->pSetup['includeLibs.'])) {
180 $incLibs = $GLOBALS['TSFE']->pSetup['includeLibs.'];
181 } else {
182 $incLibs = array();
183 }
184 if (is_array($GLOBALS['TSFE']->tmpl->setup['includeLibs.'])) {
185 // toplevel 'includeLibs' is added to the PAGE.includeLibs. In that way, PAGE-libs get first priority, because if the key already exist, it's not altered. (Due to investigation by me)
186 $incLibs += $GLOBALS['TSFE']->tmpl->setup['includeLibs.'];
187 }
188 if (count($incLibs)) {
189 foreach ($incLibs as $theLib) {
190 if (!is_array($theLib) && ($incFile = $GLOBALS['TSFE']->tmpl->getFileName($theLib))) {
191 $incFilesArray[] = $incFile;
192 }
193 }
194 }
195 return $incFilesArray;
196 }
197
198 /**
199 * Processing JavaScript handlers
200 *
201 * @return array Array with a) a JavaScript section with event handlers and variables set and b) an array with attributes for the body tag.
202 */
203 static public function JSeventFunctions() {
204 $functions = array();
205 $setEvents = array();
206 $setBody = array();
207 foreach ($GLOBALS['TSFE']->JSeventFuncCalls as $event => $handlers) {
208 if (count($handlers)) {
209 $functions[] = ' function T3_' . $event . 'Wrapper(e) { ' . implode(' ', $handlers) . ' }';
210 $setEvents[] = ' document.' . $event . '=T3_' . $event . 'Wrapper;';
211 if ($event == 'onload') {
212 // Dubiuos double setting breaks on some browser - do we need it?
213 $setBody[] = 'onload="T3_onloadWrapper();"';
214 }
215 }
216 }
217 return array(count($functions) ? implode(LF, $functions) . LF . implode(LF, $setEvents) : '', $setBody);
218 }
219
220 /**
221 * Rendering the page content
222 *
223 * @return void
224 */
225 static public function renderContent() {
226 // PAGE CONTENT
227 $GLOBALS['TT']->incStackPointer();
228 $GLOBALS['TT']->push($GLOBALS['TSFE']->sPre, 'PAGE');
229 $pageContent = $GLOBALS['TSFE']->cObj->cObjGet($GLOBALS['TSFE']->pSetup);
230 if ($GLOBALS['TSFE']->pSetup['wrap']) {
231 $pageContent = $GLOBALS['TSFE']->cObj->wrap($pageContent, $GLOBALS['TSFE']->pSetup['wrap']);
232 }
233 if ($GLOBALS['TSFE']->pSetup['stdWrap.']) {
234 $pageContent = $GLOBALS['TSFE']->cObj->stdWrap($pageContent, $GLOBALS['TSFE']->pSetup['stdWrap.']);
235 }
236 // PAGE HEADER (after content - maybe JS is inserted!
237 // if 'disableAllHeaderCode' is set, all the header-code is discarded!
238 if ($GLOBALS['TSFE']->config['config']['disableAllHeaderCode']) {
239 $GLOBALS['TSFE']->content = $pageContent;
240 } else {
241 self::renderContentWithHeader($pageContent);
242 }
243 $GLOBALS['TT']->pull($GLOBALS['TT']->LR ? $GLOBALS['TSFE']->content : '');
244 $GLOBALS['TT']->decStackPointer();
245 }
246
247 /**
248 * Rendering normal HTML-page with header by wrapping the generated content ($pageContent) in body-tags and setting the header accordingly.
249 *
250 * @param string $pageContent The page content which TypoScript objects has generated
251 * @return void
252 */
253 static public function renderContentWithHeader($pageContent) {
254 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
255 $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
256 if ($GLOBALS['TSFE']->config['config']['moveJsFromHeaderToFooter']) {
257 $pageRenderer->enableMoveJsFromHeaderToFooter();
258 }
259 if ($GLOBALS['TSFE']->config['config']['pageRendererTemplateFile']) {
260 $file = $GLOBALS['TSFE']->tmpl->getFileName($GLOBALS['TSFE']->config['config']['pageRendererTemplateFile']);
261 if ($file) {
262 $pageRenderer->setTemplateFile($file);
263 }
264 }
265 $headerComment = $GLOBALS['TSFE']->config['config']['headerComment'];
266 if (trim($headerComment)) {
267 $pageRenderer->addInlineComment(TAB . str_replace(LF, (LF . TAB), trim($headerComment)) . LF);
268 }
269 // Setting charset:
270 $theCharset = $GLOBALS['TSFE']->metaCharset;
271 // Reset the content variables:
272 $GLOBALS['TSFE']->content = '';
273 $htmlTagAttributes = array();
274 $htmlLang = $GLOBALS['TSFE']->config['config']['htmlTag_langKey'] ? $GLOBALS['TSFE']->config['config']['htmlTag_langKey'] : 'en';
275 // Set content direction: (More info: http://www.tau.ac.il/~danon/Hebrew/HTML_and_Hebrew.html)
276 if ($GLOBALS['TSFE']->config['config']['htmlTag_dir']) {
277 $htmlTagAttributes['dir'] = htmlspecialchars($GLOBALS['TSFE']->config['config']['htmlTag_dir']);
278 }
279 // Setting document type:
280 $docTypeParts = array();
281 $xmlDocument = TRUE;
282 // Part 1: XML prologue
283 switch ((string) $GLOBALS['TSFE']->config['config']['xmlprologue']) {
284 case 'none':
285 $xmlDocument = FALSE;
286 $GLOBALS['TSFE']->config['config']['xhtml_cleaning'] = 'none';
287 break;
288 case 'xml_10':
289 $docTypeParts[] = '<?xml version="1.0" encoding="' . $theCharset . '"?>';
290 break;
291 case 'xml_11':
292 $docTypeParts[] = '<?xml version="1.1" encoding="' . $theCharset . '"?>';
293 break;
294 case '':
295 if ($GLOBALS['TSFE']->xhtmlVersion) {
296 $docTypeParts[] = '<?xml version="1.0" encoding="' . $theCharset . '"?>';
297 }
298 break;
299 default:
300 $docTypeParts[] = $GLOBALS['TSFE']->config['config']['xmlprologue'];
301 }
302 // Part 2: DTD
303 $doctype = $GLOBALS['TSFE']->config['config']['doctype'];
304 if ($doctype) {
305 switch ($doctype) {
306 case 'xhtml_trans':
307 $docTypeParts[] = '<!DOCTYPE html
308 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
309 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
310 break;
311 case 'xhtml_strict':
312 $docTypeParts[] = '<!DOCTYPE html
313 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
314 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
315 break;
316 case 'xhtml_frames':
317 $docTypeParts[] = '<!DOCTYPE html
318 PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
319 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
320 break;
321 case 'xhtml_basic':
322 $docTypeParts[] = '<!DOCTYPE html
323 PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
324 "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">';
325 break;
326 case 'xhtml_11':
327 $docTypeParts[] = '<!DOCTYPE html
328 PUBLIC "-//W3C//DTD XHTML 1.1//EN"
329 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
330 break;
331 case 'xhtml_2':
332 $docTypeParts[] = '<!DOCTYPE html
333 PUBLIC "-//W3C//DTD XHTML 2.0//EN"
334 "http://www.w3.org/TR/xhtml2/DTD/xhtml2.dtd">';
335 break;
336 case 'xhtml+rdfa_10':
337 $docTypeParts[] = '<!DOCTYPE html
338 PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
339 "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">';
340 break;
341 case 'html5':
342 $docTypeParts[] = '<!DOCTYPE html>';
343 if ($xmlDocument) {
344 $pageRenderer->setMetaCharsetTag('<meta charset="|" />');
345 } else {
346 $pageRenderer->setMetaCharsetTag('<meta charset="|">');
347 }
348 break;
349 case 'none':
350 break;
351 default:
352 $docTypeParts[] = $doctype;
353 }
354 } else {
355 $docTypeParts[] = '<!DOCTYPE html>';
356 if ($xmlDocument){
357 $pageRenderer->setMetaCharsetTag('<meta charset="|" />');
358 } else {
359 $pageRenderer->setMetaCharsetTag('<meta charset="|">');
360 }
361 }
362 if ($GLOBALS['TSFE']->xhtmlVersion) {
363 $htmlTagAttributes['xml:lang'] = $htmlLang;
364 }
365 if ($GLOBALS['TSFE']->xhtmlVersion < 110 || $doctype === 'html5') {
366 $htmlTagAttributes['lang'] = $htmlLang;
367 }
368 if ($GLOBALS['TSFE']->xhtmlVersion || $doctype === 'html5' && $xmlDocument) {
369 // We add this to HTML5 to achieve a slightly better backwards compatibility
370 $htmlTagAttributes['xmlns'] = 'http://www.w3.org/1999/xhtml';
371 if (is_array($GLOBALS['TSFE']->config['config']['namespaces.'])) {
372 foreach ($GLOBALS['TSFE']->config['config']['namespaces.'] as $prefix => $uri) {
373 // $uri gets htmlspecialchared later
374 $htmlTagAttributes['xmlns:' . htmlspecialchars($prefix)] = $uri;
375 }
376 }
377 }
378 // Swap XML and doctype order around (for MSIE / Opera standards compliance)
379 if ($GLOBALS['TSFE']->config['config']['doctypeSwitch']) {
380 $docTypeParts = array_reverse($docTypeParts);
381 }
382 // Adding doctype parts:
383 if (count($docTypeParts)) {
384 $pageRenderer->setXmlPrologAndDocType(implode(LF, $docTypeParts));
385 }
386 // Begin header section:
387 if (strcmp($GLOBALS['TSFE']->config['config']['htmlTag_setParams'], 'none')) {
388 $_attr = $GLOBALS['TSFE']->config['config']['htmlTag_setParams'] ? $GLOBALS['TSFE']->config['config']['htmlTag_setParams'] : GeneralUtility::implodeAttributes($htmlTagAttributes);
389 } else {
390 $_attr = '';
391 }
392 $htmlTag = '<html' . ($_attr ? ' ' . $_attr : '') . '>';
393 if (isset($GLOBALS['TSFE']->config['config']['htmlTag_stdWrap.'])) {
394 $htmlTag = $GLOBALS['TSFE']->cObj->stdWrap($htmlTag, $GLOBALS['TSFE']->config['config']['htmlTag_stdWrap.']);
395 }
396 $pageRenderer->setHtmlTag($htmlTag);
397 // Head tag:
398 $headTag = $GLOBALS['TSFE']->pSetup['headTag'] ? $GLOBALS['TSFE']->pSetup['headTag'] : '<head>';
399 $pageRenderer->setHeadTag($headTag);
400 // Setting charset meta tag:
401 $pageRenderer->setCharSet($theCharset);
402 $pageRenderer->addInlineComment(' This website is powered by TYPO3 - inspiring people to share!
403 TYPO3 is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.
404 TYPO3 is copyright ' . TYPO3_copyright_year . ' of Kasper Skaarhoj. Extensions are copyright of their respective owners.
405 Information and contribution at ' . TYPO3_URL_ORG . '
406 ');
407 if ($GLOBALS['TSFE']->baseUrl) {
408 $pageRenderer->setBaseUrl($GLOBALS['TSFE']->baseUrl);
409 }
410 if ($GLOBALS['TSFE']->pSetup['shortcutIcon']) {
411 $favIcon = $GLOBALS['TSFE']->tmpl->getFileName($GLOBALS['TSFE']->pSetup['shortcutIcon']);
412 $iconMimeType = '';
413 if (function_exists('finfo_open')) {
414 if ($finfo = @finfo_open(FILEINFO_MIME)) {
415 $iconMimeType = ' type="' . finfo_file($finfo, (PATH_site . $favIcon)) . '"';
416 finfo_close($finfo);
417 $pageRenderer->setIconMimeType($iconMimeType);
418 }
419 }
420 $pageRenderer->setFavIcon(GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $favIcon);
421 }
422 // Including CSS files
423 if (is_array($GLOBALS['TSFE']->tmpl->setup['plugin.'])) {
424 $temp_styleLines = array();
425 foreach ($GLOBALS['TSFE']->tmpl->setup['plugin.'] as $key => $iCSScode) {
426 if (is_array($iCSScode)) {
427 if ($iCSScode['_CSS_DEFAULT_STYLE'] && empty($GLOBALS['TSFE']->config['config']['removeDefaultCss'])) {
428 $temp_styleLines[] = '/* default styles for extension "' . substr($key, 0, -1) . '" */' . LF . $iCSScode['_CSS_DEFAULT_STYLE'];
429 }
430 if ($iCSScode['_CSS_PAGE_STYLE'] && empty($GLOBALS['TSFE']->config['config']['removePageCss'])) {
431 $temp_styleLines[] = '/* specific page styles for extension "' . substr($key, 0, -1) . '" */' . LF . implode(LF, $iCSScode['_CSS_PAGE_STYLE']);
432 }
433 }
434 }
435 if (count($temp_styleLines)) {
436 if ($GLOBALS['TSFE']->config['config']['inlineStyle2TempFile']) {
437 $pageRenderer->addCssFile(self::inline2TempFile(implode(LF, $temp_styleLines), 'css'));
438 } else {
439 $pageRenderer->addCssInlineBlock('TSFEinlineStyle', implode(LF, $temp_styleLines));
440 }
441 }
442 }
443 if ($GLOBALS['TSFE']->pSetup['stylesheet']) {
444 $ss = $GLOBALS['TSFE']->tmpl->getFileName($GLOBALS['TSFE']->pSetup['stylesheet']);
445 if ($ss) {
446 $pageRenderer->addCssFile($ss);
447 }
448 }
449 /**********************************************************************/
450 /* includeCSS
451 /* config.includeCSS {
452 /*
453 /* }
454 /**********************************************************************/
455 if (is_array($GLOBALS['TSFE']->pSetup['includeCSS.'])) {
456 foreach ($GLOBALS['TSFE']->pSetup['includeCSS.'] as $key => $CSSfile) {
457 if (!is_array($CSSfile)) {
458 $ss = $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['external'] ? $CSSfile : $GLOBALS['TSFE']->tmpl->getFileName($CSSfile);
459 if (isset($GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['if.']) && !$GLOBALS['TSFE']->cObj->checkIf($GLOBALS['TSFE']->pSetup['includeCSS.'][($key . '.')]['if.'])) {
460 continue;
461 }
462 if ($ss) {
463 if ($GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['import']) {
464 if (!$GLOBALS['TSFE']->pSetup['includeCSS.'][($key . '.')]['external'] && substr($ss, 0, 1) != '/') {
465 // To fix MSIE 6 that cannot handle these as relative paths (according to Ben v Ende)
466 $ss = GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/' . $ss;
467 }
468 $pageRenderer->addCssInlineBlock('import_' . $key, '@import url("' . htmlspecialchars($ss) . '") ' . htmlspecialchars($GLOBALS['TSFE']->pSetup['includeCSS.'][($key . '.')]['media']) . ';', empty($GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['disableCompression']), $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['forceOnTop'] ? TRUE : FALSE, '');
469 } else {
470 $pageRenderer->addCssFile($ss, $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['alternate'] ? 'alternate stylesheet' : 'stylesheet', $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['media'] ? $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['media'] : 'all', $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['title'] ? $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['title'] : '', empty($GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['disableCompression']), $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['forceOnTop'] ? TRUE : FALSE, $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['allWrap'], $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.']['excludeFromConcatenation'] ? TRUE : FALSE);
471 }
472 }
473 }
474 }
475 }
476 // Stylesheets
477 $style = '';
478 if ($GLOBALS['TSFE']->pSetup['insertClassesFromRTE']) {
479 $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
480 $RTEclasses = $pageTSConfig['RTE.']['classes.'];
481 if (is_array($RTEclasses)) {
482 foreach ($RTEclasses as $RTEclassName => $RTEvalueArray) {
483 if ($RTEvalueArray['value']) {
484 $style .= '
485 .' . substr($RTEclassName, 0, -1) . ' {' . $RTEvalueArray['value'] . '}';
486 }
487 }
488 }
489 if ($GLOBALS['TSFE']->pSetup['insertClassesFromRTE.']['add_mainStyleOverrideDefs'] && is_array($pageTSConfig['RTE.']['default.']['mainStyleOverride_add.'])) {
490 $mSOa_tList = GeneralUtility::trimExplode(',', strtoupper($GLOBALS['TSFE']->pSetup['insertClassesFromRTE.']['add_mainStyleOverrideDefs']), TRUE);
491 foreach ($pageTSConfig['RTE.']['default.']['mainStyleOverride_add.'] as $mSOa_key => $mSOa_value) {
492 if (!is_array($mSOa_value) && (in_array('*', $mSOa_tList) || in_array($mSOa_key, $mSOa_tList))) {
493 $style .= '
494 ' . $mSOa_key . ' {' . $mSOa_value . '}';
495 }
496 }
497 }
498 }
499 // Setting body tag margins in CSS:
500 if (isset($GLOBALS['TSFE']->pSetup['bodyTagMargins']) && $GLOBALS['TSFE']->pSetup['bodyTagMargins.']['useCSS']) {
501 $margins = intval($GLOBALS['TSFE']->pSetup['bodyTagMargins']);
502 $style .= '
503 BODY {margin: ' . $margins . 'px ' . $margins . 'px ' . $margins . 'px ' . $margins . 'px;}';
504 }
505 if ($GLOBALS['TSFE']->pSetup['adminPanelStyles']) {
506 $style .= '
507
508 /* Default styles for the Admin Panel */
509 TABLE.typo3-adminPanel { border: 1px solid black; background-color: #F6F2E6; }
510 TABLE.typo3-adminPanel TR.typo3-adminPanel-hRow TD { background-color: #9BA1A8; }
511 TABLE.typo3-adminPanel TR.typo3-adminPanel-itemHRow TD { background-color: #ABBBB4; }
512 TABLE.typo3-adminPanel TABLE, TABLE.typo3-adminPanel TD { border: 0px; }
513 TABLE.typo3-adminPanel TD FONT { font-family: verdana; font-size: 10px; color: black; }
514 TABLE.typo3-adminPanel TD A FONT { font-family: verdana; font-size: 10px; color: black; }
515 TABLE.typo3-editPanel { border: 1px solid black; background-color: #F6F2E6; }
516 TABLE.typo3-editPanel TD { border: 0px; }
517 ';
518 }
519 // CSS_inlineStyle from TS
520 $style .= trim($GLOBALS['TSFE']->pSetup['CSS_inlineStyle']);
521 $style .= $GLOBALS['TSFE']->cObj->cObjGet($GLOBALS['TSFE']->pSetup['cssInline.'], 'cssInline.');
522 if (trim($style)) {
523 if ($GLOBALS['TSFE']->config['config']['inlineStyle2TempFile']) {
524 $pageRenderer->addCssFile(self::inline2TempFile($style, 'css'));
525 } else {
526 $pageRenderer->addCssInlineBlock('additionalTSFEInlineStyle', $style);
527 }
528 }
529 // Javascript Libraries
530 if (is_array($GLOBALS['TSFE']->pSetup['javascriptLibs.'])) {
531 if ($GLOBALS['TSFE']->pSetup['javascriptLibs.']['SVG']) {
532 $pageRenderer->loadSvg();
533 if ($GLOBALS['TSFE']->pSetup['javascriptLibs.']['SVG.']['debug']) {
534 $pageRenderer->enableSvgDebug();
535 }
536 if ($GLOBALS['TSFE']->pSetup['javascriptLibs.']['SVG.']['forceFlash']) {
537 $pageRenderer->svgForceFlash();
538 }
539 }
540 if ($GLOBALS['TSFE']->pSetup['javascriptLibs.']['Prototype']) {
541 $pageRenderer->loadPrototype();
542 }
543 if ($GLOBALS['TSFE']->pSetup['javascriptLibs.']['Scriptaculous']) {
544 $modules = $GLOBALS['TSFE']->pSetup['javascriptLibs.']['Scriptaculous.']['modules'] ? $GLOBALS['TSFE']->pSetup['javascriptLibs.']['Scriptaculous.']['modules'] : '';
545 $pageRenderer->loadScriptaculous($modules);
546 }
547 if ($GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtCore']) {
548 $pageRenderer->loadExtCore();
549 if ($GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtCore.']['debug']) {
550 $pageRenderer->enableExtCoreDebug();
551 }
552 }
553 // Include jQuery into the page renderer
554 if (!empty($GLOBALS['TSFE']->pSetup['javascriptLibs.']['jQuery'])) {
555 $jQueryTS = $GLOBALS['TSFE']->pSetup['javascriptLibs.']['jQuery.'];
556 // Check if version / source is set, if not set variable to "NULL" to use the default of the page renderer
557 $version = isset($jQueryTS['version']) ? $jQueryTS['version'] : NULL;
558 $source = isset($jQueryTS['source']) ? $jQueryTS['source'] : NULL;
559 // When "noConflict" is not set or "1" enable the default jQuery noConflict mode, otherwise disable the namespace
560 if (!isset($jQueryTS['noConflict']) || !empty($jQueryTS['noConflict'])) {
561 // Set namespace to the "noConflict.namespace" value if "noConflict.namespace" has a value
562 if (!empty($jQueryTS['noConflict.']['namespace'])) {
563 $namespace = $jQueryTS['noConflict.']['namespace'];
564 } else {
565 $namespace = \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT;
566 }
567 } else {
568 $namespace = \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_NONE;
569 }
570 $pageRenderer->loadJQuery($version, $source, $namespace);
571 }
572 if ($GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtJs']) {
573 $css = $GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtJs.']['css'] ? TRUE : FALSE;
574 $theme = $GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtJs.']['theme'] ? TRUE : FALSE;
575 $adapter = $GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtJs.']['adapter'] ? $GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtJs.']['adapter'] : '';
576 $pageRenderer->loadExtJs($css, $theme, $adapter);
577 if ($GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtJs.']['debug']) {
578 $pageRenderer->enableExtJsDebug();
579 }
580 if ($GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtJs.']['quickTips']) {
581 $pageRenderer->enableExtJSQuickTips();
582 }
583 }
584 }
585 // JavaScript library files
586 if (is_array($GLOBALS['TSFE']->pSetup['includeJSlibs.'])) {
587 foreach ($GLOBALS['TSFE']->pSetup['includeJSlibs.'] as $key => $JSfile) {
588 if (!is_array($JSfile)) {
589 if (isset($GLOBALS['TSFE']->pSetup['includeJSlibs.'][$key . '.']['if.']) && !$GLOBALS['TSFE']->cObj->checkIf($GLOBALS['TSFE']->pSetup['includeJSlibs.'][($key . '.')]['if.'])) {
590 continue;
591 }
592 $ss = $GLOBALS['TSFE']->pSetup['includeJSlibs.'][$key . '.']['external'] ? $JSfile : $GLOBALS['TSFE']->tmpl->getFileName($JSfile);
593 if ($ss) {
594 $type = $GLOBALS['TSFE']->pSetup['includeJSlibs.'][$key . '.']['type'];
595 if (!$type) {
596 $type = 'text/javascript';
597 }
598 $pageRenderer->addJsLibrary($key, $ss, $type, empty($GLOBALS['TSFE']->pSetup['includeJSlibs.'][$key . '.']['disableCompression']), $GLOBALS['TSFE']->pSetup['includeJSlibs.'][$key . '.']['forceOnTop'] ? TRUE : FALSE, $GLOBALS['TSFE']->pSetup['includeJSlibs.'][$key . '.']['allWrap'], $GLOBALS['TSFE']->pSetup['includeJSlibs.'][$key . '.']['excludeFromConcatenation'] ? TRUE : FALSE);
599 }
600 }
601 }
602 }
603 if (is_array($GLOBALS['TSFE']->pSetup['includeJSFooterlibs.'])) {
604 foreach ($GLOBALS['TSFE']->pSetup['includeJSFooterlibs.'] as $key => $JSfile) {
605 if (!is_array($JSfile)) {
606 if (isset($GLOBALS['TSFE']->pSetup['includeJSFooterlibs.'][$key . '.']['if.']) && !$GLOBALS['TSFE']->cObj->checkIf($GLOBALS['TSFE']->pSetup['includeJSFooterlibs.'][($key . '.')]['if.'])) {
607 continue;
608 }
609 $ss = $GLOBALS['TSFE']->pSetup['includeJSFooterlibs.'][$key . '.']['external'] ? $JSfile : $GLOBALS['TSFE']->tmpl->getFileName($JSfile);
610 if ($ss) {
611 $type = $GLOBALS['TSFE']->pSetup['includeJSFooterlibs.'][$key . '.']['type'];
612 if (!$type) {
613 $type = 'text/javascript';
614 }
615 $pageRenderer->addJsFooterLibrary($key, $ss, $type, empty($GLOBALS['TSFE']->pSetup['includeJSFooterlibs.'][$key . '.']['disableCompression']), $GLOBALS['TSFE']->pSetup['includeJSFooterlibs.'][$key . '.']['forceOnTop'] ? TRUE : FALSE, $GLOBALS['TSFE']->pSetup['includeJSFooterlibs.'][$key . '.']['allWrap'], $GLOBALS['TSFE']->pSetup['includeJSFooterlibs.'][$key . '.']['excludeFromConcatenation'] ? TRUE : FALSE);
616 }
617 }
618 }
619 }
620 // JavaScript files
621 if (is_array($GLOBALS['TSFE']->pSetup['includeJS.'])) {
622 foreach ($GLOBALS['TSFE']->pSetup['includeJS.'] as $key => $JSfile) {
623 if (!is_array($JSfile)) {
624 if (isset($GLOBALS['TSFE']->pSetup['includeJS.'][$key . '.']['if.']) && !$GLOBALS['TSFE']->cObj->checkIf($GLOBALS['TSFE']->pSetup['includeJS.'][($key . '.')]['if.'])) {
625 continue;
626 }
627 $ss = $GLOBALS['TSFE']->pSetup['includeJS.'][$key . '.']['external'] ? $JSfile : $GLOBALS['TSFE']->tmpl->getFileName($JSfile);
628 if ($ss) {
629 $type = $GLOBALS['TSFE']->pSetup['includeJS.'][$key . '.']['type'];
630 if (!$type) {
631 $type = 'text/javascript';
632 }
633 $pageRenderer->addJsFile($ss, $type, empty($GLOBALS['TSFE']->pSetup['includeJS.'][$key . '.']['disableCompression']), $GLOBALS['TSFE']->pSetup['includeJS.'][$key . '.']['forceOnTop'] ? TRUE : FALSE, $GLOBALS['TSFE']->pSetup['includeJS.'][$key . '.']['allWrap'], $GLOBALS['TSFE']->pSetup['includeJS.'][$key . '.']['excludeFromConcatenation'] ? TRUE : FALSE);
634 }
635 }
636 }
637 }
638 if (is_array($GLOBALS['TSFE']->pSetup['includeJSFooter.'])) {
639 foreach ($GLOBALS['TSFE']->pSetup['includeJSFooter.'] as $key => $JSfile) {
640 if (!is_array($JSfile)) {
641 if (isset($GLOBALS['TSFE']->pSetup['includeJSFooter.'][$key . '.']['if.']) && !$GLOBALS['TSFE']->cObj->checkIf($GLOBALS['TSFE']->pSetup['includeJSFooter.'][($key . '.')]['if.'])) {
642 continue;
643 }
644 $ss = $GLOBALS['TSFE']->pSetup['includeJSFooter.'][$key . '.']['external'] ? $JSfile : $GLOBALS['TSFE']->tmpl->getFileName($JSfile);
645 if ($ss) {
646 $type = $GLOBALS['TSFE']->pSetup['includeJSFooter.'][$key . '.']['type'];
647 if (!$type) {
648 $type = 'text/javascript';
649 }
650 $pageRenderer->addJsFooterFile($ss, $type, empty($GLOBALS['TSFE']->pSetup['includeJSFooter.'][$key . '.']['disableCompression']), $GLOBALS['TSFE']->pSetup['includeJSFooter.'][$key . '.']['forceOnTop'] ? TRUE : FALSE, $GLOBALS['TSFE']->pSetup['includeJSFooter.'][$key . '.']['allWrap'], $GLOBALS['TSFE']->pSetup['includeJSFooter.'][$key . '.']['excludeFromConcatenation'] ? TRUE : FALSE);
651 }
652 }
653 }
654 }
655 // Headerdata
656 if (is_array($GLOBALS['TSFE']->pSetup['headerData.'])) {
657 $pageRenderer->addHeaderData($GLOBALS['TSFE']->cObj->cObjGet($GLOBALS['TSFE']->pSetup['headerData.'], 'headerData.'));
658 }
659 // Footerdata
660 if (is_array($GLOBALS['TSFE']->pSetup['footerData.'])) {
661 $pageRenderer->addFooterData($GLOBALS['TSFE']->cObj->cObjGet($GLOBALS['TSFE']->pSetup['footerData.'], 'footerData.'));
662 }
663 // Title
664 $titleTagContent = $GLOBALS['TSFE']->tmpl->printTitle($GLOBALS['TSFE']->altPageTitle ? $GLOBALS['TSFE']->altPageTitle : $GLOBALS['TSFE']->page['title'], $GLOBALS['TSFE']->config['config']['noPageTitle'], $GLOBALS['TSFE']->config['config']['pageTitleFirst']);
665 if ($GLOBALS['TSFE']->config['config']['titleTagFunction']) {
666 $titleTagContent = $GLOBALS['TSFE']->cObj->callUserFunction($GLOBALS['TSFE']->config['config']['titleTagFunction'], array(), $titleTagContent);
667 }
668 if (strlen($titleTagContent) && intval($GLOBALS['TSFE']->config['config']['noPageTitle']) !== 2) {
669 $pageRenderer->setTitle($titleTagContent);
670 }
671 // Add ending slash only to documents rendered as xhtml
672 $endingSlash = $GLOBALS['TSFE']->xhtmlVersion ? ' /' : '';
673 $pageRenderer->addMetaTag('<meta name="generator" content="TYPO3 ' . TYPO3_branch . ' CMS"' . $endingSlash . '>');
674 $conf = $GLOBALS['TSFE']->pSetup['meta.'];
675 if (is_array($conf)) {
676 foreach ($conf as $theKey => $theValue) {
677 // Only if 1) the property is set but not the value itself, 2) the value and/or any property
678 if (!strstr($theKey, '.') || !isset($conf[substr($theKey, 0, -1)])) {
679 if (strstr($theKey, '.')) {
680 $theKey = substr($theKey, 0, -1);
681 }
682 $val = $GLOBALS['TSFE']->cObj->stdWrap($conf[$theKey], $conf[$theKey . '.']);
683 $key = $theKey;
684 if (trim($val)) {
685 $a = 'name';
686 if (strtolower($key) === 'refresh' || !empty($conf[($theKey . '.')]['httpEquivalent'])) {
687 $a = 'http-equiv';
688 }
689 $pageRenderer->addMetaTag('<meta ' . $a . '="' . $key . '" content="' . htmlspecialchars(trim($val)) . '"' . $endingSlash . '>');
690 }
691 }
692 }
693 }
694 unset($GLOBALS['TSFE']->additionalHeaderData['JSCode']);
695 unset($GLOBALS['TSFE']->additionalHeaderData['JSImgCode']);
696 if (is_array($GLOBALS['TSFE']->config['INTincScript'])) {
697 // Storing the JSCode and JSImgCode vars...
698 $GLOBALS['TSFE']->additionalHeaderData['JSCode'] = $GLOBALS['TSFE']->JSCode;
699 $GLOBALS['TSFE']->additionalHeaderData['JSImgCode'] = $GLOBALS['TSFE']->JSImgCode;
700 $GLOBALS['TSFE']->config['INTincScript_ext']['divKey'] = $GLOBALS['TSFE']->uniqueHash();
701 $GLOBALS['TSFE']->config['INTincScript_ext']['additionalHeaderData'] = $GLOBALS['TSFE']->additionalHeaderData;
702 // Storing the header-data array
703 $GLOBALS['TSFE']->config['INTincScript_ext']['additionalFooterData'] = $GLOBALS['TSFE']->additionalFooterData;
704 // Storing the footer-data array
705 $GLOBALS['TSFE']->config['INTincScript_ext']['additionalJavaScript'] = $GLOBALS['TSFE']->additionalJavaScript;
706 // Storing the JS-data array
707 $GLOBALS['TSFE']->config['INTincScript_ext']['additionalCSS'] = $GLOBALS['TSFE']->additionalCSS;
708 // Storing the Style-data array
709 $GLOBALS['TSFE']->additionalHeaderData = array('<!--HD_' . $GLOBALS['TSFE']->config['INTincScript_ext']['divKey'] . '-->');
710 // Clearing the array
711 $GLOBALS['TSFE']->additionalFooterData = array('<!--FD_' . $GLOBALS['TSFE']->config['INTincScript_ext']['divKey'] . '-->');
712 // Clearing the array
713 $GLOBALS['TSFE']->divSection .= '<!--TDS_' . $GLOBALS['TSFE']->config['INTincScript_ext']['divKey'] . '-->';
714 } else {
715 $GLOBALS['TSFE']->INTincScript_loadJSCode();
716 }
717 $JSef = self::JSeventFunctions();
718 $scriptJsCode = $JSef[0];
719
720 if ($GLOBALS['TSFE']->spamProtectEmailAddresses && $GLOBALS['TSFE']->spamProtectEmailAddresses !== 'ascii') {
721 $scriptJsCode .= '
722 // decrypt helper function
723 function decryptCharcode(n,start,end,offset) {
724 n = n + offset;
725 if (offset > 0 && n > end) {
726 n = start + (n - end - 1);
727 } else if (offset < 0 && n < start) {
728 n = end - (start - n - 1);
729 }
730 return String.fromCharCode(n);
731 }
732 // decrypt string
733 function decryptString(enc,offset) {
734 var dec = "";
735 var len = enc.length;
736 for(var i=0; i < len; i++) {
737 var n = enc.charCodeAt(i);
738 if (n >= 0x2B && n <= 0x3A) {
739 dec += decryptCharcode(n,0x2B,0x3A,offset); // 0-9 . , - + / :
740 } else if (n >= 0x40 && n <= 0x5A) {
741 dec += decryptCharcode(n,0x40,0x5A,offset); // A-Z @
742 } else if (n >= 0x61 && n <= 0x7A) {
743 dec += decryptCharcode(n,0x61,0x7A,offset); // a-z
744 } else {
745 dec += enc.charAt(i);
746 }
747 }
748 return dec;
749 }
750 // decrypt spam-protected emails
751 function linkTo_UnCryptMailto(s) {
752 location.href = decryptString(s,' . $GLOBALS['TSFE']->spamProtectEmailAddresses * -1 . ');
753 }
754 ';
755 }
756 // Add inline JS
757 $inlineJS = '';
758 // defined in php
759 if (is_array($GLOBALS['TSFE']->inlineJS)) {
760 foreach ($GLOBALS['TSFE']->inlineJS as $key => $val) {
761 if (!is_array($val)) {
762 $inlineJS .= LF . $val . LF;
763 }
764 }
765 }
766 // defined in TS with page.inlineJS
767 // Javascript inline code
768 $inline = $GLOBALS['TSFE']->cObj->cObjGet($GLOBALS['TSFE']->pSetup['jsInline.'], 'jsInline.');
769 if ($inline) {
770 $inlineJS .= LF . $inline . LF;
771 }
772 // Javascript inline code for Footer
773 $inlineFooterJs = $GLOBALS['TSFE']->cObj->cObjGet($GLOBALS['TSFE']->pSetup['jsFooterInline.'], 'jsFooterInline.');
774 // Should minify?
775 if ($GLOBALS['TSFE']->config['config']['compressJs']) {
776 $pageRenderer->enableCompressJavascript();
777 $minifyErrorScript = ($minifyErrorInline = '');
778 $scriptJsCode = GeneralUtility::minifyJavaScript($scriptJsCode, $minifyErrorScript);
779 if ($minifyErrorScript) {
780 $GLOBALS['TT']->setTSlogMessage($minifyErrorScript, 3);
781 }
782 if ($inlineJS) {
783 $inlineJS = GeneralUtility::minifyJavaScript($inlineJS, $minifyErrorInline);
784 if ($minifyErrorInline) {
785 $GLOBALS['TT']->setTSlogMessage($minifyErrorInline, 3);
786 }
787 }
788 if ($inlineFooterJs) {
789 $inlineFooterJs = GeneralUtility::minifyJavaScript($inlineFooterJs, $minifyErrorInline);
790 if ($minifyErrorInline) {
791 $GLOBALS['TT']->setTSlogMessage($minifyErrorInline, 3);
792 }
793 }
794 }
795 if (!$GLOBALS['TSFE']->config['config']['removeDefaultJS']) {
796 // inlude default and inlineJS
797 if ($scriptJsCode) {
798 $pageRenderer->addJsInlineCode('_scriptCode', $scriptJsCode, $GLOBALS['TSFE']->config['config']['compressJs']);
799 }
800 if ($inlineJS) {
801 $pageRenderer->addJsInlineCode('TS_inlineJS', $inlineJS, $GLOBALS['TSFE']->config['config']['compressJs']);
802 }
803 if ($inlineFooterJs) {
804 $pageRenderer->addJsFooterInlineCode('TS_inlineFooter', $inlineFooterJs, $GLOBALS['TSFE']->config['config']['compressJs']);
805 }
806 } elseif ($GLOBALS['TSFE']->config['config']['removeDefaultJS'] === 'external') {
807 /*
808 * This keeps inlineJS from *_INT Objects from being moved to external files.
809 * At this point in frontend rendering *_INT Objects only have placeholders instead
810 * of actual content so moving these placeholders to external files would
811 * a) break the JS file (syntax errors due to the placeholders)
812 * b) the needed JS would never get included to the page
813 * Therefore inlineJS from *_INT Objects must not be moved to external files but
814 * kept internal.
815 */
816 $inlineJSint = '';
817 self::stripIntObjectPlaceholder($inlineJS, $inlineJSint);
818 if ($inlineJSint) {
819 $pageRenderer->addJsInlineCode('TS_inlineJSint', $inlineJSint, $GLOBALS['TSFE']->config['config']['compressJs']);
820 }
821 if (trim($scriptJsCode . $inlineJS)) {
822 $pageRenderer->addJsFile(self::inline2TempFile($scriptJsCode . $inlineJS, 'js'), 'text/javascript', $GLOBALS['TSFE']->config['config']['compressJs']);
823 }
824 if ($inlineFooterJs) {
825 $inlineFooterJSint = '';
826 self::stripIntObjectPlaceholder($inlineFooterJs, $inlineFooterJSint);
827 if ($inlineFooterJSint) {
828 $pageRenderer->addJsFooterInlineCode('TS_inlineFooterJSint', $inlineFooterJSint, $GLOBALS['TSFE']->config['config']['compressJs']);
829 }
830 $pageRenderer->addJsFooterFile(self::inline2TempFile($inlineFooterJs, 'js'), 'text/javascript', $GLOBALS['TSFE']->config['config']['compressJs']);
831 }
832 } else {
833 // Include only inlineJS
834 if ($inlineJS) {
835 $pageRenderer->addJsInlineCode('TS_inlineJS', $inlineJS, $GLOBALS['TSFE']->config['config']['compressJs']);
836 }
837 if ($inlineFooterJs) {
838 $pageRenderer->addJsFooterInlineCode('TS_inlineFooter', $inlineFooterJs, $GLOBALS['TSFE']->config['config']['compressJs']);
839 }
840 }
841 // ExtJS specific code
842 if (is_array($GLOBALS['TSFE']->pSetup['inlineLanguageLabel.'])) {
843 $pageRenderer->addInlineLanguageLabelArray($GLOBALS['TSFE']->pSetup['inlineLanguageLabel.']);
844 }
845 if (is_array($GLOBALS['TSFE']->pSetup['inlineSettings.'])) {
846 $pageRenderer->addInlineSettingArray('TS', $GLOBALS['TSFE']->pSetup['inlineSettings.']);
847 }
848 if (is_array($GLOBALS['TSFE']->pSetup['extOnReady.'])) {
849 $pageRenderer->addExtOnReadyCode($GLOBALS['TSFE']->cObj->cObjGet($GLOBALS['TSFE']->pSetup['extOnReady.'], 'extOnReady.'));
850 }
851 // Compression and concatenate settings
852 if ($GLOBALS['TSFE']->config['config']['compressCss']) {
853 $pageRenderer->enableCompressCss();
854 }
855 if ($GLOBALS['TSFE']->config['config']['compressJs']) {
856 $pageRenderer->enableCompressJavascript();
857 }
858 if ($GLOBALS['TSFE']->config['config']['concatenateCss']) {
859 $pageRenderer->enableConcatenateCss();
860 }
861 if ($GLOBALS['TSFE']->config['config']['concatenateJs']) {
862 $pageRenderer->enableConcatenateJavascript();
863 }
864 // Backward compatibility for old configuration
865 if ($GLOBALS['TSFE']->config['config']['concatenateJsAndCss']) {
866 $pageRenderer->enableConcatenateFiles();
867 }
868 // Add header data block
869 if ($GLOBALS['TSFE']->additionalHeaderData) {
870 $pageRenderer->addHeaderData(implode(LF, $GLOBALS['TSFE']->additionalHeaderData));
871 }
872 // Add footer data block
873 if ($GLOBALS['TSFE']->additionalFooterData) {
874 $pageRenderer->addFooterData(implode(LF, $GLOBALS['TSFE']->additionalFooterData));
875 }
876 // Header complete, now add content
877 if ($GLOBALS['TSFE']->pSetup['frameSet.']) {
878 $fs = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\FramesetRenderer');
879 $pageRenderer->addBodyContent($fs->make($GLOBALS['TSFE']->pSetup['frameSet.']));
880 $pageRenderer->addBodyContent(LF . '<noframes>' . LF);
881 }
882 // Bodytag:
883 if ($GLOBALS['TSFE']->config['config']['disableBodyTag']) {
884 $bodyTag = '';
885 } else {
886 $defBT = $GLOBALS['TSFE']->pSetup['bodyTagCObject'] ? $GLOBALS['TSFE']->cObj->cObjGetSingle($GLOBALS['TSFE']->pSetup['bodyTagCObject'], $GLOBALS['TSFE']->pSetup['bodyTagCObject.'], 'bodyTagCObject') : '';
887 if (!$defBT) {
888 $defBT = $GLOBALS['TSFE']->defaultBodyTag;
889 }
890 $bodyTag = $GLOBALS['TSFE']->pSetup['bodyTag'] ? $GLOBALS['TSFE']->pSetup['bodyTag'] : $defBT;
891 if ($bgImg = $GLOBALS['TSFE']->cObj->getImgResource($GLOBALS['TSFE']->pSetup['bgImg'], $GLOBALS['TSFE']->pSetup['bgImg.'])) {
892 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' background="' . $GLOBALS['TSFE']->absRefPrefix . $bgImg[3] . '">';
893 }
894 if (isset($GLOBALS['TSFE']->pSetup['bodyTagMargins'])) {
895 $margins = intval($GLOBALS['TSFE']->pSetup['bodyTagMargins']);
896 if ($GLOBALS['TSFE']->pSetup['bodyTagMargins.']['useCSS']) {
897
898 } else {
899 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' leftmargin="' . $margins . '" topmargin="' . $margins . '" marginwidth="' . $margins . '" marginheight="' . $margins . '">';
900 }
901 }
902 if (trim($GLOBALS['TSFE']->pSetup['bodyTagAdd'])) {
903 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' ' . trim($GLOBALS['TSFE']->pSetup['bodyTagAdd']) . '>';
904 }
905 // Event functions
906 if (count($JSef[1])) {
907 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' ' . trim(implode(' ', $JSef[1])) . '>';
908 }
909 }
910 $pageRenderer->addBodyContent(LF . $bodyTag);
911 // Div-sections
912 if ($GLOBALS['TSFE']->divSection) {
913 $pageRenderer->addBodyContent(LF . $GLOBALS['TSFE']->divSection);
914 }
915 // Page content
916 $pageRenderer->addBodyContent(LF . $pageContent);
917 if (!empty($GLOBALS['TSFE']->config['INTincScript']) && is_array($GLOBALS['TSFE']->config['INTincScript'])) {
918 // Store the serialized pageRenderer in configuration
919 $GLOBALS['TSFE']->config['INTincScript_ext']['pageRenderer'] = serialize($pageRenderer);
920 // Render complete page, keep placeholders for JavaScript and CSS
921 $GLOBALS['TSFE']->content = $pageRenderer->renderPageWithUncachedObjects($GLOBALS['TSFE']->config['INTincScript_ext']['divKey']);
922 } else {
923 // Render complete page
924 $GLOBALS['TSFE']->content = $pageRenderer->render();
925 }
926 // Ending page
927 if ($GLOBALS['TSFE']->pSetup['frameSet.']) {
928 $GLOBALS['TSFE']->content .= LF . '</noframes>';
929 }
930 }
931
932 /*************************
933 *
934 * Helper functions
935 * Remember: Calls internally must still be done on the non-instantiated class: TSpagegen::inline2TempFile()
936 *
937 *************************/
938 /**
939 * Searches for placeholder created from *_INT cObjects, removes them from
940 * $searchString and merges them to $intObjects
941 *
942 * @param string $searchString The String which should be cleaned from int-object markers
943 * @param string $intObjects The String the found int-placeholders are moved to (for further processing)
944 */
945 static protected function stripIntObjectPlaceholder(&$searchString, &$intObjects) {
946 $tempArray = array();
947 preg_match_all('/\\<\\!--INT_SCRIPT.[a-z0-9]*--\\>/', $searchString, $tempArray);
948 $searchString = preg_replace('/\\<\\!--INT_SCRIPT.[a-z0-9]*--\\>/', '', $searchString);
949 $intObjects = implode('', $tempArray[0]);
950 }
951
952 /**
953 * Writes string to a temporary file named after the md5-hash of the string
954 *
955 * @param string $str CSS styles / JavaScript to write to file.
956 * @param string $ext Extension: "css" or "js
957 * @return string <script> or <link> tag for the file.
958 */
959 static public function inline2TempFile($str, $ext) {
960 // Create filename / tags:
961 $script = '';
962 switch ($ext) {
963 case 'js':
964 $script = 'typo3temp/javascript_' . substr(md5($str), 0, 10) . '.js';
965 break;
966 case 'css':
967 $script = 'typo3temp/stylesheet_' . substr(md5($str), 0, 10) . '.css';
968 break;
969 }
970 // Write file:
971 if ($script) {
972 if (!@is_file((PATH_site . $script))) {
973 GeneralUtility::writeFile(PATH_site . $script, $str);
974 }
975 }
976 return $script;
977 }
978
979 /**
980 * Checks if the value defined in "config.linkVars" contains an allowed value. Otherwise, return FALSE which means the value will not be added to any links.
981 *
982 * @param string $haystack The string in which to find $needle
983 * @param string $needle The string to find in $haystack
984 * @return boolean Returns TRUE if $needle matches or is found in $haystack
985 */
986 static public function isAllowedLinkVarValue($haystack, $needle) {
987 $OK = FALSE;
988 // Integer
989 if ($needle == 'int' || $needle == 'integer') {
990 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($haystack)) {
991 $OK = TRUE;
992 }
993 } elseif (preg_match('/^\\/.+\\/[imsxeADSUXu]*$/', $needle)) {
994 // Regular expression, only "//" is allowed as delimiter
995 if (@preg_match($needle, $haystack)) {
996 $OK = TRUE;
997 }
998 } elseif (strstr($needle, '-')) {
999 // Range
1000 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($haystack)) {
1001 $range = explode('-', $needle);
1002 if ($range[0] <= $haystack && $range[1] >= $haystack) {
1003 $OK = TRUE;
1004 }
1005 }
1006 } elseif (strstr($needle, '|')) {
1007 // List
1008 // Trim the input
1009 $haystack = str_replace(' ', '', $haystack);
1010 if (strstr('|' . $needle . '|', '|' . $haystack . '|')) {
1011 $OK = TRUE;
1012 }
1013 } elseif (!strcmp($needle, $haystack)) {
1014 // String comparison
1015 $OK = TRUE;
1016 }
1017 return $OK;
1018 }
1019
1020 }
1021
1022
1023 ?>