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 9d856f5..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>
  */
 
 /**
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
-
-require_once (PATH_t3lib.'class.t3lib_lock.php');
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 /**
  * 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
  */
- class tslib_fe        {
+ class tslib_fe {
 
                // CURRENT PAGE:
        var $id='';                                                     // The page id (int)
@@ -253,6 +231,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
        var $beUserLogin='';                            // Flag that indicates if a Backend user is logged in!
        var $workspacePreview='';                       // Integer, that indicates which workspace is being previewed.
        var $loginAllowedInBranch = TRUE;       // Shows whether logins are allowed in branch
+       var $loginAllowedInBranch_mode = '';    // Shows specific mode (all or groups)
        var $ADMCMD_preview_BEUSER_uid = 0;     // Integer, set to backend user ID to initialize when keyword-based preview is used.
 
                // PREVIEW
@@ -274,7 +253,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * @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.
@@ -419,6 +398,11 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
        var $pages_lockObj;                                     // Locking object for accessing "cache_pages"
 
        /**
+        * @var t3lib_PageRenderer
+        */
+       protected $pageRenderer;
+
+       /**
         * the page cache object, use this to save pages to the cache and to
         * retrieve them again
         *
@@ -457,7 +441,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                $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);
                }
@@ -478,7 +462,9 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        }
                }
 
-               $this->initCaches();
+               if (TYPO3_UseCachingFramework) {
+                       $this->initCaches();
+               }
        }
 
        /**
@@ -486,9 +472,11 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * May exit after outputting an error message or some JavaScript redirecting to the install tool.
         *
         * @return      void
-        * @deprecated since TYPO3 3.8 - 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();
+
                $this->connectToDB();
        }
 
@@ -499,7 +487,16 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * @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:
@@ -567,7 +564,19 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                }
        }
 
-
+       /**
+        * Gets instance of PageRenderer
+        *
+        * @return      t3lib_PageRenderer
+        */
+       public function getPageRenderer() {
+               if (!isset($this->pageRenderer)) {
+                       $this->pageRenderer = t3lib_div::makeInstance('t3lib_PageRenderer');
+                       $this->pageRenderer->setTemplateFile(PATH_tslib . 'templates/tslib_page_frontend.html');
+                       $this->pageRenderer->setBackPath(TYPO3_mainDir);
+               }
+               return $this->pageRenderer;
+       }
 
 
 
@@ -596,28 +605,30 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * @return      void
         */
        protected function initCaches() {
-               $GLOBALS['TT']->push('Initializing the Caching System','');
+               if (TYPO3_UseCachingFramework) {
+                       $GLOBALS['TT']->push('Initializing the Caching System','');
 
-               $GLOBALS['typo3CacheManager'] = t3lib_div::makeInstance('t3lib_cache_Manager');
-               $GLOBALS['typo3CacheFactory'] = t3lib_div::makeInstance('t3lib_cache_Factory');
-               $GLOBALS['typo3CacheFactory']->setCacheManager($GLOBALS['typo3CacheManager']);
+                       $GLOBALS['typo3CacheManager'] = t3lib_div::makeInstance('t3lib_cache_Manager');
+                       $GLOBALS['typo3CacheFactory'] = t3lib_div::makeInstance('t3lib_cache_Factory');
+                       $GLOBALS['typo3CacheFactory']->setCacheManager($GLOBALS['typo3CacheManager']);
 
-               try {
-                       $this->pageCache = $GLOBALS['typo3CacheManager']->getCache(
-                               'cache_pages'
-                       );
-               } catch(t3lib_cache_exception_NoSuchCache $e) {
-                       t3lib_cache::initPageCache();
+                       try {
+                               $this->pageCache = $GLOBALS['typo3CacheManager']->getCache(
+                                       'cache_pages'
+                               );
+                       } catch(t3lib_cache_exception_NoSuchCache $e) {
+                               t3lib_cache::initPageCache();
 
-                       $this->pageCache = $GLOBALS['typo3CacheManager']->getCache(
-                               'cache_pages'
-                       );
-               }
+                               $this->pageCache = $GLOBALS['typo3CacheManager']->getCache(
+                                       'cache_pages'
+                               );
+                       }
 
-               t3lib_cache::initPageSectionCache();
-               t3lib_cache::initContentHashCache();
+                       t3lib_cache::initPageSectionCache();
+                       t3lib_cache::initContentHashCache();
 
-               $GLOBALS['TT']->pull();
+                       $GLOBALS['TT']->pull();
+               }
        }
 
        /**
@@ -698,7 +709,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        // Clean up.
                $gr_array = array_unique($gr_array);    // Make unique...
                sort($gr_array);        // sort
-               if (count($gr_array))   {
+               if (count($gr_array) && !$this->loginAllowedInBranch_mode)      {
                        $this->gr_list.=','.implode(',',$gr_array);
                }
 
@@ -828,7 +839,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
 
                                // If the front-end is showing a preview, caching MUST be disabled.
                        if ($this->fePreview)   {
-                               $this->set_no_cache();
+                               $this->disableCache();
                        }
                }
                $GLOBALS['TT']->pull();
@@ -853,10 +864,13 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                $this->loginAllowedInBranch = $this->checkIfLoginAllowedInBranch();
                if (!$this->loginAllowedInBranch)       {       // Logins are not allowed:
                        if ($this->isUserOrGroupSet())  {       // Only if there is a login will we run this...
-
-                                       // Clear out user and group:
-                               unset($this->fe_user->user);
-                               $this->gr_list = '0,-1';
+                               if ($this->loginAllowedInBranch_mode=='all')    {
+                                               // Clear out user and group:
+                                       unset($this->fe_user->user);
+                                       $this->gr_list = '0,-1';
+                               } else {
+                                       $this->gr_list = '0,-2';
+                               }
 
                                        // Fetching the id again, now with the preview settings reset.
                                $this->fetch_the_id();
@@ -968,6 +982,23 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        $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();
@@ -1104,7 +1135,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * 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.
@@ -1122,13 +1153,11 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                $pageArray = $this->sys_page->getMenu($idArray[0]?$idArray[0]:$thisUid,'*','sorting','AND pages.doktype<199 AND pages.doktype!=6');
                                $pO = 0;
                                if ($mode==2 && count($pageArray))      {       // random
-                                       $this->make_seed();
                                        $randval = intval(rand(0,count($pageArray)-1));
                                        $pO = $randval;
                                }
                                $c = 0;
-                               reset($pageArray);
-                               while(list(,$pV)=each($pageArray))      {
+                               foreach ($pageArray as $pV) {
                                        if ($c==$pO)    {
                                                $page = $pV;
                                                break;
@@ -1136,6 +1165,10 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                        $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;
@@ -1259,7 +1292,15 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        if ($this->rootLine[$a]['fe_login_mode'] > 0)   {
 
                                        // Determine state from value:
-                               $disable = (int)$this->rootLine[$a]['fe_login_mode'] === 1 ? TRUE : FALSE;
+                               if ((int)$this->rootLine[$a]['fe_login_mode'] === 1)    {
+                                       $disable = TRUE;
+                                       $this->loginAllowedInBranch_mode = 'all';
+                               } elseif ((int)$this->rootLine[$a]['fe_login_mode'] === 3)      {
+                                       $disable = TRUE;
+                                       $this->loginAllowedInBranch_mode = 'groups';
+                               } else {
+                                       $disable = FALSE;
+                               }
                        }
                }
 
@@ -1324,9 +1365,8 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
 
                // 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;
@@ -1479,8 +1519,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                $this->printError('Configuration Error: 404 page "'.$readFile.'" could not be found.');
                        }
                } elseif (t3lib_div::isFirstPartOfStr($code,'REDIRECT:')) {
-                       header('Location: '.t3lib_div::locationHeaderUrl(substr($code,9)));
-                       exit;
+                       t3lib_utility_Http::redirect(substr($code, 9));
                } elseif (strlen($code))        {
                                // Check if URL is relative
                        $url_parts = parse_url($code);
@@ -1497,7 +1536,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                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();
                        }
@@ -1510,12 +1549,12 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        $res = t3lib_div::getURL($code, 1, $headerArr);
 
                                // Header and content are separated by an empty line
-                       list($header, $content) = preg_split("/[\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
-                               header('Location: '.t3lib_div::locationHeaderUrl($code));
+                               t3lib_utility_Http::redirect($code);
                        } else {
 
                                $forwardHeaders = array(        // Forward these response headers to the client
@@ -1550,7 +1589,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                                $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 {
@@ -1592,6 +1631,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * @return      void
         * @access private
         * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.5, please use the "simulatestatic" sysext directly
+        * @todo        Deprecated but still used in the Core!
         */
        function idPartsAnalyze($str)   {
                $GET_VARS = '';
@@ -1665,13 +1705,15 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                        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))
                                        ));
                        }
 
@@ -1680,7 +1722,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                '*',
                                'sys_preview',
                                'keyword='.$GLOBALS['TYPO3_DB']->fullQuoteStr($inputCode, 'sys_preview').
-                                       ' AND endtime>'.time()
+                                       ' AND endtime>' . $GLOBALS['EXEC_TIME']
                        );
 
                                // Get: Backend login status, Frontend login status
@@ -1756,10 +1798,15 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * @see reqCHash()
         */
        function makeCacheHash()        {
+               // No need to test anything if caching was already disabled.
+               if ($this->no_cache && !$this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
+                       return;
+               }
+
                $GET = t3lib_div::_GET();
                if ($this->cHash && is_array($GET))     {
                        $this->cHash_array = t3lib_div::cHashParams(t3lib_div::implodeArrayForUrl('',$GET));
-                       $cHash_calc = t3lib_div::shortMD5(serialize($this->cHash_array));
+                       $cHash_calc = t3lib_div::calculateCHash($this->cHash_array);
 
                        if ($cHash_calc!=$this->cHash)  {
                                if ($this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
@@ -1880,8 +1927,16 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                                        // Release this lock
                                                $this->releasePageGenerationLock($this->pages_lockObj);
 
+                                                       // Call hook when a page is retrieved from cache:
+                                               if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageLoadedFromCache']))  {
+                                                       $_params = array('pObj' => &$this, 'cache_pages_row' => &$row);
+                                                       foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageLoadedFromCache'] as $_funcRef)   {
+                                                               t3lib_div::callUserFunction($_funcRef,$_params,$this);
+                                                       }
+                                               }
+
                                                $this->config = (array)unserialize($row['cache_data']);         // Fetches the lowlevel config stored with the cached data
-                                               $this->content = $row['HTML'];  // Getting the content
+                                               $this->content = (TYPO3_UseCachingFramework ? $row['content'] : $row['HTML']);  // Getting the content
                                                $this->tempContent = $row['temp_content'];      // Flag for temp content
                                                $this->cacheContentFlag = 1;    // Setting flag, so we know, that some cached content has been loaded
                                                $this->cacheExpires = $row['expires'];
@@ -1890,7 +1945,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                                        $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();
@@ -1907,11 +1962,31 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * @return      array           Cached row, if any. Otherwise void.
         */
        function getFromCache_queryRow() {
-               $GLOBALS['TT']->push('Cache Query', '');
-               $cachedPage = $this->pageCache->get($this->newHash);
-               $GLOBALS['TT']->pull();
+               if (TYPO3_UseCachingFramework) {
+                       $GLOBALS['TT']->push('Cache Query', '');
+                       $row = $this->pageCache->get($this->newHash);
+                       $GLOBALS['TT']->pull();
+               } else {
+                       $GLOBALS['TT']->push('Cache Query','');
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                               'S.*',
+                               'cache_pages S,pages P',
+                               'S.hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->newHash, 'cache_pages').'
+                                       AND S.page_id=P.uid
+                                       AND S.expires > '.intval($GLOBALS['ACCESS_TIME']).'
+                                       AND P.deleted=0
+                                       AND P.hidden=0
+                                       AND P.starttime<='.intval($GLOBALS['ACCESS_TIME']).'
+                                       AND (P.endtime=0 OR P.endtime>'.intval($GLOBALS['ACCESS_TIME']).')'
+                       );
+                       $GLOBALS['TT']->pull();
 
-               return $cachedPage;
+                       if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                               $this->pageCachePostProcess($row,'get');
+                       }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+               }
+               return $row;
        }
 
        /**
@@ -1958,7 +2033,8 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                'type' => intval($this->type),
                                'gr_list' => (string)$this->gr_list,
                                'MP' => (string)$this->MP,
-                               'cHash' => $this->cHash_array
+                               'cHash' => $this->cHash_array,
+                               'domainStartPage' => $this->domainStartPage,
                        )
                );
 
@@ -1980,7 +2056,8 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                'type' => intval($this->type),
                                'gr_list' => (string)$this->gr_list,
                                'MP' => (string)$this->MP,
-                               'cHash' => $this->cHash_array
+                               'cHash' => $this->cHash_array,
+                               'domainStartPage' => $this->domainStartPage,
                        )
                );
 
@@ -2059,6 +2136,16 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
 
                                        $this->config['FEData'] = $this->tmpl->setup['FEData'];
                                        $this->config['FEData.'] = $this->tmpl->setup['FEData.'];
+
+                                               // class for render Header and Footer parts
+                                       $template = '';
+                                       if ($this->pSetup['pageHeaderFooterTemplateFile']) {
+                                               $file = $this->tmpl->getFileName($this->pSetup['pageHeaderFooterTemplateFile']);
+                                               if ($file) {
+                                                       $this->setTemplateFile($file);
+                                               }
+                                       }
+
                                }
                                $GLOBALS['TT']->pull();
                        } else {
@@ -2085,6 +2172,15 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        // No cache
                if ($this->config['config']['no_cache'])        { $this->set_no_cache(); }              // Set $this->no_cache true if the config.no_cache value is set!
 
+                       // merge GET with defaultGetVars
+               if (!empty($this->config['config']['defaultGetVars.'])) {
+                       $modifiedGetVars = t3lib_div::array_merge_recursive_overrule(
+                               t3lib_div::removeDotsFromTS($this->config['config']['defaultGetVars.']),
+                               t3lib_div::_GET()
+                       );
+
+                       t3lib_div::_GETset($modifiedGetVars);
+               }
 
                        // Hook for postProcessing the configuration array
                if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc'])) {
@@ -2212,6 +2308,13 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         */
        function settingLanguage()      {
 
+               if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_preProcess']))   {
+                       $_params = array();
+                       foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_preProcess'] as $_funcRef)   {
+                               t3lib_div::callUserFunction($_funcRef, $_params, $this);
+                       }
+               }
+
                        // Get values from TypoScript:
                $this->sys_language_uid = $this->sys_language_content = intval($this->config['config']['sys_language_uid']);
                list($this->sys_language_mode,$sys_language_content) = t3lib_div::trimExplode(';', $this->config['config']['sys_language_mode']);
@@ -2277,14 +2380,12 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
 
                        // 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]);
                        }
                }
@@ -2311,6 +2412,13 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        list($tN,$fN) = explode(':',$TF);
                        $this->TCAcachedExtras[$tN]['l10n_mode'][$fN] = 'exclude';
                }
+
+               if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_postProcess']))  {
+                       $_params = array();
+                       foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_postProcess'] as $_funcRef)  {
+                               t3lib_div::callUserFunction($_funcRef, $_params, $this);
+                       }
+               }
        }
 
        /**
@@ -2322,7 +2430,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
 
                        // 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']);
@@ -2331,7 +2439,13 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        # 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']);
 
@@ -2403,7 +2517,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        // Hook for processing data submission to extensions:
                if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkDataSubmission']))  {
                        foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkDataSubmission'] as $_classRef)  {
-                               $_procObj = &t3lib_div::getUserObj($_classRef);
+                               $_procObj = t3lib_div::getUserObj($_classRef);
                                $_procObj->checkDataSubmission($this);
                        }
                }
@@ -2482,7 +2596,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        // Hook for preprocessing of the content for formmails:
                if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['sendFormmail-PreProcClass']))    {
                        foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['sendFormmail-PreProcClass'] as $_classRef)    {
-                               $_procObj = &t3lib_div::getUserObj($_classRef);
+                               $_procObj = t3lib_div::getUserObj($_classRef);
                                $EMAIL_VARS = $_procObj->sendFormmail_preProcessVariables($EMAIL_VARS,$this);
                        }
                }
@@ -2544,26 +2658,31 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
        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.
-                                               if (@is_file($this->jumpurl))   {
-                                                       $mimeType = t3lib_div::_GP('mimeType');
-                                                       $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);
-                                                       exit;
-                                               } else die('jumpurl Secure: "'.$this->jumpurl.'" was not a valid file!');
+                                                       // 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)
+                                               $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($absoluteFileName) . '"');
+                                                               readfile($absoluteFileName);
+                                                               exit;
+                                                       } else die('jumpurl Secure: "'.$this->jumpurl.'" was not a valid file!');
+                                               } 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 {
@@ -2576,23 +2695,21 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                                if ($TSConf['TSFE.']['jumpURL_HTTPStatusCode']) {
                                        switch (intval($TSConf['TSFE.']['jumpURL_HTTPStatusCode'])){
                                                case 301:
-                                                       header(t3lib_div::HTTP_STATUS_301);
+                                                       $statusCode = t3lib_utility_Http::HTTP_STATUS_301;
                                                        break;
                                                case 302:
-                                                       header(t3lib_div::HTTP_STATUS_302);
-                                                       break;
-                                               case 303:
-                                                       header(t3lib_div::HTTP_STATUS_303);
+                                                       $statusCode = t3lib_utility_Http::HTTP_STATUS_302;
                                                        break;
                                                case 307:
-                                                       header(t3lib_div::HTTP_STATUS_307);
+                                                       $statusCode = t3lib_utility_Http::HTTP_STATUS_307;
                                                        break;
+                                               case 303:
                                                default:
+                                                       $statusCode = t3lib_utility_Http::HTTP_STATUS_303;
                                                        break;
                                        }
                                }
-                               header('Location: '.$this->jumpurl);
-                               exit;
+                               t3lib_utility_Http::redirect($this->jumpurl, $statusCode);
                        }
                }
        }
@@ -2692,7 +2809,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        $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())     {
@@ -2728,7 +2845,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        // Hook for cache post processing (eg. writing static files!)
                if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['insertPageIncache']))    {
                        foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['insertPageIncache'] as $_classRef)    {
-                               $_procObj = &t3lib_div::getUserObj($_classRef);
+                               $_procObj = t3lib_div::getUserObj($_classRef);
                                $_procObj->insertPageIncache($this,$timeOutTime);
                        }
                }
@@ -2744,35 +2861,55 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * @see realPageCacheContent(), tempPageCacheContent()
         */
        function setPageCacheContent($content, $data, $expirationTstamp) {
-               $this->clearPageCacheContent();
-
-               $cacheData = array(
-                       'hash'         => $this->newHash,
-                       'page_id'      => $this->id,
-                       'HTML'         => $content,
-                       'temp_content' => $this->tempContent,
-                       'cache_data'   => serialize($data),
-                       'expires'      => $expirationTstamp,
-                       'tstamp'       => $GLOBALS['EXEC_TIME']
-               );
 
-               $this->cacheExpires = $expirationTstamp;
+               if (TYPO3_UseCachingFramework) {
+                       $cacheData = array(
+                               'identifier'    => $this->newHash,
+                               'page_id'               => $this->id,
+                               'content'                       => $content,
+                               'temp_content'  => $this->tempContent,
+                               'cache_data'    => serialize($data),
+                               'expires'               => $expirationTstamp,
+                               'tstamp'                => $GLOBALS['EXEC_TIME']
+                       );
+
+                       $this->cacheExpires = $expirationTstamp;
 
-               $this->pageCacheTags[] = 'pageId_' . $cacheData['page_id'];
+                       $this->pageCacheTags[] = 'pageId_' . $cacheData['page_id'];
 
-               if ($this->page_cache_reg1) {
-                       $reg1 = intval($this->page_cache_reg1);
+                       if ($this->page_cache_reg1) {
+                               $reg1 = intval($this->page_cache_reg1);
 
-                       $cacheData['reg1']     = $reg1;
-                       $this->pageCacheTags[] = 'reg1_' . $reg1;
-               }
+                               $cacheData['reg1']     = $reg1;
+                               $this->pageCacheTags[] = 'reg1_' . $reg1;
+                       }
 
-               $this->pageCache->set(
-                       $cacheData['hash'],
-                       $cacheData,
-                       $this->pageCacheTags,
-                       $cacheData['expires'] - $GLOBALS['EXEC_TIME']
-               );
+                       $this->pageCache->set(
+                               $this->newHash,
+                               $cacheData,
+                               $this->pageCacheTags,
+                               $expirationTstamp - $GLOBALS['EXEC_TIME']
+                       );
+               } else {
+                       $this->clearPageCacheContent();
+                       $insertFields = array(
+                               'hash' => $this->newHash,
+                               'page_id' => $this->id,
+                               'HTML' => $content,
+                               'temp_content' => $this->tempContent,
+                               'cache_data' => serialize($data),
+                               'expires' => $expirationTstamp,
+                               'tstamp' => $GLOBALS['EXEC_TIME']
+                       );
+
+                       $this->cacheExpires = $expirationTstamp;
+
+                       if ($this->page_cache_reg1)     {
+                               $insertFields['reg1'] = intval($this->page_cache_reg1);
+                       }
+                       $this->pageCachePostProcess($insertFields,'set');
+                       $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pages', $insertFields);
+               }
        }
 
        /**
@@ -2781,7 +2918,34 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * @return      void
         */
        function clearPageCacheContent() {
-               $this->pageCache->remove($this->newHash);
+               if (TYPO3_UseCachingFramework) {
+                       $this->pageCache->remove($this->newHash);
+               } else {
+                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->newHash, 'cache_pages'));
+               }
+       }
+
+       /**
+        * Post processing page cache rows for both get and set.
+        *
+        * @param       array           Input "cache_pages" row, passed by reference!
+        * @param       string          Type of operation, either "get" or "set"
+        * @return      void
+        */
+       function pageCachePostProcess(&$row,$type)      {
+
+               if ($this->TYPO3_CONF_VARS['FE']['pageCacheToExternalFiles'])   {
+                       $cacheFileName = PATH_site.'typo3temp/cache_pages/'.$row['hash']{0}.$row['hash']{1}.'/'.$row['hash'].'.html';
+                       switch((string)$type)   {
+                               case 'get':
+                                       $row['HTML'] = @is_file($cacheFileName) ? t3lib_div::getUrl($cacheFileName) : '<!-- CACHING ERROR, sorry -->';
+                               break;
+                               case 'set':
+                                       t3lib_div::writeFileToTypo3tempDir($cacheFileName, $row['HTML']);
+                                       $row['HTML'] = '';
+                               break;
+                       }
+               }
        }
 
        /**
@@ -2791,10 +2955,13 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
         * @return      void
         */
        function clearPageCacheContent_pidList($pidList) {
-               $pageIds = t3lib_div::trimExplode(',', $pidList);
-
-               foreach ($pageIds as $pageId) {
-                       $this->pageCache->flushByTag('pageId_' . (int) $pageId);
+               if (TYPO3_UseCachingFramework) {
+                       $pageIds = t3lib_div::trimExplode(',', $pidList);
+                       foreach ($pageIds as $pageId) {
+                               $this->pageCache->flushByTag('pageId_' . (int) $pageId);
+                       }
+               } else {
+                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'page_id IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($pidList).')');
                }
        }
 
@@ -3015,7 +3182,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
                        // Hook for indexing pages
                if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageIndexing'])) {
                        foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageIndexing'] as $_classRef) {
-                               $_procObj = &t3lib_div::getUserObj($_classRef);
+                               $_procObj = t3lib_div::getUserObj($_classRef);
                                $_procObj->hook_indexContent($this);
                        }
                }
@@ -3061,7 +3228,7 @@ require_once (PATH_t3lib.'class.t3lib_lock.php');
 
                $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();
@@ -3154,7 +3321,7 @@ if (version == "n3") {
 <script type="text/javascript">
        /*<![CDATA[*/
 <!--
-'.implode(chr(10),$this->additionalJavaScript).'
+'.implode(LF,$this->additionalJavaScript).'
 '.trim($this->JSCode).'
 // -->
        /*]]>*/
@@ -3165,7 +3332,7 @@ if (version == "n3") {
 <style type="text/css">
        /*<![CDATA[*/
 <!--
-'.implode(chr(10),$this->additionalCSS).'
+'.implode(LF,$this->additionalCSS).'
 // -->
        /*]]>*/
 </style>';
@@ -3196,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;
        }
 
 
@@ -3232,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);
@@ -3249,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);
                        }
@@ -3277,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();
                }
 
@@ -3288,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'] &&
@@ -3335,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
@@ -3418,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'];
@@ -3462,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']));
        }
 
        /**
@@ -3481,11 +3650,15 @@ if (version == "n3") {
         * @access private
         */
        function setParseTime() {
-                       // Compensates for the time consumed with Back end user initialization.
-               $this->scriptParseTime = $GLOBALS['TT']->convertMicrotime($GLOBALS['TYPO3_MISC']['microtime_end'])
-                                                               - $GLOBALS['TT']->convertMicrotime($GLOBALS['TYPO3_MISC']['microtime_start'])
-                                                               - ($GLOBALS['TT']->convertMicrotime($GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'])-$GLOBALS['TT']->convertMicrotime($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.
@@ -3594,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');
@@ -3646,9 +3819,9 @@ 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);
+                                                       $_procObj = t3lib_div::getUserObj($_classRef);
                                                        $insertFields = $_procObj->sysstat_preProcessFields($insertFields,$this);
                                                }
                                        }
@@ -3660,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
@@ -3676,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();
 
@@ -3702,8 +3875,8 @@ if (version == "n3") {
         * @return      void
         */
        function previewInfo()  {
-               if ($this->fePreview)   {
-                               if ($this->fePreview==2)        {
+               if ($this->fePreview) {
+                               if ($this->fePreview === 2) {
                                        $onclickForStoppingPreview = 'document.location="'.t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev=LOGOUT&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')).'";return false;';
                                        $text = 'Preview of workspace "'.$this->whichWorkspace(TRUE).'" ('.$this->whichWorkspace().')';
                                        $html = $this->doWorkspacePreview() ? '<br/><input name="_" type="submit" value="Stop preview" onclick="'.htmlspecialchars($onclickForStoppingPreview).'" />' : '';
@@ -3714,7 +3887,7 @@ if (version == "n3") {
 
                                $stdMsg = '<div id="typo3-previewInfo" style="position: absolute; top: 20px; right: 20px; border: 2px solid #000; padding: 5px 5px; background: #f00; font: 1em Verdana; color: #000; font-weight: bold; z-index: 10001">'.htmlspecialchars($text).$html.'</div>';
 
-                               if ($this->fePreview==2)        {
+                               if ($this->fePreview === 2) {
                                        $temp_content = $this->config['config']['message_preview_workspace'] ?
                                                @sprintf($this->config['config']['message_preview_workspace'], $this->whichWorkspace(TRUE),$this->whichWorkspace()) :
                                                $stdMsg;
@@ -3733,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);
@@ -3747,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)     {
@@ -3812,9 +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,
@@ -3839,9 +4015,11 @@ 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();
+
                if (t3lib_extMgm::isLoaded('simulatestatic')) {
                        return t3lib_div::callUserFunction(
                                'EXT:simulatestatic/class.tx_simulatestatic.php:&tx_simulatestatic->processEncodedQueryString',
@@ -3858,9 +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),
@@ -3872,9 +4053,11 @@ 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();
+
                $replacement = $defChar = t3lib_div::compat_version('4.0') ? '-' : '_';
                if (isset($this->config['config']['simulateStaticDocuments_replacementChar'])) {
                        $replacement = trim($this->config['config']['simulateStaticDocuments_replacementChar']);
@@ -3893,9 +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'];
@@ -3994,20 +4179,27 @@ if (version == "n3") {
        }
 
        /**
-        * Encrypts a strings by XOR'ing all characters with the ASCII value of a character in $this->TYPO3_CONF_VARS['SYS']['encryptionKey']
-        * If $this->TYPO3_CONF_VARS['SYS']['encryptionKey'] is empty, 255 is used for XOR'ing. Using XOR means that the string can be decrypted by simply calling the function again - just like rot-13 works (but in this case for ANY byte value).
+        * Encrypts a strings by XOR'ing all characters with a key derived from the
+        * TYPO3 encryption key.
+        *
+        * Using XOR means that the string can be decrypted by simply calling the
+        * function again - just like rot-13 works (but in this case for ANY byte
+        * value).
         *
-        * @param       string          Input string
-        * @return      string          Output string
+        * @param string $string string to crypt, may be empty
+        *
+        * @return string binary crypt string, will have the same length as $string
         */
-       function roundTripCryptString($string)  {
+       protected function roundTripCryptString($string) {
                $out = '';
-               $strLen = strlen($string);
-               $cryptLen = strlen($this->TYPO3_CONF_VARS['SYS']['encryptionKey']);
 
-               for ($a=0; $a < $strLen; $a++)  {
-                       $xorVal = $cryptLen>0 ? ord($this->TYPO3_CONF_VARS['SYS']['encryptionKey']{($a%$cryptLen)}) : 255;
-                       $out.= chr(ord($string{$a}) ^ $xorVal);
+               $cleartextLength = strlen($string);
+               $key = sha1($this->TYPO3_CONF_VARS['SYS']['encryptionKey']);
+               $keyLength = strlen($key);
+
+               for ($a = 0; $a < $cleartextLength; $a++) {
+                       $xorVal = ord($key{($a % $keyLength)});
+                       $out .= chr(ord($string{$a}) ^ $xorVal);
                }
 
                return $out;
@@ -4051,8 +4243,11 @@ if (version == "n3") {
                if ($this->absRefPrefix)        {
                        $this->content = str_replace('"media/', '"'.t3lib_extMgm::siteRelPath('cms').'tslib/media/', $this->content);
                        $this->content = str_replace('"typo3conf/ext/', '"'.$this->absRefPrefix.'typo3conf/ext/', $this->content);
-                       $this->content = str_replace('"typo3/contrib/', '"'.$this->absRefPrefix.'typo3/contrib/', $this->content);
+                       $this->content = str_replace('"' . TYPO3_mainDir . 'contrib/', '"' . $this->absRefPrefix . TYPO3_mainDir . 'contrib/', $this->content);
+                       $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) {
@@ -4093,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);
        }
 
        /**
@@ -4112,7 +4311,10 @@ if (version == "n3") {
         * @access private
         */
        function updateMD5paramsRecord($hash)   {
-               $GLOBALS['TYPO3_DB']->exec_UPDATEquery('cache_md5params', 'md5hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_md5params'), array('tstamp' => time()));
+               $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
+                       'cache_md5params',
+                       'md5hash=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_md5params'), array('tstamp' => $GLOBALS['EXEC_TIME'])
+               );
        }
 
        /**
@@ -4133,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);
@@ -4280,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;
                }
@@ -4295,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))      {
@@ -4380,8 +4580,11 @@ if (version == "n3") {
         * Seeds the random number engine.
         *
         * @return      void
+        * @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();
+
                list($usec, $sec) = explode(' ', microtime());
                $seedV = (float)$sec + ((float)$usec * 100000);
                srand($seedV);
@@ -4401,10 +4604,14 @@ if (version == "n3") {
        /**
         * Sets the cache-flag to 1. Could be called from user-included php-files in order to ensure that a page is not cached.
         *
+        * @param       string          $reason: An optional reason to be written to the syslog.
+        *                                              If not set, debug_backtrace() will be used to track down the call.
         * @return      void
         */
-       function set_no_cache() {
-               if (function_exists('debug_backtrace')) {
+       function set_no_cache($reason = '') {
+               if (strlen($reason)) {
+                       $warning = '$TSFE->set_no_cache() was triggered. Reason: ' . $reason . '.';
+               } else {
                        $trace = debug_backtrace();
                                // This is a hack to work around ___FILE___ resolving symbolic links
                        $PATH_site_real = str_replace('t3lib','',realpath(PATH_site.'t3lib'));
@@ -4416,22 +4623,32 @@ if (version == "n3") {
                        }
                        $line = $trace[0]['line'];
                        $trigger = $file.' on line '.$line;
-               } else {
-                       $trigger = '[unknown]';
+
+                       $warning = '$TSFE->set_no_cache() was triggered by ' . $trigger.'.';
                }
 
-               $warning = '$TSFE->set_no_cache() was triggered by '.$trigger.'. ';
                if ($this->TYPO3_CONF_VARS['FE']['disableNoCacheParameter']) {
-                       $warning.= 'However $TYPO3_CONF_VARS[\'FE\'][\'disableNoCacheParameter\'] is set, so it will be ignored!';
+                       $warning.= ' However, $TYPO3_CONF_VARS[\'FE\'][\'disableNoCacheParameter\'] is set, so it will be ignored!';
                        $GLOBALS['TT']->setTSlogMessage($warning,2);
                } else {
-                       $warning.= 'Caching is disabled!';
-                       $this->no_cache = 1;
+                       $warning.= ' Caching is disabled!';
+                       $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
@@ -4449,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;
@@ -4593,9 +4810,10 @@ if (version == "n3") {
 
                        // Setting language key and split index:
                $this->lang = $this->config['config']['language'] ? $this->config['config']['language'] : 'default';
+               $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;}
                }
 
@@ -4657,4 +4875,4 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_fe.php']);
 }
 
-?>
\ No newline at end of file
+?>