[BUGFIX] Doctype set to html5 should not render xmlns attribute
[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 } else {
279 $xmlDocument = FALSE;
280 }
281 break;
282 default:
283 $docTypeParts[] = $tsfe->config['config']['xmlprologue'];
284 }
285 // Part 2: DTD
286 $doctype = $tsfe->config['config']['doctype'];
287 if ($doctype) {
288 switch ($doctype) {
289 case 'xhtml_trans':
290 $docTypeParts[] = '<!DOCTYPE html
291 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
292 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
293 break;
294 case 'xhtml_strict':
295 $docTypeParts[] = '<!DOCTYPE html
296 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
297 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
298 break;
299 case 'xhtml_frames':
300 $docTypeParts[] = '<!DOCTYPE html
301 PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
302 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
303 break;
304 case 'xhtml_basic':
305 $docTypeParts[] = '<!DOCTYPE html
306 PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
307 "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">';
308 break;
309 case 'xhtml_11':
310 $docTypeParts[] = '<!DOCTYPE html
311 PUBLIC "-//W3C//DTD XHTML 1.1//EN"
312 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
313 break;
314 case 'xhtml_2':
315 $docTypeParts[] = '<!DOCTYPE html
316 PUBLIC "-//W3C//DTD XHTML 2.0//EN"
317 "http://www.w3.org/TR/xhtml2/DTD/xhtml2.dtd">';
318 break;
319 case 'xhtml+rdfa_10':
320 $docTypeParts[] = '<!DOCTYPE html
321 PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
322 "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">';
323 break;
324 case 'html5':
325 $docTypeParts[] = '<!DOCTYPE html>';
326 if ($xmlDocument) {
327 $pageRenderer->setMetaCharsetTag('<meta charset="|" />');
328 } else {
329 $pageRenderer->setMetaCharsetTag('<meta charset="|">');
330 }
331 break;
332 case 'none':
333 break;
334 default:
335 $docTypeParts[] = $doctype;
336 }
337 } else {
338 $docTypeParts[] = '<!DOCTYPE html>';
339 if ($xmlDocument){
340 $pageRenderer->setMetaCharsetTag('<meta charset="|" />');
341 } else {
342 $pageRenderer->setMetaCharsetTag('<meta charset="|">');
343 }
344 }
345 if ($tsfe->xhtmlVersion) {
346 $htmlTagAttributes['xml:lang'] = $htmlLang;
347 }
348 if ($tsfe->xhtmlVersion < 110 || $doctype === 'html5') {
349 $htmlTagAttributes['lang'] = $htmlLang;
350 }
351 if ($tsfe->xhtmlVersion || $doctype === 'html5' && $xmlDocument) {
352 // We add this to HTML5 to achieve a slightly better backwards compatibility
353 $htmlTagAttributes['xmlns'] = 'http://www.w3.org/1999/xhtml';
354 if (is_array($tsfe->config['config']['namespaces.'])) {
355 foreach ($tsfe->config['config']['namespaces.'] as $prefix => $uri) {
356 // $uri gets htmlspecialchared later
357 $htmlTagAttributes['xmlns:' . htmlspecialchars($prefix)] = $uri;
358 }
359 }
360 }
361 // Swap XML and doctype order around (for MSIE / Opera standards compliance)
362 if ($tsfe->config['config']['doctypeSwitch']) {
363 $docTypeParts = array_reverse($docTypeParts);
364 }
365 // Adding doctype parts:
366 if (!empty($docTypeParts)) {
367 $pageRenderer->setXmlPrologAndDocType(implode(LF, $docTypeParts));
368 }
369 // Begin header section:
370 if ($tsfe->config['config']['htmlTag_setParams'] !== 'none') {
371 $_attr = $tsfe->config['config']['htmlTag_setParams'] ? $tsfe->config['config']['htmlTag_setParams'] : GeneralUtility::implodeAttributes($htmlTagAttributes);
372 } else {
373 $_attr = '';
374 }
375 $htmlTag = '<html' . ($_attr ? ' ' . $_attr : '') . '>';
376 if (isset($tsfe->config['config']['htmlTag_stdWrap.'])) {
377 $htmlTag = $tsfe->cObj->stdWrap($htmlTag, $tsfe->config['config']['htmlTag_stdWrap.']);
378 }
379 $pageRenderer->setHtmlTag($htmlTag);
380 // Head tag:
381 $headTag = $tsfe->pSetup['headTag'] ?: '<head>';
382 if (isset($tsfe->pSetup['headTag.'])) {
383 $headTag = $tsfe->cObj->stdWrap($headTag, $tsfe->pSetup['headTag.']);
384 }
385 $pageRenderer->setHeadTag($headTag);
386 // Setting charset meta tag:
387 $pageRenderer->setCharSet($theCharset);
388 $pageRenderer->addInlineComment(' This website is powered by TYPO3 - inspiring people to share!
389 TYPO3 is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.
390 TYPO3 is copyright ' . TYPO3_copyright_year . ' of Kasper Skaarhoj. Extensions are copyright of their respective owners.
391 Information and contribution at ' . TYPO3_URL_GENERAL . '
392 ');
393 if ($tsfe->baseUrl) {
394 $pageRenderer->setBaseUrl($tsfe->baseUrl);
395 }
396 if ($tsfe->pSetup['shortcutIcon']) {
397 $favIcon = $tsfe->tmpl->getFileName($tsfe->pSetup['shortcutIcon']);
398 $iconFileInfo = GeneralUtility::makeInstance(ImageInfo::class, PATH_site . $favIcon);
399 if ($iconFileInfo->isFile()) {
400 $iconMimeType = $iconFileInfo->getMimeType();
401 if ($iconMimeType) {
402 $iconMimeType = ' type="' . $iconMimeType . '"';
403 $pageRenderer->setIconMimeType($iconMimeType);
404 }
405 $pageRenderer->setFavIcon(GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $favIcon);
406 }
407 }
408 // Including CSS files
409 if (is_array($tsfe->tmpl->setup['plugin.'])) {
410 $stylesFromPlugins = '';
411 foreach ($tsfe->tmpl->setup['plugin.'] as $key => $iCSScode) {
412 if (is_array($iCSScode)) {
413 if ($iCSScode['_CSS_DEFAULT_STYLE'] && empty($tsfe->config['config']['removeDefaultCss'])) {
414 if (isset($iCSScode['_CSS_DEFAULT_STYLE.'])) {
415 $cssDefaultStyle = $tsfe->cObj->stdWrap($iCSScode['_CSS_DEFAULT_STYLE'], $iCSScode['_CSS_DEFAULT_STYLE.']);
416 } else {
417 $cssDefaultStyle = $iCSScode['_CSS_DEFAULT_STYLE'];
418 }
419 $stylesFromPlugins .= '/* default styles for extension "' . substr($key, 0, -1) . '" */' . LF . $cssDefaultStyle . LF;
420 }
421 if ($iCSScode['_CSS_PAGE_STYLE'] && empty($tsfe->config['config']['removePageCss'])) {
422 $cssPageStyle = implode(LF, $iCSScode['_CSS_PAGE_STYLE']);
423 if (isset($iCSScode['_CSS_PAGE_STYLE.'])) {
424 $cssPageStyle = $tsfe->cObj->stdWrap($cssPageStyle, $iCSScode['_CSS_PAGE_STYLE.']);
425 }
426 $cssPageStyle = '/* specific page styles for extension "' . substr($key, 0, -1) . '" */' . LF . $cssPageStyle;
427 self::addCssToPageRenderer($cssPageStyle, TRUE);
428 }
429 }
430 }
431 if (!empty($stylesFromPlugins)) {
432 self::addCssToPageRenderer($stylesFromPlugins);
433 }
434 }
435 if ($tsfe->pSetup['stylesheet']) {
436 $ss = $tsfe->tmpl->getFileName($tsfe->pSetup['stylesheet']);
437 if ($ss) {
438 $pageRenderer->addCssFile($ss);
439 }
440 }
441 /**********************************************************************/
442 /* config.includeCSS / config.includeCSSLibs
443 /**********************************************************************/
444 if (is_array($tsfe->pSetup['includeCSS.'])) {
445 foreach ($tsfe->pSetup['includeCSS.'] as $key => $CSSfile) {
446 if (!is_array($CSSfile)) {
447 $cssFileConfig = &$tsfe->pSetup['includeCSS.'][$key . '.'];
448 if (isset($cssFileConfig['if.']) && !$tsfe->cObj->checkIf($cssFileConfig['if.'])) {
449 continue;
450 }
451 $ss = $cssFileConfig['external'] ? $CSSfile : $tsfe->tmpl->getFileName($CSSfile);
452 if ($ss) {
453 if ($cssFileConfig['import']) {
454 if (!$cssFileConfig['external'] && $ss[0] !== '/') {
455 // To fix MSIE 6 that cannot handle these as relative paths (according to Ben v Ende)
456 $ss = GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/' . $ss;
457 }
458 $pageRenderer->addCssInlineBlock('import_' . $key, '@import url("' . htmlspecialchars($ss) . '") ' . htmlspecialchars($cssFileConfig['media']) . ';', empty($cssFileConfig['disableCompression']), (bool)$cssFileConfig['forceOnTop'], '');
459 } else {
460 $pageRenderer->addCssFile(
461 $ss,
462 $cssFileConfig['alternate'] ? 'alternate stylesheet' : 'stylesheet',
463 $cssFileConfig['media'] ?: 'all',
464 $cssFileConfig['title'] ?: '',
465 empty($cssFileConfig['disableCompression']),
466 (bool)$cssFileConfig['forceOnTop'],
467 $cssFileConfig['allWrap'],
468 (bool)$cssFileConfig['excludeFromConcatenation'],
469 $cssFileConfig['allWrap.']['splitChar']
470 );
471 unset($cssFileConfig);
472 }
473 }
474 }
475 }
476 }
477 if (is_array($tsfe->pSetup['includeCSSLibs.'])) {
478 foreach ($tsfe->pSetup['includeCSSLibs.'] as $key => $CSSfile) {
479 if (!is_array($CSSfile)) {
480 $cssFileConfig = &$tsfe->pSetup['includeCSSLibs.'][$key . '.'];
481 if (isset($cssFileConfig['if.']) && !$tsfe->cObj->checkIf($cssFileConfig['if.'])) {
482 continue;
483 }
484 $ss = $cssFileConfig['external'] ? $CSSfile : $tsfe->tmpl->getFileName($CSSfile);
485 if ($ss) {
486 if ($cssFileConfig['import']) {
487 if (!$cssFileConfig['external'] && $ss[0] !== '/') {
488 // To fix MSIE 6 that cannot handle these as relative paths (according to Ben v Ende)
489 $ss = GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/' . $ss;
490 }
491 $pageRenderer->addCssInlineBlock('import_' . $key, '@import url("' . htmlspecialchars($ss) . '") ' . htmlspecialchars($cssFileConfig['media']) . ';', empty($cssFileConfig['disableCompression']), (bool)$cssFileConfig['forceOnTop'], '');
492 } else {
493 $pageRenderer->addCssLibrary(
494 $ss,
495 $cssFileConfig['alternate'] ? 'alternate stylesheet' : 'stylesheet',
496 $cssFileConfig['media'] ?: 'all',
497 $cssFileConfig['title'] ?: '',
498 empty($cssFileConfig['disableCompression']),
499 (bool)$cssFileConfig['forceOnTop'],
500 $cssFileConfig['allWrap'],
501 (bool)$cssFileConfig['excludeFromConcatenation'],
502 $cssFileConfig['allWrap.']['splitChar']
503 );
504 unset($cssFileConfig);
505 }
506 }
507 }
508 }
509 }
510
511 // Stylesheets
512 $style = '';
513 if ($tsfe->pSetup['insertClassesFromRTE']) {
514 $pageTSConfig = $tsfe->getPagesTSconfig();
515 $RTEclasses = $pageTSConfig['RTE.']['classes.'];
516 if (is_array($RTEclasses)) {
517 foreach ($RTEclasses as $RTEclassName => $RTEvalueArray) {
518 if ($RTEvalueArray['value']) {
519 $style .= '
520 .' . substr($RTEclassName, 0, -1) . ' {' . $RTEvalueArray['value'] . '}';
521 }
522 }
523 }
524 if ($tsfe->pSetup['insertClassesFromRTE.']['add_mainStyleOverrideDefs'] && is_array($pageTSConfig['RTE.']['default.']['mainStyleOverride_add.'])) {
525 $mSOa_tList = GeneralUtility::trimExplode(',', strtoupper($tsfe->pSetup['insertClassesFromRTE.']['add_mainStyleOverrideDefs']), TRUE);
526 foreach ($pageTSConfig['RTE.']['default.']['mainStyleOverride_add.'] as $mSOa_key => $mSOa_value) {
527 if (!is_array($mSOa_value) && (in_array('*', $mSOa_tList) || in_array($mSOa_key, $mSOa_tList))) {
528 $style .= '
529 ' . $mSOa_key . ' {' . $mSOa_value . '}';
530 }
531 }
532 }
533 }
534 // Setting body tag margins in CSS:
535 if (isset($tsfe->pSetup['bodyTagMargins']) && $tsfe->pSetup['bodyTagMargins.']['useCSS']) {
536 $margins = (int)$tsfe->pSetup['bodyTagMargins'];
537 $style .= '
538 BODY {margin: ' . $margins . 'px ' . $margins . 'px ' . $margins . 'px ' . $margins . 'px;}';
539 }
540 // CSS_inlineStyle from TS
541 $style .= trim($tsfe->pSetup['CSS_inlineStyle']);
542 $style .= $tsfe->cObj->cObjGet($tsfe->pSetup['cssInline.'], 'cssInline.');
543 if (trim($style)) {
544 self::addCssToPageRenderer($style, TRUE, 'additionalTSFEInlineStyle');
545 }
546 // Javascript Libraries
547 if (is_array($tsfe->pSetup['javascriptLibs.'])) {
548 // Include jQuery into the page renderer
549 if (!empty($tsfe->pSetup['javascriptLibs.']['jQuery'])) {
550 $jQueryTS = $tsfe->pSetup['javascriptLibs.']['jQuery.'];
551 // Check if version / source is set, if not set variable to "NULL" to use the default of the page renderer
552 $version = isset($jQueryTS['version']) ? $jQueryTS['version'] : NULL;
553 $source = isset($jQueryTS['source']) ? $jQueryTS['source'] : NULL;
554 // When "noConflict" is not set or "1" enable the default jQuery noConflict mode, otherwise disable the namespace
555 if (!isset($jQueryTS['noConflict']) || !empty($jQueryTS['noConflict'])) {
556 // Set namespace to the "noConflict.namespace" value if "noConflict.namespace" has a value
557 if (!empty($jQueryTS['noConflict.']['namespace'])) {
558 $namespace = $jQueryTS['noConflict.']['namespace'];
559 } else {
560 $namespace = PageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT;
561 }
562 } else {
563 $namespace = PageRenderer::JQUERY_NAMESPACE_NONE;
564 }
565 $pageRenderer->loadJQuery($version, $source, $namespace);
566 }
567 if ($tsfe->pSetup['javascriptLibs.']['ExtJs']) {
568 $css = (bool)$tsfe->pSetup['javascriptLibs.']['ExtJs.']['css'];
569 $theme = (bool)$tsfe->pSetup['javascriptLibs.']['ExtJs.']['theme'];
570 $pageRenderer->loadExtJs($css, $theme);
571 if ($tsfe->pSetup['javascriptLibs.']['ExtJs.']['debug']) {
572 $pageRenderer->enableExtJsDebug();
573 }
574 }
575 }
576 // JavaScript library files
577 if (is_array($tsfe->pSetup['includeJSlibs.']) || is_array($tsfe->pSetup['includeJSLibs.'])) {
578 if (!is_array($tsfe->pSetup['includeJSlibs.'])) {
579 $tsfe->pSetup['includeJSlibs.'] = array();
580 } else {
581 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.');
582 }
583 if (!is_array($tsfe->pSetup['includeJSLibs.'])) {
584 $tsfe->pSetup['includeJSLibs.'] = array();
585 }
586 ArrayUtility::mergeRecursiveWithOverrule(
587 $tsfe->pSetup['includeJSLibs.'],
588 $tsfe->pSetup['includeJSlibs.']
589 );
590 unset($tsfe->pSetup['includeJSlibs.']);
591 foreach ($tsfe->pSetup['includeJSLibs.'] as $key => $JSfile) {
592 if (!is_array($JSfile)) {
593 if (isset($tsfe->pSetup['includeJSLibs.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJSLibs.'][($key . '.')]['if.'])) {
594 continue;
595 }
596 $ss = $tsfe->pSetup['includeJSLibs.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
597 if ($ss) {
598 $jsFileConfig = &$tsfe->pSetup['includeJSLibs.'][$key . '.'];
599 $type = $jsFileConfig['type'];
600 if (!$type) {
601 $type = 'text/javascript';
602 }
603
604 $pageRenderer->addJsLibrary(
605 $key,
606 $ss,
607 $type,
608 empty($jsFileConfig['disableCompression']),
609 (bool)$jsFileConfig['forceOnTop'],
610 $jsFileConfig['allWrap'],
611 (bool)$jsFileConfig['excludeFromConcatenation'],
612 $jsFileConfig['allWrap.']['splitChar'],
613 (bool)$jsFileConfig['async'],
614 $jsFileConfig['integrity']
615 );
616 unset($jsFileConfig);
617 }
618 }
619 }
620 }
621 if (is_array($tsfe->pSetup['includeJSFooterlibs.'])) {
622 foreach ($tsfe->pSetup['includeJSFooterlibs.'] as $key => $JSfile) {
623 if (!is_array($JSfile)) {
624 if (isset($tsfe->pSetup['includeJSFooterlibs.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJSFooterlibs.'][($key . '.')]['if.'])) {
625 continue;
626 }
627 $ss = $tsfe->pSetup['includeJSFooterlibs.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
628 if ($ss) {
629 $jsFileConfig = &$tsfe->pSetup['includeJSFooterlibs.'][$key . '.'];
630 $type = $jsFileConfig['type'];
631 if (!$type) {
632 $type = 'text/javascript';
633 }
634 $pageRenderer->addJsFooterLibrary(
635 $key,
636 $ss,
637 $type,
638 empty($jsFileConfig['disableCompression']),
639 (bool)$jsFileConfig['forceOnTop'],
640 $jsFileConfig['allWrap'],
641 (bool)$jsFileConfig['excludeFromConcatenation'],
642 $jsFileConfig['allWrap.']['splitChar'],
643 (bool)$jsFileConfig['async'],
644 $jsFileConfig['integrity']
645 );
646 unset($jsFileConfig);
647 }
648 }
649 }
650 }
651 // JavaScript files
652 if (is_array($tsfe->pSetup['includeJS.'])) {
653 foreach ($tsfe->pSetup['includeJS.'] as $key => $JSfile) {
654 if (!is_array($JSfile)) {
655 if (isset($tsfe->pSetup['includeJS.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJS.'][($key . '.')]['if.'])) {
656 continue;
657 }
658 $ss = $tsfe->pSetup['includeJS.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
659 if ($ss) {
660 $jsConfig = &$tsfe->pSetup['includeJS.'][$key . '.'];
661 $type = $jsConfig['type'];
662 if (!$type) {
663 $type = 'text/javascript';
664 }
665 $pageRenderer->addJsFile(
666 $ss,
667 $type,
668 empty($jsConfig['disableCompression']),
669 (bool)$jsConfig['forceOnTop'],
670 $jsConfig['allWrap'],
671 (bool)$jsConfig['excludeFromConcatenation'],
672 $jsConfig['allWrap.']['splitChar'],
673 (bool)$jsConfig['async'],
674 $jsConfig['integrity']
675 );
676 unset($jsConfig);
677 }
678 }
679 }
680 }
681 if (is_array($tsfe->pSetup['includeJSFooter.'])) {
682 foreach ($tsfe->pSetup['includeJSFooter.'] as $key => $JSfile) {
683 if (!is_array($JSfile)) {
684 if (isset($tsfe->pSetup['includeJSFooter.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJSFooter.'][($key . '.')]['if.'])) {
685 continue;
686 }
687 $ss = $tsfe->pSetup['includeJSFooter.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
688 if ($ss) {
689 $jsConfig = &$tsfe->pSetup['includeJSFooter.'][$key . '.'];
690 $type = $jsConfig['type'];
691 if (!$type) {
692 $type = 'text/javascript';
693 }
694 $pageRenderer->addJsFooterFile(
695 $ss,
696 $type,
697 empty($jsConfig['disableCompression']),
698 (bool)$jsConfig['forceOnTop'],
699 $jsConfig['allWrap'],
700 (bool)$jsConfig['excludeFromConcatenation'],
701 $jsConfig['allWrap.']['splitChar'],
702 (bool)$jsConfig['async'],
703 $jsConfig['integrity']
704 );
705 unset($jsConfig);
706 }
707 }
708 }
709 }
710 // Headerdata
711 if (is_array($tsfe->pSetup['headerData.'])) {
712 $pageRenderer->addHeaderData($tsfe->cObj->cObjGet($tsfe->pSetup['headerData.'], 'headerData.'));
713 }
714 // Footerdata
715 if (is_array($tsfe->pSetup['footerData.'])) {
716 $pageRenderer->addFooterData($tsfe->cObj->cObjGet($tsfe->pSetup['footerData.'], 'footerData.'));
717 }
718 static::generatePageTitle();
719
720 $metaTagsHtml = static::generateMetaTagHtml(
721 isset($tsfe->pSetup['meta.']) ? $tsfe->pSetup['meta.'] : array(),
722 $tsfe->xhtmlVersion,
723 $tsfe->cObj
724 );
725 foreach ($metaTagsHtml as $metaTag) {
726 $pageRenderer->addMetaTag($metaTag);
727 }
728
729 unset($tsfe->additionalHeaderData['JSCode']);
730 if (is_array($tsfe->config['INTincScript'])) {
731 $tsfe->additionalHeaderData['JSCode'] = $tsfe->JSCode;
732 // Storing the JSCode vars...
733 $tsfe->config['INTincScript_ext']['divKey'] = $tsfe->uniqueHash();
734 $tsfe->config['INTincScript_ext']['additionalHeaderData'] = $tsfe->additionalHeaderData;
735 // Storing the header-data array
736 $tsfe->config['INTincScript_ext']['additionalFooterData'] = $tsfe->additionalFooterData;
737 // Storing the footer-data array
738 $tsfe->config['INTincScript_ext']['additionalJavaScript'] = $tsfe->additionalJavaScript;
739 // Storing the JS-data array
740 $tsfe->config['INTincScript_ext']['additionalCSS'] = $tsfe->additionalCSS;
741 // Storing the Style-data array
742 $tsfe->additionalHeaderData = array('<!--HD_' . $tsfe->config['INTincScript_ext']['divKey'] . '-->');
743 // Clearing the array
744 $tsfe->additionalFooterData = array('<!--FD_' . $tsfe->config['INTincScript_ext']['divKey'] . '-->');
745 // Clearing the array
746 $tsfe->divSection .= '<!--TDS_' . $tsfe->config['INTincScript_ext']['divKey'] . '-->';
747 } else {
748 $tsfe->INTincScript_loadJSCode();
749 }
750 $JSef = self::JSeventFunctions();
751 $scriptJsCode = $JSef[0];
752
753 if ($tsfe->spamProtectEmailAddresses && $tsfe->spamProtectEmailAddresses !== 'ascii') {
754 $scriptJsCode = '
755 // decrypt helper function
756 function decryptCharcode(n,start,end,offset) {
757 n = n + offset;
758 if (offset > 0 && n > end) {
759 n = start + (n - end - 1);
760 } else if (offset < 0 && n < start) {
761 n = end - (start - n - 1);
762 }
763 return String.fromCharCode(n);
764 }
765 // decrypt string
766 function decryptString(enc,offset) {
767 var dec = "";
768 var len = enc.length;
769 for(var i=0; i < len; i++) {
770 var n = enc.charCodeAt(i);
771 if (n >= 0x2B && n <= 0x3A) {
772 dec += decryptCharcode(n,0x2B,0x3A,offset); // 0-9 . , - + / :
773 } else if (n >= 0x40 && n <= 0x5A) {
774 dec += decryptCharcode(n,0x40,0x5A,offset); // A-Z @
775 } else if (n >= 0x61 && n <= 0x7A) {
776 dec += decryptCharcode(n,0x61,0x7A,offset); // a-z
777 } else {
778 dec += enc.charAt(i);
779 }
780 }
781 return dec;
782 }
783 // decrypt spam-protected emails
784 function linkTo_UnCryptMailto(s) {
785 location.href = decryptString(s,' . $tsfe->spamProtectEmailAddresses * -1 . ');
786 }
787 ';
788 }
789 // Add inline JS
790 $inlineJS = '';
791 // defined in php
792 if (is_array($tsfe->inlineJS)) {
793 foreach ($tsfe->inlineJS as $key => $val) {
794 if (!is_array($val)) {
795 $inlineJS .= LF . $val . LF;
796 }
797 }
798 }
799 // defined in TS with page.inlineJS
800 // Javascript inline code
801 $inline = $tsfe->cObj->cObjGet($tsfe->pSetup['jsInline.'], 'jsInline.');
802 if ($inline) {
803 $inlineJS .= LF . $inline . LF;
804 }
805 // Javascript inline code for Footer
806 $inlineFooterJs = $tsfe->cObj->cObjGet($tsfe->pSetup['jsFooterInline.'], 'jsFooterInline.');
807 // Should minify?
808 if ($tsfe->config['config']['compressJs']) {
809 $pageRenderer->enableCompressJavascript();
810 $minifyErrorScript = ($minifyErrorInline = '');
811 $scriptJsCode = GeneralUtility::minifyJavaScript($scriptJsCode, $minifyErrorScript);
812 if ($minifyErrorScript) {
813 $timeTracker->setTSlogMessage($minifyErrorScript, 3);
814 }
815 if ($inlineJS) {
816 $inlineJS = GeneralUtility::minifyJavaScript($inlineJS, $minifyErrorInline);
817 if ($minifyErrorInline) {
818 $timeTracker->setTSlogMessage($minifyErrorInline, 3);
819 }
820 }
821 if ($inlineFooterJs) {
822 $inlineFooterJs = GeneralUtility::minifyJavaScript($inlineFooterJs, $minifyErrorInline);
823 if ($minifyErrorInline) {
824 $timeTracker->setTSlogMessage($minifyErrorInline, 3);
825 }
826 }
827 }
828 if (!$tsfe->config['config']['removeDefaultJS']) {
829 // inlude default and inlineJS
830 if ($scriptJsCode) {
831 $pageRenderer->addJsInlineCode('_scriptCode', $scriptJsCode, $tsfe->config['config']['compressJs']);
832 }
833 if ($inlineJS) {
834 $pageRenderer->addJsInlineCode('TS_inlineJS', $inlineJS, $tsfe->config['config']['compressJs']);
835 }
836 if ($inlineFooterJs) {
837 $pageRenderer->addJsFooterInlineCode('TS_inlineFooter', $inlineFooterJs, $tsfe->config['config']['compressJs']);
838 }
839 } elseif ($tsfe->config['config']['removeDefaultJS'] === 'external') {
840 /*
841 * This keeps inlineJS from *_INT Objects from being moved to external files.
842 * At this point in frontend rendering *_INT Objects only have placeholders instead
843 * of actual content so moving these placeholders to external files would
844 * a) break the JS file (syntax errors due to the placeholders)
845 * b) the needed JS would never get included to the page
846 * Therefore inlineJS from *_INT Objects must not be moved to external files but
847 * kept internal.
848 */
849 $inlineJSint = '';
850 self::stripIntObjectPlaceholder($inlineJS, $inlineJSint);
851 if ($inlineJSint) {
852 $pageRenderer->addJsInlineCode('TS_inlineJSint', $inlineJSint, $tsfe->config['config']['compressJs']);
853 }
854 if (trim($scriptJsCode . $inlineJS)) {
855 $pageRenderer->addJsFile(self::inline2TempFile($scriptJsCode . $inlineJS, 'js'), 'text/javascript', $tsfe->config['config']['compressJs']);
856 }
857 if ($inlineFooterJs) {
858 $inlineFooterJSint = '';
859 self::stripIntObjectPlaceholder($inlineFooterJs, $inlineFooterJSint);
860 if ($inlineFooterJSint) {
861 $pageRenderer->addJsFooterInlineCode('TS_inlineFooterJSint', $inlineFooterJSint, $tsfe->config['config']['compressJs']);
862 }
863 $pageRenderer->addJsFooterFile(self::inline2TempFile($inlineFooterJs, 'js'), 'text/javascript', $tsfe->config['config']['compressJs']);
864 }
865 } else {
866 // Include only inlineJS
867 if ($inlineJS) {
868 $pageRenderer->addJsInlineCode('TS_inlineJS', $inlineJS, $tsfe->config['config']['compressJs']);
869 }
870 if ($inlineFooterJs) {
871 $pageRenderer->addJsFooterInlineCode('TS_inlineFooter', $inlineFooterJs, $tsfe->config['config']['compressJs']);
872 }
873 }
874 if (is_array($tsfe->pSetup['inlineLanguageLabelFiles.'])) {
875 foreach ($tsfe->pSetup['inlineLanguageLabelFiles.'] as $key => $languageFile) {
876 if (is_array($languageFile)) {
877 continue;
878 }
879 $languageFileConfig = &$tsfe->pSetup['inlineLanguageLabelFiles.'][$key . '.'];
880 if (isset($languageFileConfig['if.']) && !$tsfe->cObj->checkIf($languageFileConfig['if.'])) {
881 continue;
882 }
883 $pageRenderer->addInlineLanguageLabelFile(
884 $languageFile,
885 $languageFileConfig['selectionPrefix'] ?: '',
886 $languageFileConfig['stripFromSelectionName'] ?: '',
887 $languageFileConfig['errorMode'] ? (int)$languageFileConfig['errorMode'] : 0
888 );
889 }
890 }
891 // ExtJS specific code
892 if (is_array($tsfe->pSetup['inlineLanguageLabel.'])) {
893 $pageRenderer->addInlineLanguageLabelArray($tsfe->pSetup['inlineLanguageLabel.'], TRUE);
894 }
895 if (is_array($tsfe->pSetup['inlineSettings.'])) {
896 $pageRenderer->addInlineSettingArray('TS', $tsfe->pSetup['inlineSettings.']);
897 }
898 if (is_array($tsfe->pSetup['extOnReady.'])) {
899 $pageRenderer->addExtOnReadyCode($tsfe->cObj->cObjGet($tsfe->pSetup['extOnReady.'], 'extOnReady.'));
900 }
901 // Compression and concatenate settings
902 if ($tsfe->config['config']['compressCss']) {
903 $pageRenderer->enableCompressCss();
904 }
905 if ($tsfe->config['config']['compressJs']) {
906 $pageRenderer->enableCompressJavascript();
907 }
908 if ($tsfe->config['config']['concatenateCss']) {
909 $pageRenderer->enableConcatenateCss();
910 }
911 if ($tsfe->config['config']['concatenateJs']) {
912 $pageRenderer->enableConcatenateJavascript();
913 }
914 // Backward compatibility for old configuration
915 if ($tsfe->config['config']['concatenateJsAndCss']) {
916 $pageRenderer->enableConcatenateFiles();
917 }
918 // Add header data block
919 if ($tsfe->additionalHeaderData) {
920 $pageRenderer->addHeaderData(implode(LF, $tsfe->additionalHeaderData));
921 }
922 // Add footer data block
923 if ($tsfe->additionalFooterData) {
924 $pageRenderer->addFooterData(implode(LF, $tsfe->additionalFooterData));
925 }
926 // Header complete, now add content
927 if ($tsfe->pSetup['frameSet.']) {
928 $fs = GeneralUtility::makeInstance(FramesetRenderer::class);
929 $pageRenderer->addBodyContent($fs->make($tsfe->pSetup['frameSet.']));
930 $pageRenderer->addBodyContent(LF . '<noframes>' . LF);
931 }
932 // Bodytag:
933 if ($tsfe->config['config']['disableBodyTag']) {
934 $bodyTag = '';
935 } else {
936 $defBT = $tsfe->pSetup['bodyTagCObject'] ? $tsfe->cObj->cObjGetSingle($tsfe->pSetup['bodyTagCObject'], $tsfe->pSetup['bodyTagCObject.'], 'bodyTagCObject') : '';
937 if (!$defBT) {
938 $defBT = $tsfe->defaultBodyTag;
939 }
940 $bodyTag = $tsfe->pSetup['bodyTag'] ? $tsfe->pSetup['bodyTag'] : $defBT;
941 if ($bgImg = $tsfe->cObj->getImgResource($tsfe->pSetup['bgImg'], $tsfe->pSetup['bgImg.'])) {
942 GeneralUtility::deprecationLog('The option "page.bgImg" is deprecated since TYPO3 CMS 7, and will be removed with CMS 8');
943 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' background="' . $tsfe->absRefPrefix . $bgImg[3] . '">';
944 }
945 if (isset($tsfe->pSetup['bodyTagMargins'])) {
946 $margins = (int)$tsfe->pSetup['bodyTagMargins'];
947 if ($tsfe->pSetup['bodyTagMargins.']['useCSS']) {
948
949 } else {
950 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' leftmargin="' . $margins . '" topmargin="' . $margins . '" marginwidth="' . $margins . '" marginheight="' . $margins . '">';
951 }
952 }
953 if (trim($tsfe->pSetup['bodyTagAdd'])) {
954 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' ' . trim($tsfe->pSetup['bodyTagAdd']) . '>';
955 }
956 // Event functions
957 if (!empty($JSef[1])) {
958 $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' ' . trim(implode(' ', $JSef[1])) . '>';
959 }
960 }
961 $pageRenderer->addBodyContent(LF . $bodyTag);
962 // Div-sections
963 if ($tsfe->divSection) {
964 $pageRenderer->addBodyContent(LF . $tsfe->divSection);
965 }
966 // Page content
967 $pageRenderer->addBodyContent(LF . $pageContent);
968 if (!empty($tsfe->config['INTincScript']) && is_array($tsfe->config['INTincScript'])) {
969 // Store the serialized pageRenderer in configuration
970 $tsfe->config['INTincScript_ext']['pageRenderer'] = serialize($pageRenderer);
971 // Render complete page, keep placeholders for JavaScript and CSS
972 $tsfe->content = $pageRenderer->renderPageWithUncachedObjects($tsfe->config['INTincScript_ext']['divKey']);
973 } else {
974 // Render complete page
975 $tsfe->content = $pageRenderer->render();
976 }
977 // Ending page
978 if ($tsfe->pSetup['frameSet.']) {
979 $tsfe->content .= LF . '</noframes>';
980 }
981 }
982
983 /*************************
984 *
985 * Helper functions
986 * Remember: Calls internally must still be done on the non-instantiated class: PageGenerator::inline2TempFile()
987 *
988 *************************/
989 /**
990 * Searches for placeholder created from *_INT cObjects, removes them from
991 * $searchString and merges them to $intObjects
992 *
993 * @param string $searchString The String which should be cleaned from int-object markers
994 * @param string $intObjects The String the found int-placeholders are moved to (for further processing)
995 */
996 static protected function stripIntObjectPlaceholder(&$searchString, &$intObjects) {
997 $tempArray = array();
998 preg_match_all('/\\<\\!--INT_SCRIPT.[a-z0-9]*--\\>/', $searchString, $tempArray);
999 $searchString = preg_replace('/\\<\\!--INT_SCRIPT.[a-z0-9]*--\\>/', '', $searchString);
1000 $intObjects = implode('', $tempArray[0]);
1001 }
1002
1003 /**
1004 * Writes string to a temporary file named after the md5-hash of the string
1005 *
1006 * @param string $str CSS styles / JavaScript to write to file.
1007 * @param string $ext Extension: "css" or "js
1008 * @return string <script> or <link> tag for the file.
1009 */
1010 static public function inline2TempFile($str, $ext) {
1011 // Create filename / tags:
1012 $script = '';
1013 switch ($ext) {
1014 case 'js':
1015 $script = 'typo3temp/Assets/' . substr(md5($str), 0, 10) . '.js';
1016 break;
1017 case 'css':
1018 $script = 'typo3temp/Assets/' . substr(md5($str), 0, 10) . '.css';
1019 break;
1020 }
1021 // Write file:
1022 if ($script) {
1023 if (!@is_file(PATH_site . $script)) {
1024 GeneralUtility::writeFileToTypo3tempDir(PATH_site . $script, $str);
1025 }
1026 }
1027 return $script;
1028 }
1029
1030 /**
1031 * 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.
1032 *
1033 * @param string $haystack The string in which to find $needle
1034 * @param string $needle The string to find in $haystack
1035 * @return bool Returns TRUE if $needle matches or is found in $haystack
1036 */
1037 static public function isAllowedLinkVarValue($haystack, $needle) {
1038 $OK = FALSE;
1039 // Integer
1040 if ($needle == 'int' || $needle == 'integer') {
1041 if (MathUtility::canBeInterpretedAsInteger($haystack)) {
1042 $OK = TRUE;
1043 }
1044 } elseif (preg_match('/^\\/.+\\/[imsxeADSUXu]*$/', $needle)) {
1045 // Regular expression, only "//" is allowed as delimiter
1046 if (@preg_match($needle, $haystack)) {
1047 $OK = TRUE;
1048 }
1049 } elseif (strstr($needle, '-')) {
1050 // Range
1051 if (MathUtility::canBeInterpretedAsInteger($haystack)) {
1052 $range = explode('-', $needle);
1053 if ($range[0] <= $haystack && $range[1] >= $haystack) {
1054 $OK = TRUE;
1055 }
1056 }
1057 } elseif (strstr($needle, '|')) {
1058 // List
1059 // Trim the input
1060 $haystack = str_replace(' ', '', $haystack);
1061 if (strstr('|' . $needle . '|', '|' . $haystack . '|')) {
1062 $OK = TRUE;
1063 }
1064 } elseif ((string)$needle === (string)$haystack) {
1065 // String comparison
1066 $OK = TRUE;
1067 }
1068 return $OK;
1069 }
1070
1071 /**
1072 * Generate title for page.
1073 * Takes the settings [config][noPageTitle], [config][pageTitleFirst], [config][titleTagFunction]
1074 * [config][pageTitleSeparator] and [config][noPageTitle] into account.
1075 * Furthermore $GLOBALS[TSFE]->altPageTitle is observed.
1076 *
1077 * @return void
1078 */
1079 static public function generatePageTitle() {
1080 /** @var TypoScriptFrontendController $tsfe */
1081 $tsfe = $GLOBALS['TSFE'];
1082
1083 $pageTitleSeparator = '';
1084
1085 // check for a custom pageTitleSeparator, and perform stdWrap on it
1086 if (isset($tsfe->config['config']['pageTitleSeparator']) && $tsfe->config['config']['pageTitleSeparator'] !== '') {
1087 $pageTitleSeparator = $tsfe->config['config']['pageTitleSeparator'];
1088
1089 if (isset($tsfe->config['config']['pageTitleSeparator.']) && is_array($tsfe->config['config']['pageTitleSeparator.'])) {
1090 $pageTitleSeparator = $tsfe->cObj->stdWrap($pageTitleSeparator, $tsfe->config['config']['pageTitleSeparator.']);
1091 } else {
1092 $pageTitleSeparator .= ' ';
1093 }
1094 }
1095
1096 $titleTagContent = $tsfe->tmpl->printTitle(
1097 $tsfe->altPageTitle ?: $tsfe->page['title'],
1098 $tsfe->config['config']['noPageTitle'],
1099 $tsfe->config['config']['pageTitleFirst'],
1100 $pageTitleSeparator
1101 );
1102 if ($tsfe->config['config']['titleTagFunction']) {
1103 $titleTagContent = $tsfe->cObj->callUserFunction(
1104 $tsfe->config['config']['titleTagFunction'],
1105 array(),
1106 $titleTagContent
1107 );
1108 }
1109 // stdWrap around the title tag
1110 if (isset($tsfe->config['config']['pageTitle.']) && is_array($tsfe->config['config']['pageTitle.'])) {
1111 $titleTagContent = $tsfe->cObj->stdWrap($titleTagContent, $tsfe->config['config']['pageTitle.']);
1112 }
1113 if ($titleTagContent !== '' && (int)$tsfe->config['config']['noPageTitle'] !== self::NO_PAGE_TITLE) {
1114 static::getPageRenderer()->setTitle($titleTagContent);
1115 }
1116 }
1117
1118 /**
1119 * Generate meta tags from meta tag TypoScript
1120 *
1121 * @param array $metaTagTypoScript TypoScript configuration for meta tags (e.g. $GLOBALS['TSFE']->pSetup['meta.'])
1122 * @param bool $xhtml Whether xhtml tag-style should be used. (e.g. pass $GLOBALS['TSFE']->xhtmlVersion here)
1123 * @param ContentObjectRenderer $cObj
1124 * @return array Array of HTML meta tags
1125 */
1126 static protected function generateMetaTagHtml(array $metaTagTypoScript, $xhtml, ContentObjectRenderer $cObj) {
1127 // Add ending slash only to documents rendered as xhtml
1128 $endingSlash = $xhtml ? ' /' : '';
1129
1130 $metaTags = array(
1131 '<meta name="generator" content="TYPO3 CMS"' . $endingSlash . '>'
1132 );
1133
1134 /** @var TypoScriptService $typoScriptService */
1135 $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
1136 $conf = $typoScriptService->convertTypoScriptArrayToPlainArray($metaTagTypoScript);
1137 foreach ($conf as $key => $properties) {
1138 if (is_array($properties)) {
1139 $nodeValue = isset($properties['_typoScriptNodeValue']) ? $properties['_typoScriptNodeValue'] : '';
1140 $value = trim($cObj->stdWrap($nodeValue, $metaTagTypoScript[$key . '.']));
1141 if ($value === '' && !empty($properties['value'])) {
1142 $value = $properties['value'];
1143 }
1144 } else {
1145 $value = $properties;
1146 }
1147
1148 $attribute = 'name';
1149 if ((is_array($properties) && !empty($properties['httpEquivalent'])) || strtolower($key) === 'refresh') {
1150 $attribute = 'http-equiv';
1151 }
1152 if (is_array($properties) && !empty($properties['attribute'])) {
1153 $attribute = $properties['attribute'];
1154 }
1155
1156 if (!is_array($value)) {
1157 $value = (array)$value;
1158 }
1159 foreach ($value as $subValue) {
1160 if (trim($subValue) !== '') {
1161 $metaTags[] = '<meta ' . $attribute . '="' . $key . '" content="' . htmlspecialchars($subValue) . '"' . $endingSlash . '>';
1162 }
1163 }
1164 }
1165 return $metaTags;
1166 }
1167
1168 /**
1169 * Fills the sWordList property and builds the regular expression in TSFE that can be used to split
1170 * strings by the submitted search words.
1171 *
1172 * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::sWordList
1173 * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::sWordRegEx
1174 */
1175 static protected function initializeSearchWordDataInTsfe() {
1176 /** @var TypoScriptFrontendController $tsfe */
1177 $tsfe = $GLOBALS['TSFE'];
1178
1179 $tsfe->sWordRegEx = '';
1180 $tsfe->sWordList = GeneralUtility::_GP('sword_list');
1181 if (is_array($tsfe->sWordList)) {
1182 $space = !empty($tsfe->config['config']['sword_standAlone']) ? '[[:space:]]' : '';
1183 foreach ($tsfe->sWordList as $val) {
1184 if (trim($val) !== '') {
1185 $tsfe->sWordRegEx .= $space . preg_quote($val, '/') . $space . '|';
1186 }
1187 }
1188 $tsfe->sWordRegEx = rtrim($tsfe->sWordRegEx, '|');
1189 }
1190 }
1191
1192 /**
1193 * @return PageRenderer
1194 */
1195 static protected function getPageRenderer() {
1196 return GeneralUtility::makeInstance(PageRenderer::class);
1197 }
1198
1199 /**
1200 * Adds inline CSS code, by respecting the inlineStyle2TempFile option
1201 *
1202 * @param string $cssStyles the inline CSS styling
1203 * @param bool $excludeFromConcatenation option to see if it should be conctatenated
1204 * @param string $inlineBlockName the block name to add it
1205 */
1206 static protected function addCssToPageRenderer($cssStyles, $excludeFromConcatenation = FALSE, $inlineBlockName = 'TSFEinlineStyle') {
1207 if (empty($GLOBALS['TSFE']->config['config']['inlineStyle2TempFile'])) {
1208 self::getPageRenderer()->addCssInlineBlock($inlineBlockName, $cssStyles, !empty($GLOBALS['TSFE']->config['config']['compressCss']));
1209 } else {
1210 self::getPageRenderer()->addCssFile(
1211 self::inline2TempFile($cssStyles, 'css'),
1212 'stylesheet',
1213 'all',
1214 '',
1215 (bool)$GLOBALS['TSFE']->config['config']['compressCss'],
1216 FALSE,
1217 '',
1218 $excludeFromConcatenation
1219 );
1220 }
1221 }
1222 }