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