[TASK] PATH_tslib is defined twice in bootstrap
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / index_ts.php
index cc6d5e3..2d6b81e 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * 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.
  * All the real data processing goes on in the "tslib/" classes which this script will include and use as needed.
  *
  * 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.
  * All the real data processing goes on in the "tslib/" classes which this script will include and use as needed.
  *
- * $Id$
- * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
+ * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
  *
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage tslib
  */
  * @package TYPO3
  * @subpackage tslib
  */
 // *******************************
 // Checking PHP version
 // *******************************
 // *******************************
 // Checking PHP version
 // *******************************
-if (version_compare(phpversion(), '5.2', '<')) die ('TYPO3 requires PHP 5.2.0 or higher.');
+if (version_compare(phpversion(), '5.3', '<')) die ('TYPO3 requires PHP 5.3.0 or higher.');
 
 // *******************************
 // Set error reporting
 // *******************************
 
 // *******************************
 // Set error reporting
 // *******************************
-error_reporting (E_ALL ^ E_NOTICE);
+error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
 
 
 // ******************
 // Constants defined
 // ******************
 
 
 // ******************
 // Constants defined
 // ******************
-$TYPO3_MISC['microtime_start'] = microtime();
+$TYPO3_MISC['microtime_start'] = microtime(TRUE);
 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
 define('TYPO3_MODE','FE');
 
 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_name()=='cgi'||php_sapi_name()=='isapi' ||php_sapi_name()=='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_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/');
 
 if (!defined('PATH_site'))                     define('PATH_site', dirname(PATH_thisScript).'/');
 if (!defined('PATH_t3lib'))            define('PATH_t3lib', PATH_site.'t3lib/');
 
@@ -64,65 +70,75 @@ define('TYPO3_mainDir', 'typo3/');          // This is the directory of the backend admi
 define('PATH_typo3', PATH_site.TYPO3_mainDir);
 define('PATH_typo3conf', PATH_site.'typo3conf/');
 
 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.');
 
 // *********************
 if (!@is_dir(PATH_typo3conf))  die('Cannot find configuration. This file is probably executed from the wrong location.');
 
 // *********************
-// Prevent any output until AJAX/compression is initialized to stop
-// AJAX/compression data corruption
+// Unset variable(s) in global scope (fixes #13959)
 // *********************
 // *********************
-ob_start();
+unset($error);
 
 // *********************
 
 // *********************
-// Timetracking started
+// Prevent any output until AJAX/compression is initialized to stop
+// AJAX/compression data corruption
 // *********************
 // *********************
-require_once(PATH_t3lib.'class.t3lib_timetrack.php');
-$TT = new t3lib_timeTrack;
-$TT->start();
-$TT->push('','Script start');
+ob_start();
 
 
 // *********************
 // Mandatory libraries included
 // *********************
 
 
 // *********************
 // 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
 // **********************
 
 
 // **********************
 // 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.');
 
 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/');
+
+// *********************
+// 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
+// *********************
+if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
+       $TT->push('Register Exceptionhandler', '');
+       if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
+                       // register an error handler for the given errorHandlerErrors
+               $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
+                       // set errors which will be converted in an exception
+               $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
+       }
+       $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
+       $TT->pull();
 }
 
 }
 
-require_once(PATH_t3lib.'class.t3lib_db.php');
 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
 $TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
 
 $CLIENT = t3lib_div::clientInfo();                             // Set to the browser: net / msie if 4+ browsers
 $TT->pull();
 
 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
 $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
 // *******************************
 // *******************************
 // Checking environment
 // *******************************
-if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS']))       die('You cannot set the GLOBALS-array from outside the script.');
+if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
+       throw new Exception('You cannot set the GLOBALS-array from outside the script.', 1294585200);
+}
 if (!get_magic_quotes_gpc())   {
        $TT->push('Add slashes to GET/POST arrays','');
        t3lib_div::addSlashesOnArray($_GET);
 if (!get_magic_quotes_gpc())   {
        $TT->push('Add slashes to GET/POST arrays','');
        t3lib_div::addSlashesOnArray($_GET);
@@ -152,23 +168,11 @@ if ($temp_extId = t3lib_div::_GP('eID'))  {
                // Remove any output produced until now
                ob_clean();
 
                // Remove any output produced until now
                ob_clean();
 
-               require_once(PATH_tslib.'class.tslib_eidtools.php');
                require($classPath);
        }
        exit;
 }
 
                require($classPath);
        }
        exit;
 }
 
-// *********************
-// Libraries included
-// *********************
-$TT->push('Include Frontend libraries','');
-       require_once(PATH_tslib.'class.tslib_fe.php');
-       require_once(PATH_t3lib.'class.t3lib_page.php');
-       require_once(PATH_t3lib.'class.t3lib_userauth.php');
-       require_once(PATH_tslib.'class.tslib_feuserauth.php');
-       require_once(PATH_t3lib.'class.t3lib_tstemplate.php');
-       require_once(PATH_t3lib.'class.t3lib_cs.php');
-$TT->pull();
 
 // ***********************************
 // Create $TSFE object (TSFE = TypoScript Front End)
 
 // ***********************************
 // Create $TSFE object (TSFE = TypoScript Front End)
@@ -184,7 +188,7 @@ $TSFE = t3lib_div::makeInstance('tslib_fe',
        t3lib_div::_GP('MP'),
        t3lib_div::_GP('RDCT')
 );
        t3lib_div::_GP('MP'),
        t3lib_div::_GP('RDCT')
 );
-/* @var $TSFE tslib_fe */
+/** @var $TSFE tslib_fe */
 
 if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
        !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
 
 if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
        !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
@@ -194,22 +198,7 @@ if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
 
 $TSFE->connectToDB();
 
 
 $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();
 
 
 // *******************
 
 
 // *******************
@@ -218,11 +207,10 @@ if ($TSFE->RDCT)  {$TSFE->sendRedirect();}
 // Remove any output produced until now
 ob_clean();
 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib'))    {
 // 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']);
        }
                // Prevent errors if ini_set() is unavailable (safe mode)
                @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
        }
-       require_once(PATH_tslib . 'class.tslib_fecompression.php');
        ob_start(array(t3lib_div::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
 }
 
        ob_start(array(t3lib_div::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
 }
 
@@ -234,71 +222,12 @@ $TT->push('Front End user initialized','');
        $TSFE->initFEuser();
 $TT->pull();
 
        $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
 // *********
-$BE_USER='';
-if ($_COOKIE['be_typo_user']) {                // If the backend cookie is set, we proceed and checks if a backend user is logged in.
-       $TYPO3_MISC['microtime_BE_USER_start'] = microtime();
-       $TT->push('Back End user initialized','');
-               require_once (PATH_t3lib.'class.t3lib_befunc.php');
-               require_once (PATH_t3lib.'class.t3lib_userauthgroup.php');
-               require_once (PATH_t3lib.'class.t3lib_beuserauth.php');
-               require_once (PATH_t3lib.'class.t3lib_tsfebeuserauth.php');
-
-                       // 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='';
-                       $TSFE->beUserLogin=0;
-               }
-       $TT->pull();
-       $TYPO3_MISC['microtime_BE_USER_end'] = microtime();
-} elseif ($TSFE->ADMCMD_preview_BEUSER_uid)    {
-       require_once (PATH_t3lib.'class.t3lib_befunc.php');
-       require_once (PATH_t3lib.'class.t3lib_userauthgroup.php');
-       require_once (PATH_t3lib.'class.t3lib_beuserauth.php');
-       require_once (PATH_t3lib.'class.t3lib_tsfebeuserauth.php');
-
-               // 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 = '';
-               $TSFE->beUserLogin = 0;
-       }
-}
-
-// ********************
-// Workspace preview:
-// ********************
-$TSFE->workspacePreviewInit();
+/** @var $BE_USER t3lib_tsfeBeUserAuth */
+$BE_USER = $TSFE->initializeBackendUser();
 
 
 // *****************************************
 
 
 // *****************************************
@@ -306,12 +235,17 @@ $TSFE->workspacePreviewInit();
 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
 // *****************************************
 $TT->push('Process ID','');
 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
 // *****************************************
 $TT->push('Process ID','');
+               // Initialize admin panel since simulation settings are required here:
+       if ($TSFE->isBackendUserLoggedIn()) {
+               $BE_USER->initializeAdminPanel();
+       }
+
        $TSFE->checkAlternativeIdMethods();
        $TSFE->clear_preview();
        $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!
        $TSFE->checkAlternativeIdMethods();
        $TSFE->clear_preview();
        $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);
 
                        // Remove user
                unset($BE_USER);
@@ -326,15 +260,19 @@ $TT->push('Process ID','');
 $TT->pull();
 
 // *****************************************
 $TT->pull();
 
 // *****************************************
-// Frontend editing
+// 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();
        $BE_USER->initializeFrontendEdit();
-       if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
-               require_once(t3lib_extMgm::extPath('lang').'lang.php');
+       if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
                $LANG = t3lib_div::makeInstance('language');
                $LANG->init($BE_USER->uc['lang']);
                $LANG = t3lib_div::makeInstance('language');
                $LANG->init($BE_USER->uc['lang']);
-
+       }
+       if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
                $BE_USER->frontendEdit->initConfigOptions();
        }
 }
                $BE_USER->frontendEdit->initConfigOptions();
        }
 }
@@ -396,12 +334,9 @@ $TSFE->checkJumpUrlReferer();
 // *******************************
 switch($TSFE->checkDataSubmission())   {
        case 'email':
 // *******************************
 switch($TSFE->checkDataSubmission())   {
        case 'email':
-               require_once(PATH_t3lib.'class.t3lib_htmlmail.php');
-               require_once(PATH_t3lib.'class.t3lib_formmail.php');
                $TSFE->sendFormmail();
        break;
        case 'fe_tce':
                $TSFE->sendFormmail();
        break;
        case 'fe_tce':
-               require_once(PATH_tslib.'class.tslib_fetce.php');
                $TSFE->includeTCA();
                $TT->push('fe_tce','');
                $TSFE->fe_tce();
                $TSFE->includeTCA();
                $TT->push('fe_tce','');
                $TSFE->fe_tce();
@@ -410,15 +345,18 @@ switch($TSFE->checkDataSubmission())      {
 }
 
 
 }
 
 
+// *******************************
+// Check for shortcut page and redirect
+// *******************************
+$TSFE->checkPageForShortcutRedirect();
+
+
 // ********************************
 // Generate page
 // *******************************
 $TSFE->setUrlIdToken();
 
 $TT->push('Page generation','');
 // ********************************
 // Generate page
 // *******************************
 $TSFE->setUrlIdToken();
 
 $TT->push('Page generation','');
-       if ($TSFE->doXHTML_cleaning()) {
-               require_once(PATH_t3lib.'class.t3lib_parsehtml.php');
-       }
        if ($TSFE->isGeneratePage()) {
                $TSFE->generatePage_preProcessing();
                $temp_theScript=$TSFE->generatePage_whichScript();
        if ($TSFE->isGeneratePage()) {
                $TSFE->generatePage_preProcessing();
                $temp_theScript=$TSFE->generatePage_whichScript();
@@ -426,12 +364,10 @@ $TT->push('Page generation','');
                if ($temp_theScript) {
                        include($temp_theScript);
                } else {
                if ($temp_theScript) {
                        include($temp_theScript);
                } else {
-                       require_once(PATH_tslib.'class.tslib_pagegen.php');
                        include(PATH_tslib.'pagegen.php');
                }
                $TSFE->generatePage_postProcessing();
        } elseif ($TSFE->isINTincScript()) {
                        include(PATH_tslib.'pagegen.php');
                }
                $TSFE->generatePage_postProcessing();
        } elseif ($TSFE->isINTincScript()) {
-               require_once(PATH_tslib.'class.tslib_pagegen.php');
                include(PATH_tslib.'pagegen.php');
        }
 $TT->pull();
                include(PATH_tslib.'pagegen.php');
        }
 $TT->pull();
@@ -449,6 +385,7 @@ if ($TSFE->isINTincScript())                {
 // ***************
 // Output content
 // ***************
 // ***************
 // Output content
 // ***************
+$sendTSFEContent = FALSE;
 if ($TSFE->isOutputting())     {
        $TT->push('Print Content','');
        $TSFE->processOutput();
 if ($TSFE->isOutputting())     {
        $TT->push('Print Content','');
        $TSFE->processOutput();
@@ -463,16 +400,14 @@ if ($TSFE->isOutputting())        {
                        $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$TSFE->content);      // Splits content with the key
 
                                // Special feature: Include libraries
                        $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$TSFE->content);      // Splits content with the key
 
                                // Special feature: Include libraries
-                       reset($EXTiS_config);
-                       while(list(,$EXTiS_cPart)=each($EXTiS_config))  {
+                       foreach ($EXTiS_config as $EXTiS_cPart) {
                                if (isset($EXTiS_cPart['conf']['includeLibs']) && $EXTiS_cPart['conf']['includeLibs']) {
                                if (isset($EXTiS_cPart['conf']['includeLibs']) && $EXTiS_cPart['conf']['includeLibs']) {
-                                       $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'], true);
+                                       $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'], TRUE);
                                        $TSFE->includeLibraries($EXTiS_resourceList);
                                }
                        }
 
                                        $TSFE->includeLibraries($EXTiS_resourceList);
                                }
                        }
 
-                       reset($EXTiS_splitC);
-                       while(list($EXTiS_c,$EXTiS_cPart)=each($EXTiS_splitC))  {
+                       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]))        {
                                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]))        {
@@ -490,7 +425,7 @@ if ($TSFE->isOutputting())  {
 
                $TT->pull();
        } else {
 
                $TT->pull();
        } else {
-               echo $TSFE->content;
+               $sendTSFEContent = TRUE;
        }
        $TT->pull();
 }
        }
        $TT->pull();
 }
@@ -505,11 +440,10 @@ $TSFE->storeSessionData();
 // ***********
 // Statistics
 // ***********
 // ***********
 // Statistics
 // ***********
-$TYPO3_MISC['microtime_end'] = microtime();
+$TYPO3_MISC['microtime_end'] = microtime(TRUE);
 $TSFE->setParseTime();
 $TSFE->setParseTime();
-if ($TSFE->isOutputting() && ($TSFE->TYPO3_CONF_VARS['FE']['debug'] || $TSFE->config['config']['debug']))      {
-       echo '
-<!-- Parsetime: '.$TSFE->scriptParseTime.' ms-->';
+if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS['FE']['debug']) || !empty($TSFE->config['config']['debug']))) {
+       $TSFE->content .=  LF . '<!-- Parsetime: ' . $TSFE->scriptParseTime . 'ms -->';
 }
 $TSFE->statistics();
 
 }
 $TSFE->statistics();
 
@@ -527,16 +461,6 @@ $TSFE->previewInfo();
 
 
 // ******************
 
 
 // ******************
-// Publishing static
-// ******************
-if (is_object($BE_USER) && ($BE_USER->frontendEdit instanceof t3lib_frontendedit)) {
-       if ($BE_USER->frontendEdit->isAdminModuleEnabled('publish') && $BE_USER->frontendEdit->getExtPublishList()) {
-               include_once(PATH_tslib.'publish.php');
-       }
-}
-
-
-// ******************
 // Hook for end-of-frontend
 // ******************
 $TSFE->hook_eofe();
 // Hook for end-of-frontend
 // ******************
 $TSFE->hook_eofe();
@@ -547,6 +471,10 @@ $TSFE->hook_eofe();
 // ********************
 $TT->pull();
 
 // ********************
 $TT->pull();
 
+// ******************
+// Check memory usage
+// ******************
+t3lib_utility_Monitor::peakMemoryUsage();
 
 // ******************
 // beLoginLinkIPList
 
 // ******************
 // beLoginLinkIPList
@@ -557,18 +485,23 @@ echo $TSFE->beLoginLinkIPList();
 // *************
 // Admin panel
 // *************
 // *************
 // Admin panel
 // *************
-if (is_object($BE_USER) && $TSFE->beUserLogin && ($BE_USER->frontendEdit instanceof t3lib_frontendedit)) {
-       echo $BE_USER->frontendEdit->displayAdmin();
+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);
+}
+
+if ($sendTSFEContent) {
+       echo $TSFE->content;
 }
 
 // *************
 // Debugging Output
 // *************
 }
 
 // *************
 // Debugging Output
 // *************
-if(@is_callable(array($error,'debugOutput'))) {
+if(isset($error) && is_object($error) && @is_callable(array($error,'debugOutput'))) {
        $error->debugOutput();
 }
 if (TYPO3_DLOG) {
        t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
 }
 
        $error->debugOutput();
 }
 if (TYPO3_DLOG) {
        t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
 }
 
-?>
\ No newline at end of file
+?>