[TASK] Remove SVN auto properties $Id$
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / index_ts.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 * This is the MAIN DOCUMENT of the TypoScript driven standard front-end (from the "cms" extension)
29 * Basically put this is the "index.php" script which all requests for TYPO3 delivered pages goes to in the frontend (the website)
30 * The script configures constants, includes libraries and does a little logic here and there in order to instantiate the right classes to create the webpage.
31 * All the real data processing goes on in the "tslib/" classes which this script will include and use as needed.
32 *
33 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 * @package TYPO3
37 * @subpackage tslib
38 */
39
40 // *******************************
41 // Checking PHP version
42 // *******************************
43 if (version_compare(phpversion(), '5.2', '<')) die ('TYPO3 requires PHP 5.2.0 or higher.');
44
45 // *******************************
46 // Set error reporting
47 // *******************************
48 if (defined('E_DEPRECATED')) {
49 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
50 } else {
51 error_reporting(E_ALL ^ E_NOTICE);
52 }
53
54
55 // ******************
56 // Constants defined
57 // ******************
58 $TYPO3_MISC['microtime_start'] = microtime(true);
59 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
60 define('TYPO3_MODE','FE');
61
62 if(!defined('PATH_thisScript')) {
63 define('PATH_thisScript', str_replace('//', '/', str_replace('\\', '/',
64 (PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi') &&
65 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ?
66 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) :
67 ($_SERVER['ORIG_SCRIPT_FILENAME'] ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME']))));
68 }
69
70 if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/');
71 if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
72
73 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
74 define('PATH_typo3', PATH_site.TYPO3_mainDir);
75 define('PATH_typo3conf', PATH_site.'typo3conf/');
76
77 if (!defined('PATH_tslib')) {
78 if (@is_dir(PATH_site.TYPO3_mainDir.'sysext/cms/tslib/')) {
79 define('PATH_tslib', PATH_site.TYPO3_mainDir.'sysext/cms/tslib/');
80 } elseif (@is_dir(PATH_site.'tslib/')) {
81 define('PATH_tslib', PATH_site.'tslib/');
82 }
83 }
84
85 if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
86
87 // *********************
88 // Unset variable(s) in global scope (fixes #13959)
89 // *********************
90 unset($error);
91
92 // *********************
93 // Prevent any output until AJAX/compression is initialized to stop
94 // AJAX/compression data corruption
95 // *********************
96 ob_start();
97
98 // *********************
99 // Timetracking started
100 // *********************
101 if ($_COOKIE['be_typo_user']) {
102 require_once(PATH_t3lib.'class.t3lib_timetrack.php');
103 $TT = new t3lib_timeTrack;
104 } else {
105 require_once(PATH_t3lib.'class.t3lib_timetracknull.php');
106 $TT = new t3lib_timeTrackNull;
107 }
108
109 $TT->start();
110 $TT->push('','Script start');
111
112
113 // *********************
114 // Mandatory libraries included
115 // *********************
116 $TT->push('Include class t3lib_db, t3lib_div, t3lib_extmgm','');
117 require_once(PATH_t3lib.'class.t3lib_div.php');
118 require_once(PATH_t3lib.'class.t3lib_extmgm.php');
119 $TT->pull();
120
121
122
123 // **********************
124 // Include configuration
125 // **********************
126 $TT->push('Include config files','');
127 require(PATH_t3lib.'config_default.php');
128 if (!defined ('TYPO3_db')) die ('The configuration file was not included.'); // the name of the TYPO3 database is stored in this constant. Here the inclusion of the config-file is verified by checking if this var is set.
129 if (!t3lib_extMgm::isLoaded('cms')) die('<strong>Error:</strong> The main frontend extension "cms" was not loaded. Enable it in the extension manager in the backend.');
130
131 if (!defined('PATH_tslib')) {
132 define('PATH_tslib', t3lib_extMgm::extPath('cms').'tslib/');
133 }
134
135
136
137
138 // *********************
139 // Error & Exception handling
140 // *********************
141 if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
142 $TT->push('Register Exceptionhandler', '');
143 if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
144 // register an error handler for the given errorHandlerErrors
145 $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
146 // set errors which will be converted in an exception
147 $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
148 }
149 $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
150 $TT->pull();
151 }
152
153 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
154 $TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
155
156 $CLIENT = t3lib_div::clientInfo(); // Set to the browser: net / msie if 4+ browsers
157 $TT->pull();
158
159
160 // *******************************
161 // Checking environment
162 // *******************************
163 if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
164 throw new Exception('You cannot set the GLOBALS-array from outside the script.', 1294585200);
165 }
166 if (!get_magic_quotes_gpc()) {
167 $TT->push('Add slashes to GET/POST arrays','');
168 t3lib_div::addSlashesOnArray($_GET);
169 t3lib_div::addSlashesOnArray($_POST);
170 $HTTP_GET_VARS = $_GET;
171 $HTTP_POST_VARS = $_POST;
172 $TT->pull();
173 }
174
175
176 // Hook to preprocess the current request:
177 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
178 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
179 $hookParameters = array();
180 t3lib_div::callUserFunction($hookFunction, $hookParameters, $hookParameters);
181 }
182 unset($hookFunction);
183 unset($hookParameters);
184 }
185
186
187 // *********************
188 // Look for extension ID which will launch alternative output engine
189 // *********************
190 if ($temp_extId = t3lib_div::_GP('eID')) {
191 if ($classPath = t3lib_div::getFileAbsFileName($TYPO3_CONF_VARS['FE']['eID_include'][$temp_extId])) {
192 // Remove any output produced until now
193 ob_clean();
194
195 require($classPath);
196 }
197 exit;
198 }
199
200
201 // ***********************************
202 // Create $TSFE object (TSFE = TypoScript Front End)
203 // Connecting to database
204 // ***********************************
205 $TSFE = t3lib_div::makeInstance('tslib_fe',
206 $TYPO3_CONF_VARS,
207 t3lib_div::_GP('id'),
208 t3lib_div::_GP('type'),
209 t3lib_div::_GP('no_cache'),
210 t3lib_div::_GP('cHash'),
211 t3lib_div::_GP('jumpurl'),
212 t3lib_div::_GP('MP'),
213 t3lib_div::_GP('RDCT')
214 );
215 /** @var $TSFE tslib_fe */
216
217 if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
218 !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
219 $TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
220 }
221
222
223 $TSFE->connectToDB();
224
225 // In case of a keyword-authenticated preview, re-initialize the TSFE object:
226 if ($temp_previewConfig = $TSFE->ADMCMD_preview()) {
227 $TSFE = t3lib_div::makeInstance('tslib_fe',
228 $TYPO3_CONF_VARS,
229 t3lib_div::_GP('id'),
230 t3lib_div::_GP('type'),
231 t3lib_div::_GP('no_cache'),
232 t3lib_div::_GP('cHash'),
233 t3lib_div::_GP('jumpurl'),
234 t3lib_div::_GP('MP'),
235 t3lib_div::_GP('RDCT')
236 );
237 $TSFE->ADMCMD_preview_postInit($temp_previewConfig);
238 }
239
240 if ($TSFE->RDCT) {$TSFE->sendRedirect();}
241
242
243 // *******************
244 // Output compression
245 // *******************
246 // Remove any output produced until now
247 ob_clean();
248 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
249 if (t3lib_div::testInt($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
250 // Prevent errors if ini_set() is unavailable (safe mode)
251 @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
252 }
253 ob_start(array(t3lib_div::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
254 }
255
256 // *********
257 // FE_USER
258 // *********
259 $TT->push('Front End user initialized','');
260 /* @var $TSFE tslib_fe */
261 $TSFE->initFEuser();
262 $TT->pull();
263
264 // ****************
265 // PRE BE_USER HOOK
266 // ****************
267 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'])) {
268 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'] as $_funcRef) {
269 $_params = array();
270 t3lib_div::callUserFunction($_funcRef, $_params , $_params);
271 }
272 }
273
274
275 // *********
276 // BE_USER
277 // *********
278 $BE_USER = NULL;
279 /** @var $BE_USER t3lib_tsfeBeUserAuth */
280 if ($_COOKIE['be_typo_user']) { // If the backend cookie is set, we proceed and checks if a backend user is logged in.
281 $TYPO3_MISC['microtime_BE_USER_start'] = microtime(true);
282 $TT->push('Back End user initialized','');
283
284 // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
285 $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
286 $BE_USER->OS = TYPO3_OS;
287 $BE_USER->lockIP = $TYPO3_CONF_VARS['BE']['lockIP'];
288 $BE_USER->start(); // Object is initialized
289 $BE_USER->unpack_uc('');
290 if ($BE_USER->user['uid']) {
291 $BE_USER->fetchGroupData();
292 $TSFE->beUserLogin = 1;
293 }
294 // Unset the user initialization.
295 if (!$BE_USER->checkLockToIP() || !$BE_USER->checkBackendAccessSettingsFromInitPhp() || !$BE_USER->user['uid']) {
296 $BE_USER = NULL;
297 $TSFE->beUserLogin=0;
298 }
299 $TT->pull();
300 $TYPO3_MISC['microtime_BE_USER_end'] = microtime(true);
301 } elseif ($TSFE->ADMCMD_preview_BEUSER_uid) {
302
303 // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
304 $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
305 $BE_USER->userTS_dontGetCached = 1;
306 $BE_USER->OS = TYPO3_OS;
307 $BE_USER->setBeUserByUid($TSFE->ADMCMD_preview_BEUSER_uid);
308 $BE_USER->unpack_uc('');
309 if ($BE_USER->user['uid']) {
310 $BE_USER->fetchGroupData();
311 $TSFE->beUserLogin = 1;
312 } else {
313 $BE_USER = NULL;
314 $TSFE->beUserLogin = 0;
315 }
316 }
317
318 // ********************
319 // Workspace preview:
320 // ********************
321 $TSFE->workspacePreviewInit();
322
323
324 // *****************************************
325 // Process the ID, type and other parameters
326 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
327 // *****************************************
328 $TT->push('Process ID','');
329 // Initialize admin panel since simulation settings are required here:
330 if ($TSFE->beUserLogin) {
331 $BE_USER->initializeAdminPanel();
332 }
333
334 $TSFE->checkAlternativeIdMethods();
335 $TSFE->clear_preview();
336 $TSFE->determineId();
337
338 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
339 if ($TSFE->beUserLogin && (!$BE_USER->extPageReadAccess($TSFE->page) || t3lib_div::_GP('ADMCMD_noBeUser'))) { // t3lib_div::_GP('ADMCMD_noBeUser') is placed here because workspacePreviewInit() might need to know if a backend user is logged in!
340
341 // Remove user
342 unset($BE_USER);
343 $TSFE->beUserLogin = 0;
344
345 // Re-evaluate the page-id.
346 $TSFE->checkAlternativeIdMethods();
347 $TSFE->clear_preview();
348 $TSFE->determineId();
349 }
350 $TSFE->makeCacheHash();
351 $TT->pull();
352
353 // *****************************************
354 // Admin Panel & Frontend editing
355 // *****************************************
356 if ($TSFE->beUserLogin) {
357 // if a BE User is present load, the sprite manager for frontend-editing
358 $spriteManager = t3lib_div::makeInstance('t3lib_SpriteManager', FALSE);
359 $spriteManager->loadCacheFile();
360
361 $BE_USER->initializeFrontendEdit();
362 if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
363 $LANG = t3lib_div::makeInstance('language');
364 $LANG->init($BE_USER->uc['lang']);
365 }
366 if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
367 $BE_USER->frontendEdit->initConfigOptions();
368 }
369 }
370
371 // *******************************************
372 // Get compressed $TCA-Array();
373 // After this, we should now have a valid $TCA, though minimized
374 // *******************************************
375 $TSFE->getCompressedTCarray();
376
377
378 // ********************************
379 // Starts the template
380 // *******************************
381 $TT->push('Start Template','');
382 $TSFE->initTemplate();
383 $TT->pull();
384
385
386 // ********************************
387 // Get from cache
388 // *******************************
389 $TT->push('Get Page from cache','');
390 $TSFE->getFromCache();
391 $TT->pull();
392
393
394 // ******************************************************
395 // Get config if not already gotten
396 // After this, we should have a valid config-array ready
397 // ******************************************************
398 $TSFE->getConfigArray();
399
400 // ********************************
401 // Convert POST data to internal "renderCharset" if different from the metaCharset
402 // *******************************
403 $TSFE->convPOSTCharset();
404
405
406 // *******************************************
407 // Setting language and locale
408 // *******************************************
409 $TT->push('Setting language and locale','');
410 $TSFE->settingLanguage();
411 $TSFE->settingLocale();
412 $TT->pull();
413
414
415 // ********************************
416 // Check JumpUrl
417 // *******************************
418 $TSFE->setExternalJumpUrl();
419 $TSFE->checkJumpUrlReferer();
420
421
422 // ********************************
423 // Check Submission of data.
424 // This is done at this point, because we need the config values
425 // *******************************
426 switch($TSFE->checkDataSubmission()) {
427 case 'email':
428 $TSFE->sendFormmail();
429 break;
430 case 'fe_tce':
431 $TSFE->includeTCA();
432 $TT->push('fe_tce','');
433 $TSFE->fe_tce();
434 $TT->pull();
435 break;
436 }
437
438
439 // ********************************
440 // Generate page
441 // *******************************
442 $TSFE->setUrlIdToken();
443
444 $TT->push('Page generation','');
445 if ($TSFE->isGeneratePage()) {
446 $TSFE->generatePage_preProcessing();
447 $temp_theScript=$TSFE->generatePage_whichScript();
448
449 if ($temp_theScript) {
450 include($temp_theScript);
451 } else {
452 include(PATH_tslib.'pagegen.php');
453 }
454 $TSFE->generatePage_postProcessing();
455 } elseif ($TSFE->isINTincScript()) {
456 include(PATH_tslib.'pagegen.php');
457 }
458 $TT->pull();
459
460
461 // ********************************
462 // $TSFE->config['INTincScript']
463 // *******************************
464 if ($TSFE->isINTincScript()) {
465 $TT->push('Non-cached objects','');
466 $TSFE->INTincScript();
467 $TT->pull();
468 }
469
470 // ***************
471 // Output content
472 // ***************
473 $sendTSFEContent = false;
474 if ($TSFE->isOutputting()) {
475 $TT->push('Print Content','');
476 $TSFE->processOutput();
477
478 // ***************************************
479 // Outputs content / Includes EXT scripts
480 // ***************************************
481 if ($TSFE->isEXTincScript()) {
482 $TT->push('External PHP-script','');
483 // Important global variables here are $EXTiS_*, they must not be overridden in include-scripts!!!
484 $EXTiS_config = $TSFE->config['EXTincScript'];
485 $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$TSFE->content); // Splits content with the key
486
487 // Special feature: Include libraries
488 foreach ($EXTiS_config as $EXTiS_cPart) {
489 if (isset($EXTiS_cPart['conf']['includeLibs']) && $EXTiS_cPart['conf']['includeLibs']) {
490 $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'], true);
491 $TSFE->includeLibraries($EXTiS_resourceList);
492 }
493 }
494
495 foreach ($EXTiS_splitC as $EXTiS_c => $EXTiS_cPart) {
496 if (substr($EXTiS_cPart,32,3)=='-->') { // If the split had a comment-end after 32 characters it's probably a split-string
497 $EXTiS_key = 'EXT_SCRIPT.'.substr($EXTiS_cPart,0,32);
498 if (is_array($EXTiS_config[$EXTiS_key])) {
499 $REC = $EXTiS_config[$EXTiS_key]['data'];
500 $CONF = $EXTiS_config[$EXTiS_key]['conf'];
501 $content = '';
502 include($EXTiS_config[$EXTiS_key]['file']);
503 echo $content; // The script MAY return content in $content or the script may just output the result directly!
504 }
505 echo substr($EXTiS_cPart,35);
506 } else {
507 echo ($c?'<!--EXT_SCRIPT.':'').$EXTiS_cPart;
508 }
509 }
510
511 $TT->pull();
512 } else {
513 $sendTSFEContent = true;
514 }
515 $TT->pull();
516 }
517
518
519 // ********************************
520 // Store session data for fe_users
521 // ********************************
522 $TSFE->storeSessionData();
523
524
525 // ***********
526 // Statistics
527 // ***********
528 $TYPO3_MISC['microtime_end'] = microtime(true);
529 $TSFE->setParseTime();
530 if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS['FE']['debug']) || !empty($TSFE->config['config']['debug']))) {
531 $TSFE->content .= LF . '<!-- Parsetime: ' . $TSFE->scriptParseTime . 'ms -->';
532 }
533 $TSFE->statistics();
534
535
536 // ***************
537 // Check JumpUrl
538 // ***************
539 $TSFE->jumpurl();
540
541
542 // *************
543 // Preview info
544 // *************
545 $TSFE->previewInfo();
546
547
548 // ******************
549 // Publishing static
550 // ******************
551 if (is_object($BE_USER) && ($BE_USER->adminPanel instanceof tslib_AdminPanel)) {
552 if ($BE_USER->adminPanel->isAdminModuleEnabled('publish') && $BE_USER->adminPanel->getExtPublishList()) {
553 include_once(PATH_tslib.'publish.php');
554 }
555 }
556
557
558 // ******************
559 // Hook for end-of-frontend
560 // ******************
561 $TSFE->hook_eofe();
562
563
564 // ********************
565 // Finish timetracking
566 // ********************
567 $TT->pull();
568
569
570 // ******************
571 // beLoginLinkIPList
572 // ******************
573 echo $TSFE->beLoginLinkIPList();
574
575
576 // *************
577 // Admin panel
578 // *************
579 if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->beUserLogin) {
580 $TSFE->content = str_ireplace('</head>', $BE_USER->adminPanel->getAdminPanelHeaderData() . '</head>', $TSFE->content);
581 $TSFE->content = str_ireplace('</body>', $BE_USER->displayAdminPanel() . '</body>', $TSFE->content);
582 }
583
584 if ($sendTSFEContent) {
585 echo $TSFE->content;
586 }
587
588 // *************
589 // Debugging Output
590 // *************
591 if(isset($error) && is_object($error) && @is_callable(array($error,'debugOutput'))) {
592 $error->debugOutput();
593 }
594 if (TYPO3_DLOG) {
595 t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
596 }
597
598 ?>