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