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