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