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