Fixed bug #9741: wrong anchor links with absRefPrefix option enabled
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_pagegen.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 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 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 = ereg_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 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 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 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 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-2008 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 $style.='
584 A:link {text-decoration: none}
585 A:visited {text-decoration: none}
586 A:active {text-decoration: none}';
587 }
588 if (trim($GLOBALS['TSFE']->pSetup['hover'])) {
589 $style.='
590 A:hover {color: '.trim($GLOBALS['TSFE']->pSetup['hover']).';}';
591 }
592 if (trim($GLOBALS['TSFE']->pSetup['hoverStyle'])) {
593 $style.='
594 A:hover {'.trim($GLOBALS['TSFE']->pSetup['hoverStyle']).'}';
595 }
596 if ($GLOBALS['TSFE']->pSetup['smallFormFields']) {
597 $style.='
598 SELECT { font-family: Verdana, Arial, Helvetica; font-size: 10px }
599 TEXTAREA { font-family: Verdana, Arial, Helvetica; font-size: 10px}
600 INPUT { font-family: Verdana, Arial, Helvetica; font-size: 10px }';
601 }
602 if ($GLOBALS['TSFE']->pSetup['adminPanelStyles']) {
603 $style.='
604
605 /* Default styles for the Admin Panel */
606 TABLE.typo3-adminPanel { border: 1px solid black; background-color: #F6F2E6; }
607 TABLE.typo3-adminPanel TR.typo3-adminPanel-hRow TD { background-color: #9BA1A8; }
608 TABLE.typo3-adminPanel TR.typo3-adminPanel-itemHRow TD { background-color: #ABBBB4; }
609 TABLE.typo3-adminPanel TABLE, TABLE.typo3-adminPanel TD { border: 0px; }
610 TABLE.typo3-adminPanel TD FONT { font-family: verdana; font-size: 10px; color: black; }
611 TABLE.typo3-adminPanel TD A FONT { font-family: verdana; font-size: 10px; color: black; }
612 TABLE.typo3-editPanel { border: 1px solid black; background-color: #F6F2E6; }
613 TABLE.typo3-editPanel TD { border: 0px; }
614 ';
615 }
616
617 if (trim($style)) {
618 if ($GLOBALS['TSFE']->config['config']['inlineStyle2TempFile']) {
619 $GLOBALS['TSFE']->content.=TSpagegen::inline2TempFile($style, 'css');
620 } else {
621 $GLOBALS['TSFE']->content.='
622 <style type="text/css">
623 /*<![CDATA[*/
624 <!--'.$style.'
625 -->
626 /*]]>*/
627 </style>';
628 }
629 }
630
631 // JavaScript files
632 if (is_array($GLOBALS['TSFE']->pSetup['includeJS.'])) {
633 foreach ($GLOBALS['TSFE']->pSetup['includeJS.'] as $key=>$JSfile) {
634 if (!is_array($JSfile)) {
635 $ss = $GLOBALS['TSFE']->tmpl->getFileName($JSfile);
636 if ($ss) {
637 $type = $GLOBALS['TSFE']->pSetup['includeJS.'][$key.'.']['type'];
638 if (!$type) $type = 'text/javascript';
639
640 $GLOBALS['TSFE']->content.='
641 <script src="' . htmlspecialchars($GLOBALS['TSFE']->absRefPrefix . $ss) . '" type="' . htmlspecialchars($type) . '"></script>';
642 }
643 }
644 }
645 }
646
647
648
649
650
651 // Headerdata
652 if (is_array($GLOBALS['TSFE']->pSetup['headerData.'])) {
653 $GLOBALS['TSFE']->content.= chr(10).$GLOBALS['TSFE']->cObj->cObjGet($GLOBALS['TSFE']->pSetup['headerData.'],'headerData.');
654 }
655
656 // Title
657 $titleTagContent = $GLOBALS['TSFE']->tmpl->printTitle(
658 $GLOBALS['TSFE']->altPageTitle?$GLOBALS['TSFE']->altPageTitle:$GLOBALS['TSFE']->page['title'],
659 $GLOBALS['TSFE']->config['config']['noPageTitle'],
660 $GLOBALS['TSFE']->config['config']['pageTitleFirst']
661 );
662 if ($GLOBALS['TSFE']->config['config']['titleTagFunction']) {
663 $titleTagContent = $GLOBALS['TSFE']->cObj->callUserFunction($GLOBALS['TSFE']->config['config']['titleTagFunction'], array(), $titleTagContent);
664 }
665
666 if (strlen($titleTagContent) && intval($GLOBALS['TSFE']->config['config']['noPageTitle'])!==2) {
667 $GLOBALS['TSFE']->content.='
668 <title>'.htmlspecialchars($titleTagContent).'</title>';
669 }
670 $GLOBALS['TSFE']->content.='
671 <meta name="generator" content="TYPO3 '.TYPO3_branch.' CMS" />';
672
673 $conf=$GLOBALS['TSFE']->pSetup['meta.'];
674 if (is_array($conf)) {
675 reset($conf);
676 while(list($theKey,$theValue)=each($conf)) {
677 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
678 if (strstr($theKey,'.')) {
679 $theKey = substr($theKey,0,-1);
680 }
681 $val = $GLOBALS['TSFE']->cObj->stdWrap($conf[$theKey],$conf[$theKey.'.']);
682 $key = $theKey;
683 if (trim($val)) {
684 $a='name';
685 if (strtolower($key)=='refresh') {$a='http-equiv';}
686 $GLOBALS['TSFE']->content.= '
687 <meta '.$a.'="'.$key.'" content="'.htmlspecialchars(trim($val)).'" />';
688 }
689 }
690 }
691 }
692
693 unset($GLOBALS['TSFE']->additionalHeaderData['JSCode']);
694 unset($GLOBALS['TSFE']->additionalHeaderData['JSImgCode']);
695
696 if (is_array($GLOBALS['TSFE']->config['INTincScript'])) {
697 // Storing the JSCode and JSImgCode vars...
698 $GLOBALS['TSFE']->additionalHeaderData['JSCode'] = $GLOBALS['TSFE']->JSCode;
699 $GLOBALS['TSFE']->additionalHeaderData['JSImgCode'] = $GLOBALS['TSFE']->JSImgCode;
700 $GLOBALS['TSFE']->config['INTincScript_ext']['divKey'] = $GLOBALS['TSFE']->uniqueHash();
701 $GLOBALS['TSFE']->config['INTincScript_ext']['additionalHeaderData'] = $GLOBALS['TSFE']->additionalHeaderData; // Storing the header-data array
702 $GLOBALS['TSFE']->config['INTincScript_ext']['additionalJavaScript'] = $GLOBALS['TSFE']->additionalJavaScript; // Storing the JS-data array
703 $GLOBALS['TSFE']->config['INTincScript_ext']['additionalCSS'] = $GLOBALS['TSFE']->additionalCSS; // Storing the Style-data array
704
705 $GLOBALS['TSFE']->additionalHeaderData = array('<!--HD_'.$GLOBALS['TSFE']->config['INTincScript_ext']['divKey'].'-->'); // Clearing the array
706 $GLOBALS['TSFE']->divSection.= '<!--TDS_'.$GLOBALS['TSFE']->config['INTincScript_ext']['divKey'].'-->';
707 } else {
708 $GLOBALS['TSFE']->INTincScript_loadJSCode();
709 }
710 $JSef = TSpagegen::JSeventFunctions();
711
712 // Adding default Java Script:
713 $_scriptCode = '
714 var browserName = navigator.appName;
715 var browserVer = parseInt(navigator.appVersion);
716 var version = "";
717 var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
718 if ((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName=="Konqueror" || browserName=="Opera") {version = "n3";} else {version = "n2";}
719 // Blurring links:
720 function blurLink(theObject) { //
721 if (msie4) {theObject.blur();}
722 }
723 ' . $JSef[0];
724
725 if ($GLOBALS['TSFE']->spamProtectEmailAddresses && $GLOBALS['TSFE']->spamProtectEmailAddresses !== 'ascii') {
726 $_scriptCode.= '
727 // decrypt helper function
728 function decryptCharcode(n,start,end,offset) {
729 n = n + offset;
730 if (offset > 0 && n > end) {
731 n = start + (n - end - 1);
732 } else if (offset < 0 && n < start) {
733 n = end - (start - n - 1);
734 }
735 return String.fromCharCode(n);
736 }
737 // decrypt string
738 function decryptString(enc,offset) {
739 var dec = "";
740 var len = enc.length;
741 for(var i=0; i < len; i++) {
742 var n = enc.charCodeAt(i);
743 if (n >= 0x2B && n <= 0x3A) {
744 dec += decryptCharcode(n,0x2B,0x3A,offset); // 0-9 . , - + / :
745 } else if (n >= 0x40 && n <= 0x5A) {
746 dec += decryptCharcode(n,0x40,0x5A,offset); // A-Z @
747 } else if (n >= 0x61 && n <= 0x7A) {
748 dec += decryptCharcode(n,0x61,0x7A,offset); // a-z
749 } else {
750 dec += enc.charAt(i);
751 }
752 }
753 return dec;
754 }
755 // decrypt spam-protected emails
756 function linkTo_UnCryptMailto(s) {
757 location.href = decryptString(s,'.($GLOBALS['TSFE']->spamProtectEmailAddresses*-1).');
758 }
759 ';
760 }
761
762 //add inline JS
763 $_inlineJS = '';
764 // defined in TS with page.inlineJS
765 if (is_array($GLOBALS['TSFE']->pSetup['inlineJS.'])) {
766 $GLOBALS['TSFE']->inlineJS[]= $GLOBALS['TSFE']->cObj->cObjGet($GLOBALS['TSFE']->pSetup['inlineJS.'],'inlineJS.');
767 }
768 // defined in php
769 if(is_array($GLOBALS['TSFE']->inlineJS)) {
770 foreach($GLOBALS['TSFE']->inlineJS as $key=>$val) {
771 if(!is_array($val)) {
772 $_inlineJS .= chr(10).$val.chr(10);
773 }
774 }
775 }
776
777 // Should minify?
778 if ($GLOBALS['TSFE']->config['config']['minifyJS']) {
779 $minifyErrorScript = $minifyErrorInline = '';
780 $_scriptCode = t3lib_div::minifyJavaScript($_scriptCode,$minifyErrorScript);
781 if ($minifyErrorScript) {
782 $GLOBALS['TT']->setTSlogMessage($minifyErrorScript, 3);
783 }
784 if ($_inlineJS) {
785 $_inlineJS = t3lib_div::minifyJavaScript($_inlineJS,$minifyErrorInline);
786 if ($minifyErrorInline) {
787 $GLOBALS['TT']->setTSlogMessage($minifyErrorInline, 3);
788 }
789 }
790 }
791
792 if (!$GLOBALS['TSFE']->config['config']['removeDefaultJS']) {
793 // inlude default and inlineJS
794 $GLOBALS['TSFE']->content.='
795 <script type="text/javascript">
796 /*<![CDATA[*/
797 <!--'.$_scriptCode.$_inlineJS.'
798 // -->
799 /*]]>*/
800 </script>';
801 } elseif ($GLOBALS['TSFE']->config['config']['removeDefaultJS']==='external') {
802 // put default and inlineJS in external file
803 $GLOBALS['TSFE']->content.= TSpagegen::inline2TempFile($_scriptCode.$_inlineJS, 'js');
804 } elseif ($_inlineJS) {
805 // include only inlineJS
806 $GLOBALS['TSFE']->content.='
807 <script type="text/javascript">
808 /*<![CDATA[*/
809 <!--'.$_inlineJS.'
810 // -->
811 /*]]>*/
812 </script>';
813 }
814
815 $GLOBALS['TSFE']->content.= chr(10).implode($GLOBALS['TSFE']->additionalHeaderData,chr(10)).'
816 </head>';
817 if ($GLOBALS['TSFE']->pSetup['frameSet.']) {
818 $fs = t3lib_div::makeInstance('tslib_frameset');
819 $GLOBALS['TSFE']->content.= $fs->make($GLOBALS['TSFE']->pSetup['frameSet.']);
820 $GLOBALS['TSFE']->content.= chr(10).'<noframes>'.chr(10);
821 }
822
823 // Bodytag:
824 $defBT = $GLOBALS['TSFE']->pSetup['bodyTagCObject'] ? $GLOBALS['TSFE']->cObj->cObjGetSingle($GLOBALS['TSFE']->pSetup['bodyTagCObject'],$GLOBALS['TSFE']->pSetup['bodyTagCObject.'],'bodyTagCObject') : '';
825 if (!$defBT) $defBT = $GLOBALS['TSFE']->defaultBodyTag;
826 $bodyTag = $GLOBALS['TSFE']->pSetup['bodyTag'] ? $GLOBALS['TSFE']->pSetup['bodyTag'] : $defBT;
827 if ($bgImg=$GLOBALS['TSFE']->cObj->getImgResource($GLOBALS['TSFE']->pSetup['bgImg'],$GLOBALS['TSFE']->pSetup['bgImg.'])) {
828 $bodyTag = ereg_replace('>$','',trim($bodyTag)).' background="'.$GLOBALS["TSFE"]->absRefPrefix.$bgImg[3].'">';
829 }
830
831 if (isset($GLOBALS['TSFE']->pSetup['bodyTagMargins'])) {
832 $margins = intval($GLOBALS['TSFE']->pSetup['bodyTagMargins']);
833 if ($GLOBALS['TSFE']->pSetup['bodyTagMargins.']['useCSS']) {
834 // Setting margins in CSS, see above
835 } else {
836 $bodyTag = ereg_replace('>$','',trim($bodyTag)).' leftmargin="'.$margins.'" topmargin="'.$margins.'" marginwidth="'.$margins.'" marginheight="'.$margins.'">';
837 }
838 }
839
840 if (trim($GLOBALS['TSFE']->pSetup['bodyTagAdd'])) {
841 $bodyTag = ereg_replace('>$','',trim($bodyTag)).' '.trim($GLOBALS['TSFE']->pSetup['bodyTagAdd']).'>';
842 }
843
844 if (count($JSef[1])) { // Event functions:
845 $bodyTag = ereg_replace('>$','',trim($bodyTag)).' '.trim(implode(' ',$JSef[1])).'>';
846 }
847 $GLOBALS['TSFE']->content.= chr(10).$bodyTag;
848
849
850 // Div-sections
851 if ($GLOBALS['TSFE']->divSection) {
852 $GLOBALS['TSFE']->content.= chr(10).$GLOBALS['TSFE']->divSection;
853 }
854
855 // Page content
856 $GLOBALS['TSFE']->content.= chr(10).$pageContent;
857
858 // Ending page
859 $GLOBALS['TSFE']->content.= chr(10).'</body>';
860 if ($GLOBALS['TSFE']->pSetup['frameSet.']) {
861 $GLOBALS['TSFE']->content.= chr(10).'</noframes>';
862 }
863 $GLOBALS['TSFE']->content.=chr(10).'</html>';
864 }
865
866
867
868
869
870
871
872
873
874
875
876
877
878 /*************************
879 *
880 * Helper functions
881 * Remember: Calls internally must still be done on the non-instantiated class: TSpagegen::inline2TempFile()
882 *
883 *************************/
884
885 /**
886 * Writes string to a temporary file named after the md5-hash of the string
887 *
888 * @param string CSS styles / JavaScript to write to file.
889 * @param string Extension: "css" or "js"
890 * @return string <script> or <link> tag for the file.
891 */
892 function inline2TempFile($str,$ext) {
893
894 // Create filename / tags:
895 $script = '';
896 switch($ext) {
897 case 'js':
898 $script = 'typo3temp/javascript_'.substr(md5($str),0,10).'.js';
899 $output = '
900 <script type="text/javascript" src="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$script).'"></script>';
901 break;
902 case 'css':
903 $script = 'typo3temp/stylesheet_'.substr(md5($str),0,10).'.css';
904 $output = '
905 <link rel="stylesheet" type="text/css" href="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$script).'" />';
906 break;
907 }
908
909 // Write file:
910 if ($script) {
911 if (!@is_file(PATH_site.$script)) {
912 t3lib_div::writeFile(PATH_site.$script,$str);
913 }
914 }
915
916 return $output;
917 }
918
919 /**
920 * 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.
921 *
922 * @param string The string in which to find $needle
923 * @param string The string to find in $haystack
924 * @return boolean Returns true if $needle matches or is found in $haystack
925 */
926 function isAllowedLinkVarValue($haystack,$needle) {
927 $OK = false;
928
929 if ($needle=='int' || $needle=='integer') { // Integer
930
931 if (t3lib_div::testInt($haystack)) {
932 $OK = true;
933 }
934
935 } elseif (preg_match('/^\/.+\/[imsxeADSUXu]*$/', $needle)) { // Regular expression, only "//" is allowed as delimiter
936
937 if (@preg_match($needle, $haystack)) {
938 $OK = true;
939 }
940
941 } elseif (strstr($needle,'-')) { // Range
942
943 if (t3lib_div::testInt($haystack)) {
944 $range = explode('-',$needle);
945 if ($range[0] <= $haystack && $range[1] >= $haystack) {
946 $OK = true;
947 }
948 }
949
950 } elseif (strstr($needle,'|')) { // List
951
952 $haystack = str_replace(' ','',$haystack); // Trim the input
953 if (strstr('|'.$needle.'|', '|'.$haystack.'|')) {
954 $OK = true;
955 }
956
957 } elseif (!strcmp($needle,$haystack)) { // String comparison
958 $OK = true;
959 }
960
961 return $OK;
962 }
963 }
964
965 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_pagegen.php']) {
966 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_pagegen.php']);
967 }
968
969
970
971 // ********************************************************
972 // Includes the search-class if $sword and $scols are set.
973 // ********************************************************
974 if (t3lib_div::_GP('sword') && t3lib_div::_GP('scols')) {
975 require_once(PATH_tslib.'class.tslib_search.php');
976 }
977
978 // ************
979 // LoadDBGroup
980 // ************
981 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
982
983 /**
984 * Class for fetching record relations for the frontend.
985 *
986 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
987 * @package TYPO3
988 * @subpackage tslib
989 * @see tslib_cObj::RECORDS()
990 */
991 class FE_loadDBGroup extends t3lib_loadDBGroup {
992 var $fromTC = 0; // Means that everything is returned instead of only uid and label-field
993 }
994
995 // **********************************
996 // includes stuff for graphical work
997 // **********************************
998 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
999 require_once(PATH_tslib.'class.tslib_gifbuilder.php');
1000
1001 // *************************
1002 // includes menu-management
1003 // *************************
1004 require_once(PATH_tslib.'class.tslib_menu.php');
1005
1006 // *************************
1007 // Global content object...
1008 // *************************
1009 require_once(PATH_tslib.'class.tslib_content.php');
1010
1011 ?>