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