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