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