📄 class.tslib_fe.php
字号:
// Clean up. $gr_array = array_unique($gr_array); // Make unique... sort($gr_array); // sort if (count($gr_array)) { $this->gr_list.=','.implode(',',$gr_array); } if ($this->fe_user->writeDevLog) t3lib_div::devLog('Valid usergroups for TSFE: '.$this->gr_list, 'tslib_fe'); } /** * Checking if a user is logged in or a group constellation different from "0,-1" * * @return boolean TRUE if either a login user is found (array fe_user->user) OR if the gr_list is set to something else than '0,-1' (could be done even without a user being logged in!) */ function isUserOrGroupSet() { return is_array($this->fe_user->user) || $this->gr_list!=='0,-1'; } /** * Provides ways to bypass the '?id=[xxx]&type=[xx]' format, using either PATH_INFO or virtual HTML-documents (using Apache mod_rewrite) * * Three options: * 1) Apache mod_rewrite: Here a .htaccess file maps all .html-files to index.php and then we extract the id and type from the name of that HTML-file. (AKA "simulateStaticDocuments") * 2) Use PATH_INFO (also Apache) to extract id and type from that var. Does not require any special modules compiled with apache. (less typical) * 3) Using hook which enables features like those provided from "realurl" extension (AKA "Speaking URLs") * * Support for RewriteRule to generate (simulateStaticDocuments) * With the mod_rewrite compiled into apache, put these lines into a .htaccess in this directory: * RewriteEngine On * RewriteRule ^[^/]*\.html$ index.php * The url must end with '.html' and the format must comply with either of these: * 1: '[title].[id].[type].html' - title is just for easy recognition in the logfile!; no practical use of the title for TYPO3. * 2: '[id].[type].html' - above, but title is omitted; no practical use of the title for TYPO3. * 3: '[id].html' - only id, type is set to the default, zero! * NOTE: In all case 'id' may be the uid-number OR the page alias (if any) * * @return void * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&cHash=4ad9d7acb4 */ function checkAlternativeIdMethods() { $this->siteScript = t3lib_div::getIndpEnv('TYPO3_SITE_SCRIPT'); // Resolving of "simulateStaticDocuments" URLs: 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 $uParts = parse_url($this->siteScript); // Parse the path: $fI = t3lib_div::split_fileref($uParts['path']); if (!$fI['path'] && $fI['file'] && substr($fI['file'],-5)=='.html') { $parts = explode('.',$fI['file']); $pCount = count($parts); if ($pCount>2) { $this->type = intval($parts[$pCount-2]); $this->id = $parts[$pCount-3]; } else { $this->type = 0; $this->id = $parts[0]; } } } // If PATH_INFO if (t3lib_div::getIndpEnv('PATH_INFO')) { // If pathinfo contains stuff... $parts=t3lib_div::trimExplode('/',t3lib_div::getIndpEnv('PATH_INFO'),1); $parts[]='html'; $pCount = count($parts); if ($pCount>2) { $this->type = intval($parts[$pCount-2]); $this->id = $parts[$pCount-3]; } else { $this->type = 0; $this->id = $parts[0]; } $this->absRefPrefix_force=1; } // Call post processing function for custom URL methods. if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'])) { $_params = array('pObj' => &$this); foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'] as $_funcRef) { t3lib_div::callUserFunction($_funcRef,$_params,$this); } } } /** * Clears the preview-flags, sets sim_exec_time to current time. * Hidden pages must be hidden as default, $GLOBALS['SIM_EXEC_TIME'] is set to $GLOBALS['EXEC_TIME'] in t3lib/config_default.inc. Alter it by adding or subtracting seconds. * * @return void */ function clear_preview() { $this->showHiddenPage = 0; $this->showHiddenRecords = 0; $GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME']; $this->fePreview = 0; } /** * Determines the id and evaluates any preview settings * Basically this function is about determining whether a backend user is logged in, if he has read access to the page and if he's previewing the page. That all determines which id to show and how to initialize the id. * * @return void */ function determineId() { // Getting ARG-v values if some $this->setIDfromArgV(); // If there is a Backend login we are going to check for any preview settings: $GLOBALS['TT']->push('beUserLogin',''); if ($this->beUserLogin || $this->doWorkspacePreview()) { // Backend user preview features: if ($this->beUserLogin) { $this->fePreview = $GLOBALS['BE_USER']->extGetFeAdminValue('preview') ? 1 : 0; // If admin panel preview is enabled... if ($this->fePreview) { $fe_user_OLD_USERGROUP = $this->fe_user->user['usergroup']; $this->showHiddenPage = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','showHiddenPages'); $this->showHiddenRecords = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','showHiddenRecords'); // simulate date $simTime = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','simulateDate'); if ($simTime) $GLOBALS['SIM_EXEC_TIME']=$simTime; // simulate user $simUserGroup = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','simulateUserGroup'); $this->simUserGroup = $simUserGroup; if ($simUserGroup) $this->fe_user->user['usergroup']=$simUserGroup; if (!$simUserGroup && !$simTime && !$this->showHiddenPage && !$this->showHiddenRecords) { $this->fePreview=0; } } } if ($this->id) { // Now it's investigated if the raw page-id points to a hidden page and if so, the flag is set. // This does not require the preview flag to be set in the admin panel $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... $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('hidden', 'pages', $idQ.' AND hidden!=0 AND deleted=0'); if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { $this->fePreview = 1; // The preview flag is set only if the current page turns out to actually be hidden! $this->showHiddenPage = 1; } // For Live workspace: Check root line for proper connection to tree root (done because of possible preview of page / branch versions) if (!$this->fePreview && $this->whichWorkspace()===0) { // 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) { // Setting versioningPreview flag and try again: $temp_sys_page->versioningPreview = TRUE; if (count($temp_sys_page->getRootLine($this->id,$this->MP))) { // 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. $this->fePreview = 1; } } } } // The preview flag will be set if a backend user is in an offline workspace if (($GLOBALS['BE_USER']->user['workspace_preview'] || t3lib_div::_GP('ADMCMD_view') || $this->doWorkspacePreview()) && ($this->whichWorkspace()===-1 || $this->whichWorkspace()>0)) { $this->fePreview = 2; // Will show special preview message. } // If the front-end is showing a preview, caching MUST be disabled. if ($this->fePreview) { $this->set_no_cache(); } } $GLOBALS['TT']->pull(); // Now, get the id, validate access etc: $this->fetch_the_id(); // Check if backend user has read access to this page. If not, recalculate the id. if ($this->beUserLogin && $this->fePreview) { if (!$GLOBALS['BE_USER']->doesUserHaveAccess($this->page,1)) { // Resetting $this->clear_preview(); $this->fe_user->user['usergroup'] = $fe_user_OLD_USERGROUP; // Fetching the id again, now with the preview settings reset. $this->fetch_the_id(); } } // Checks if user logins are blocked for a certain branch and if so, will unset user login and re-fetch ID. $this->loginAllowedInBranch = $this->checkIfLoginAllowedInBranch(); if (!$this->loginAllowedInBranch) { // Logins are not allowed: if ($this->isUserOrGroupSet()) { // Only if there is a login will we run this... // Clear out user and group: unset($this->fe_user->user); $this->gr_list = '0,-1'; // Fetching the id again, now with the preview settings reset. $this->fetch_the_id(); } } // Final cleaning. $this->id = $this->contentPid = intval($this->id); // Make sure it's an integer $this->type = intval($this->type); // Make sure it's an integer // Look for alternative content PID if page is under version preview: if ($this->fePreview) { if ($this->page['_ORIG_pid']==-1 && $this->page['t3ver_swapmode']==0) { // Current page must have been an offline version and have swapmode set to 0: // Setting contentPid here for preview might not be completely correct to do. Strictly the "_ORIG_uid" value should be used for tables where "versioning_followPages" is set and for others not. However this is a working quick-fix to display content elements at least! $this->contentPid = $this->page['_ORIG_uid']; } } // Call post processing function for id determination: if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'])) { $_params = array('pObj' => &$this); foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'] as $_funcRef) { t3lib_div::callUserFunction($_funcRef,$_params,$this); } } } /** * Get The Page ID * This gets the id of the page, checks if the page is in the domain and if the page is accessible * Sets variables such as $this->sys_page, $this->loginUser, $this->gr_list, $this->id, $this->type, $this->domainStartPage, $this->idParts * * @return void * @access private */ function fetch_the_id() { $GLOBALS['TT']->push('fetch_the_id initialize/',''); // Initialize the page-select functions. $this->sys_page = t3lib_div::makeInstance('t3lib_pageSelect'); $this->sys_page->versioningPreview = $this->fePreview ? TRUE : FALSE; $this->sys_page->versioningWorkspaceId = $this->whichWorkspace(); $this->sys_page->init($this->showHiddenPage); // Set the valid usergroups for FE $this->initUserGroups(); // Sets sys_page where-clause $this->setSysPageWhereClause(); // Splitting $this->id by a period (.). First part is 'id' and second part - if exists - will overrule the &type param if given $pParts = explode('.',$this->id); $this->id = $pParts[0]; // Set it. if (isset($pParts[1])) {$this->type=$pParts[1];} // Splitting $this->id by a comma (,). First part is 'id' and other parts are just stored for use in scripts. $this->idParts = explode(',',$this->id); // Splitting by a '+' sign - used for base64/md5 methods of parameter encryption for simulate static documents. list($pgID,$SSD_p)=explode('+',$this->idParts[0],2); if ($SSD_p) { $this->idPartsAnalyze($SSD_p); } $this->id = $pgID; // Set id // If $this->id is a string, it's an alias $this->checkAndSetAlias(); // The id and type is set to the integer-value - just to be sure... $this->id = intval($this->id); $this->type = intval($this->type); $GLOBALS['TT']->pull(); // We find the first page belonging to the current domain $GLOBALS['TT']->push('fetch_the_id domain/',''); $this->domainStartPage = $this->findDomainRecord($this->TYPO3_CONF_VARS['SYS']['recursiveDomainSearch']); // the page_id of the current domain if (!$this->id) { if ($this->domainStartPage) { $this->id = $this->domainStartPage; // If the id was not previously set, set it to the id of the domain. } else { $theFirstPage = $this->sys_page->getFirstWebPage($this->id); // Find the first 'visible' page in that domain if ($theFirstPage) { $this->id = $theFirstPage['uid']; } else { $this->printError('No pages are found on the rootlevel!'); exit; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -