2 /***************************************************************
5 * (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
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.
34 * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
36 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
41 // *******************************
42 // Checking PHP version
43 // *******************************
44 if (version_compare(phpversion(), '5.2', '<')) die ('TYPO3 requires PHP 5.2.0 or higher.');
46 // *******************************
47 // Set error reporting
48 // *******************************
49 if (defined('E_DEPRECATED')) {
50 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED
);
52 error_reporting(E_ALL ^ E_NOTICE
);
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');
63 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']))));
64 if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript
).'/');
65 if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site
.'t3lib/');
67 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
68 define('PATH_typo3', PATH_site
.TYPO3_mainDir
);
69 define('PATH_typo3conf', PATH_site
.'typo3conf/');
71 if (!defined('PATH_tslib')) {
72 if (@is_dir
(PATH_site
.TYPO3_mainDir
.'sysext/cms/tslib/')) {
73 define('PATH_tslib', PATH_site
.TYPO3_mainDir
.'sysext/cms/tslib/');
74 } elseif (@is_dir
(PATH_site
.'tslib/')) {
75 define('PATH_tslib', PATH_site
.'tslib/');
79 if (!@is_dir
(PATH_typo3conf
)) die('Cannot find configuration. This file is probably executed from the wrong location.');
81 // *********************
82 // Unset variable(s) in global scope (fixes #13959)
83 // *********************
86 // *********************
87 // Prevent any output until AJAX/compression is initialized to stop
88 // AJAX/compression data corruption
89 // *********************
92 // *********************
93 // Timetracking started
94 // *********************
95 if ($_COOKIE['be_typo_user']) {
96 require_once(PATH_t3lib
.'class.t3lib_timetrack.php');
97 $TT = new t3lib_timeTrack
;
99 require_once(PATH_t3lib
.'class.t3lib_timetracknull.php');
100 $TT = new t3lib_timeTrackNull
;
104 $TT->push('','Script start');
107 // *********************
108 // Mandatory libraries included
109 // *********************
110 $TT->push('Include class t3lib_db, t3lib_div, t3lib_extmgm','');
111 require_once(PATH_t3lib
.'class.t3lib_div.php');
112 require_once(PATH_t3lib
.'class.t3lib_extmgm.php');
117 // **********************
118 // Include configuration
119 // **********************
120 $TT->push('Include config files','');
121 require(PATH_t3lib
.'config_default.php');
122 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.
123 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.');
125 if (!defined('PATH_tslib')) {
126 define('PATH_tslib', t3lib_extMgm
::extPath('cms').'tslib/');
132 // *********************
133 // Error & Exception handling
134 // *********************
135 if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
136 $TT->push('Register Exceptionhandler', '');
137 if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
138 // register an error handler for the given errorHandlerErrors
139 $errorHandler = t3lib_div
::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
140 // set errors which will be converted in an exception
141 $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
143 $exceptionHandler = t3lib_div
::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
147 $TYPO3_DB = t3lib_div
::makeInstance('t3lib_DB');
148 $TYPO3_DB->debugOutput
= $TYPO3_CONF_VARS['SYS']['sqlDebug'];
150 $CLIENT = t3lib_div
::clientInfo(); // Set to the browser: net / msie if 4+ browsers
154 // *******************************
155 // Checking environment
156 // *******************************
157 if (isset($_POST['GLOBALS']) ||
isset($_GET['GLOBALS'])) die('You cannot set the GLOBALS-array from outside the script.');
158 if (!get_magic_quotes_gpc()) {
159 $TT->push('Add slashes to GET/POST arrays','');
160 t3lib_div
::addSlashesOnArray($_GET);
161 t3lib_div
::addSlashesOnArray($_POST);
162 $HTTP_GET_VARS = $_GET;
163 $HTTP_POST_VARS = $_POST;
168 // Hook to preprocess the current request:
169 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
170 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
171 $hookParameters = array();
172 t3lib_div
::callUserFunction($hookFunction, $hookParameters, $hookParameters);
174 unset($hookFunction);
175 unset($hookParameters);
179 // *********************
180 // Look for extension ID which will launch alternative output engine
181 // *********************
182 if ($temp_extId = t3lib_div
::_GP('eID')) {
183 if ($classPath = t3lib_div
::getFileAbsFileName($TYPO3_CONF_VARS['FE']['eID_include'][$temp_extId])) {
184 // Remove any output produced until now
193 // ***********************************
194 // Create $TSFE object (TSFE = TypoScript Front End)
195 // Connecting to database
196 // ***********************************
197 $TSFE = t3lib_div
::makeInstance('tslib_fe',
199 t3lib_div
::_GP('id'),
200 t3lib_div
::_GP('type'),
201 t3lib_div
::_GP('no_cache'),
202 t3lib_div
::_GP('cHash'),
203 t3lib_div
::_GP('jumpurl'),
204 t3lib_div
::_GP('MP'),
205 t3lib_div
::_GP('RDCT')
207 /* @var $TSFE tslib_fe */
209 if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
210 !t3lib_div
::cmpIP(t3lib_div
::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
211 $TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
215 $TSFE->connectToDB();
217 // In case of a keyword-authenticated preview, re-initialize the TSFE object:
218 if ($temp_previewConfig = $TSFE->ADMCMD_preview()) {
219 $TSFE = t3lib_div
::makeInstance('tslib_fe',
221 t3lib_div
::_GP('id'),
222 t3lib_div
::_GP('type'),
223 t3lib_div
::_GP('no_cache'),
224 t3lib_div
::_GP('cHash'),
225 t3lib_div
::_GP('jumpurl'),
226 t3lib_div
::_GP('MP'),
227 t3lib_div
::_GP('RDCT')
229 $TSFE->ADMCMD_preview_postInit($temp_previewConfig);
232 if ($TSFE->RDCT
) {$TSFE->sendRedirect();}
235 // *******************
236 // Output compression
237 // *******************
238 // Remove any output produced until now
240 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
241 if (t3lib_div
::testInt($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
242 // Prevent errors if ini_set() is unavailable (safe mode)
243 @ini_set
('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
245 ob_start(array(t3lib_div
::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
251 $TT->push('Front End user initialized','');
252 /* @var $TSFE tslib_fe */
259 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'])) {
260 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'] as $_funcRef) {
262 t3lib_div
::callUserFunction($_funcRef, $_params , $_params);
271 if ($_COOKIE['be_typo_user']) { // If the backend cookie is set, we proceed and checks if a backend user is logged in.
272 $TYPO3_MISC['microtime_BE_USER_start'] = microtime(true);
273 $TT->push('Back End user initialized','');
275 // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
276 $BE_USER = t3lib_div
::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
277 $BE_USER->OS
= TYPO3_OS
;
278 $BE_USER->lockIP
= $TYPO3_CONF_VARS['BE']['lockIP'];
279 $BE_USER->start(); // Object is initialized
280 $BE_USER->unpack_uc('');
281 if ($BE_USER->user
['uid']) {
282 $BE_USER->fetchGroupData();
283 $TSFE->beUserLogin
= 1;
285 // Unset the user initialization.
286 if (!$BE_USER->checkLockToIP() ||
!$BE_USER->checkBackendAccessSettingsFromInitPhp() ||
!$BE_USER->user
['uid']) {
288 $TSFE->beUserLogin
=0;
291 $TYPO3_MISC['microtime_BE_USER_end'] = microtime(true);
292 } elseif ($TSFE->ADMCMD_preview_BEUSER_uid
) {
294 // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
295 $BE_USER = t3lib_div
::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
296 $BE_USER->userTS_dontGetCached
= 1;
297 $BE_USER->OS
= TYPO3_OS
;
298 $BE_USER->setBeUserByUid($TSFE->ADMCMD_preview_BEUSER_uid
);
299 $BE_USER->unpack_uc('');
300 if ($BE_USER->user
['uid']) {
301 $BE_USER->fetchGroupData();
302 $TSFE->beUserLogin
= 1;
305 $TSFE->beUserLogin
= 0;
309 // ********************
310 // Workspace preview:
311 // ********************
312 $TSFE->workspacePreviewInit();
315 // *****************************************
316 // Process the ID, type and other parameters
317 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
318 // *****************************************
319 $TT->push('Process ID','');
320 // Initialize admin panel since simulation settings are required here:
321 if ($TSFE->beUserLogin
) {
322 $BE_USER->initializeAdminPanel();
325 $TSFE->checkAlternativeIdMethods();
326 $TSFE->clear_preview();
327 $TSFE->determineId();
329 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
330 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!
334 $TSFE->beUserLogin
= 0;
336 // Re-evaluate the page-id.
337 $TSFE->checkAlternativeIdMethods();
338 $TSFE->clear_preview();
339 $TSFE->determineId();
341 $TSFE->makeCacheHash();
344 // *****************************************
345 // Admin Panel & Frontend editing
346 // *****************************************
347 if ($TSFE->beUserLogin
) {
348 $BE_USER->initializeFrontendEdit();
349 if ($BE_USER->adminPanel
instanceof tslib_AdminPanel
) {
350 $LANG = t3lib_div
::makeInstance('language');
351 $LANG->init($BE_USER->uc
['lang']);
353 if ($BE_USER->frontendEdit
instanceof t3lib_frontendedit
) {
354 $BE_USER->frontendEdit
->initConfigOptions();
358 // *******************************************
359 // Get compressed $TCA-Array();
360 // After this, we should now have a valid $TCA, though minimized
361 // *******************************************
362 $TSFE->getCompressedTCarray();
365 // ********************************
366 // Starts the template
367 // *******************************
368 $TT->push('Start Template','');
369 $TSFE->initTemplate();
373 // ********************************
375 // *******************************
376 $TT->push('Get Page from cache','');
377 $TSFE->getFromCache();
381 // ******************************************************
382 // Get config if not already gotten
383 // After this, we should have a valid config-array ready
384 // ******************************************************
385 $TSFE->getConfigArray();
387 // ********************************
388 // Convert POST data to internal "renderCharset" if different from the metaCharset
389 // *******************************
390 $TSFE->convPOSTCharset();
393 // *******************************************
394 // Setting language and locale
395 // *******************************************
396 $TT->push('Setting language and locale','');
397 $TSFE->settingLanguage();
398 $TSFE->settingLocale();
402 // ********************************
404 // *******************************
405 $TSFE->setExternalJumpUrl();
406 $TSFE->checkJumpUrlReferer();
409 // ********************************
410 // Check Submission of data.
411 // This is done at this point, because we need the config values
412 // *******************************
413 switch($TSFE->checkDataSubmission()) {
415 $TSFE->sendFormmail();
419 $TT->push('fe_tce','');
426 // ********************************
428 // *******************************
429 $TSFE->setUrlIdToken();
431 $TT->push('Page generation','');
432 if ($TSFE->isGeneratePage()) {
433 $TSFE->generatePage_preProcessing();
434 $temp_theScript=$TSFE->generatePage_whichScript();
436 if ($temp_theScript) {
437 include($temp_theScript);
439 include(PATH_tslib
.'pagegen.php');
441 $TSFE->generatePage_postProcessing();
442 } elseif ($TSFE->isINTincScript()) {
443 include(PATH_tslib
.'pagegen.php');
448 // ********************************
449 // $TSFE->config['INTincScript']
450 // *******************************
451 if ($TSFE->isINTincScript()) {
452 $TT->push('Non-cached objects','');
453 $TSFE->INTincScript();
460 if ($TSFE->isOutputting()) {
461 $TT->push('Print Content','');
462 $TSFE->processOutput();
464 // ***************************************
465 // Outputs content / Includes EXT scripts
466 // ***************************************
467 if ($TSFE->isEXTincScript()) {
468 $TT->push('External PHP-script','');
469 // Important global variables here are $EXTiS_*, they must not be overridden in include-scripts!!!
470 $EXTiS_config = $TSFE->config
['EXTincScript'];
471 $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$TSFE->content
); // Splits content with the key
473 // Special feature: Include libraries
474 foreach ($EXTiS_config as $EXTiS_cPart) {
475 if (isset($EXTiS_cPart['conf']['includeLibs']) && $EXTiS_cPart['conf']['includeLibs']) {
476 $EXTiS_resourceList = t3lib_div
::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'], true);
477 $TSFE->includeLibraries($EXTiS_resourceList);
481 foreach ($EXTiS_splitC as $EXTiS_c => $EXTiS_cPart) {
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'];
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!
491 echo substr($EXTiS_cPart,35);
493 echo ($c?
'<!--EXT_SCRIPT.':'').$EXTiS_cPart;
505 // ********************************
506 // Store session data for fe_users
507 // ********************************
508 $TSFE->storeSessionData();
514 $TYPO3_MISC['microtime_end'] = microtime(true);
515 $TSFE->setParseTime();
516 if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS
['FE']['debug']) ||
!empty($TSFE->config
['config']['debug']))) {
518 <!-- Parsetime: '.$TSFE->scriptParseTime
.' ms-->';
532 $TSFE->previewInfo();
535 // ******************
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');
545 // ******************
546 // Hook for end-of-frontend
547 // ******************
551 // ********************
552 // Finish timetracking
553 // ********************
557 // ******************
559 // ******************
560 echo $TSFE->beLoginLinkIPList();
566 if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->beUserLogin
) {
567 echo $BE_USER->displayAdminPanel();
573 if(isset($error) && is_object($error) && @is_callable
(array($error,'debugOutput'))) {
574 $error->debugOutput();
577 t3lib_div
::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));