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