git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2471 709f56b5-9817-0410-a4d7...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_fe.php
index 8a9636b..eb39175 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2007 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
        var $rootLine='';                                       // The rootLine (all the way to tree root, not only the current site!) (array)
        var $page='';                                           // The pagerecord (array)
        var $contentPid=0;                                      // This will normally point to the same value as id, but can be changed to point to another page from which content will then be displayed instead.
-       var $sys_page='';                                       // The object with pagefunctions (object)
+
+       /**
+        * sys_page-object, pagefunctions
+        *
+        * @var t3lib_pageSelect
+        */
+       var $sys_page='';
        var $jumpurl='';
        var $pageNotFound=0;                            // Is set to 1 if a pageNotFound handler could have been called.
        var $domainStartPage=0;                         // Domain start page
        var $siteScript='';                                     // Contains the value of the current script path that activated the frontend. Typically "index.php" but by rewrite rules it could be something else! Used for Speaking Urls / Simulate Static Documents.
 
                // USER
-       var $fe_user='';                                        // The user (object)
+
+       /**
+        * The FE user
+        *
+        * @var tslib_feUserAuth
+        */
+       var $fe_user='';
        var $loginUser='';                                      // Global flag indicating that a front-end user is logged in. This is set only if a user really IS logged in. The group-list may show other groups (like added by IP filter or so) even though there is no user.
        var $gr_list='';                                        // (RO=readonly) The group list, sorted numerically. Group '0,-1' is the default group, but other groups may be added by other means than a user being logged in though...
        var $beUserLogin='';                            // Flag that indicates if a Backend user is logged in!
        var $TCAcachedExtras=array();           // Array of cached information from TCA. This is NOT TCA itself!
 
                // TEMPLATE / CACHE
-       var $tmpl='';                                           // The TypoScript template object. Used to parse the TypoScript template
+
+       /**
+        * The TypoScript template object. Used to parse the TypoScript template
+        *
+        * @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 $cacheContentFlag='';                       // Set internally if cached content is fetched from the database
        var $cacheExpires=0;                            // Set to the expire time of cached content
        var $JSeventFuncCalls = array(          // you can add JavaScript functions to each entry in these arrays. Please see how this is done in the GMENU_LAYERS script. The point is that many applications on a page can set handlers for onload, onmouseover and onmouseup
                'onmousemove' => array(),
                'onmouseup' => array(),
+               'onmousemove' => array(),
+               'onkeydown' => array(),
+               'onkeyup' => array(),
+               'onkeypress' => array(),
                'onload' => array(),
+               'onunload' => array(),
        );
        var $JSCode='';                                         // Deprecated, use additionalJavaScript instead.
        var $JSImgCode='';                                      // Used to accumulate JavaScript loaded images (by menus)
        var $baseUrl='';                                        // The base URL set for the page header.
        var $anchorPrefix='';                           // The proper anchor prefix needed when using speaking urls. (only set if baseUrl is set)
 
-               // Page content render object
-       var $cObj ='';                                          // is instantiated object of tslib_cObj
+       /**
+        * Page content render object
+        *
+        * @var tslib_cObj
+        */
+       var $cObj ='';
 
                // CONTENT accumulation
        var $content='';                                        // All page content is accumulated in this variable. See pagegen.php
        var $TCAloaded = 0;                                     // Set ONLY if the full TCA is loaded
 
                // Character set (charset) conversion object:
-       var $csConvObj;                                         // An instance of the "t3lib_cs" class. May be used by any application.
+
+       /**
+        * charset conversion class. May be used by any application.
+        *
+        * @var t3lib_cs
+        */
+       var $csConvObj;
        var $defaultCharSet = 'iso-8859-1';     // The default charset used in the frontend if nothing else is set.
        var $renderCharset='';                          // Internal charset of the frontend during rendering: Defaults to "forceCharset" and if that is not set, to ->defaultCharSet
        var $metaCharset='';                            // Output charset of the websites content. This is the charset found in the header, meta tag etc. If different from $renderCharset a conversion happens before output to browser. Defaults to ->renderCharset if not set.
                                        </script>';
                                exit;
                        } elseif (!$GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db))       {
+                               header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
                                $this->printError('Cannot connect to the current database, "'.TYPO3_db.'"','Database Error');
                                exit;
                        }
                                        </script>';
                                exit;
                        }
+                       header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
                        $this->printError('The current username, password or host was not accepted when the connection to the database was attempted to be established!','Database Error');
                        exit;
                }
                                                // Initialize the page-select functions to check rootline:
                                        $temp_sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
                                        $temp_sys_page->init($this->showHiddenPage);
-
                                                // If root line contained NO records and ->error_getRootLine_failPid tells us that it was because of a pid=-1 (indicating a "version" record)...:
                                        if (!count($temp_sys_page->getRootLine($this->id,$this->MP)) && $temp_sys_page->error_getRootLine_failPid==-1)  {
 
                                if ($theFirstPage)      {
                                        $this->id = $theFirstPage['uid'];
                                } else {
+                                       header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
+                                       t3lib_div::sysLog('No pages are found on the rootlevel!', 'cms', 3);
                                        $this->printError('No pages are found on the rootlevel!');
                                        exit;
                                }
                                        $c--;
                                        $this->id = $this->rootLine[$c]['uid'];
                                        $this->page = $this->sys_page->getPage($this->id);
-                                       if (count($this->page)){ break; }
+                                       if (count($this->page)) { break; }
                                }
                        }
                                // If still no page...
                                if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling'])      {
                                        $this->pageNotFoundAndExit('The requested page does not exist!');
                                } else {
+                                       header( 'HTTP/1.0 404 Page Not Found' );
+                                       t3lib_div::sysLog('The requested page does not exist!', 'cms', 3);
                                        $this->printError('The requested page does not exist!');
                                        exit;
                                }
                        if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling'])      {
                                $this->pageNotFoundAndExit('The requested page does not exist!');
                        } else {
+                               header( 'HTTP/1.0 404 Page Not Found' );
+                               t3lib_div::sysLog('The requested page does not exist!', 'cms', 3);
                                $this->printError('The requested page does not exist!');
                                exit;
                        }
 
                        // If not rootline we're off...
                if (!count($this->rootLine))    {
-                       $this->printError('The requested page didn\'t have a proper connection to the tree-root! <br /><br />('.$this->sys_page->error_getRootLine.')');
-                       exit;
+                       $ws = $this->whichWorkspace();
+                       if ($this->sys_page->error_getRootLine_failPid==-1 && $ws) {
+                               $this->sys_page->versioningPreview = TRUE;
+                               $this->versioningWorkspaceId = $ws;
+                               $this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
+                       }
+                       if (!count($this->rootLine))    {
+                               header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
+                               t3lib_div::sysLog('The requested page didn\'t have a proper connection to the tree-root! ('.$this->sys_page->error_getRootLine.')', 'cms', 3);
+                               $this->printError('The requested page didn\'t have a proper connection to the tree-root! <br /><br />('.$this->sys_page->error_getRootLine.')');
+                               exit;
+                       }
+                       $this->fePreview = 1;
                }
 
                        // Checking for include section regarding the hidden/starttime/endtime/fe_user (that is access control of a whole subbranch!)
                if ($this->checkRootlineForIncludeSection())    {
                        if (!count($this->rootLine))    {
+                               header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
+                               t3lib_div::sysLog('The requested page was not accessible!', 'cms', 3);
                                $this->printError('The requested page was not accessible!');
                                exit;
                        } else {
                                $page = $this->getPageShortcut($page['shortcut'],$page['shortcut_mode'],$page['uid'],$itera-1,$pageLog);
                        } else {
                                $pageLog[] = $page['uid'];
+                               header( 'HTTP/1.0 500 Internal Server Error' );
+                               t3lib_div::sysLog('Page shortcuts were looping in uids '.implode(',',$pageLog).'...!', 'cms', 3);
                                $this->printError('Page shortcuts were looping in uids '.implode(',',$pageLog).'...!');
                                exit;
                        }
                        }
                }
 
-                       // Convert $code in case it was written as a string (e.g. if edited in Install Tool)
-                       // TODO: Once the Install Tool handles such data types correctly, this workaround should be removed again...
-               if (!strcasecmp($code,'TRUE'))  { $code=TRUE; }
-
                        // Create response:
                if (gettype($code)=='boolean' || !strcmp($code,1))      {       // Simply boolean; Just shows TYPO3 error page with reason:
                        $this->printError('The page did not exist or was inaccessible.'.($reason ? ' Reason: '.htmlspecialchars($reason) : ''));
                                                $base.= $url_parts['host'];
 
                                                        // Add path portion skipping possible file name
-                                               $base.= preg_replace('/(.*\/)[^\/]*/', '\1', $url_parts['path']);
+                                               $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);
         */
        function ADMCMD_preview(){
                $inputCode = t3lib_div::_GP('ADMCMD_prev');
+               $cookieTTL = 60*60;
+
+                       // If cookie is set, see what to do:
+               if ($_COOKIE['ADMCMD_prev'])    {
+                       
+                               // If no input code is given by GET method, lets look it up in a cookie (for workspace previews not only tied to the page) and update the cookie time:
+                       if (!$inputCode)        {
+                               $inputCode = $_COOKIE['ADMCMD_prev'];
+                               SetCookie('ADMCMD_prev', $inputCode, time()+$cookieTTL);
+                       } else {        // Otherwise "log out":
+                               SetCookie('ADMCMD_prev', '', 0);
+                               die("You logged out from Workspace preview mode. Reload the browser to log in again.");
+                       }
+               }
 
+                       // If inputcode now, look up the settings:
                if ($inputCode) {
 
                                // Look for keyword configuration record:
                                // - Make sure to remove fe/be cookies (temporarily); BE already done in ADMCMD_preview_postInit()
                        if (is_array($previewData))     {
                                if (!count(t3lib_div::_POST())) {
-                                       if (t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev='.$inputCode === t3lib_div::getIndpEnv('TYPO3_REQUEST_URL')) {
-
-                                                       // Unserialize configuration:
-                                               $previewConfig = unserialize($previewData['config']);
+                                               // Unserialize configuration:
+                                       $previewConfig = unserialize($previewData['config']);
+
+                                       if ($previewConfig['fullWorkspace']) {  // For full workspace preview we only ADD a get variable to set the preview of the workspace - so all other Get vars are accepted. Hope this is not a security problem. Still posting is not allowed and even if a backend user get initialized it shouldn't lead to situations where users can use those credentials.
+                                       
+                                                       // Set the workspace preview value:
+                                               t3lib_div::_GETset($previewConfig['fullWorkspace'],'ADMCMD_previewWS');
+                                               
+                                                       // If ADMCMD_prev is set the $inputCode value cannot come from a cookie and we set that cookie here. Next time it will be found from the cookie if ADMCMD_prev is not set again...
+                                               if (t3lib_div::_GP('ADMCMD_prev'))      {
+                                                       SetCookie('ADMCMD_prev', t3lib_div::_GP('ADMCMD_prev'), time()+$cookieTTL);     // Lifetime is 1 hour, does it matter much? Requires the user to click the link from their email again if it expires.
+                                               }
+                                               return $previewConfig;
+                                       } elseif (t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev='.$inputCode === t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'))   {
 
                                                        // Set GET variables:
                                                $GET_VARS = '';
                                $this->pSetup = $this->tmpl->setup[$this->sPre.'.'];
 
                                if (!is_array($this->pSetup))   {
+                                       header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
+                                       t3lib_div::sysLog('The page is not configured! [type= '.$this->type.']['.$this->sPre.']', 'cms', 3);
                                        $this->printError('The page is not configured! [type= '.$this->type.']['.$this->sPre.']');
                                        exit;
                                } else {
                                }
                                $GLOBALS['TT']->pull();
                        } else {
+                               header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
+                               t3lib_div::sysLog('No template found!', 'cms', 3);
                                $this->printError('No template found!');
                                exit;
                        }
                                $c = count($temp);
                                for ($i=0; $i<$c; $i++) {
                                        if ($temp[$i]['uid'])   {
-                                               $p = $this->csConvObj->crop('utf-8',$this->csConvObj->utf8_encode($temp[$i]['title'],$this->renderCharset),$len,"\xE2\x80\xA6");        // U+2026; HORIZONTAL ELLIPSIS 
+                                               $p = $this->csConvObj->crop('utf-8',$this->csConvObj->utf8_encode($temp[$i]['title'],$this->renderCharset),$len,"\xE2\x80\xA6");        // U+2026; HORIZONTAL ELLIPSIS
                                                $path .= '/' . rawurlencode($p);
                                        }
                                }
                if ($this->absRefPrefix_force && strcmp($this->config['config']['simulateStaticDocuments'],'PATH_INFO'))        {
                        $redirectUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR').'index.php?id='.$this->id.'&type='.$this->type;
                        if ($this->config['config']['simulateStaticDocuments_dontRedirectPathInfoError'])       {
+                               header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
+                               t3lib_div::sysLog('PATH_INFO was not configured for this website, and the URL tries to find the page by PATH_INFO!', 'cms', 3);
                                $this->printError('PATH_INFO was not configured for this website, and the URL tries to find the page by PATH_INFO!<br /><br /><a href="'.htmlspecialchars($redirectUrl).'">Click here to get to the right page.</a>','Error: PATH_INFO not configured');
                        } else {
                                header('Location: '.t3lib_div::locationHeaderUrl($redirectUrl));
         * @return      void
         */
        function realPageCacheContent() {
-               $cache_timeout = $this->page['cache_timeout'] ? $this->page['cache_timeout'] : ($this->cacheTimeOutDefault ? $this->cacheTimeOutDefault : 60*60*24);            // seconds until a cached page is too old
+               $cache_timeout = $this->get_cache_timeout();            // seconds until a cached page is too old
                $timeOutTime = $GLOBALS['EXEC_TIME']+$cache_timeout;
                if ($this->config['config']['cache_clearAtMidnight'])   {
                        $midnightTime = mktime (0,0,0,date('m',$timeOutTime),date('d',$timeOutTime),date('Y',$timeOutTime));
@@ -3202,7 +3284,7 @@ if (version == "n3") {
                                $stdMsg = '
                                <br />
                                <div align="center">
-                                       <table border="3" bordercolor="black" cellpadding="2" bgcolor="red">
+                                       <table border="3" bordercolor="black" cellpadding="2" bgcolor="red" summary="">
                                                <tr>
                                                        <td>&nbsp;&nbsp;<font face="Verdana" size="1"><b>'.htmlspecialchars($text).'</b></font>&nbsp;&nbsp;</td>
                                                </tr>
@@ -3651,7 +3733,7 @@ if (version == "n3") {
         */
        function prefixLocalAnchorsWithScript() {
                $scriptPath = substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'),strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL')));
-               $this->content = preg_replace('/(<(a|area).*?href=")(#[^"]*")/i','$1' . htmlspecialchars($scriptPath) . '$3',$this->content);
+               $this->content = preg_replace('/(<(a|area).*?href=")(#[^"]*")/i','${1}' . htmlspecialchars($scriptPath) . '${3}',$this->content);
        }
 
        /**
@@ -3799,13 +3881,13 @@ if (version == "n3") {
 '              // JS function for mouse-over
        function over(name,imgObj)      {       //
                if (version == "n3" && document[name]) {document[name].src = eval(name+"_h.src");}
-               else if (typeof(document.getElementById)=="function" && document.getElementById(name)) {document.getElementById(name).src = eval(name+"_h.src");}
+               else if (document.getElementById && document.getElementById(name)) {document.getElementById(name).src = eval(name+"_h.src");}
                else if (imgObj)        {imgObj.src = eval(name+"_h.src");}
        }
                // JS function for mouse-out
        function out(name,imgObj)       {       //
                if (version == "n3" && document[name]) {document[name].src = eval(name+"_n.src");}
-               else if (typeof(document.getElementById)=="function" && document.getElementById(name)) {document.getElementById(name).src = eval(name+"_n.src");}
+               else if (document.getElementById && document.getElementById(name)) {document.getElementById(name).src = eval(name+"_n.src");}
                else if (imgObj)        {imgObj.src = eval(name+"_n.src");}
        }';
                                break;
@@ -3883,6 +3965,25 @@ if (version == "n3") {
        }
 
        /**
+        * Get the cache timeout for the current page.
+        *
+        * @return      integer         The cache timeout for the current page.
+        */
+       function get_cache_timeout() {
+                       // Cache period was set for the page:
+               if ($this->page['cache_timeout']) {
+                       $cacheTimeout = $this->page['cache_timeout'];
+                       // Cache period was set for the whole site:
+               } elseif ($this->cacheTimeOutDefault) {
+                       $cacheTimeout = $this->cacheTimeOutDefault;
+                       // No cache period set at all, so we take one day (60*60*24 seconds = 86400 seconds):
+               } else {
+                       $cacheTimeout = 86400;
+               }
+               return $cacheTimeout;
+       }
+
+       /**
         * Substitute function for the PHP mail() function.
         * It will encode the email with the setting of TS 'config.notification_email_encoding' (base64 or none)
         * It will also find all links to http:// in the text and substitute with a shorter link using the redirect feature which stores the long link in the database. Depends on configuration in TS 'config.notification_email_urlmode'