Added feature #15621: Feature: TYPO3 misses page-option to force SSL oder Non-SSL...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_fe.php
index 809cc7f..c1d5eda 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * The use of this class should be inspired by the order of function calls as found in index_ts.php.
  *
  * $Id$
- * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
+ * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
  * XHTML compliant
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 
 /**
 /**
  * Main frontend class, instantiated in the index_ts.php script as the global object TSFE
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage tslib
  */
         * @var t3lib_TStemplate
         */
        var $tmpl='';
-       var $cacheTimeOutDefault='';            // Is set to the time-to-live time of cached pages. If false, default is 60*60*24, which is 24 hours.
+       var $cacheTimeOutDefault = FALSE;               // Is set to the time-to-live time of cached pages. If false, default is 60*60*24, which is 24 hours.
        var $cacheContentFlag = 0;                      // Set internally if cached content is fetched from the database
        var $cacheExpires=0;                            // Set to the expire time of cached content
        var $isClientCachable=FALSE;            // Set if cache headers allowing caching are sent.
                                $GLOBALS['TT']->setTSlogMessage($warning,2);
                        } else {
                                $warning = '&no_cache=1 has been supplied, so caching is disabled! URL: "'.t3lib_div::getIndpEnv('TYPO3_REQUEST_URL').'"';
-                               $this->no_cache = $no_cache ? 1 : 0;
+                               $this->disableCache();
                        }
                        t3lib_div::sysLog($warning, 'cms', 2);
                }
         * May exit after outputting an error message or some JavaScript redirecting to the install tool.
         *
         * @return      void
-        * @deprecated since TYPO3 3.8, this function will be removed in TYPO3 4.5, use connectToDB() instead!
+        * @deprecated since TYPO3 3.8, this function will be removed in TYPO3 4.6, use connectToDB() instead!
         */
        function connectToMySQL()       {
                t3lib_div::logDeprecatedFunction();
         * @return      void
         */
        function connectToDB()  {
-               if ($GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password))    {
+               try {
+                       $link = $GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
+               } catch (RuntimeException $e) {
+                       if (TYPO3_db) {
+                                       // Database is defined, this should normally not happen, user should be informed
+                               throw $e;
+                       }
+                       $link = FALSE;
+               }
+               if ($link !== FALSE) {
                        if (!TYPO3_db)  {
                                $this->printError('No database selected','Database Error');
                                        // Redirects to the Install Tool:
 
                                // If the front-end is showing a preview, caching MUST be disabled.
                        if ($this->fePreview)   {
-                               $this->set_no_cache();
+                               $this->disableCache();
                        }
                }
                $GLOBALS['TT']->pull();
                        $this->pageNotFoundAndExit($pNotFoundMsg[$this->pageNotFound]);
                }
 
+               if ($this->page['url_scheme'] > 0) {
+                       $newUrl = '';
+                       $requestUrlScheme = parse_url(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), PHP_URL_SCHEME);
+                       if ((int) $this->page['url_scheme'] === t3lib_utility_http::SCHEME_HTTP && $requestUrlScheme == 'https') {
+                               $newUrl = 'http://' . substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), 8);
+                       } elseif ((int) $this->page['url_scheme'] === t3lib_utility_http::SCHEME_HTTPS && $requestUrlScheme == 'http') {
+                               $newUrl = 'https://' . substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), 7);
+                       }
+                       if ($newUrl !== '') {
+                               if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+                                       $headerCode = t3lib_utility_Http::HTTP_STATUS_303;
+                               } else {
+                                       $headerCode = t3lib_utility_Http::HTTP_STATUS_301;
+                               }
+                               t3lib_utility_http::redirect($newUrl, $headerCode);
+                       }
+               }
                        // set no_cache if set
                if ($this->page['no_cache'])    {
                        $this->set_no_cache();
         * Get page shortcut; Finds the records pointed to by input value $SC (the shortcut value)
         *
         * @param       integer         The value of the "shortcut" field from the pages record
-        * @param       integer         The shortcut mode: 1 and 2 will select either first subpage or random subpage; the default is the page pointed to by $SC
+        * @param       integer         The shortcut mode: 1 will select first subpage, 2 a random subpage, 3 the parent page; default is the page pointed to by $SC
         * @param       integer         The current page UID of the page which is a shortcut
         * @param       integer         Safety feature which makes sure that the function is calling itself recursively max 20 times (since this function can find shortcuts to other shortcuts to other shortcuts...)
         * @param       array           An array filled with previous page uids tested by the function - new page uids are evaluated against this to avoid going in circles.
                                        $pO = $randval;
                                }
                                $c = 0;
-                               reset($pageArray);
-                               while(list(,$pV)=each($pageArray))      {
+                               foreach ($pageArray as $pV) {
                                        if ($c==$pO)    {
                                                $page = $pV;
                                                break;
                                        $c++;
                                }
                        break;
+                       case 3:
+                               $parent = $this->sys_page->getPage($thisUid);
+                               $page = $this->sys_page->getPage($parent['pid']);
+                       break;
                        default:
                                $page = $this->sys_page->getPage($idArray[0]);
                        break;
 
                // Checks if the $domain-startpage is in the rootLine. This is necessary so that references to page-id's from other domains are not possible.
                if ($domainStartPage && is_array($this->rootLine)) {
-                       reset ($this->rootLine);
                        $idFound = 0;
-                       while(list($key,$val)=each($this->rootLine)) {
+                       foreach ($this->rootLine as $key => $val) {
                                if ($val['uid']==$domainStartPage)      {
                                        $idFound=1;
                                        break;
                                if ($reason == '') {
                                        $reason = 'Page cannot be found.';
                                }
-                               $reason.= chr(10) . chr(10) . 'Additionally, ' . $code . ' was not found while trying to retrieve the error document.';
+                               $reason.= LF . LF . 'Additionally, ' . $code . ' was not found while trying to retrieve the error document.';
                                $this->printError('Reason: '.nl2br(htmlspecialchars($reason)));
                                exit();
                        }
                        $res = t3lib_div::getURL($code, 1, $headerArr);
 
                                // Header and content are separated by an empty line
-                       list($header, $content) = explode("\r\n\r\n", $res, 2);
-                       $content.= "\r\n";
+                       list($header, $content) = explode(CRLF . CRLF, $res, 2);
+                       $content.= CRLF;
 
                        if (false === $res) {
                                        // Last chance -- redirect
                                                $base.= preg_replace('/(.*\/)[^\/]*/', '${1}', $url_parts['path']);
 
                                                        // Put it into content (generate also <head> if necessary)
-                                               $replacement = chr(10) . '<base href="' . htmlentities($base) . '" />' . chr(10);
+                                               $replacement = LF . '<base href="' . htmlentities($base) . '" />' . LF;
                                                if (stristr($content, '<head>'))        {
                                                        $content = preg_replace('/(<head>)/i', '\1' . $replacement, $content);
                                                } else {
                                        if (@is_file(PATH_site.$this->TYPO3_CONF_VARS['FE']['workspacePreviewLogoutTemplate'])) {
                                                $message = t3lib_div::getUrl(PATH_site.$this->TYPO3_CONF_VARS['FE']['workspacePreviewLogoutTemplate']);
                                        } else {
-                                               $message = '<b>ERROR!</b><br>Template File "'.$this->TYPO3_CONF_VARS['FE']['workspacePreviewLogoutTemplate'].'" configured with $TYPO3_CONF_VARS["FE"]["workspacePreviewLogoutTemplate"] not found. Please contact webmaster about this problem.';
+                                               $message = '<strong>ERROR!</strong><br>Template File "'.$this->TYPO3_CONF_VARS['FE']['workspacePreviewLogoutTemplate'].'" configured with $TYPO3_CONF_VARS["FE"]["workspacePreviewLogoutTemplate"] not found. Please contact webmaster about this problem.';
                                        }
                                } else {
                                        $message = 'You logged out from Workspace preview mode. Click this link to <a href="%1$s">go back to the website</a>';
                                }
+
+                               $returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GET('returnUrl'));
                                die(sprintf($message,
-                                       htmlspecialchars(preg_replace('/\&?ADMCMD_prev=[[:alnum:]]+/','',t3lib_div::_GET('returnUrl')))
+                                       htmlspecialchars(preg_replace('/\&?ADMCMD_prev=[[:alnum:]]+/', '', $returnUrl))
                                        ));
                        }
 
                                                        $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
                                                        $timeFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
 
-                                                       $this->content.= chr(10).'<!-- Cached page generated '.date($dateFormat.' '.$timeFormat, $row['tstamp']).'. Expires '.Date($dateFormat.' '.$timeFormat, $row['expires']).' -->';
+                                                       $this->content.= LF.'<!-- Cached page generated '.date($dateFormat.' '.$timeFormat, $row['tstamp']).'. Expires '.Date($dateFormat.' '.$timeFormat, $row['expires']).' -->';
                                                }
                                        }
                                $GLOBALS['TT']->pull();
 
                        // Updating content of the two rootLines IF the language key is set!
                if ($this->sys_language_uid && is_array($this->tmpl->rootLine)) {
-                       reset($this->tmpl->rootLine);
-                       while(list($rLk)=each($this->tmpl->rootLine))   {
+                       foreach ($this->tmpl->rootLine as $rLk => $value) {
                                $this->tmpl->rootLine[$rLk] = $this->sys_page->getPageOverlay($this->tmpl->rootLine[$rLk]);
                        }
                }
                if ($this->sys_language_uid && is_array($this->rootLine))       {
-                       reset($this->rootLine);
-                       while(list($rLk)=each($this->rootLine)) {
+                       foreach ($this->rootLine as $rLk => $value) {
                                $this->rootLine[$rLk] = $this->sys_page->getPageOverlay($this->rootLine[$rLk]);
                        }
                }
 
                        // Setting locale
                if ($this->config['config']['locale_all'])      {
-                       # Change by Rene Fritz, 22/10 2002
+                       # Change by René Fritz, 22/10 2002
                        # there's a problem that PHP parses float values in scripts wrong if the locale LC_NUMERIC is set to something with a comma as decimal point
                        # this does not work in php 4.2.3
                        #setlocale('LC_ALL',$this->config['config']['locale_all']);
                        # so we set all except LC_NUMERIC
                        $locale = setlocale(LC_COLLATE, $this->config['config']['locale_all']);
                        if ($locale) {
-                               setlocale(LC_CTYPE, $this->config['config']['locale_all']);
+
+                                       // PHP fatals with uppercase I characters in method names with turkish locale LC_CTYPE
+                                       // @see http://bugs.php.net/bug.php?id=35050
+                               if (substr($this->config['config']['locale_all'], 0, 2) != 'tr') {
+                                       setlocale(LC_CTYPE, $this->config['config']['locale_all']);
+                               }
+
                                setlocale(LC_MONETARY, $this->config['config']['locale_all']);
                                setlocale(LC_TIME, $this->config['config']['locale_all']);
 
        function jumpUrl()      {
                if ($this->jumpurl)     {
                        if (t3lib_div::_GP('juSecure')) {
+                               $locationData = (string)t3lib_div::_GP('locationData');
+                               $mimeType = (string)t3lib_div::_GP('mimeType');  // Need a type cast here because mimeType is optional!
+
                                $hArr = array(
                                        $this->jumpurl,
-                                       t3lib_div::_GP('locationData'),
-                                       $this->TYPO3_CONF_VARS['SYS']['encryptionKey']
+                                       $locationData,
+                                       $mimeType
                                );
-                               $calcJuHash=t3lib_div::shortMD5(serialize($hArr));
-                               $locationData = t3lib_div::_GP('locationData');
-                               $juHash = t3lib_div::_GP('juHash');
-                               if ($juHash == $calcJuHash)     {
+                               $calcJuHash = t3lib_div::hmac(serialize($hArr));
+                               $juHash = (string)t3lib_div::_GP('juHash');
+                               if ($juHash === $calcJuHash)    {
                                        if ($this->locDataCheck($locationData)) {
                                                $this->jumpurl = rawurldecode($this->jumpurl);  // 211002 - goes with cObj->filelink() rawurlencode() of filenames so spaces can be allowed.
                                                        // Deny access to files that match TYPO3_CONF_VARS[SYS][fileDenyPattern] and whose parent directory is typo3conf/ (there could be a backup file in typo3conf/ which does not match against the fileDenyPattern)
-                                               if (t3lib_div::verifyFilenameAgainstDenyPattern($this->jumpurl) && basename(dirname($this->jumpurl)) !== 'typo3conf') {
-                                                       if (@is_file($this->jumpurl)) {
-                                                               $mimeType = t3lib_div::_GP('mimeType');
+                                               $absoluteFileName = t3lib_div::getFileAbsFileName(t3lib_div::resolveBackPath($this->jumpurl), FALSE);
+                                               if (t3lib_div::isAllowedAbsPath($absoluteFileName) && t3lib_div::verifyFilenameAgainstDenyPattern($absoluteFileName) && !t3lib_div::isFirstPartOfStr($absoluteFileName, PATH_site . 'typo3conf')) {
+                                                       if (@is_file($absoluteFileName)) {
                                                                $mimeType = $mimeType ? $mimeType : 'application/octet-stream';
                                                                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                                                                header('Content-Type: '.$mimeType);
-                                                               header('Content-Disposition: attachment; filename='.basename($this->jumpurl));
-                                                               readfile($this->jumpurl);
+                                                               header('Content-Disposition: attachment; filename="'.basename($absoluteFileName) . '"');
+                                                               readfile($absoluteFileName);
                                                                exit;
                                                        } else die('jumpurl Secure: "'.$this->jumpurl.'" was not a valid file!');
-                                               } else die('jumpurl Secure: The requested file type was not allowed to be accessed through jumpUrl (fileDenyPattern)!');
+                                               } else die('jumpurl Secure: The requested file was not allowed to be accessed through jumpUrl (path or file not allowed)!');
                                        } else die('jumpurl Secure: locationData, '.$locationData.', was not accessible.');
                                } else die('jumpurl Secure: Calculated juHash did not match the submitted juHash.');
                        } else {
                        $padSuffix = '<!--pad-->';      // prevent any trims
                        $padSize = 768 - strlen($padSuffix) - strlen($temp_content);
                        if ($padSize > 0) {
-                               $temp_content = str_pad($temp_content, $padSize, "\n") . $padSuffix;
+                               $temp_content = str_pad($temp_content, $padSize, LF) . $padSuffix;
                        }
 
                        if (!$this->headerNoCache() && $cachedRow = $this->getFromCache_queryRow())     {
 
                $GLOBALS['TT']->push('Substitute header section');
                $this->INTincScript_loadJSCode();
-               $this->content = str_replace('<!--HD_'.$this->config['INTincScript_ext']['divKey'].'-->', $this->convOutputCharset(implode(chr(10),$this->additionalHeaderData),'HD'), $this->content);
+               $this->content = str_replace('<!--HD_'.$this->config['INTincScript_ext']['divKey'].'-->', $this->convOutputCharset(implode(LF,$this->additionalHeaderData),'HD'), $this->content);
                $this->content = str_replace('<!--TDS_'.$this->config['INTincScript_ext']['divKey'].'-->', $this->convOutputCharset($this->divSection,'TDS'), $this->content);
                $this->setAbsRefPrefix();
                $GLOBALS['TT']->pull();
@@ -3285,7 +3321,7 @@ if (version == "n3") {
 <script type="text/javascript">
        /*<![CDATA[*/
 <!--
-'.implode(chr(10),$this->additionalJavaScript).'
+'.implode(LF,$this->additionalJavaScript).'
 '.trim($this->JSCode).'
 // -->
        /*]]>*/
@@ -3296,7 +3332,7 @@ if (version == "n3") {
 <style type="text/css">
        /*<![CDATA[*/
 <!--
-'.implode(chr(10),$this->additionalCSS).'
+'.implode(LF,$this->additionalCSS).'
 // -->
        /*]]>*/
 </style>';
@@ -3327,7 +3363,7 @@ if (version == "n3") {
         * @return      string          Keyword: "all", "cached" or "output"
         */
        function doLocalAnchorFix()     {
-               return $this->config['config']['prefixLocalAnchors'];
+               return (isset($this->config['config']['prefixLocalAnchors'])) ? $this->config['config']['prefixLocalAnchors'] : NULL;
        }
 
 
@@ -3363,7 +3399,9 @@ if (version == "n3") {
                $enableOutput = (!$this->jumpurl);
 
                        // Call hook for possible disabling of output:
-               if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['isOutputting'])) {
+               if (isset($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['isOutputting'])
+                       && is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['isOutputting'])) {
+
                        $_params = array('pObj' => &$this, 'enableOutput' => &$enableOutput);
                        foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['isOutputting'] as $_funcRef)  {
                                t3lib_div::callUserFunction($_funcRef,$_params,$this);
@@ -3380,23 +3418,23 @@ if (version == "n3") {
         *
         * @return      void
         */
-       function processOutput()        {
+       function processOutput() {
 
                        // Set header for charset-encoding unless disabled
-               if (!$this->config['config']['disableCharsetHeader'])   {
+               if (empty($this->config['config']['disableCharsetHeader'])) {
                        $headLine = 'Content-Type: text/html; charset='.trim($this->metaCharset);
                        header($headLine);
                }
 
                        // Set cache related headers to client (used to enable proxy / client caching!)
-               if ($this->config['config']['sendCacheHeaders'])        {
+               if (!empty($this->config['config']['sendCacheHeaders'])) {
                        $this->sendCacheHeaders();
                }
 
                        // Set headers, if any
-               if ($this->config['config']['additionalHeaders'])       {
+               if (!empty($this->config['config']['additionalHeaders'])) {
                        $headerArray = explode('|', $this->config['config']['additionalHeaders']);
-                       while(list(,$headLine)=each($headerArray))      {
+                       foreach ($headerArray as $headLine) {
                                $headLine = trim($headLine);
                                header($headLine);
                        }
@@ -3408,7 +3446,7 @@ if (version == "n3") {
                }
 
                        // Make substitution of eg. username/uid in content only if cache-headers for client/proxy caching is NOT sent!
-               if (!$this->isClientCachable)   {
+               if (!$this->isClientCachable) {
                        $this->contentStrReplace();
                }
 
@@ -3419,30 +3457,30 @@ if (version == "n3") {
                        $GLOBALS['TT']->pull();
                }
                        // XHTML-clean the code, if flag set
-               if ($this->doXHTML_cleaning() == 'output')              {
+               if ($this->doXHTML_cleaning() == 'output') {
                        $GLOBALS['TT']->push('XHTML clean, output','');
                                $XHTML_clean = t3lib_div::makeInstance('t3lib_parsehtml');
                                $this->content = $XHTML_clean->XHTML_clean($this->content);
                        $GLOBALS['TT']->pull();
                }
                        // Fix local anchors in links, if flag set
-               if ($this->doLocalAnchorFix() == 'output')              {
+               if ($this->doLocalAnchorFix() == 'output') {
                        $GLOBALS['TT']->push('Local anchor fix, output','');
                                $this->prefixLocalAnchorsWithScript();
                        $GLOBALS['TT']->pull();
                }
 
                        // Hook for post-processing of page content before output:
-               if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output']))       {
+               if (isset($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output']) && is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output'])) {
                        $_params = array('pObj' => &$this);
-                       foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output'] as $_funcRef)        {
+                       foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output'] as $_funcRef) {
                                t3lib_div::callUserFunction($_funcRef,$_params,$this);
                        }
                }
 
                        // Send content-lenght header.
                        // Notice that all HTML content outside the length of the content-length header will be cut off! Therefore content of unknown length from included PHP-scripts and if admin users are logged in (admin panel might show...) or if debug mode is turned on, we disable it!
-               if ($this->config['config']['enableContentLengthHeader'] &&
+               if (!empty($this->config['config']['enableContentLengthHeader']) &&
                        !$this->isEXTincScript() &&
                        !$this->beUserLogin  &&
                        !$this->TYPO3_CONF_VARS['FE']['debug'] &&
@@ -3466,7 +3504,7 @@ if (version == "n3") {
                $doCache = $this->isStaticCacheble();
 
                        // This variable will be TRUE unless cache headers are configured to be sent ONLY if a branch does not allow logins and logins turns out to be allowed anyway...
-               $loginsDeniedCfg = !$this->config['config']['sendCacheHeaders_onlyWhenLoginDeniedInBranch'] || !$this->loginAllowedInBranch;
+               $loginsDeniedCfg = (empty($this->config['config']['sendCacheHeaders_onlyWhenLoginDeniedInBranch']) || empty($this->loginAllowedInBranch));
 
                        // Finally, when backend users are logged in, do not send cache headers at all (Admin Panel might be displayed for instance).
                if ($doCache
@@ -3549,12 +3587,12 @@ if (version == "n3") {
                if ($this->fe_user->user['uid'])        {
 
                                // User name:
-                       $token = trim($this->config['config']['USERNAME_substToken']);
+                       $token = (isset($this->config['config']['USERNAME_substToken'])) ? trim($this->config['config']['USERNAME_substToken']) : '';
                        $search[] = ($token ? $token : '<!--###USERNAME###-->');
                        $replace[] = $this->fe_user->user['username'];
 
                                // User uid (if configured):
-                       $token = trim($this->config['config']['USERUID_substToken']);
+                       $token = (isset($this->config['config']['USERUID_substToken'])) ? trim($this->config['config']['USERUID_substToken']) : '';
                        if ($token) {
                                $search[] = $token;
                                $replace[] = $this->fe_user->user['uid'];
@@ -3593,7 +3631,7 @@ if (version == "n3") {
         * @see tslib_cObj::PHP_SCRIPT
         */
        function isEXTincScript()       {
-               return is_array($this->config['EXTincScript']);
+               return (isset($this->config['EXTincScript']) && is_array($this->config['EXTincScript']));
        }
 
        /**
@@ -3612,11 +3650,15 @@ if (version == "n3") {
         * @access private
         */
        function setParseTime() {
-                       // Compensates for the time consumed with Back end user initialization.
-               $this->scriptParseTime = $GLOBALS['TT']->getMilliseconds($GLOBALS['TYPO3_MISC']['microtime_end'])
-                                                               - $GLOBALS['TT']->getMilliseconds($GLOBALS['TYPO3_MISC']['microtime_start'])
-                                                               - ($GLOBALS['TT']->getMilliseconds($GLOBALS['TYPO3_MISC']['microtime_BE_USER_end']) - $GLOBALS['TT']->getMilliseconds($GLOBALS['TYPO3_MISC']['microtime_BE_USER_start']));
-       }
+        // Compensates for the time consumed with Back end user initialization.
+        $microtime_start            = (isset($GLOBALS['TYPO3_MISC']['microtime_start'])) ? $GLOBALS['TYPO3_MISC']['microtime_start'] : NULL;
+        $microtime_end              = (isset($GLOBALS['TYPO3_MISC']['microtime_end'])) ? $GLOBALS['TYPO3_MISC']['microtime_end'] : NULL;
+        $microtime_BE_USER_start    = (isset($GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'])) ? $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'] : NULL;
+        $microtime_BE_USER_end      = (isset($GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'])) ? $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'] : NULL;
+
+        $this->scriptParseTime = $GLOBALS['TT']->getMilliseconds($microtime_end) - $GLOBALS['TT']->getMilliseconds($microtime_start)
+                                - ($GLOBALS['TT']->getMilliseconds($microtime_BE_USER_end) - $GLOBALS['TT']->getMilliseconds($microtime_BE_USER_start));
+    }
 
        /**
         * Initialize file-based statistics handling: Check filename and permissions, and create the logfile if it does not exist yet.
@@ -3725,13 +3767,13 @@ if (version == "n3") {
         * @return      void
         */
        function statistics()   {
-               if ($this->config['config']['stat'] &&
+               if (!empty($this->config['config']['stat']) &&
                                (!strcmp('',$this->config['config']['stat_typeNumList']) || t3lib_div::inList(str_replace(' ','',$this->config['config']['stat_typeNumList']), $this->type)) &&
-                               (!$this->config['config']['stat_excludeBEuserHits'] || !$this->beUserLogin) &&
-                               (!$this->config['config']['stat_excludeIPList'] || !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'),str_replace(' ','',$this->config['config']['stat_excludeIPList'])))) {
+                               (empty($this->config['config']['stat_excludeBEuserHits']) || !$this->beUserLogin) &&
+                               (empty($this->config['config']['stat_excludeIPList']) || !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'),str_replace(' ','',$this->config['config']['stat_excludeIPList'])))) {
 
                        $GLOBALS['TT']->push('Stat');
-                               if (t3lib_extMgm::isLoaded('sys_stat') && $this->config['config']['stat_mysql'])        {
+                               if (t3lib_extMgm::isLoaded('sys_stat') && !empty($this->config['config']['stat_mysql'])) {
 
                                                // Jumpurl:
                                        $sword = t3lib_div::_GP('sword');
@@ -3777,7 +3819,7 @@ if (version == "n3") {
                                        );
 
                                                // Hook for preprocessing the list of fields to insert into sys_stat:
-                                       if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['sys_stat-PreProcClass']))    {
+                                       if (isset($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['sys_stat-PreProcClass']) && is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['sys_stat-PreProcClass'])) {
                                                foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['sys_stat-PreProcClass'] as $_classRef)    {
                                                        $_procObj = t3lib_div::getUserObj($_classRef);
                                                        $insertFields = $_procObj->sysstat_preProcessFields($insertFields,$this);
@@ -3791,11 +3833,11 @@ if (version == "n3") {
                                }
 
                                        // Apache:
-                               if ($this->config['config']['stat_apache'] && $this->config['stat_vars']['pageName'])   {
+                               if (!empty($this->config['config']['stat_apache']) && !empty($this->config['stat_vars']['pageName'])) {
                                        if (@is_file($this->config['stat_vars']['logFile'])) {
                                                        // Build a log line (format is derived from the NCSA extended/combined log format)
                                                        // Log part 1: Remote hostname / address
-                                               $LogLine = (t3lib_div::getIndpEnv('REMOTE_HOST') && !$this->config['config']['stat_apache_noHost']) ? t3lib_div::getIndpEnv('REMOTE_HOST') : t3lib_div::getIndpEnv('REMOTE_ADDR');
+                                               $LogLine = (t3lib_div::getIndpEnv('REMOTE_HOST') && empty($this->config['config']['stat_apache_noHost'])) ? t3lib_div::getIndpEnv('REMOTE_HOST') : t3lib_div::getIndpEnv('REMOTE_ADDR');
                                                        // Log part 2: Fake the remote logname
                                                $LogLine.= ' -';
                                                        // Log part 3: Remote username
@@ -3807,14 +3849,14 @@ if (version == "n3") {
                                                        // Log part 6: Status and content length (ignores special content like admin panel!)
                                                $LogLine.= ' 200 '.strlen($this->content);
 
-                                               if (!$this->config['config']['stat_apache_notExtended']) {
+                                               if (empty($this->config['config']['stat_apache_notExtended'])) {
                                                        $referer = t3lib_div::getIndpEnv('HTTP_REFERER');
                                                        $LogLine.= ' "'.($referer ? $referer : '-').'" "'.t3lib_div::getIndpEnv('HTTP_USER_AGENT').'"';
                                                }
 
                                                $GLOBALS['TT']->push('Write to log file (fputs)');
                                                        $logfilehandle = fopen($this->config['stat_vars']['logFile'], 'a');
-                                                       fputs($logfilehandle, $LogLine.chr(10));
+                                                       fputs($logfilehandle, $LogLine.LF);
                                                        @fclose($logfilehandle);
                                                $GLOBALS['TT']->pull();
 
@@ -3864,7 +3906,7 @@ if (version == "n3") {
        function hook_eofe()    {
 
                        // Call hook for end-of-frontend processing:
-               if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_eofe']))    {
+               if (isset($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_eofe']) && is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_eofe'])) {
                        $_params = array('pObj' => &$this);
                        foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_eofe'] as $_funcRef)     {
                                t3lib_div::callUserFunction($_funcRef,$_params,$this);
@@ -3878,7 +3920,7 @@ if (version == "n3") {
         * @return      string          HTML, a tag for a link to the backend.
         */
        function beLoginLinkIPList()    {
-               if ($this->config['config']['beLoginLinkIPList']) {
+               if (!empty($this->config['config']['beLoginLinkIPList'])) {
                        if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $this->config['config']['beLoginLinkIPList']))       {
                                $label = !$this->beUserLogin ? $this->config['config']['beLoginLinkIPList_login'] : $this->config['config']['beLoginLinkIPList_logout'];
                                if ($label)     {
@@ -3943,10 +3985,12 @@ if (version == "n3") {
         * @param       boolean         The "no_cache" status of the link.
         * @return      string          The body of the filename.
         * @see getSimulFileName(), t3lib_tstemplate::linkData(), tslib_frameset::frameParams()
-        * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.5, please use the "simulatestatic" sysext directly
+        * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.6, please use the "simulatestatic" sysext directly
         * @todo        Deprecated but still used in the Core!
         */
        function makeSimulFileName($inTitle, $page, $type, $addParams = '', $no_cache = false) {
+               t3lib_div::logDeprecatedFunction();
+
                if (t3lib_extMgm::isLoaded('simulatestatic')) {
                        $parameters = array(
                                'inTitle' => $inTitle,
@@ -3971,7 +4015,7 @@ if (version == "n3") {
         * @param       string          Query string to analyse
         * @return      array           Two num keys returned, first is the parameters that MAY be encoded, second is the non-encodable parameters.
         * @see makeSimulFileName(), t3lib_tstemplate::linkData()
-        * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.5, please use the "simulatestatic" sysext directly
+        * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.6, please use the "simulatestatic" sysext directly
         */
        function simulateStaticDocuments_pEnc_onlyP_proc($linkVars)     {
                t3lib_div::logDeprecatedFunction();
@@ -3992,10 +4036,12 @@ if (version == "n3") {
         *
         * @return      string          The filename (without path)
         * @see makeSimulFileName(), publish.php
-        * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.5, please use the "simulatestatic" sysext directly
+        * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.6, please use the "simulatestatic" sysext directly
         * @todo        Deprecated but still used in the Core!
         */
        function getSimulFileName()     {
+               t3lib_div::logDeprecatedFunction();
+
                return $this->makeSimulFileName(
                        $this->page['title'],
                        ($this->page['alias'] ? $this->page['alias'] : $this->id),
@@ -4007,7 +4053,7 @@ if (version == "n3") {
         * Checks and sets replacement character for simulateStaticDocuments. Default is underscore.
         *
         * @return      void
-        * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.5, please use the "simulatestatic" sysext directly
+        * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.6, please use the "simulatestatic" sysext directly
         */
        function setSimulReplacementChar() {
                t3lib_div::logDeprecatedFunction();
@@ -4030,10 +4076,11 @@ if (version == "n3") {
         * @param       integer         Number of characters in the string
         * @param       string          Character to put in the end of string to merge it with the next value.
         * @return      string          String
-        * @deprecated since TYPO3, 4.3, will be removed in TYPO3 4.5, please use the "simulatestatic" sysext directly
+        * @deprecated since TYPO3, 4.3, will be removed in TYPO3 4.6, please use the "simulatestatic" sysext directly
         * @todo        Deprecated but still used in the Core!
         */
        function fileNameASCIIPrefix($inTitle,$titleChars,$mergeChar='.')       {
+               t3lib_div::logDeprecatedFunction();
                $out = $this->csConvObj->specCharsToASCII($this->renderCharset, $inTitle);
                        // Get replacement character
                $replacementChar = $this->config['config']['simulateStaticDocuments_replacementChar'];
@@ -4200,6 +4247,7 @@ if (version == "n3") {
                        $this->content = str_replace('"' . TYPO3_mainDir . 'ext/', '"' . $this->absRefPrefix . TYPO3_mainDir . 'ext/', $this->content);
                        $this->content = str_replace('"' . TYPO3_mainDir . 'sysext/' , '"' . $this->absRefPrefix . TYPO3_mainDir . 'sysext/', $this->content);
                        $this->content = str_replace('"'.$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '"'.$this->absRefPrefix.$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], $this->content);
+                       $this->content = str_replace('"' . $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'], '"' . $this->absRefPrefix . $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'], $this->content);
                        // Process additional directories
                        $directories = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['additionalAbsRefPrefixDirectories'], true);
                        foreach ($directories as $directory) {
@@ -4240,15 +4288,19 @@ if (version == "n3") {
 
        /**
         * Logs access to deprecated TypoScript objects and properties.
+        *
         * Dumps message to the TypoScript message log (admin panel) and the TYPO3 deprecation log.
+        * Note: The second parameter was introduced in TYPO3 4.5 and is not available in older versions
         *
-        * @param       string          Message string
+        * @param       string          Deprecated object or property
+        * @param       string          Message or additional information
         * @return      void
         * @see t3lib_div::deprecationLog(), t3lib_timeTrack::setTSlogMessage()
         */
-       function logDeprecatedTyposcript($msg) {
-               $GLOBALS['TT']->setTSlogMessage($msg . ' is deprecated.', 2);
-               t3lib_div::deprecationLog('TypoScript ' . $msg);
+       function logDeprecatedTyposcript($typoScriptProperty, $explanation = '') {
+               $explanationText = (strlen($explanation) ? ' - ' . $explanation : '');
+               $GLOBALS['TT']->setTSlogMessage($typoScriptProperty . ' is deprecated.' . $explanationText, 2);
+               t3lib_div::deprecationLog('TypoScript ' . $typoScriptProperty . ' is deprecated' . $explanationText);
        }
 
        /**
@@ -4283,7 +4335,7 @@ if (version == "n3") {
 
                        exec ($this->TYPO3_CONF_VARS['FE']['tidy_path'].' '.$fname, $output);                   // run the $content through 'tidy', which formats the HTML to nice code.
                        @unlink ($fname);       // Delete the tempfile again
-                       $content = implode(chr(10),$output);
+                       $content = implode(LF,$output);
                        if (!trim($content))    {
                                $content = $oldContent; // Restore old content due empty return value.
                                $GLOBALS['TT']->setTSlogMessage('"tidy" returned an empty value!',2);
@@ -4430,8 +4482,7 @@ if (version == "n3") {
                        return array();
                }
 
-               reset($this->rootLine);
-               while(list(,$rC)=each($this->rootLine)) {
+               foreach ($this->rootLine as $rC) {
                        if (!$res['_STORAGE_PID'])      $res['_STORAGE_PID']=intval($rC['storage_pid']);
                        if (!$res['_SITEROOT']) $res['_SITEROOT']=$rC['is_siteroot']?intval($rC['uid']):0;
                }
@@ -4445,15 +4496,14 @@ if (version == "n3") {
         */
        function getPagesTSconfig()     {
                if (!is_array($this->pagesTSconfig))    {
-                       reset($this->rootLine);
                        $TSdataArray = array();
                        $TSdataArray[] = $this->TYPO3_CONF_VARS['BE']['defaultPageTSconfig'];   // Setting default configuration:
-                       while(list($k,$v)=each($this->rootLine))        {
+                       foreach ($this->rootLine as $k => $v) {
                                $TSdataArray[]=$v['TSconfig'];
                        }
                                // Parsing the user TS (or getting from cache)
                        $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
-                       $userTS = implode(chr(10).'[GLOBAL]'.chr(10),$TSdataArray);
+                       $userTS = implode(LF.'[GLOBAL]'.LF,$TSdataArray);
                        $hash = md5('pageTS:'.$userTS);
                        $cachedContent = $this->sys_page->getHash($hash);
                        if (isset($cachedContent))      {
@@ -4530,7 +4580,7 @@ if (version == "n3") {
         * Seeds the random number engine.
         *
         * @return      void
-        * @deprecated since TYPO3 4.3, this function will be removed in TYPO3 4.5, the random number generator is seeded automatically since PHP 4.2.0
+        * @deprecated since TYPO3 4.3, this function will be removed in TYPO3 4.6, the random number generator is seeded automatically since PHP 4.2.0
         */
        function make_seed() {
                t3lib_div::logDeprecatedFunction();
@@ -4582,13 +4632,23 @@ if (version == "n3") {
                        $GLOBALS['TT']->setTSlogMessage($warning,2);
                } else {
                        $warning.= ' Caching is disabled!';
-                       $this->no_cache = 1;
+                       $this->disableCache();
                }
 
                t3lib_div::sysLog($warning, 'cms', 2);
        }
 
        /**
+        * Disables caching of the current page.
+        *
+        * @return void
+        * @internal
+        */
+       protected function disableCache() {
+               $this->no_cache = 1;
+       }
+
+       /**
         * Sets the cache-timeout in seconds
         *
         * @param       integer         cache-timeout in seconds
@@ -4606,7 +4666,7 @@ if (version == "n3") {
        function get_cache_timeout() {
                        // Cache period was set for the page:
                if ($this->page['cache_timeout']) {
-                       $cacheTimeout = $this->page['cache_timeout'];
+                       $cacheTimeout = intval($this->page['cache_timeout']);
                        // Cache period was set for the whole site:
                } elseif ($this->cacheTimeOutDefault) {
                        $cacheTimeout = $this->cacheTimeOutDefault;
@@ -4753,7 +4813,7 @@ if (version == "n3") {
                $this->getPageRenderer()->setLanguage($this->lang);
 
                $ls = explode('|',TYPO3_languages);
-               while(list($i,$v)=each($ls))    {
+               foreach ($ls as $i => $v) {
                        if ($v==$this->lang)    {$this->langSplitIndex=$i; break;}
                }