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