[!!!][TASK] Bootstrap: Central constants and path handling
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / index_ts.php
index 642fc24..ac78e7d 100644 (file)
 // *******************************
 // Checking PHP version
 // *******************************
-if (version_compare(phpversion(), '5.2', '<')) die ('TYPO3 requires PHP 5.2.0 or higher.');
-
-// *******************************
-// Set error reporting
-// *******************************
-error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
+if (version_compare(phpversion(), '5.3', '<')) die ('TYPO3 requires PHP 5.3.0 or higher.');
 
 
 // ******************
 // Constants defined
 // ******************
 $TYPO3_MISC['microtime_start'] = microtime(TRUE);
-define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
 define('TYPO3_MODE','FE');
 
-if(!defined('PATH_thisScript')) {
-       define('PATH_thisScript', str_replace('//', '/', str_replace('\\', '/',
-               (PHP_SAPI == 'fpm-fcgi' || 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']))));
-}
-
-if (!defined('PATH_site'))                     define('PATH_site', dirname(PATH_thisScript).'/');
-if (!defined('PATH_t3lib'))            define('PATH_t3lib', PATH_site.'t3lib/');
-
-define('TYPO3_mainDir', 'typo3/');             // This is the directory of the backend administration for the sites of this TYPO3 installation.
-define('PATH_typo3', PATH_site.TYPO3_mainDir);
-define('PATH_typo3conf', PATH_site.'typo3conf/');
-
-if (!defined('PATH_tslib')) {
-       if (@is_dir(PATH_site.TYPO3_mainDir.'sysext/cms/tslib/')) {
-               define('PATH_tslib', PATH_site.TYPO3_mainDir.'sysext/cms/tslib/');
-       } elseif (@is_dir(PATH_site.'tslib/')) {
-               define('PATH_tslib', PATH_site.'tslib/');
-       }
-}
-
-if (!@is_dir(PATH_typo3conf))  die('Cannot find configuration. This file is probably executed from the wrong location.');
-
 // *********************
 // Unset variable(s) in global scope (fixes #13959)
 // *********************
@@ -91,53 +60,34 @@ unset($error);
 // *********************
 ob_start();
 
-// *********************
-// Timetracking started
-// *********************
-if ($_SESSION['TYPO3-TT-start']) {
-       require_once(PATH_t3lib.'class.t3lib_timetrack.php');
-       $TT = new t3lib_timeTrack;
-} else {
-       require_once(PATH_t3lib.'class.t3lib_timetracknull.php');
-       $TT = new t3lib_timeTrackNull;
-}
-
-$TT->start();
-$TT->push('','Script start');
-
 
 // *********************
 // Mandatory libraries included
 // *********************
-$TT->push('Include class t3lib_db, t3lib_div, t3lib_extmgm','');
-       require_once(PATH_t3lib.'class.t3lib_div.php');
-       require_once(PATH_t3lib.'class.t3lib_extmgm.php');
-$TT->pull();
-
+require_once(PATH_t3lib . 'class.t3lib_div.php');
+require_once(PATH_t3lib . 'class.t3lib_extmgm.php');
 
 
 // **********************
 // Include configuration
 // **********************
-$TT->push('Include config files','');
 require(PATH_t3lib.'config_default.php');
 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.
 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.');
 
-if (!defined('PATH_tslib')) {
-       define('PATH_tslib', t3lib_extMgm::extPath('cms').'tslib/');
-}
-
-
-// Restart time tracking if BE login exists
-if (!$_SESSION['TYPO3-TT-start'] && $_COOKIE[t3lib_beUserAuth::getCookieName()]) {
-       $_SESSION['TYPO3-TT-start'] = TRUE;
 
-       $TT = new t3lib_timeTrack;
-       $TT->start();
-       $TT->push('', 'Script start (late)');
+// *********************
+// Timetracking started
+// *********************
+if ($_COOKIE[t3lib_beUserAuth::getCookieName()]) {
+       require_once(PATH_t3lib . 'class.t3lib_timetrack.php');
+       $TT = new t3lib_timeTrack();
+} else {
+       require_once(PATH_t3lib . 'class.t3lib_timetracknull.php');
+       $TT = new t3lib_timeTrackNull();
 }
-
+$TT->start();
+$TT->push('', 'Script start');
 
 // *********************
 // Error & Exception handling
@@ -160,7 +110,6 @@ $TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
 $CLIENT = t3lib_div::clientInfo();                             // Set to the browser: net / msie if 4+ browsers
 $TT->pull();
 
-
 // *******************************
 // Checking environment
 // *******************************
@@ -226,22 +175,7 @@ if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
 
 $TSFE->connectToDB();
 
-       // In case of a keyword-authenticated preview, re-initialize the TSFE object:
-if ($temp_previewConfig = $TSFE->ADMCMD_preview())     {
-       $TSFE = t3lib_div::makeInstance('tslib_fe',
-               $TYPO3_CONF_VARS,
-               t3lib_div::_GP('id'),
-               t3lib_div::_GP('type'),
-               t3lib_div::_GP('no_cache'),
-               t3lib_div::_GP('cHash'),
-               t3lib_div::_GP('jumpurl'),
-               t3lib_div::_GP('MP'),
-               t3lib_div::_GP('RDCT')
-       );
-       $TSFE->ADMCMD_preview_postInit($temp_previewConfig);
-}
-
-if ($TSFE->RDCT)       {$TSFE->sendRedirect();}
+$TSFE->sendRedirect();
 
 
 // *******************
@@ -250,7 +184,7 @@ if ($TSFE->RDCT)    {$TSFE->sendRedirect();}
 // Remove any output produced until now
 ob_clean();
 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib'))    {
-       if (t3lib_div::testInt($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
+       if (t3lib_utility_Math::canBeInterpretedAsInteger($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
                // Prevent errors if ini_set() is unavailable (safe mode)
                @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
        }
@@ -265,66 +199,12 @@ $TT->push('Front End user initialized','');
        $TSFE->initFEuser();
 $TT->pull();
 
-// ****************
-// PRE BE_USER HOOK
-// ****************
-if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'])) {
-       foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'] as $_funcRef) {
-               $_params = array();
-               t3lib_div::callUserFunction($_funcRef, $_params , $_params);
-       }
-}
-
 
 // *********
 // BE_USER
 // *********
-$BE_USER = NULL;
 /** @var $BE_USER t3lib_tsfeBeUserAuth */
-if ($_COOKIE[t3lib_beUserAuth::getCookieName()]) {             // If the backend cookie is set, we proceed and checks if a backend user is logged in.
-       $TYPO3_MISC['microtime_BE_USER_start'] = microtime(TRUE);
-       $TT->push('Back End user initialized','');
-
-                       // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
-               $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth');     // New backend user object
-               $BE_USER->OS = TYPO3_OS;
-               $BE_USER->lockIP = $TYPO3_CONF_VARS['BE']['lockIP'];
-               $BE_USER->start();                      // Object is initialized
-               $BE_USER->unpack_uc('');
-               if ($BE_USER->user['uid'])      {
-                       $BE_USER->fetchGroupData();
-                       $TSFE->beUserLogin = 1;
-               }
-                       // Unset the user initialization.
-               if (!$BE_USER->checkLockToIP() || !$BE_USER->checkBackendAccessSettingsFromInitPhp() || !$BE_USER->user['uid']) {
-                       $BE_USER = NULL;
-                       $TSFE->beUserLogin=0;
-                       $_SESSION['TYPO3-TT-start'] = FALSE;
-               }
-       $TT->pull();
-       $TYPO3_MISC['microtime_BE_USER_end'] = microtime(TRUE);
-} elseif ($TSFE->ADMCMD_preview_BEUSER_uid)    {
-
-               // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
-       $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth');     // New backend user object
-       $BE_USER->userTS_dontGetCached = 1;
-       $BE_USER->OS = TYPO3_OS;
-       $BE_USER->setBeUserByUid($TSFE->ADMCMD_preview_BEUSER_uid);
-       $BE_USER->unpack_uc('');
-       if ($BE_USER->user['uid'])      {
-               $BE_USER->fetchGroupData();
-               $TSFE->beUserLogin = 1;
-       } else {
-               $BE_USER = NULL;
-               $TSFE->beUserLogin = 0;
-               $_SESSION['TYPO3-TT-start'] = FALSE;
-       }
-}
-
-// ********************
-// Workspace preview:
-// ********************
-$TSFE->workspacePreviewInit();
+$BE_USER = $TSFE->initializeBackendUser();
 
 
 // *****************************************
@@ -333,7 +213,7 @@ $TSFE->workspacePreviewInit();
 // *****************************************
 $TT->push('Process ID','');
                // Initialize admin panel since simulation settings are required here:
-       if ($TSFE->beUserLogin) {
+       if ($TSFE->isBackendUserLoggedIn()) {
                $BE_USER->initializeAdminPanel();
        }
 
@@ -342,7 +222,7 @@ $TT->push('Process ID','');
        $TSFE->determineId();
 
                // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
-       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!
+       if ($TSFE->isBackendUserLoggedIn() && (!$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!
 
                        // Remove user
                unset($BE_USER);
@@ -359,16 +239,16 @@ $TT->pull();
 // *****************************************
 // Admin Panel & Frontend editing
 // *****************************************
-if ($TSFE->beUserLogin) {
+if ($TSFE->isBackendUserLoggedIn()) {
                // if a BE User is present load, the sprite manager for frontend-editing
        $spriteManager = t3lib_div::makeInstance('t3lib_SpriteManager', FALSE);
        $spriteManager->loadCacheFile();
 
        $BE_USER->initializeFrontendEdit();
-       if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
+       if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
                $LANG = t3lib_div::makeInstance('language');
                $LANG->init($BE_USER->uc['lang']);
-       }
+       }
        if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
                $BE_USER->frontendEdit->initConfigOptions();
        }
@@ -433,15 +313,15 @@ switch($TSFE->checkDataSubmission())      {
        case 'email':
                $TSFE->sendFormmail();
        break;
-       case 'fe_tce':
-               $TSFE->includeTCA();
-               $TT->push('fe_tce','');
-               $TSFE->fe_tce();
-               $TT->pull();
-       break;
 }
 
 
+// *******************************
+// Check for shortcut page and redirect
+// *******************************
+$TSFE->checkPageForShortcutRedirect();
+
+
 // ********************************
 // Generate page
 // *******************************
@@ -480,44 +360,7 @@ $sendTSFEContent = FALSE;
 if ($TSFE->isOutputting())     {
        $TT->push('Print Content','');
        $TSFE->processOutput();
-
-       // ***************************************
-       // Outputs content / Includes EXT scripts
-       // ***************************************
-       if ($TSFE->isEXTincScript())    {
-               $TT->push('External PHP-script','');
-                               // Important global variables here are $EXTiS_*, they must not be overridden in include-scripts!!!
-                       $EXTiS_config = $TSFE->config['EXTincScript'];
-                       $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$TSFE->content);      // Splits content with the key
-
-                               // Special feature: Include libraries
-                       foreach ($EXTiS_config as $EXTiS_cPart) {
-                               if (isset($EXTiS_cPart['conf']['includeLibs']) && $EXTiS_cPart['conf']['includeLibs']) {
-                                       $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'], TRUE);
-                                       $TSFE->includeLibraries($EXTiS_resourceList);
-                               }
-                       }
-
-                       foreach ($EXTiS_splitC as $EXTiS_c => $EXTiS_cPart) {
-                               if (substr($EXTiS_cPart,32,3)=='-->')   {       // If the split had a comment-end after 32 characters it's probably a split-string
-                                       $EXTiS_key = 'EXT_SCRIPT.'.substr($EXTiS_cPart,0,32);
-                                       if (is_array($EXTiS_config[$EXTiS_key]))        {
-                                               $REC = $EXTiS_config[$EXTiS_key]['data'];
-                                               $CONF = $EXTiS_config[$EXTiS_key]['conf'];
-                                               $content = '';
-                                               include($EXTiS_config[$EXTiS_key]['file']);
-                                               echo $content;  // The script MAY return content in $content or the script may just output the result directly!
-                                       }
-                                       echo substr($EXTiS_cPart,35);
-                               } else {
-                                       echo ($c?'<!--EXT_SCRIPT.':'').$EXTiS_cPart;
-                               }
-                       }
-
-               $TT->pull();
-       } else {
-               $sendTSFEContent = TRUE;
-       }
+       $sendTSFEContent = TRUE;
        $TT->pull();
 }
 
@@ -552,16 +395,6 @@ $TSFE->previewInfo();
 
 
 // ******************
-// Publishing static
-// ******************
-if (is_object($BE_USER) && ($BE_USER->adminPanel instanceof tslib_AdminPanel)) {
-       if ($BE_USER->adminPanel->isAdminModuleEnabled('publish') && $BE_USER->adminPanel->getExtPublishList()) {
-               include_once(PATH_tslib.'publish.php');
-       }
-}
-
-
-// ******************
 // Hook for end-of-frontend
 // ******************
 $TSFE->hook_eofe();
@@ -572,6 +405,10 @@ $TSFE->hook_eofe();
 // ********************
 $TT->pull();
 
+// ******************
+// Check memory usage
+// ******************
+t3lib_utility_Monitor::peakMemoryUsage();
 
 // ******************
 // beLoginLinkIPList
@@ -582,7 +419,7 @@ echo $TSFE->beLoginLinkIPList();
 // *************
 // Admin panel
 // *************
-if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->beUserLogin) {
+if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->isBackendUserLoggedIn()) {
        $TSFE->content = str_ireplace('</head>',  $BE_USER->adminPanel->getAdminPanelHeaderData() . '</head>', $TSFE->content);
        $TSFE->content = str_ireplace('</body>',  $BE_USER->displayAdminPanel() . '</body>', $TSFE->content);
 }