tslib/class.tslib_fe.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00201  class tslib_fe {
00202 
00203                 // CURRENT PAGE:
00204         var $id='';                                                     // The page id (int)
00205         var $type='';                                           // RO The type (int)
00206         var $idParts=array();                           // Loaded with the id, exploded by ','
00207         var $cHash='';                                          // The submitted cHash
00208         var $no_cache='';                                       // Page will not be cached. Write only true. Never clear value (some other code might have reasons to set it true)
00209         var $rootLine='';                                       // The rootLine (all the way to tree root, not only the current site!) (array)
00210         var $page='';                                           // The pagerecord (array)
00211         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.
00212         var $sys_page='';                                       // The object with pagefunctions (object)
00213         var $jumpurl='';
00214         var $pageNotFound=0;                            // Is set to 1 if a pageNotFound handler could have been called.
00215         var $domainStartPage=0;                         // Domain start page
00216         var $pageAccessFailureHistory=array();  // Array containing a history of why a requested page was not accessible.
00217         var $MP='';
00218         var $RDCT='';
00219         var $page_cache_reg1=0;                         // This can be set from applications as a way to tag cached versions of a page and later perform some external cache management, like clearing only a part of the cache of a page...
00220         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.
00221 
00222                 // USER
00223         var $fe_user='';                                        // The user (object)
00224         var $loginUser='';                                      // Global falg 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.
00225         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...
00226         var $beUserLogin='';                            // Flag that indicates if a Backend user is logged in!
00227         var $loginAllowedInBranch = TRUE;       // Shows whether logins are allowed in branch
00228 
00229                 // PREVIEW
00230         var $fePreview='';                                      // Flag indication that preview is active. This is based on the login of a backend user and whether the backend user has read access to the current page.
00231         var $showHiddenPage='';                         // Flag indicating that hidden pages should be shown, selected and so on. This goes for almost all selection of pages!
00232         var $showHiddenRecords='';                      // Flag indicating that hidden records should be shown. This includes sys_template, pages_language_overlay and even fe_groups in addition to all other regular content. So in effect, this includes everything except pages.
00233         var $simUserGroup='0';                          // Value that contains the simulated usergroup if any
00234         var $versionPreviewMap=array();         // Versioning Preview record map (temporary, for sys_page)
00235 
00236                 // CONFIGURATION
00237         var $TYPO3_CONF_VARS=array();           // The configuration array as set up in t3lib/config_default.php. Should be an EXACT copy of the global array.
00238         var $config='';                                         // 'CONFIG' object from TypoScript. Array generated based on the TypoScript configuration of the current page. Saved with the cached pages.
00239         var $TCAcachedExtras=array();           // Array of cached information from TCA. This is NOT TCA itself!
00240 
00241                 // TEMPLATE / CACHE
00242         var $tmpl='';                                           // The TypoScript template object. Used to parse the TypoScript template
00243         var $cacheTimeOutDefault='';            // Is set to the time-to-live time of cached pages. If false, default is 60*60*24, which is 24 hours.
00244         var $cacheContentFlag='';                       // Set internally if cached content is fetched from the database
00245         var $cacheExpires=0;                            // Set to the expire time of cached content
00246         var $isClientCachable=FALSE;            // Set if cache headers allowing caching are sent.
00247         var $all='';                                            // $all used by template fetching system. This array is an identification of the template. If $this->all is empty it's because the template-data is not cached, which it must be.
00248         var $sPre='';                                           // toplevel - objArrayName, eg 'page'
00249         var $pSetup='';                                         // TypoScript configuration of the page-object pointed to by sPre. $this->tmpl->setup[$this->sPre.'.']
00250         var $newHash='';                                        // This hash is unique to the template, the $this->id and $this->type vars and the gr_list (list of groups). Used to get and later store the cached data
00251         var $getMethodUrlIdToken='';            // If config.ftu (Frontend Track User) is set in TypoScript for the current page, the string value of this var is substituted in the rendered source-code with the string, '&ftu=[token...]' which enables GET-method usertracking as opposed to cookie based
00252         var $noCacheBeforePageGen='';           // This flag is set before inclusion of pagegen.php IF no_cache is set. If this flag is set after the inclusion of pagegen.php, no_cache is forced to be set. This is done in order to make sure that php-code from pagegen does not falsely clear the no_cache flag.
00253         var $tempContent = FALSE;                       // This flag indicates if temporary content went into the cache during page-generation.
00254         var $forceTemplateParsing='';                           // Boolean, passed to TypoScript template class and tells it to render the template forcibly
00255         var $cHash_array=array();                       // The array which cHash_calc is based on, see ->makeCacheHash().
00256         var $hash_base='';                                      // Loaded with the serialized array that is used for generating a hashstring for the cache
00257         var $pagesTSconfig='';                          // May be set to the pagesTSconfig
00258                 // PAGE-GENERATION / cOBJ
00259         /*
00260                 Eg. insert JS-functions in this array ($additionalHeaderData) to include them once. Use associative keys.
00261                 Keys in use:
00262                         JSFormValidate  :               <script type="text/javascript" src="'.$GLOBALS["TSFE"]->absRefPrefix.'t3lib/jsfunc.validateform.js"></script>
00263                         JSincludeFormupdate :   <script type="text/javascript" src="t3lib/jsfunc.updateform.js"></script>
00264                         JSMenuCode, JSMenuCode_menu :                   JavaScript for the JavaScript menu
00265                         JSCode : reserved
00266                         JSImgCode : reserved
00267         */
00268         var $defaultBodyTag='<body bgcolor="#FFFFFF">';         // Default bodytag, if nothing else is set. This can be overridden by applications like TemplaVoila.
00269         var $additionalHeaderData=array();      // used to accumulate additional HTML-code for the header-section, <head>...</head>. Insert either associative keys (like additionalHeaderData['myStyleSheet'], see reserved keys above) or num-keys (like additionalHeaderData[] = '...')
00270         var $additionalJavaScript=array();      // used to accumulate additional JavaScript-code. Works like additionalHeaderData. Reserved keys at 'openPic' and 'mouseOver'
00271         var $additionalCSS=array();                     // used to accumulate additional Style code. Works like additionalHeaderData.
00272         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
00273                 'onmousemove' => array(),
00274                 'onmouseup' => array(),
00275                 'onload' => array(),
00276         );
00277         var $JSCode='';                                         // Depreciated, use additionalJavaScript instead.
00278         var $JSImgCode='';                                      // Used to accumulate JavaScript loaded images (by menus)
00279         var $divSection='';                                     // Used to accumulate DHTML-layers.
00280 
00281                 // RENDERING configuration, settings from TypoScript is loaded into these vars. See pagegen.php
00282         var $debug='';                                          // Debug flag, may output special debug html-code.
00283         var $intTarget='';                                      // Default internal target
00284         var $extTarget='';                                      // Default external target
00285         var $MP_defaults=array();                       // Keys are page ids and values are default &MP (mount point) values to set when using the linking features...)
00286         var $spamProtectEmailAddresses=0;       // If set, typolink() function encrypts email addresses. Is set in pagegen-class.
00287         var $absRefPrefix='';                           // Absolute Reference prefix
00288         var $absRefPrefix_force=0;                      // Absolute Reference prefix force flag. This is set, if the type and id is retrieve from PATH_INFO and thus we NEED to prefix urls with at least '/'
00289         var $compensateFieldWidth='';           // Factor for form-field widths compensation
00290         var $lockFilePath='';                           // Lock file path
00291         var $ATagParams='';                                     // <A>-tag parameters
00292         var $sWordRegEx='';                                     // Search word regex, calculated if there has been search-words send. This is used to mark up the found search words on a page when jumped to from a link in a search-result.
00293         var $sWordList='';                                      // Is set to the incoming array sword_list in case of a page-view jumped to from a search-result.
00294         var $linkVars='';                                       // A string prepared for insertion in all links on the page as url-parameters. Based on configuration in TypoScript where you defined which GET_VARS you would like to pass on.
00295         var $excludeCHashVars='';                       // A string set with a comma list of additional GET vars which should NOT be included in the cHash calculation. These vars should otherwise be detected and involved in caching, eg. through a condition in TypoScript.
00296         var $displayEditIcons='';                       // If set, edit icons are rendered aside content records. Must be set only if the ->beUserLogin flag is set and set_no_cache() must be called as well.
00297         var $displayFieldEditIcons='';          // If set, edit icons are rendered aside individual fields of content. Must be set only if the ->beUserLogin flag is set and set_no_cache() must be called as well.
00298         var $sys_language_uid=0;                        // Site language, 0 (zero) is default, int+ is uid pointing to a sys_language record. Should reflect which language it DOES actually display!
00299         var $sys_language_mode='';                      // Site language mode
00300         var $sys_language_content=0;            // Site content selection uid
00301         var $sys_language_contentOL=0;          // Site content overlay flag; If set - and sys_language_content is > 0 - , records selected will try to look for a translation pointing to their uid. (If configured in [ctrl][languageField] / [ctrl][transOrigP...]
00302         var $sys_language_isocode = '';         // Is set to the iso code of the sys_language_content if that is properly defined by the sys_language record representing the sys_language_uid. (Requires the extension "static_info_tables")
00303 
00304                 // RENDERING data
00305         var $applicationData=Array();           //       'Global' Storage for various applications. Keys should be 'tx_'.extKey for extensions.
00306         var $register=Array();
00307         var $registerStack=Array();                     // Stack used for storing array and retrieving register arrays (see LOAD_REGISTER and CLEAR_REGISTER)
00308         var $cObjectDepthCounter = 50;          // Checking that the function is not called eternally. This is done by interrupting at a depth of 50
00309         var $recordRegister = Array();          // used by cObj->RECORDS and cObj->CONTENT to ensure the a records is NOT rendered twice through it!
00310         var $currentRecord = '';                        // This is set to the [table]:[uid] of the latest record rendered. Note that class tslib_cObj has an equal value, but that is pointing to the record delivered in the $data-array of the tslib_cObj instance, if the cObjects CONTENT or RECORD created that instance
00311         var $accessKey =array();                        // Used by class tslib_menu to keep track of access-keys.
00312         var $imagesOnPage=array();                      // Numerical array where image filenames are added if they are referenced in the rendered document. This includes only TYPO3 generated/inserted images.
00313         var $lastImageInfo=array();                     // Is set in tslib_cObj->cImage() function to the info-array of the most recent rendered image. The information is used in tslib_cObj->IMGTEXT
00314         var $uniqueCounter=0;                           // Used to generate page-unique keys. Point is that uniqid() functions is very slow, so a unikey key is made based on this, see function uniqueHash()
00315         var $uniqueString='';
00316         var $indexedDocTitle='';                        // This value will be used as the title for the page in the indexer (if indexing happens)
00317         var $altPageTitle='';                           // Alternative page title (normally the title of the page record). Can be set from applications you make.
00318         var $pEncAllowedParamNames=array();     // An array that holds parameter names (keys) of GET parameters which MAY be MD5/base64 encoded with simulate_static_documents method.
00319         var $baseUrl='';                                        // The Base url set for the page header.
00320         var $anchorPrefix='';                           // The proper anchor prefix needed when using speaking urls. (only set if baseUrl is set)
00321 
00322                 // Page content render object
00323         var $cObj ='';                                          // is instantiated object of tslib_cObj
00324 
00325                 // CONTENT accumulation
00326         var $content='';                                        // All page content is accumulated in this variable. See pagegen.php
00327 
00328                 // GENERAL
00329         var $clientInfo='';                                     // Set to the browser: net / msie if 4+ browsers
00330         var $scriptParseTime=0;
00331         var $TCAloaded = 0;                                     // Set ONLY if the full TCA is loaded
00332 
00333                 // Character set (charset) conversion object:
00334         var $csConvObj;                                         // An instance of the "t3lib_cs" class. May be used by any application.
00335         var $defaultCharSet = 'iso-8859-1';     // The default charset used in the frontend if nothing else is set.
00336         var $renderCharset='';                          // Internal charset of the frontend during rendering: Defaults to "forceCharset" and if that is not set, to ->defaultCharSet
00337         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.
00338         var $localeCharset='';                          // Assumed charset of locale strings.
00339 
00340                 // LANG:
00341         var $lang='';                                           // Set to the system language key (used on the site)
00342         var $langSplitIndex=0;                          // Set to the index number of the language key
00343         var $labelsCharset='';                          // Charset of the labels from locallang (based on $this->lang)
00344         var $convCharsetToFrom='';                      // Set to the charsets to convert from/to IF there are any difference. Otherwise this stays a string
00345         var $LL_labels_cache=array();
00346         var $LL_files_cache=array();
00347 
00348 
00349 
00350 
00351 
00369         function tslib_fe($TYPO3_CONF_VARS, $id, $type, $no_cache='', $cHash='', $jumpurl='',$MP='',$RDCT='')   {
00370 
00371                         // Setting some variables:
00372                 $this->TYPO3_CONF_VARS = $TYPO3_CONF_VARS;
00373                 $this->id = $id;
00374                 $this->type = $type;
00375                 $this->no_cache = $no_cache ? 1 : 0;
00376                 $this->cHash = $cHash;
00377                 $this->jumpurl = $jumpurl;
00378                 $this->MP = $this->TYPO3_CONF_VARS['FE']['enable_mount_pids'] ? (string)$MP : '';
00379                 $this->RDCT = $RDCT;
00380                 $this->clientInfo = t3lib_div::clientInfo();
00381                 $this->uniqueString=md5(microtime());
00382 
00383                 $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
00384 
00385                         // Call post processing function for constructor:
00386                 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc']))    {
00387                         $_params = array('pObj' => &$this);
00388                         foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'] as $_funcRef)     {
00389                                 t3lib_div::callUserFunction($_funcRef,$_params,$this);
00390                         }
00391                 }
00392         }
00393 
00402         function connectToMySQL()       {
00403           $this->connectToDB();
00404         }
00405 
00412         function connectToDB()  {
00413                 if ($GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password))    {
00414                         if (!TYPO3_db)  {
00415                                 $this->printError('No database selected','Database Error');
00416                                         // Redirects to the Install Tool:
00417                                 echo '<script type="text/javascript">
00418                                                 /*<![CDATA[*/
00419                                         document.location = "'.TYPO3_mainDir.'install/index.php?mode=123&step=1&password=joh316";
00420                                                 /*]]>*/
00421                                         </script>';
00422                                 exit;
00423                         } elseif (!$GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db))       {
00424                                 $this->printError('Cannot connect to the current database, "'.TYPO3_db.'"','Database Error');
00425                                 exit;
00426                         }
00427                 } else {
00428                         if (!TYPO3_db)  {
00429                                         // Redirects to the Install Tool:
00430                                 echo '<script type="text/javascript">
00431                                                 /*<![CDATA[*/
00432                                         document.location = "'.TYPO3_mainDir.'install/index.php?mode=123&step=1&password=joh316";
00433                                                 /*]]>*/
00434                                         </script>';
00435                                 exit;
00436                         }
00437                         $this->printError('The current username, password or host was not accepted when the connection to the database was attempted to be established!','Database Error');
00438                         exit;
00439                 }
00440 
00441 
00442                         // Call post processing function for DB connection:
00443                 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB']))  {
00444                         $_params = array('pObj' => &$this);
00445                         foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'] as $_funcRef)   {
00446                                 t3lib_div::callUserFunction($_funcRef,$_params,$this);
00447                         }
00448                 }
00449         }
00450 
00457         function sendRedirect() {
00458                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('params', 'cache_md5params', 'md5hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->RDCT, 'cache_md5params'));
00459                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00460                         $this->updateMD5paramsRecord($this->RDCT);
00461                         header('Location: '.$row['params']);
00462                         exit;
00463                 }
00464         }
00465 
00466 
00467 
00468 
00469 
00470 
00471 
00472 
00473 
00474 
00475 
00476 
00477 
00478 
00479 
00480 
00481 
00482 
00483         /********************************************
00484          *
00485          * Initializing, resolving page id
00486          *
00487          ********************************************/
00488 
00489 
00495         function initFEuser()   {
00496                 $this->fe_user = t3lib_div::makeInstance('tslib_feUserAuth');
00497 
00498                 $this->fe_user->lockIP = $this->TYPO3_CONF_VARS['FE']['lockIP'];
00499                 $this->fe_user->lockHashKeyWords = $this->TYPO3_CONF_VARS['FE']['lockHashKeyWords'];
00500                 $this->fe_user->checkPid = $this->TYPO3_CONF_VARS['FE']['checkFeUserPid'];
00501                 $this->fe_user->lifetime = intval($this->TYPO3_CONF_VARS['FE']['lifetime']);
00502                 $this->fe_user->checkPid_value = $GLOBALS['TYPO3_DB']->cleanIntList(t3lib_div::_GP('pid'));     // List of pid's acceptable
00503 
00504                         // Check if a session is transferred:
00505                 if (t3lib_div::_GP('FE_SESSION_KEY'))   {
00506                         $fe_sParts = explode('-',t3lib_div::_GP('FE_SESSION_KEY'));
00507                         if (!strcmp(md5($fe_sParts[0].'/'.$this->TYPO3_CONF_VARS['SYS']['encryptionKey']), $fe_sParts[1]))      {       // If the session key hash check is OK:
00508                                 $_COOKIE[$this->fe_user->name] = $fe_sParts[0];
00509                                 $this->fe_user->forceSetCookie = 1;
00510                         }
00511                 }
00512 
00513                 if ($this->TYPO3_CONF_VARS['FE']['dontSetCookie'])      {
00514                         $this->fe_user->dontSetCookie=1;
00515                 }
00516 
00517                 $this->fe_user->start();
00518                 $this->fe_user->unpack_uc('');
00519                 $this->fe_user->fetchSessionData();     // Gets session data
00520                 $recs = t3lib_div::_GP('recs');
00521                 if (is_array($recs))    {       // If any record registration is submitted, register the record.
00522                         $this->fe_user->record_registration($recs, $this->TYPO3_CONF_VARS['FE']['maxSessionDataSize']);
00523                 }
00524 
00525                         // Call hook for possible manipulation of frontend user object
00526                 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser']))   {
00527                         $_params = array('pObj' => &$this);
00528                         foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'] as $_funcRef)    {
00529                                 t3lib_div::callUserFunction($_funcRef,$_params,$this);
00530                         }
00531                 }
00532 
00533                         // For every 60 seconds the is_online timestamp is updated.
00534                 if (is_array($this->fe_user->user) && $this->fe_user->user['uid'] && $this->fe_user->user['is_online']<($GLOBALS['EXEC_TIME']-60))      {
00535                         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid='.intval($this->fe_user->user['uid']), array('is_online' => $GLOBALS['EXEC_TIME']));
00536                 }
00537         }
00538 
00545         function initUserGroups() {
00546 
00547                 $this->fe_user->showHiddenRecords = $this->showHiddenRecords;           // This affects the hidden-flag selecting the fe_groups for the user!
00548                 $this->fe_user->fetchGroupData();       // no matter if we have an active user we try to fetch matching groups which can be set without an user (simulation for instance!)
00549 
00550                 if (is_array($this->fe_user->user) && count($this->fe_user->groupData['uid']))  {
00551                         $this->loginUser=1;     // global flag!
00552                         $this->gr_list = '0,-2';        // group -2 is not an existing group, but denotes a 'default' group when a user IS logged in. This is used to let elements be shown for all logged in users!
00553                         $gr_array = $this->fe_user->groupData['uid'];
00554                 } else {
00555                         $this->loginUser=0;
00556                         $this->gr_list = '0,-1';        // group -1 is not an existing group, but denotes a 'default' group when not logged in. This is used to let elements be hidden, when a user is logged in!
00557 
00558                         if ($this->loginAllowedInBranch)        {
00559                                 $gr_array = $this->fe_user->groupData['uid'];   // For cases where logins are not banned from a branch usergroups can be set based on IP masks so we should add the usergroups uids.
00560                         } else {
00561                                 $gr_array = array();            // Set to blank since we will NOT risk any groups being set when no logins are allowed!
00562                         }
00563                 }
00564 
00565                         // Clean up.
00566                 $gr_array = array_unique($gr_array);    // Make unique...
00567                 sort($gr_array);        // sort
00568                 if (count($gr_array))   {
00569                         $this->gr_list.=','.implode(',',$gr_array);
00570                 }
00571 
00572                 if ($this->fe_user->writeDevLog)        t3lib_div::devLog('Valid usergroups for TSFE: '.$this->gr_list, 'tslib_fe');
00573         }
00574 
00580         function isUserOrGroupSet()     {
00581                 return is_array($this->fe_user->user) || $this->gr_list!=='0,-1';
00582         }
00583 
00605         function checkAlternativeIdMethods()    {
00606 
00607                 $this->siteScript = t3lib_div::getIndpEnv('TYPO3_SITE_SCRIPT');
00608 
00609                         // Resolving of "simulateStaticDocuments" URLs:
00610                 if ($this->siteScript && substr($this->siteScript,0,9)!='index.php')    {               // If there has been a redirect (basically; we arrived here otherwise than via "index.php" in the URL) this can happend either due to a CGI-script or because of reWrite rule. Earlier we used $_SERVER['REDIRECT_URL'] to check but
00611                         $uParts = parse_url($this->siteScript); // Parse the path:
00612                         $fI = t3lib_div::split_fileref($uParts['path']);
00613 
00614                         if (!$fI['path'] && $fI['file'] && substr($fI['file'],-5)=='.html')     {
00615                                 $parts = explode('.',$fI['file']);
00616                                 $pCount = count($parts);
00617                                 if ($pCount>2)  {
00618                                         $this->type = intval($parts[$pCount-2]);
00619                                         $this->id = $parts[$pCount-3];
00620                                 } else {
00621                                         $this->type = 0;
00622                                         $this->id = $parts[0];
00623                                 }
00624                         }
00625                 }
00626 
00627                         // If PATH_INFO
00628                 if (t3lib_div::getIndpEnv('PATH_INFO')) {               // If pathinfo contains stuff...
00629                         $parts=t3lib_div::trimExplode('/',t3lib_div::getIndpEnv('PATH_INFO'),1);
00630                         $parts[]='html';
00631                         $pCount = count($parts);
00632                         if ($pCount>2)  {
00633                                 $this->type = intval($parts[$pCount-2]);
00634                                 $this->id = $parts[$pCount-3];
00635                         } else {
00636                                 $this->type = 0;
00637                                 $this->id = $parts[0];
00638                         }
00639                         $this->absRefPrefix_force=1;
00640                 }
00641 
00642                         // Call post processing function for custom URL methods.
00643                 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc']))   {
00644                         $_params = array('pObj' => &$this);
00645                         foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'] as $_funcRef)    {
00646                                 t3lib_div::callUserFunction($_funcRef,$_params,$this);
00647                         }
00648                 }
00649         }
00650 
00657         function clear_preview()        {
00658                 $this->showHiddenPage = 0;
00659                 $this->showHiddenRecords = 0;
00660                 $GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
00661                 $this->fePreview = 0;
00662         }
00663 
00670         function determineId()  {
00671 
00672                         // Getting ARG-v values if some
00673                 $this->setIDfromArgV();
00674 
00675                         // If there is a Backend login we are going to check for any preview settings:
00676                 $GLOBALS['TT']->push('beUserLogin','');
00677                 if ($this->beUserLogin) {
00678                         $this->fePreview = $GLOBALS['BE_USER']->extGetFeAdminValue('preview');
00679 
00680                                 // If admin panel preview is enabled...
00681                         if ($this->fePreview)   {
00682                                 $fe_user_OLD_USERGROUP = $this->fe_user->user['usergroup'];
00683 
00684                                 $this->showHiddenPage = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','showHiddenPages');
00685                                 $this->showHiddenRecords = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','showHiddenRecords');
00686                                         // simulate date
00687                                 $simTime = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','simulateDate');
00688                                 if ($simTime)   $GLOBALS['SIM_EXEC_TIME']=$simTime;
00689                                         // simulate user
00690                                 $simUserGroup = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','simulateUserGroup');
00691                                 $this->simUserGroup = $simUserGroup;
00692                                 if ($simUserGroup)      $this->fe_user->user['usergroup']=$simUserGroup;
00693                                 if (!$simUserGroup && !$simTime && !$this->showHiddenPage && !$this->showHiddenRecords) {
00694                                         $this->fePreview=0;
00695                                 }
00696                         }
00697 
00698                                 // Now it's investigated if the raw page-id points to a hidden page and if so, the flag is set.
00699                                 // This does not require the preview flag to be set in the admin panel
00700                         if ($this->id)  {
00701                                 $idQ = t3lib_div::testInt($this->id) ? 'uid='.intval($this->id) : 'alias='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, 'pages').' AND pid>=0';        // pid>=0 added for the sake of versioning...
00702                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('hidden', 'pages', $idQ.' AND hidden!=0 AND deleted=0');
00703                                 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {
00704                                         $this->fePreview = 1;   // The preview flag is set only if the current page turns out to actually be hidden!
00705                                         $this->showHiddenPage = 1;
00706                                 }
00707 
00708                                         // Check root line for proper connection to tree root (done because of possible preview of page / branch versions)
00709                                 if (!$this->fePreview)  {
00710 
00711                                                 // Initialize the page-select functions to check rootline:
00712                                         $temp_sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
00713                                         $temp_sys_page->init($this->showHiddenPage);
00714 
00715                                                 // If root line contained NO records and ->error_getRootLine_failPid tells us that it was because of a pid=-1 (indicating a "version" record)...:
00716                                         if (!count($temp_sys_page->getRootLine($this->id,$this->MP)) && $temp_sys_page->error_getRootLine_failPid==-1)  {
00717 
00718                                                         // Setting versioningPreview flag and try again:
00719                                                 $temp_sys_page->versioningPreview = TRUE;
00720                                                 if (count($temp_sys_page->getRootLine($this->id,$this->MP)))    {
00721                                                                 // Finally, we got a root line (meaning that it WAS due to versioning preview of a page somewhere) and we set the fePreview flag which in itself will allow sys_page class to display previews of versionized records.
00722                                                         $this->fePreview = 1;
00723 #debug('version in rootline...');
00724                                                 }
00725                                         }
00726                                 }
00727                         }
00728 
00729                                 // Checking for specific version preview of records:
00730                         if (is_array(t3lib_div::_GP('ADMCMD_vPrev')))   {
00731                                 $this->fePreview = 1;
00732                                 $this->versionPreviewMap = t3lib_div::_GP('ADMCMD_vPrev');
00733                         }
00734 
00735                         if ($this->fePreview)   {       // If the front-end is showing a preview, caching MUST be disabled.
00736                                 $this->set_no_cache();
00737                         }
00738                 }
00739                 $GLOBALS['TT']->pull();
00740 
00741                         // Now, get the id, validate access etc:
00742                 $this->fetch_the_id();
00743 
00744                         // Check if backend user has read access to this page. If not, recalculate the id.
00745                 if ($this->beUserLogin && $this->fePreview)     {
00746                         if (!$GLOBALS['BE_USER']->doesUserHaveAccess($this->page,1))    {
00747                                         // Resetting
00748                                 $this->clear_preview();
00749                                 $this->fe_user->user['usergroup'] = $fe_user_OLD_USERGROUP;
00750 
00751                                         // Fetching the id again, now with the preview settings reset.
00752                                 $this->fetch_the_id();
00753                         }
00754                 }
00755 
00756                         // Checks if user logins are blocked for a certain branch and if so, will unset user login and re-fetch ID.
00757                 $this->loginAllowedInBranch = $this->checkIfLoginAllowedInBranch();
00758                 if (!$this->loginAllowedInBranch)       {       // Logins are not allowed:
00759                         if ($this->isUserOrGroupSet())  {       // Only if there is a login will we run this...
00760 
00761                                         // Clear out user and group:
00762                                 unset($this->fe_user->user);
00763                                 $this->gr_list = '0,-1';
00764 
00765                                         // Fetching the id again, now with the preview settings reset.
00766                                 $this->fetch_the_id();
00767                         }
00768                 }
00769 
00770                         // Final cleaning.
00771                 $this->id = $this->contentPid = intval($this->id);      // Make sure it's an integer
00772                 $this->type = intval($this->type);      // Make sure it's an integer
00773 
00774                         // Call post processing function for id determination:
00775                 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'])) {
00776                         $_params = array('pObj' => &$this);
00777                         foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'] as $_funcRef)  {
00778                                 t3lib_div::callUserFunction($_funcRef,$_params,$this);
00779                         }
00780                 }
00781         }
00782 
00791         function fetch_the_id() {
00792                 $GLOBALS['TT']->push('fetch_the_id initialize/','');
00793 
00794                         // Initialize the page-select functions.
00795                 $this->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
00796                 $this->sys_page->init($this->showHiddenPage);
00797                 $this->sys_page->versioningPreview = $this->fePreview ? TRUE : FALSE;
00798                 if ($this->sys_page->versioningPreview) {
00799                         $this->sys_page->versionPreviewMap = $this->versionPreviewMap;
00800                 }
00801 
00802                         // Set the valid usergroups for FE
00803                 $this->initUserGroups();
00804 
00805                         // Sets sys_page where-clause
00806                 $this->setSysPageWhereClause();
00807 
00808                         // Splitting $this->id by a period (.). First part is 'id' and second part - if exists - will overrule the &type param if given
00809                 $pParts = explode('.',$this->id);
00810                 $this->id = $pParts[0]; // Set it.
00811                 if (isset($pParts[1]))  {$this->type=$pParts[1];}
00812 
00813                         // Splitting $this->id by a comma (,). First part is 'id' and other parts are just stored for use in scripts.
00814                 $this->idParts = explode(',',$this->id);
00815 
00816                         // Splitting by a '+' sign - used for base64/md5 methods of parameter encryption for simulate static documents.
00817                 list($pgID,$SSD_p)=explode('+',$this->idParts[0],2);
00818                 if ($SSD_p)     {       $this->idPartsAnalyze($SSD_p);  }
00819                 $this->id = $pgID;      // Set id
00820 
00821                         // If $this->id is a string, it's an alias
00822                 $this->checkAndSetAlias();
00823 
00824                         // The id and type is set to the integer-value - just to be sure...
00825                 $this->id = intval($this->id);
00826                 $this->type = intval($this->type);
00827                 $GLOBALS['TT']->pull();
00828 
00829                         // We find the first page belonging to the current domain
00830                 $GLOBALS['TT']->push('fetch_the_id domain/','');
00831                 $this->domainStartPage = $this->findDomainRecord($this->TYPO3_CONF_VARS['SYS']['recursiveDomainSearch']);       // the page_id of the current domain
00832                 if (!$this->id) {
00833                         if ($this->domainStartPage)     {
00834                                 $this->id = $this->domainStartPage;     // If the id was not previously set, set it to the id of the domain.
00835                         } else {
00836                                 $theFirstPage = $this->sys_page->getFirstWebPage($this->id);    // Find the first 'visible' page in that domain
00837                                 if ($theFirstPage)      {
00838                                         $this->id = $theFirstPage['uid'];
00839                                 } else {
00840                                         $this->printError('No pages are found on the rootlevel!');
00841                                         exit;
00842                                 }
00843                         }
00844                 }
00845                 $GLOBALS['TT']->pull();
00846 
00847                 $GLOBALS['TT']->push('fetch_the_id rootLine/','');
00848                 $requestedId = $this->id;               // We store the originally requested id
00849                 $this->getPageAndRootlineWithDomain($this->domainStartPage);
00850                 $GLOBALS['TT']->pull();
00851 
00852                 if ($this->pageNotFound && $this->TYPO3_CONF_VARS['FE']['pageNotFound_handling'])       {
00853                         $pNotFoundMsg = array(
00854                                 1 => 'ID was not an accessible page',
00855                                 2 => 'Subsection was found and not accessible',
00856                                 3 => 'ID was outside the domain',
00857                         );
00858                         $this->pageNotFoundAndExit($pNotFoundMsg[$this->pageNotFound]);
00859                 }
00860 
00861                         // set no_cache if set
00862                 if ($this->page['no_cache'])    {
00863                         $this->set_no_cache();
00864                 }
00865 
00866                         // Init SYS_LASTCHANGED
00867                 $this->register['SYS_LASTCHANGED'] = intval($this->page['tstamp']);
00868                 if ($this->register['SYS_LASTCHANGED'] < intval($this->page['SYS_LASTCHANGED']))        {
00869                         $this->register['SYS_LASTCHANGED'] = intval($this->page['SYS_LASTCHANGED']);
00870                 }
00871         }
00872 
00886         function getPageAndRootline() {
00887                 $this->page = $this->sys_page->getPage($this->id);
00888                 if (!count($this->page))        {
00889                                 // If no page, we try to find the page before in the rootLine.
00890                         $this->pageNotFound=1;                  // Page is 'not found' in case the id itself was not an accessible page. code 1
00891                         $this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
00892                         if (count($this->rootLine))     {
00893                                 $c=count($this->rootLine)-1;
00894                                 while($c>0)     {
00895 
00896                                                 // Add to page access failure history:
00897                                         $this->pageAccessFailureHistory['direct_access'][] = $this->rootLine[$c];
00898 
00899                                                 // Decrease to next page in rootline and check the access to that, if OK, set as page record and ID value.
00900                                         $c--;
00901                                         $this->id = $this->rootLine[$c]['uid'];
00902                                         $this->page = $this->sys_page->getPage($this->id);
00903                                         if (count($this->page)){ break; }
00904                                 }
00905                         }
00906                                 // If still no page...
00907                         if (!count($this->page))        {
00908                                 if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling'])      {
00909                                         $this->pageNotFoundAndExit('The requested page does not exist!');
00910                                 } else {
00911                                         $this->printError('The requested page does not exist!');
00912                                         exit;
00913                                 }
00914                         }
00915                 }
00916                         // Is the ID a link to another page??
00917                 if ($this->page['doktype']==4)  {
00918                         $this->MP = '';         // We need to clear MP if the page is a shortcut. Reason is if the short cut goes to another page, then we LEAVE the rootline which the MP expects.
00919                         $this->page = $this->getPageShortcut($this->page['shortcut'],$this->page['shortcut_mode'],$this->page['uid']);
00920                         $this->id = $this->page['uid'];
00921                 }
00922                         // Gets the rootLine
00923                 $this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
00924 
00925                         // If not rootline we're off...
00926                 if (!count($this->rootLine))    {
00927                         $this->printError('The requested page didn\'t have a proper connection to the tree-root! <br /><br />('.$this->sys_page->error_getRootLine.')');
00928                         exit;
00929                 }
00930 
00931                         // Checking for include section regarding the hidden/starttime/endtime/fe_user (that is access control of a whole subbranch!)
00932                 if ($this->checkRootlineForIncludeSection())    {
00933                         if (!count($this->rootLine))    {
00934                                 $this->printError('The requested page was not accessible!');
00935                                 exit;
00936                         } else {
00937                                 $el = reset($this->rootLine);
00938                                 $this->id = $el['uid'];
00939                                 $this->page = $this->sys_page->getPage($this->id);
00940                                 $this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
00941                         }
00942                 }
00943         }
00944 
00957         function getPageShortcut($SC,$mode,$thisUid,$itera=20,$pageLog=array()) {
00958                 $idArray = t3lib_div::intExplode(',',$SC);
00959 
00960                         // Find $page record depending on shortcut mode:
00961                 switch($mode)   {
00962                         case 1:
00963                         case 2:
00964                                 $pageArray = $this->sys_page->getMenu($idArray[0]?$idArray[0]:$thisUid,'*','sorting','AND pages.doktype<199 AND pages.doktype!=6');
00965                                 $pO = 0;
00966                                 if ($mode==2 && count($pageArray))      {       // random
00967                                         $this->make_seed();
00968                                         $randval = intval(rand(0,count($pageArray)-1));
00969                                         $pO = $randval;
00970                                 }
00971                                 $c = 0;
00972                                 reset($pageArray);
00973                                 while(list(,$pV)=each($pageArray))      {
00974                                         if ($c==$pO)    {
00975                                                 $page = $pV;
00976                                                 break;
00977                                         }
00978                                         $c++;
00979                                 }
00980                         break;
00981                         default:
00982                                 $page = $this->sys_page->getPage($idArray[0]);
00983                         break;
00984                 }
00985 
00986                         // Check if short cut page was a shortcut itself, if so look up recursively:
00987                 if ($page['doktype']==4)        {
00988                         if (!in_array($page['uid'],$pageLog) && $itera>0)       {
00989                                 $pageLog[] = $page['uid'];
00990                                 $page = $this->getPageShortcut($page['shortcut'],$page['shortcut_mode'],$page['uid'],$itera-1,$pageLog);
00991                         } else {
00992                                 $pageLog[] = $page['uid'];
00993                                 $this->printError('Page shortcuts were looping in uids '.implode(',',$pageLog).'...!');
00994                                 exit;
00995                         }
00996                 }
00997                         // Return resulting page:
00998                 return $page;
00999         }
01000 
01007         function checkRootlineForIncludeSection()       {
01008                 $c=count($this->rootLine);
01009                 $removeTheRestFlag=0;
01010 
01011                 for ($a=0;$a<$c;$a++)   {
01012                         if (!$this->checkPagerecordForIncludeSection($this->rootLine[$a]))      {
01013                                         // Add to page access failure history:
01014                                 $this->pageAccessFailureHistory['sub_section'][] = $this->rootLine[$a];
01015                                 $removeTheRestFlag=1;
01016                         }
01017                         if ($this->rootLine[$a]['doktype']==6)  {
01018                                 if ($this->beUserLogin) {       // If there is a backend user logged in, check if he has read access to the page:
01019                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'uid='.intval($this->id).' AND '.$GLOBALS['BE_USER']->getPagePermsClause(1));
01020                                         list($isPage) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
01021                                         if (!$isPage)   $removeTheRestFlag=1;   // If there was no page selected, the user apparently did not have read access to the current PAGE (not position in rootline) and we set the remove-flag...
01022                                 } else {        // Dont go here, if there is no backend user logged in.
01023                                         $removeTheRestFlag=1;
01024                                 }
01025                         }
01026                         if ($removeTheRestFlag) {
01027                                 $this->pageNotFound=2;                  // Page is 'not found' in case a subsection was found and not accessible, code 2
01028                                 unset($this->rootLine[$a]);
01029                         }
01030                 }
01031                 return $removeTheRestFlag;
01032         }
01033 
01044         function checkEnableFields($row,$bypassGroupCheck=FALSE)        {
01045                 if ((!$row['hidden'] || $this->showHiddenPage)
01046                         && $row['starttime']<=$GLOBALS['SIM_EXEC_TIME']
01047                         && ($row['endtime']==0 || $row['endtime']>$GLOBALS['SIM_EXEC_TIME'])
01048                         && ($bypassGroupCheck || $this->checkPageGroupAccess($row))
01049                 ) { return TRUE; }
01050         }
01051 
01060         function checkPageGroupAccess($row, $groupList=NULL) {
01061                 if(is_null($groupList)) {
01062                         $groupList = $this->gr_list;
01063                 }
01064                 if(!is_array($groupList)) {
01065                         $groupList = explode(',', $groupList);
01066                 }
01067                 $pageGroupList = explode(',', $row['fe_group']);
01068                 return count(array_intersect($groupList, $pageGroupList)) > 0;
01069         }
01070 
01079         function checkPagerecordForIncludeSection($row) {
01080                 return (!$row['extendToSubpages'] || $this->checkEnableFields($row)) ? 1 : 0;
01081         }
01082 
01088         function checkIfLoginAllowedInBranch()  {
01089 
01090                         // Initialize:
01091                 $c = count($this->rootLine);
01092                 $disable = FALSE;
01093 
01094                         // Traverse root line from root and outwards:
01095                 for ($a=0; $a<$c; $a++) {
01096 
01097                                 // If a value is set for login state:
01098                         if ($this->rootLine[$a]['fe_login_mode'] > 0)   {
01099 
01100                                         // Determine state from value:
01101                                 $disable = (int)$this->rootLine[$a]['fe_login_mode'] === 1 ? TRUE : FALSE;
01102                         }
01103                 }
01104 
01105                 return !$disable;
01106         }
01107 
01113         function getPageAccessFailureReasons()  {
01114                 $output = array();
01115 
01116                 $combinedRecords = array_merge(
01117                         is_array($this->pageAccessFailureHistory['direct_access']) ? $this->pageAccessFailureHistory['direct_access'] : array(array('fe_group'=>0)),    // Adding fake first record for direct access if none, otherwise $k==0 below will be indicating a sub-section record to be first direct_access record which is of course false!
01118                         is_array($this->pageAccessFailureHistory['sub_section']) ? $this->pageAccessFailureHistory['sub_section'] : array()
01119                 );
01120 
01121                 if (count($combinedRecords))    {
01122                         foreach($combinedRecords as $k => $pagerec)     {
01123                                 // If $k=0 then it is the very first page the original ID was pointing at and that will get a full check of course
01124                                 // If $k>0 it is parent pages being tested. They are only significant for the access to the first page IF they had the extendToSubpages flag set, hence checked only then!
01125                                 if (!$k || $pagerec['extendToSubpages'])        {
01126                                         if ($pagerec['hidden']) $output['hidden'][$pagerec['uid']] = TRUE;
01127                                         if ($pagerec['starttime'] > $GLOBALS['SIM_EXEC_TIME'])  $output['starttime'][$pagerec['uid']] = $pagerec['starttime'];
01128                                         if ($pagerec['endtime']!=0 && $pagerec['endtime'] <= $GLOBALS['SIM_EXEC_TIME']) $output['endtime'][$pagerec['uid']] = $pagerec['endtime'];
01129                                         if (!$this->checkPageGroupAccess($pagerec))     $output['fe_group'][$pagerec['uid']] = $pagerec['fe_group'];
01130                                 }
01131                         }
01132                 }
01133 
01134                 return $output;
01135         }
01136 
01145         function setIDfromArgV()        {
01146                 if (!$this->id) {
01147                         list($theAlias) = explode('&',t3lib_div::getIndpEnv('QUERY_STRING'));
01148                         $theAlias = trim($theAlias);
01149                         $this->id = $theAlias ? $theAlias : 0;
01150                 }
01151         }
01152 
01161         function getPageAndRootlineWithDomain($domainStartPage) {
01162                 $this->getPageAndRootline();
01163 
01164                 // 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.
01165                 if ($domainStartPage && is_array($this->rootLine)) {
01166                         reset ($this->rootLine);
01167                         $idFound = 0;
01168                         while(list($key,$val)=each($this->rootLine)) {
01169                                 if ($val['uid']==$domainStartPage)      {
01170                                         $idFound=1;
01171                                         break;
01172                                 }
01173                         }
01174                         if (!$idFound)  {
01175                                 $this->pageNotFound=3;                  // Page is 'not found' in case the id was outside the domain, code 3
01176                                 $this->id = $domainStartPage;
01177                                 $this->getPageAndRootline();            //re-get the page and rootline if the id was not found.
01178                         }
01179                 }
01180         }
01181 
01188         function setSysPageWhereClause() {
01189                 $this->sys_page->where_hid_del.=' AND doktype<200';
01190                 $this->sys_page->where_groupAccess = $this->getPagesGroupClause();
01191         }
01192 
01199         function getPagesGroupClause() {
01200                 return ' AND fe_group IN ('.$this->gr_list.')';
01201         }
01202 
01210         function findDomainRecord($recursive=0) {
01211                 if ($recursive) {
01212                         $host = explode('.',t3lib_div::getIndpEnv('HTTP_HOST'));
01213                         while(count($host))     {
01214                                 $pageUid = $this->sys_page->getDomainStartPage(implode('.',$host),t3lib_div::getIndpEnv('SCRIPT_NAME'),t3lib_div::getIndpEnv('REQUEST_URI'));
01215                                 if ($pageUid)   return $pageUid; else array_shift($host);
01216                         }
01217                         return $pageUid;
01218                 } else {
01219                         return $this->sys_page->getDomainStartPage(t3lib_div::getIndpEnv('HTTP_HOST'),t3lib_div::getIndpEnv('SCRIPT_NAME'),t3lib_div::getIndpEnv('REQUEST_URI'));
01220                 }
01221         }
01222 
01229         function pageNotFoundAndExit($reason='')        {
01230                 $this->pageNotFoundHandler($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling'], $this->TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'], $reason);
01231                 exit;
01232         }
01233 
01243         function pageNotFoundHandler($code, $header='', $reason='')     {
01244                         // Issue header in any case:
01245                 if ($header)    {header($header);}
01246 
01247                         // Create response:
01248                 if (gettype($code)=='boolean' || !strcmp($code,1))      {       // Simply boolean; Just shows TYPO3 error page with reason:
01249                         $this->printError('The page did not exist or was inaccessible.'.($reason ? ' Reason: '.htmlspecialchars($reason) : ''));
01250                         exit;
01251                 } elseif (t3lib_div::isFirstPartOfStr($code,'USER_FUNCTION:')) {
01252                         $funcRef = trim(substr($code,14));
01253                         $params = array(
01254                                 'currentUrl' => t3lib_div::getIndpEnv('REQUEST_URI'),
01255                                 'reasonText' => $reason,
01256                                 'pageAccessFailureReasons' => $this->getPageAccessFailureReasons()
01257                         );
01258                         echo t3lib_div::callUserFunction($funcRef,$params,$this);
01259                         exit;
01260                 } elseif (t3lib_div::isFirstPartOfStr($code,'READFILE:')) {
01261                         $readFile = t3lib_div::getFileAbsFileName(trim(substr($code,9)));
01262                         if (@is_file($readFile))        {
01263                                 $fileContent = t3lib_div::getUrl($readFile);
01264                                 $fileContent = str_replace('###CURRENT_URL###', t3lib_div::getIndpEnv('REQUEST_URI'), $fileContent);
01265                                 $fileContent = str_replace('###REASON###', htmlspecialchars($reason), $fileContent);
01266                                 echo $fileContent;
01267                         } else {
01268                                 $this->printError('Configuration Error: 404 page "'.$readFile.'" could not be found.');
01269                         }
01270                         exit;
01271                 } elseif (strlen($code)) {
01272                         header('Location: '.t3lib_div::locationHeaderUrl($code));
01273                         exit;
01274                 } else {
01275                         $this->printError('Error.'.($reason ? ' Reason: '.htmlspecialchars($reason) : ''));
01276                         exit;
01277                 }
01278         }
01279 
01287         function checkAndSetAlias()     {
01288                 if ($this->id && !t3lib_div::testInt($this->id))        {
01289                         $aid = $this->sys_page->getPageIdFromAlias($this->id);
01290                         if ($aid)       {$this->id=$aid;}
01291                 }
01292         }
01293 
01302         function idPartsAnalyze($str)   {
01303                 $GET_VARS = '';
01304                 switch(substr($str,0,2))        {
01305                         case 'B6':
01306                                 $addParams = base64_decode(str_replace('_','=',str_replace('-','/',substr($str,2))));
01307                                 parse_str($addParams,$GET_VARS);
01308                         break;
01309                         case 'M5':
01310                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('params', 'cache_md5params', 'md5hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr(substr($str,2), 'cache_md5params'));
01311                                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
01312 
01313                                 $this->updateMD5paramsRecord(substr($str,2));
01314                                 parse_str($row['params'],$GET_VARS);
01315                         break;
01316                 }
01317 
01318                 $this->mergingWithGetVars($GET_VARS);
01319         }
01320 
01327         function mergingWithGetVars($GET_VARS)  {
01328                 if (is_array($GET_VARS))        {
01329                         $realGet = t3lib_div::_GET();           // Getting $_GET var, unescaped.
01330                         if (!is_array($realGet))        $realGet = array();
01331 
01332                                 // Merge new values on top:
01333                         $realGet = t3lib_div::array_merge_recursive_overrule($realGet,$GET_VARS);
01334 
01335                                 // Write values back to $_GET:
01336                         t3lib_div::_GETset($realGet);
01337 
01338                                 // Setting these specifically (like in the init-function):
01339                         if (isset($GET_VARS['type']))           $this->type = intval($GET_VARS['type']);
01340                         if (isset($GET_VARS['cHash']))          $this->cHash = $GET_VARS['cHash'];
01341                         if (isset($GET_VARS['jumpurl']))        $this->jumpurl = $GET_VARS['jumpurl'];
01342                         if (isset($GET_VARS['MP']))                     $this->MP = $this->TYPO3_CONF_VARS['FE']['enable_mount_pids'] ? $GET_VARS['MP'] : '';
01343 
01344                         if (isset($GET_VARS['no_cache']) && $GET_VARS['no_cache'])      $this->set_no_cache();
01345                 }
01346         }
01347 
01348 
01349 
01350 
01351 
01352 
01353 
01354 
01355 
01356 
01357 
01358 
01359 
01360 
01361 
01362 
01363 
01364         /********************************************
01365          *
01366          * Template and caching related functions.
01367          *
01368          *******************************************/
01369 
01376         function makeCacheHash()        {
01377                 $GET = t3lib_div::_GET();
01378                 if ($this->cHash && is_array($GET))     {
01379                         $this->cHash_array = t3lib_div::cHashParams(t3lib_div::implodeArrayForUrl('',$GET));
01380                         $cHash_calc = t3lib_div::shortMD5(serialize($this->cHash_array));
01381 
01382                         if ($cHash_calc!=$this->cHash)  {
01383                                 if ($this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
01384