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