[FEATURE] Add page.addInlineLanguageLabelFiles
[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_GENERAL . '
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 // CSS_inlineStyle from TS
542 $style .= trim($tsfe->pSetup['CSS_inlineStyle']);
543 $style .= $tsfe->cObj->cObjGet($tsfe->pSetup['cssInline.'], 'cssInline.');
544 if (trim($style)) {
545 if ($tsfe->config['config']['inlineStyle2TempFile']) {
546 $pageRenderer->addCssFile(self::inline2TempFile($style, 'css'));
547 } else {
548 $pageRenderer->addCssInlineBlock('additionalTSFEInlineStyle', $style);
549 }
550 }
551 // Javascript Libraries
552 if (is_array($tsfe->pSetup['javascriptLibs.'])) {
553 // Include jQuery into the page renderer
554 if (!empty($tsfe->pSetup['javascriptLibs.']['jQuery'])) {
555 $jQueryTS = $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 = PageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT;
566 }
567 } else {
568 $namespace = PageRenderer::JQUERY_NAMESPACE_NONE;
569 }
570 $pageRenderer->loadJQuery($version, $source, $namespace);
571 }
572 if ($tsfe->pSetup['javascriptLibs.']['ExtJs']) {
573 $css = (bool)$tsfe->pSetup['javascriptLibs.']['ExtJs.']['css'];
574 $theme = (bool)$tsfe->pSetup['javascriptLibs.']['ExtJs.']['theme'];
575 $pageRenderer->loadExtJs($css, $theme);
576 if ($tsfe->pSetup['javascriptLibs.']['ExtJs.']['debug']) {
577 $pageRenderer->enableExtJsDebug();
578 }
579 }
580 }
581 // JavaScript library files
582 if (is_array($tsfe->pSetup['includeJSlibs.']) || is_array($tsfe->pSetup['includeJSLibs.'])) {
583 if (!is_array($tsfe->pSetup['includeJSlibs.'])) {
584 $tsfe->pSetup['includeJSlibs.'] = array();
585 } else {
586 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.');
587 }
588 if (!is_array($tsfe->pSetup['includeJSLibs.'])) {
589 $tsfe->pSetup['includeJSLibs.'] = array();
590 }
591 ArrayUtility::mergeRecursiveWithOverrule(
592 $tsfe->pSetup['includeJSLibs.'],
593 $tsfe->pSetup['includeJSlibs.']
594 );
595 unset($tsfe->pSetup['includeJSlibs.']);
596 foreach ($tsfe->pSetup['includeJSLibs.'] as $key => $JSfile) {
597 if (!is_array($JSfile)) {
598 if (isset($tsfe->pSetup['includeJSLibs.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJSLibs.'][($key . '.')]['if.'])) {
599 continue;
600 }
601 $ss = $tsfe->pSetup['includeJSLibs.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
602 if ($ss) {
603 $jsFileConfig = &$tsfe->pSetup['includeJSLibs.'][$key . '.'];
604 $type = $jsFileConfig['type'];
605 if (!$type) {
606 $type = 'text/javascript';
607 }
608
609 $pageRenderer->addJsLibrary(
610 $key,
611 $ss,
612 $type,
613 empty($jsFileConfig['disableCompression']),
614 (bool)$jsFileConfig['forceOnTop'],
615 $jsFileConfig['allWrap'],
616 (bool)$jsFileConfig['excludeFromConcatenation'],
617 $jsFileConfig['allWrap.']['splitChar'],
618 (bool)$jsFileConfig['async'],
619 $jsFileConfig['integrity']
620 );
621 unset($jsFileConfig);
622 }
623 }
624 }
625 }
626 if (is_array($tsfe->pSetup['includeJSFooterlibs.'])) {
627 foreach ($tsfe->pSetup['includeJSFooterlibs.'] as $key => $JSfile) {
628 if (!is_array($JSfile)) {
629 if (isset($tsfe->pSetup['includeJSFooterlibs.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJSFooterlibs.'][($key . '.')]['if.'])) {
630 continue;
631 }
632 $ss = $tsfe->pSetup['includeJSFooterlibs.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
633 if ($ss) {
634 $jsFileConfig = &$tsfe->pSetup['includeJSFooterlibs.'][$key . '.'];
635 $type = $jsFileConfig['type'];
636 if (!$type) {
637 $type = 'text/javascript';
638 }
639 $pageRenderer->addJsFooterLibrary(
640 $key,
641 $ss,
642 $type,
643 empty($jsFileConfig['disableCompression']),
644 (bool)$jsFileConfig['forceOnTop'],
645 $jsFileConfig['allWrap'],
646 (bool)$jsFileConfig['excludeFromConcatenation'],
647 $jsFileConfig['allWrap.']['splitChar'],
648 (bool)$jsFileConfig['async'],
649 $jsFileConfig['integrity']
650 );
651 unset($jsFileConfig);
652 }
653 }
654 }
655 }
656 // JavaScript files
657 if (is_array($tsfe->pSetup['includeJS.'])) {
658 foreach ($tsfe->pSetup['includeJS.'] as $key => $JSfile) {
659 if (!is_array($JSfile)) {
660 if (isset($tsfe->pSetup['includeJS.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJS.'][($key . '.')]['if.'])) {
661 continue;
662 }
663 $ss = $tsfe->pSetup['includeJS.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
664 if ($ss) {
665 $jsConfig = &$tsfe->pSetup['includeJS.'][$key . '.'];
666 $type = $jsConfig['type'];
667 if (!$type) {
668 $type = 'text/javascript';
669 }
670 $pageRenderer->addJsFile(
671 $ss,
672 $type,
673 empty($jsConfig['disableCompression']),
674 (bool)$jsConfig['forceOnTop'],
675 $jsConfig['allWrap'],
676 (bool)$jsConfig['excludeFromConcatenation'],
677 $jsConfig['allWrap.']['splitChar'],
678 (bool)$jsConfig['async'],
679 $jsConfig['integrity']
680 );
681 unset($jsConfig);
682 }
683 }
684 }
685 }
686 if (is_array($tsfe->pSetup['includeJSFooter.'])) {
687 foreach ($tsfe->pSetup['includeJSFooter.'] as $key => $JSfile) {
688 if (!is_array($JSfile)) {
689 if (isset($tsfe->pSetup['includeJSFooter.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJSFooter.'][($key . '.')]['if.'])) {
690 continue;
691 }
692 $ss = $tsfe->pSetup['includeJSFooter.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
693 if ($ss) {
694 $jsConfig = &$tsfe->pSetup['includeJSFooter.'][$key . '.'];
695 $type = $jsConfig['type'];
696 if (!$type) {
697 $type = 'text/javascript';
698 }
699 $pageRenderer->addJsFooterFile(
700 $ss,
701 $type,
702 empty($jsConfig['disableCompression']),
703 (bool)$jsConfig['forceOnTop'],
704 $jsConfig['allWrap'],
705 (bool)$jsConfig['excludeFromConcatenation'],
706 $jsConfig['allWrap.']['splitChar'],
707 (bool)$jsConfig['async'],
708 $jsConfig['integrity']
709 );
710 unset($jsConfig);
711 }
712 }
713 }
714 }
715 // Headerdata
716 if (is_array($tsfe->pSetup['headerData.'])) {
717 $pageRenderer->addHeaderData($tsfe->cObj->cObjGet($tsfe->pSetup['headerData.'], 'headerData.'));
718 }
719 // Footerdata
720 if (is_array($tsfe->pSetup['footerData.'])) {
721 $pageRenderer->addFooterData($tsfe->cObj->cObjGet($tsfe->pSetup['footerData.'], 'footerData.'));
722 }
723 static::generatePageTitle();
724
725 $metaTagsHtml = static::generateMetaTagHtml(
726 isset($tsfe->pSetup['meta.']) ? $tsfe->pSetup['meta.'] : array(),
727 $tsfe->xhtmlVersion,
728 $tsfe->cObj
729 );
730 foreach ($metaTagsHtml as $metaTag) {
731 $pageRenderer->addMetaTag($metaTag);
732 }
733
734 unset($tsfe->additionalHeaderData['JSCode']);
735 if (is_array($tsfe->config['INTincScript'])) {
736 $tsfe->additionalHeaderData['JSCode'] = $tsfe->JSCode;
737 // Storing the JSCode vars...
738 $tsfe->config['INTincScript_ext']['divKey'] = $tsfe->uniqueHash();
739 $tsfe->config['INTincScript_ext']['additionalHeaderData'] = $tsfe->additionalHeaderData;
740 // Storing the header-data array
741 $tsfe->config['INTincScript_ext']['additionalFooterData'] = $tsfe->additionalFooterData;
742 // Storing the footer-data array
743 $tsfe->config['INTincScript_ext']['additionalJavaScript'] = $tsfe->additionalJavaScript;
744 // Storing the JS-data array
745 $tsfe->config['INTincScript_ext']['additionalCSS'] = $tsfe->additionalCSS;
746 // Storing the Style-data array
747 $tsfe->additionalHeaderData = array('<!--HD_' . $tsfe->config['INTincScript_ext']['divKey'] . '-->');
748 // Clearing the array
749 $tsfe->additionalFooterData = array('<!--FD_' . $tsfe->config['INTincScript_ext']['divKey'] . '-->');
750 // Clearing the array
751 $tsfe->divSection .= '<!--TDS_' . $tsfe->config['INTincScript_ext']['divKey'] . '-->';
752 } else {
753 $tsfe->INTincScript_loadJSCode();
754 }
755 $JSef = self::JSeventFunctions();
756 $scriptJsCode = $JSef[0];
757
758 if ($tsfe->spamProtectEmailAddresses && $tsfe->spamProtectEmailAddresses !== 'ascii') {
759 $scriptJsCode = '
760 // decrypt helper function
761 function decryptCharcode(n,start,end,offset) {
762 n = n + offset;
763 if (offset > 0 && n > end) {
764 n = start + (n - end - 1);
765 } else if (offset < 0 && n < start) {
766 n = end - (start - n - 1);
767 }
768 return String.fromCharCode(n);
769 }
770 // decrypt string
771 function decryptString(enc,offset) {
772 var dec = "";
773 var len = enc.length;
774 for(var i=0; i < len; i++) {
775 var n = enc.charCodeAt(i);
776 if (n >= 0x2B && n <= 0x3A) {
777 dec += decryptCharcode(n,0x2B,0x3A,offset); // 0-9 . , - + / :
778 } else if (n >= 0x40 && n <= 0x5A) {
779 dec += decryptCharcode(n,0x40,0x5A,offset); // A-Z @
780 } else if (n >= 0x61 && n <= 0x7A) {
781 dec += decryptCharcode(n,0x61,0x7A,offset); // a-z
782 } else {
783 dec += enc.charAt(i);
784 }
785 }
786 return dec;
787 }
788 // decrypt spam-protected emails
789 function linkTo_UnCryptMailto(s) {
790 location.href = decryptString(s,' . $tsfe->spamProtectEmailAddresses * -1 . ');
791 }
792 ';
793 }
794 // Add inline JS
795 $inlineJS = '';
796 // defined in php
797 if (is_array($tsfe->inlineJS)) {
798 foreach ($tsfe->inlineJS as $key => $val) {
799 if (!is_array($val)) {
800 $inlineJS .= LF . $val . LF;
801 }
802 }
803 }
804 // defined in TS with page.inlineJS
805 // Javascript inline code
806 $inline = $tsfe->cObj->cObjGet($tsfe->pSetup['jsInline.'], 'jsInline.');
807 if ($inline) {
808 $inlineJS .= LF . $inline . LF;
809 }
810 // Javascript inline code for Footer
811 $inlineFooterJs = $tsfe->cObj->cObjGet($tsfe->pSetup['jsFooterInline.'], 'jsFooterInline.');
812 // Should minify?
813 if ($tsfe->config['config']['compressJs']) {
814 $pageRenderer->enableCompressJavascript();
815 $minifyErrorScript = ($minifyErrorInline = '');
816 $scriptJsCode = GeneralUtility::minifyJavaScript($scriptJsCode, $minifyErrorScript);
817 if ($minifyErrorScript) {
818 $timeTracker->setTSlogMessage($minifyErrorScript, 3);
819 }
820 if ($inlineJS) {
821 $inlineJS = GeneralUtility::minifyJavaScript($inlineJS, $minifyErrorInline);
822 if ($minifyErrorInline) {
823 $timeTracker->setTSlogMessage($minifyErrorInline, 3);
824 }
825 }
826 if ($inlineFooterJs) {
827 $inlineFooterJs = GeneralUtility::minifyJavaScript($inlineFooterJs, $minifyErrorInline);
828 if ($minifyErrorInline) {
829 $timeTracker->setTSlogMessage($minifyErrorInline, 3);
830 }
831 }
832 }
833 if (!$tsfe->config['config']['removeDefaultJS']) {
834 // inlude default and inlineJS
835 if ($scriptJsCode) {
836 $pageRenderer->addJsInlineCode('_scriptCode', $scriptJsCode, $tsfe->config['config']['compressJs']);
837 }
838 if ($inlineJS) {
839 $pageRenderer->addJsInlineCode('TS_inlineJS', $inlineJS, $tsfe->config['config']['compressJs']);
840 }
841 if ($inlineFooterJs) {
842 $pageRenderer->addJsFooterInlineCode('TS_inlineFooter', $inlineFooterJs, $tsfe->config['config']['compressJs']);
843 }
844 } elseif ($tsfe->config['config']['removeDefaultJS'] === 'external') {
845 /*
846 * This keeps inlineJS from *_INT Objects from being moved to external files.
847 * At this point in frontend rendering *_INT Objects only have placeholders instead
848 * of actual content so moving these placeholders to external files would
849 * a) break the JS file (syntax errors due to the placeholders)
850 * b) the needed JS would never get included to the page
851 * Therefore inlineJS from *_INT Objects must not be moved to external files but
852 * kept internal.
853 */
854 $inlineJSint = '';
855 self::stripIntObjectPlaceholder($inlineJS, $inlineJSint);
856 if ($inlineJSint) {
857 $pageRenderer->addJsInlineCode('TS_inlineJSint', $inlineJSint, $tsfe->config['config']['compressJs']);
858 }
859 if (trim($scriptJsCode . $inlineJS)) {
860 $pageRenderer->addJsFile(self::inline2TempFile($scriptJsCode . $inlineJS, 'js'), 'text/javascript', $tsfe->config['config']['compressJs']);
861 }
862 if ($inlineFooterJs) {
863 $inlineFooterJSint = '';
864 self::stripIntObjectPlaceholder($inlineFooterJs, $inlineFooterJSint);
865 if ($inlineFooterJSint) {
866 $pageRenderer->addJsFooterInlineCode('TS_inlineFooterJSint', $inlineFooterJSint, $tsfe->config['config']['compressJs']);
867 }
868 $pageRenderer->addJsFooterFile(self::inline2TempFile($inlineFooterJs, 'js'), 'text/javascript', $tsfe->config['config']['compressJs']);
869 }
870 } else {
871 // Include only inlineJS
872 if ($inlineJS) {
873 $pageRenderer->addJsInlineCode('TS_inlineJS', $inlineJS, $tsfe->config['config']['compressJs']);
874 }
875 if ($inlineFooterJs) {
876 $pageRenderer->addJsFooterInlineCode('TS_inlineFooter', $inlineFooterJs, $tsfe->config['config']['compressJs']);
877 }
878 }
879 if (is_array($tsfe->pSetup['inlineLanguageLabelFiles.'])) {
880 foreach ($tsfe->pSetup['inlineLanguageLabelFiles.'] as $key => $languageFile) {
881 if (is_array($languageFile)) {
882 continue;
883 }
884 $languageFileConfig = &$tsfe->pSetup['inlineLanguageLabelFiles.'][$key . '.'];
885 if (isset($languageFileConfig['if.']) && !$tsfe->cObj->checkIf($languageFileConfig['if.'])) {
886 continue;
887 }
888 $pageRenderer->addInlineLanguageLabelFile(
889 $languageFile,
890 $languageFileConfig['selectionPrefix'] ?: '',
891 $languageFileConfig['stripFromSelectionName'] ?: '',
892 $languageFileConfig['errorMode'] ? (int)$languageFileConfig['errorMode'] : 0
893 );
894 }
895 }
896 // ExtJS specific code
897 if (is_array($tsfe->pSetup['inlineLanguageLabel.'])) {
898 $pageRenderer->addInlineLanguageLabelArray($tsfe->pSetup['inlineLanguageLabel.'], TRUE);
899 }
900 if (is_array($tsfe->pSetup['inlineSettings.'])) {
901 $pageRenderer->addInlineSettingArray('TS', $tsfe->pSetup['inlineSettings.']);
902 }
903 if (is_array($tsfe->pSetup['extOnReady.'])) {
904 $pageRenderer->addExtOnReadyCode($tsfe->cObj->cObjGet($tsfe->pSetup['extOnReady.'], 'extOnReady.'));
905 }
906 // Compression and concatenate settings
907 if ($tsfe->config['config']['compressCss']) {
908 $pageRenderer->enableCompressCss();
909 }
910 if ($tsfe->config['config']['compressJs']) {
911 $pageRenderer->enableCompressJavascript();
912 }
913 if ($tsfe->config['config']['concatenateCss']) {
914 $pageRenderer->enableConcatenateCss();
915 }
916 if ($tsfe->config['config']['concatenateJs']) {
917 $pageRenderer->enableConcatenateJavascript();
918 }
919 // Backward compatibility for old configuration
920 if ($tsfe->config['config']['concatenateJsAndCss']) {
921 $pageRenderer->enableConcatenateFiles();
922 }
923 // Add header data block
924 if ($tsfe->additionalHeaderData) {
925 $pageRenderer->addHeaderData(implode(LF, $tsfe->additionalHeaderData));
926 }
927 // Add footer data block
928 if ($tsfe->additionalFooterData) {
929 $pageRenderer->addFooterData(implode(LF, $tsfe->additionalFooterData));
930 }
931 // Header complete, now add content
932 if ($tsfe->pSetup['frameSet.']) {
933 $fs = GeneralUtility::makeInstance(FramesetRenderer::class);
934 $pageRenderer->addBodyContent($fs->make($tsfe->pSetup['frameSet.']));
935 $pageRenderer->addBodyContent(LF . '<noframes>' . LF);
936 }
937 // Bodytag:
938 if ($tsfe->config['config']['disableBodyTag']) {
939 $bodyTag = '';
940 } else {
941 $defBT = $tsfe->pSetup['bodyTagCObject'] ? $tsfe->cObj->cObjGetSingle($tsfe->pSetup['bodyTagCObject'], $tsfe->pSetup['bodyTagCObject.'], 'bodyTagCObject') : '';
942 if (!$defBT) {
943 $defBT = $tsfe->defaultBodyTag;
944 }
945 $bodyTag = $tsfe->pSetup['bodyTag'] ? $tsfe->pSetup['bodyTag'] : $defBT;
946 if ($bgImg = $tsfe->cObj->getImgResource($tsfe->pSetup['bgImg'], $tsfe->pSetup['bgImg.'])) {
947 GeneralUtility::deprecationLog('The option "page.bgImg" is deprecated since TYPO3 CMS 7, and will be removed with CMS 8');
948 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' background="' . $tsfe->absRefPrefix . $bgImg[3] . '">';
949 }
950 if (isset($tsfe->pSetup['bodyTagMargins'])) {
951 $margins = (int)$tsfe->pSetup['bodyTagMargins'];
952 if ($tsfe->pSetup['bodyTagMargins.']['useCSS']) {
953
954 } else {
955 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' leftmargin="' . $margins . '" topmargin="' . $margins . '" marginwidth="' . $margins . '" marginheight="' . $margins . '">';
956 }
957 }
958 if (trim($tsfe->pSetup['bodyTagAdd'])) {
959 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' ' . trim($tsfe->pSetup['bodyTagAdd']) . '>';
960 }
961 // Event functions
962 if (!empty($JSef[1])) {
963 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' ' . trim(implode(' ', $JSef[1])) . '>';
964 }
965 }
966 $pageRenderer->addBodyContent(LF . $bodyTag);
967 // Div-sections
968 if ($tsfe->divSection) {
969 $pageRenderer->addBodyContent(LF . $tsfe->divSection);
970 }
971 // Page content
972 $pageRenderer->addBodyContent(LF . $pageContent);
973 if (!empty($tsfe->config['INTincScript']) && is_array($tsfe->config['INTincScript'])) {
974 // Store the serialized pageRenderer in configuration
975 $tsfe->config['INTincScript_ext']['pageRenderer'] = serialize($pageRenderer);
976 // Render complete page, keep placeholders for JavaScript and CSS
977 $tsfe->content = $pageRenderer->renderPageWithUncachedObjects($tsfe->config['INTincScript_ext']['divKey']);
978 } else {
979 // Render complete page
980 $tsfe->content = $pageRenderer->render();
981 }
982 // Ending page
983 if ($tsfe->pSetup['frameSet.']) {
984 $tsfe->content .= LF . '</noframes>';
985 }
986 }
987
988 /*************************
989 *
990 * Helper functions
991 * Remember: Calls internally must still be done on the non-instantiated class: PageGenerator::inline2TempFile()
992 *
993 *************************/
994 /**
995 * Searches for placeholder created from *_INT cObjects, removes them from
996 * $searchString and merges them to $intObjects
997 *
998 * @param string $searchString The String which should be cleaned from int-object markers
999 * @param string $intObjects The String the found int-placeholders are moved to (for further processing)
1000 */
1001 static protected function stripIntObjectPlaceholder(&$searchString, &$intObjects) {
1002 $tempArray = array();
1003 preg_match_all('/\\<\\!--INT_SCRIPT.[a-z0-9]*--\\>/', $searchString, $tempArray);
1004 $searchString = preg_replace('/\\<\\!--INT_SCRIPT.[a-z0-9]*--\\>/', '', $searchString);
1005 $intObjects = implode('', $tempArray[0]);
1006 }
1007
1008 /**
1009 * Writes string to a temporary file named after the md5-hash of the string
1010 *
1011 * @param string $str CSS styles / JavaScript to write to file.
1012 * @param string $ext Extension: "css" or "js
1013 * @return string <script> or <link> tag for the file.
1014 */
1015 static public function inline2TempFile($str, $ext) {
1016 // Create filename / tags:
1017 $script = '';
1018 switch ($ext) {
1019 case 'js':
1020 $script = 'typo3temp/javascript_' . substr(md5($str), 0, 10) . '.js';
1021 break;
1022 case 'css':
1023 $script = 'typo3temp/stylesheet_' . substr(md5($str), 0, 10) . '.css';
1024 break;
1025 }
1026 // Write file:
1027 if ($script) {
1028 if (!@is_file((PATH_site . $script))) {
1029 GeneralUtility::writeFile(PATH_site . $script, $str);
1030 }
1031 }
1032 return $script;
1033 }
1034
1035 /**
1036 * 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.
1037 *
1038 * @param string $haystack The string in which to find $needle
1039 * @param string $needle The string to find in $haystack
1040 * @return bool Returns TRUE if $needle matches or is found in $haystack
1041 */
1042 static public function isAllowedLinkVarValue($haystack, $needle) {
1043 $OK = FALSE;
1044 // Integer
1045 if ($needle == 'int' || $needle == 'integer') {
1046 if (MathUtility::canBeInterpretedAsInteger($haystack)) {
1047 $OK = TRUE;
1048 }
1049 } elseif (preg_match('/^\\/.+\\/[imsxeADSUXu]*$/', $needle)) {
1050 // Regular expression, only "//" is allowed as delimiter
1051 if (@preg_match($needle, $haystack)) {
1052 $OK = TRUE;
1053 }
1054 } elseif (strstr($needle, '-')) {
1055 // Range
1056 if (MathUtility::canBeInterpretedAsInteger($haystack)) {
1057 $range = explode('-', $needle);
1058 if ($range[0] <= $haystack && $range[1] >= $haystack) {
1059 $OK = TRUE;
1060 }
1061 }
1062 } elseif (strstr($needle, '|')) {
1063 // List
1064 // Trim the input
1065 $haystack = str_replace(' ', '', $haystack);
1066 if (strstr('|' . $needle . '|', '|' . $haystack . '|')) {
1067 $OK = TRUE;
1068 }
1069 } elseif ((string)$needle === (string)$haystack) {
1070 // String comparison
1071 $OK = TRUE;
1072 }
1073 return $OK;
1074 }
1075
1076 /**
1077 * Generate title for page.
1078 * Takes the settings [config][noPageTitle], [config][pageTitleFirst], [config][titleTagFunction]
1079 * [config][pageTitleSeparator] and [config][noPageTitle] into account.
1080 * Furthermore $GLOBALS[TSFE]->altPageTitle is observed.
1081 *
1082 * @return void
1083 */
1084 static public function generatePageTitle() {
1085 /** @var TypoScriptFrontendController $tsfe */
1086 $tsfe = $GLOBALS['TSFE'];
1087
1088 $pageTitleSeparator = '';
1089
1090 // check for a custom pageTitleSeparator, and perform stdWrap on it
1091 if (isset($tsfe->config['config']['pageTitleSeparator']) && $tsfe->config['config']['pageTitleSeparator'] !== '') {
1092 $pageTitleSeparator = $tsfe->config['config']['pageTitleSeparator'];
1093
1094 if (isset($tsfe->config['config']['pageTitleSeparator.']) && is_array($tsfe->config['config']['pageTitleSeparator.'])) {
1095 $pageTitleSeparator = $tsfe->cObj->stdWrap($pageTitleSeparator, $tsfe->config['config']['pageTitleSeparator.']);
1096 } else {
1097 $pageTitleSeparator .= ' ';
1098 }
1099 }
1100
1101 $titleTagContent = $tsfe->tmpl->printTitle(
1102 $tsfe->altPageTitle ?: $tsfe->page['title'],
1103 $tsfe->config['config']['noPageTitle'],
1104 $tsfe->config['config']['pageTitleFirst'],
1105 $pageTitleSeparator
1106 );
1107 if ($tsfe->config['config']['titleTagFunction']) {
1108 $titleTagContent = $tsfe->cObj->callUserFunction(
1109 $tsfe->config['config']['titleTagFunction'],
1110 array(),
1111 $titleTagContent
1112 );
1113 }
1114 // stdWrap around the title tag
1115 if (isset($tsfe->config['config']['pageTitle.']) && is_array($tsfe->config['config']['pageTitle.'])) {
1116 $titleTagContent = $tsfe->cObj->stdWrap($titleTagContent, $tsfe->config['config']['pageTitle.']);
1117 }
1118 if ($titleTagContent !== '' && (int)$tsfe->config['config']['noPageTitle'] !== self::NO_PAGE_TITLE) {
1119 static::getPageRenderer()->setTitle($titleTagContent);
1120 }
1121 }
1122
1123 /**
1124 * Generate meta tags from meta tag TypoScript
1125 *
1126 * @param array $metaTagTypoScript TypoScript configuration for meta tags (e.g. $GLOBALS['TSFE']->pSetup['meta.'])
1127 * @param bool $xhtml Whether xhtml tag-style should be used. (e.g. pass $GLOBALS['TSFE']->xhtmlVersion here)
1128 * @param ContentObjectRenderer $cObj
1129 * @return array Array of HTML meta tags
1130 */
1131 static protected function generateMetaTagHtml(array $metaTagTypoScript, $xhtml, ContentObjectRenderer $cObj) {
1132 // Add ending slash only to documents rendered as xhtml
1133 $endingSlash = $xhtml ? ' /' : '';
1134
1135 $metaTags = array(
1136 '<meta name="generator" content="TYPO3 CMS"' . $endingSlash . '>'
1137 );
1138
1139 /** @var TypoScriptService $typoScriptService */
1140 $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
1141 $conf = $typoScriptService->convertTypoScriptArrayToPlainArray($metaTagTypoScript);
1142 foreach ($conf as $key => $properties) {
1143 if (is_array($properties)) {
1144 $nodeValue = isset($properties['_typoScriptNodeValue']) ? $properties['_typoScriptNodeValue'] : '';
1145 $value = trim($cObj->stdWrap($nodeValue, $metaTagTypoScript[$key . '.']));
1146 if ($value === '' && !empty($properties['value'])) {
1147 $value = $properties['value'];
1148 }
1149 } else {
1150 $value = $properties;
1151 }
1152
1153 $attribute = 'name';
1154 if ((is_array($properties) && !empty($properties['httpEquivalent'])) || strtolower($key) === 'refresh') {
1155 $attribute = 'http-equiv';
1156 }
1157 if (is_array($properties) && !empty($properties['attribute'])) {
1158 $attribute = $properties['attribute'];
1159 }
1160
1161 if (!is_array($value)) {
1162 $value = (array)$value;
1163 }
1164 foreach ($value as $subValue) {
1165 if (trim($subValue) !== '') {
1166 $metaTags[] = '<meta ' . $attribute . '="' . $key . '" content="' . htmlspecialchars($subValue) . '"' . $endingSlash . '>';
1167 }
1168 }
1169 }
1170 return $metaTags;
1171 }
1172
1173 /**
1174 * Fills the sWordList property and builds the regular expression in TSFE that can be used to split
1175 * strings by the submitted search words.
1176 *
1177 * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::sWordList
1178 * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::sWordRegEx
1179 */
1180 static protected function initializeSearchWordDataInTsfe() {
1181 /** @var TypoScriptFrontendController $tsfe */
1182 $tsfe = $GLOBALS['TSFE'];
1183
1184 $tsfe->sWordRegEx = '';
1185 $tsfe->sWordList = GeneralUtility::_GP('sword_list');
1186 if (is_array($tsfe->sWordList)) {
1187 $space = !empty($tsfe->config['config']['sword_standAlone']) ? '[[:space:]]' : '';
1188 foreach ($tsfe->sWordList as $val) {
1189 if (trim($val) !== '') {
1190 $tsfe->sWordRegEx .= $space . preg_quote($val, '/') . $space . '|';
1191 }
1192 }
1193 $tsfe->sWordRegEx = rtrim($tsfe->sWordRegEx, '|');
1194 }
1195 }
1196
1197 /**
1198 * @return PageRenderer
1199 */
1200 static protected function getPageRenderer() {
1201 return GeneralUtility::makeInstance(PageRenderer::class);
1202 }
1203 }