PageRenderTime 60ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/typo3/sysext/cms/tslib/class.tslib_fe.php

https://bitbucket.org/linxpinx/mercurial
PHP | 4842 lines | 2699 code | 633 blank | 1510 comment | 608 complexity | ead83ebf7bf2a0da8f2109371dd3e7a8 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
  6. * All rights reserved
  7. *
  8. * This script is part of the TYPO3 project. The TYPO3 project is
  9. * free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * The GNU General Public License can be found at
  15. * http://www.gnu.org/copyleft/gpl.html.
  16. * A copy is found in the textfile GPL.txt and important notices to the license
  17. * from the author is found in LICENSE.txt distributed with these scripts.
  18. *
  19. *
  20. * This script is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * This copyright notice MUST APPEAR in all copies of the script!
  26. ***************************************************************/
  27. /**
  28. * Class for the built TypoScript based Front End
  29. *
  30. * This class has a lot of functions and internal variable which are use from index_ts.php.
  31. * The class is instantiated as $GLOBALS['TSFE'] in index_ts.php.
  32. * The use of this class should be inspired by the order of function calls as found in index_ts.php.
  33. *
  34. * $Id: class.tslib_fe.php 8429 2010-07-28 09:19:00Z ohader $
  35. * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
  36. * XHTML compliant
  37. *
  38. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  39. */
  40. /**
  41. * [CLASS/FUNCTION INDEX of SCRIPT]
  42. *
  43. *
  44. *
  45. * 213: class tslib_fe
  46. * 382: function tslib_fe($TYPO3_CONF_VARS, $id, $type, $no_cache='', $cHash='', $jumpurl='',$MP='',$RDCT='')
  47. * 415: function connectToMySQL()
  48. * 425: function connectToDB()
  49. * 470: function sendRedirect()
  50. *
  51. * SECTION: Initializing, resolving page id
  52. * 508: function initFEuser()
  53. * 558: function initUserGroups()
  54. * 593: function isUserOrGroupSet()
  55. * 618: function checkAlternativeIdMethods()
  56. * 670: function clear_preview()
  57. * 683: function determineId()
  58. * 817: function fetch_the_id()
  59. * 911: function getPageAndRootline()
  60. * 994: function getPageShortcut($SC,$mode,$thisUid,$itera=20,$pageLog=array())
  61. * 1044: function checkRootlineForIncludeSection()
  62. * 1081: function checkEnableFields($row,$bypassGroupCheck=FALSE)
  63. * 1097: function checkPageGroupAccess($row, $groupList=NULL)
  64. * 1116: function checkPagerecordForIncludeSection($row)
  65. * 1125: function checkIfLoginAllowedInBranch()
  66. * 1150: function getPageAccessFailureReasons()
  67. * 1182: function setIDfromArgV()
  68. * 1198: function getPageAndRootlineWithDomain($domainStartPage)
  69. * 1225: function setSysPageWhereClause()
  70. * 1237: function findDomainRecord($recursive=0)
  71. * 1257: function pageNotFoundAndExit($reason='', $header='')
  72. * 1272: function pageNotFoundHandler($code, $header='', $reason='')
  73. * 1316: function checkAndSetAlias()
  74. * 1335: function idPartsAnalyze($str)
  75. * 1360: function mergingWithGetVars($GET_VARS)
  76. * 1390: function ADMCMD_preview()
  77. * 1433: function ADMCMD_preview_postInit($previewConfig)
  78. *
  79. * SECTION: Template and caching related functions.
  80. * 1465: function makeCacheHash()
  81. * 1489: function reqCHash()
  82. * 1511: function cHashParams($addQueryParams)
  83. * 1520: function initTemplate()
  84. * 1532: function getFromCache()
  85. * 1578: function getFromCache_queryRow()
  86. * 1608: function headerNoCache()
  87. * 1637: function getHash()
  88. * 1657: function getConfigArray()
  89. *
  90. * SECTION: Further initialization and data processing
  91. * 1818: function getCompressedTCarray()
  92. * 1872: function includeTCA($TCAloaded=1)
  93. * 1899: function settingLanguage()
  94. * 1992: function settingLocale()
  95. * 2017: function checkDataSubmission()
  96. * 2050: function fe_tce()
  97. * 2064: function locDataCheck($locationData)
  98. * 2080: function sendFormmail()
  99. * 2131: function extractRecipientCopy($bodytext)
  100. * 2145: function setExternalJumpUrl()
  101. * 2156: function checkJumpUrlReferer()
  102. * 2171: function jumpUrl()
  103. * 2215: function setUrlIdToken()
  104. *
  105. * SECTION: Page generation; cache handling
  106. * 2258: function isGeneratePage()
  107. * 2268: function tempPageCacheContent()
  108. * 2325: function realPageCacheContent()
  109. * 2355: function setPageCacheContent($content,$data,$tstamp)
  110. * 2382: function clearPageCacheContent()
  111. * 2392: function clearPageCacheContent_pidList($pidList)
  112. * 2426: function setSysLastChanged()
  113. *
  114. * SECTION: Page generation; rendering and inclusion
  115. * 2462: function generatePage_preProcessing()
  116. * 2484: function generatePage_whichScript()
  117. * 2496: function generatePage_postProcessing()
  118. * 2588: function INTincScript()
  119. * 2648: function INTincScript_loadJSCode()
  120. * 2689: function isINTincScript()
  121. * 2698: function doXHTML_cleaning()
  122. * 2707: function doLocalAnchorFix()
  123. *
  124. * SECTION: Finished off; outputting, storing session data, statistics...
  125. * 2738: function isOutputting()
  126. * 2761: function processOutput()
  127. * 2834: function sendCacheHeaders()
  128. * 2902: function isStaticCacheble()
  129. * 2915: function contentStrReplace()
  130. * 2941: function isEXTincScript()
  131. * 2950: function storeSessionData()
  132. * 2960: function setParseTime()
  133. * 2972: function statistics()
  134. * 3066: function previewInfo()
  135. * 3101: function hook_eofe()
  136. * 3117: function beLoginLinkIPList()
  137. * 3138: function addTempContentHttpHeaders()
  138. *
  139. * SECTION: Various internal API functions
  140. * 3184: function makeSimulFileName($inTitle,$page,$type,$addParams='',$no_cache='')
  141. * 3231: function simulateStaticDocuments_pEnc_onlyP_proc($linkVars)
  142. * 3260: function getSimulFileName()
  143. * 3271: function setSimulReplacementChar()
  144. * 3291: function fileNameASCIIPrefix($inTitle,$titleChars,$mergeChar='.')
  145. * 3314: function encryptEmail($string,$back=0)
  146. * 3340: function codeString($string, $decode=FALSE)
  147. * 3366: function roundTripCryptString($string)
  148. * 3386: function checkFileInclude($incFile)
  149. * 3401: function newCObj()
  150. * 3414: function setAbsRefPrefix()
  151. * 3428: function baseUrlWrap($url)
  152. * 3447: function printError($label,$header='Error!')
  153. * 3458: function updateMD5paramsRecord($hash)
  154. * 3469: function tidyHTML($content)
  155. * 3495: function prefixLocalAnchorsWithScript()
  156. * 3505: function workspacePreviewInit()
  157. * 3521: function doWorkspacePreview()
  158. * 3531: function whichWorkspace($returnTitle = FALSE)
  159. *
  160. * SECTION: Various external API functions - for use in plugins etc.
  161. * 3589: function getStorageSiterootPids()
  162. * 3604: function getPagesTSconfig()
  163. * 3637: function setJS($key,$content='')
  164. * 3677: function setCSS($key,$content)
  165. * 3692: function make_seed()
  166. * 3705: function uniqueHash($str='')
  167. * 3714: function set_no_cache()
  168. * 3724: function set_cache_timeout_default($seconds)
  169. * 3740: function plainMailEncoded($email,$subject,$message,$headers='')
  170. *
  171. * SECTION: Localization and character set conversion
  172. * 3784: function sL($input)
  173. * 3813: function readLLfile($fileRef)
  174. * 3824: function getLLL($index,$LOCAL_LANG)
  175. * 3838: function initLLvars()
  176. * 3872: function csConv($str,$from='')
  177. * 3890: function convOutputCharset($content,$label='')
  178. * 3903: function convPOSTCharset()
  179. *
  180. * TOTAL FUNCTIONS: 116
  181. * (This index is automatically created/updated by the extension "extdeveval")
  182. *
  183. */
  184. /**
  185. * Main frontend class, instantiated in the index_ts.php script as the global object TSFE
  186. *
  187. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  188. * @package TYPO3
  189. * @subpackage tslib
  190. */
  191. class tslib_fe {
  192. // CURRENT PAGE:
  193. var $id=''; // The page id (int)
  194. var $type=''; // RO The type (int)
  195. var $idParts=array(); // Loaded with the id, exploded by ','
  196. var $cHash=''; // The submitted cHash
  197. var $no_cache=''; // Page will not be cached. Write only true. Never clear value (some other code might have reasons to set it true)
  198. var $rootLine=''; // The rootLine (all the way to tree root, not only the current site!) (array)
  199. var $page=''; // The pagerecord (array)
  200. 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.
  201. protected $originalShortcutPage = null; // gets set when we are processing a page of type shortcut in the early stages opf init.php when we do not know about languages yet, used later in init.php to determine the correct shortcut in case a translation changes the shortcut target (array)
  202. /**
  203. * sys_page-object, pagefunctions
  204. *
  205. * @var t3lib_pageSelect
  206. */
  207. var $sys_page='';
  208. var $jumpurl='';
  209. var $pageNotFound=0; // Is set to 1 if a pageNotFound handler could have been called.
  210. var $domainStartPage=0; // Domain start page
  211. var $pageAccessFailureHistory=array(); // Array containing a history of why a requested page was not accessible.
  212. var $MP='';
  213. var $RDCT='';
  214. 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...
  215. 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.
  216. // USER
  217. /**
  218. * The FE user
  219. *
  220. * @var tslib_feUserAuth
  221. */
  222. var $fe_user='';
  223. 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.
  224. 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...
  225. var $beUserLogin=''; // Flag that indicates if a Backend user is logged in!
  226. var $workspacePreview=''; // Integer, that indicates which workspace is being previewed.
  227. var $loginAllowedInBranch = TRUE; // Shows whether logins are allowed in branch
  228. var $loginAllowedInBranch_mode = ''; // Shows specific mode (all or groups)
  229. var $ADMCMD_preview_BEUSER_uid = 0; // Integer, set to backend user ID to initialize when keyword-based preview is used.
  230. // PREVIEW
  231. 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. A value of 1 means ordinary preview, 2 means preview of a non-live workspace
  232. var $showHiddenPage=''; // Flag indicating that hidden pages should be shown, selected and so on. This goes for almost all selection of pages!
  233. 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.
  234. var $simUserGroup='0'; // Value that contains the simulated usergroup if any
  235. // CONFIGURATION
  236. 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.
  237. var $config=''; // "CONFIG" object from TypoScript. Array generated based on the TypoScript configuration of the current page. Saved with the cached pages.
  238. var $TCAcachedExtras=array(); // Array of cached information from TCA. This is NOT TCA itself!
  239. // TEMPLATE / CACHE
  240. /**
  241. * The TypoScript template object. Used to parse the TypoScript template
  242. *
  243. * @var t3lib_TStemplate
  244. */
  245. var $tmpl='';
  246. var $cacheTimeOutDefault=''; // Is set to the time-to-live time of cached pages. If false, default is 60*60*24, which is 24 hours.
  247. var $cacheContentFlag = 0; // Set internally if cached content is fetched from the database
  248. var $cacheExpires=0; // Set to the expire time of cached content
  249. var $isClientCachable=FALSE; // Set if cache headers allowing caching are sent.
  250. 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.
  251. var $sPre=''; // toplevel - objArrayName, eg 'page'
  252. var $pSetup=''; // TypoScript configuration of the page-object pointed to by sPre. $this->tmpl->setup[$this->sPre.'.']
  253. 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
  254. 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
  255. var $no_CacheBeforePageGen=''; // 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.
  256. var $tempContent = FALSE; // This flag indicates if temporary content went into the cache during page-generation.
  257. var $forceTemplateParsing=''; // Boolean, passed to TypoScript template class and tells it to render the template forcibly
  258. var $cHash_array=array(); // The array which cHash_calc is based on, see ->makeCacheHash().
  259. var $hash_base=''; // Loaded with the serialized array that is used for generating a hashstring for the cache
  260. var $pagesTSconfig=''; // May be set to the pagesTSconfig
  261. // PAGE-GENERATION / cOBJ
  262. /*
  263. Eg. insert JS-functions in this array ($additionalHeaderData) to include them once. Use associative keys.
  264. Keys in use:
  265. JSFormValidate : <script type="text/javascript" src="'.$GLOBALS["TSFE"]->absRefPrefix.'t3lib/jsfunc.validateform.js"></script>
  266. JSincludeFormupdate : <script type="text/javascript" src="t3lib/jsfunc.updateform.js"></script>
  267. JSMenuCode, JSMenuCode_menu : JavaScript for the JavaScript menu
  268. JSCode : reserved
  269. JSImgCode : reserved
  270. */
  271. 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[] = '...')
  272. var $additionalJavaScript=array(); // used to accumulate additional JavaScript-code. Works like additionalHeaderData. Reserved keys at 'openPic' and 'mouseOver'
  273. var $additionalCSS=array(); // used to accumulate additional Style code. Works like additionalHeaderData.
  274. 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
  275. 'onmousemove' => array(),
  276. 'onmouseup' => array(),
  277. 'onmousemove' => array(),
  278. 'onkeydown' => array(),
  279. 'onkeyup' => array(),
  280. 'onkeypress' => array(),
  281. 'onload' => array(),
  282. 'onunload' => array(),
  283. );
  284. /**
  285. * Adds JavaScript code
  286. *
  287. * @var string
  288. * @deprecated since TYPO3 3.5 - use additionalJavaScript instead.
  289. */
  290. var $JSCode='';
  291. var $JSImgCode=''; // Used to accumulate JavaScript loaded images (by menus)
  292. var $divSection=''; // Used to accumulate DHTML-layers.
  293. var $defaultBodyTag='<body>'; // Default bodytag, if nothing else is set. This can be overridden by applications like TemplaVoila.
  294. // RENDERING configuration, settings from TypoScript is loaded into these vars. See pagegen.php
  295. var $debug=''; // Debug flag, may output special debug html-code.
  296. var $intTarget=''; // Default internal target
  297. var $extTarget=''; // Default external target
  298. var $fileTarget=''; // Default file link target
  299. var $MP_defaults=array(); // Keys are page ids and values are default &MP (mount point) values to set when using the linking features...)
  300. var $spamProtectEmailAddresses=0; // If set, typolink() function encrypts email addresses. Is set in pagegen-class.
  301. var $absRefPrefix=''; // Absolute Reference prefix
  302. 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 '/'
  303. var $compensateFieldWidth=''; // Factor for form-field widths compensation
  304. var $lockFilePath=''; // Lock file path
  305. var $ATagParams=''; // <A>-tag parameters
  306. 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.
  307. var $sWordList=''; // Is set to the incoming array sword_list in case of a page-view jumped to from a search-result.
  308. 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.
  309. 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.
  310. 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.
  311. 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.
  312. var $sys_language_uid=0; // Site language, 0 (zero) is default, int+ is uid pointing to a sys_language record. Should reflect which language menus, templates etc is displayed in (master language) - but not necessarily the content which could be falling back to default (see sys_language_content)
  313. var $sys_language_mode=''; // Site language mode for content fall back.
  314. var $sys_language_content=0; // Site content selection uid (can be different from sys_language_uid if content is to be selected from a fall-back language. Depends on sys_language_mode)
  315. 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...]
  316. 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")
  317. // RENDERING data
  318. var $applicationData=Array(); // 'Global' Storage for various applications. Keys should be 'tx_'.extKey for extensions.
  319. var $register=Array();
  320. var $registerStack=Array(); // Stack used for storing array and retrieving register arrays (see LOAD_REGISTER and CLEAR_REGISTER)
  321. var $cObjectDepthCounter = 50; // Checking that the function is not called eternally. This is done by interrupting at a depth of 50
  322. var $recordRegister = Array(); // used by cObj->RECORDS and cObj->CONTENT to ensure the a records is NOT rendered twice through it!
  323. 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
  324. var $accessKey =array(); // Used by class tslib_menu to keep track of access-keys.
  325. 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.
  326. 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
  327. 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()
  328. var $uniqueString='';
  329. var $indexedDocTitle=''; // This value will be used as the title for the page in the indexer (if indexing happens)
  330. var $altPageTitle=''; // Alternative page title (normally the title of the page record). Can be set from applications you make.
  331. /**
  332. * An array that holds parameter names (keys) of GET parameters which MAY be MD5/base64 encoded with simulate_static_documents method.
  333. * @var array
  334. * @deprecated since TYPO3 4.3, remove in TYPO3 4.5
  335. */
  336. var $pEncAllowedParamNames=array();
  337. var $baseUrl=''; // The base URL set for the page header.
  338. var $anchorPrefix=''; // The proper anchor prefix needed when using speaking urls. (only set if baseUrl is set)
  339. /**
  340. * Page content render object
  341. *
  342. * @var tslib_cObj
  343. */
  344. var $cObj ='';
  345. // CONTENT accumulation
  346. var $content=''; // All page content is accumulated in this variable. See pagegen.php
  347. // GENERAL
  348. var $clientInfo=''; // Set to the browser: net / msie if 4+ browsers
  349. var $scriptParseTime=0;
  350. var $TCAloaded = 0; // Set ONLY if the full TCA is loaded
  351. // Character set (charset) conversion object:
  352. /**
  353. * charset conversion class. May be used by any application.
  354. *
  355. * @var t3lib_cs
  356. */
  357. var $csConvObj;
  358. var $defaultCharSet = 'iso-8859-1'; // The default charset used in the frontend if nothing else is set.
  359. var $renderCharset=''; // Internal charset of the frontend during rendering: Defaults to "forceCharset" and if that is not set, to ->defaultCharSet
  360. 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.
  361. var $localeCharset=''; // Assumed charset of locale strings.
  362. // LANG:
  363. var $lang=''; // Set to the system language key (used on the site)
  364. var $langSplitIndex=0; // Set to the index number of the language key
  365. var $LL_labels_cache=array();
  366. var $LL_files_cache=array();
  367. /**
  368. * Locking object
  369. *
  370. * @var t3lib_lock
  371. */
  372. var $pagesection_lockObj; // Locking object for accessing "cache_pagesection"
  373. /**
  374. * Locking object
  375. *
  376. * @var t3lib_lock
  377. */
  378. var $pages_lockObj; // Locking object for accessing "cache_pages"
  379. /**
  380. * @var t3lib_PageRenderer
  381. */
  382. protected $pageRenderer;
  383. /**
  384. * the page cache object, use this to save pages to the cache and to
  385. * retrieve them again
  386. *
  387. * @var t3lib_cache_AbstractBackend
  388. */
  389. protected $pageCache;
  390. protected $pageCacheTags = array();
  391. /**
  392. * Class constructor
  393. * Takes a number of GET/POST input variable as arguments and stores them internally.
  394. * The processing of these variables goes on later in this class.
  395. * Also sets internal clientInfo array (browser information) and a unique string (->uniqueString) for this script instance; A md5 hash of the microtime()
  396. *
  397. * @param array The global $TYPO3_CONF_VARS array. Will be set internally in ->TYPO3_CONF_VARS
  398. * @param mixed The value of t3lib_div::_GP('id')
  399. * @param integer The value of t3lib_div::_GP('type')
  400. * @param boolean The value of t3lib_div::_GP('no_cache'), evaluated to 1/0
  401. * @param string The value of t3lib_div::_GP('cHash')
  402. * @param string The value of t3lib_div::_GP('jumpurl')
  403. * @param string The value of t3lib_div::_GP('MP')
  404. * @param string The value of t3lib_div::_GP('RDCT')
  405. * @return void
  406. * @see index_ts.php
  407. */
  408. function tslib_fe($TYPO3_CONF_VARS, $id, $type, $no_cache='', $cHash='', $jumpurl='',$MP='',$RDCT='') {
  409. // Setting some variables:
  410. $this->TYPO3_CONF_VARS = $TYPO3_CONF_VARS;
  411. $this->id = $id;
  412. $this->type = $type;
  413. if ($no_cache) {
  414. if ($this->TYPO3_CONF_VARS['FE']['disableNoCacheParameter']) {
  415. $warning = '&no_cache=1 has been ignored because $TYPO3_CONF_VARS[\'FE\'][\'disableNoCacheParameter\'] is set!';
  416. $GLOBALS['TT']->setTSlogMessage($warning,2);
  417. } else {
  418. $warning = '&no_cache=1 has been supplied, so caching is disabled! URL: "'.t3lib_div::getIndpEnv('TYPO3_REQUEST_URL').'"';
  419. $this->disableCache();
  420. }
  421. t3lib_div::sysLog($warning, 'cms', 2);
  422. }
  423. $this->cHash = $cHash;
  424. $this->jumpurl = $jumpurl;
  425. $this->MP = $this->TYPO3_CONF_VARS['FE']['enable_mount_pids'] ? (string)$MP : '';
  426. $this->RDCT = $RDCT;
  427. $this->clientInfo = t3lib_div::clientInfo();
  428. $this->uniqueString=md5(microtime());
  429. $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
  430. // Call post processing function for constructor:
  431. if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'])) {
  432. $_params = array('pObj' => &$this);
  433. foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'] as $_funcRef) {
  434. t3lib_div::callUserFunction($_funcRef,$_params,$this);
  435. }
  436. }
  437. if (TYPO3_UseCachingFramework) {
  438. $this->initCaches();
  439. }
  440. }
  441. /**
  442. * Connect to MySQL database
  443. * May exit after outputting an error message or some JavaScript redirecting to the install tool.
  444. *
  445. * @return void
  446. * @deprecated since TYPO3 3.8, this function will be removed in TYPO3 4.5, use connectToDB() instead!
  447. */
  448. function connectToMySQL() {
  449. t3lib_div::logDeprecatedFunction();
  450. $this->connectToDB();
  451. }
  452. /**
  453. * Connect to SQL database
  454. * May exit after outputting an error message or some JavaScript redirecting to the install tool.
  455. *
  456. * @return void
  457. */
  458. function connectToDB() {
  459. try {
  460. $link = $GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
  461. } catch (RuntimeException $e) {
  462. if (TYPO3_db) {
  463. // Database is defined, this should normally not happen, user should be informed
  464. throw $e;
  465. }
  466. $link = FALSE;
  467. }
  468. if ($link !== FALSE) {
  469. if (!TYPO3_db) {
  470. $this->printError('No database selected','Database Error');
  471. // Redirects to the Install Tool:
  472. echo '<script type="text/javascript">
  473. /*<![CDATA[*/
  474. window.location.href = "'.TYPO3_mainDir.'install/index.php?mode=123&step=1&password=joh316";
  475. /*]]>*/
  476. </script>';
  477. exit;
  478. } elseif (!$GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db)) {
  479. if ($this->checkPageUnavailableHandler()) {
  480. $this->pageUnavailableAndExit('Cannot connect to the current database, "'.TYPO3_db.'"');
  481. } else {
  482. $message = 'Cannot connect to the current database, "'.TYPO3_db.'"';
  483. t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
  484. header('HTTP/1.0 503 Service Temporarily Unavailable');
  485. $this->printError($message, 'Database Error');
  486. exit;
  487. }
  488. }
  489. } else {
  490. if (!TYPO3_db) {
  491. // Redirects to the Install Tool:
  492. echo '<script type="text/javascript">
  493. /*<![CDATA[*/
  494. window.location.href = "'.TYPO3_mainDir.'install/index.php?mode=123&step=1&password=joh316";
  495. /*]]>*/
  496. </script>';
  497. exit;
  498. }
  499. if ($this->checkPageUnavailableHandler()) {
  500. $this->pageUnavailableAndExit('The current username, password or host was not accepted when the connection to the database was attempted to be established!');
  501. } else {
  502. $message = 'The current username, password or host was not accepted when the connection to the database was attempted to be established!';
  503. t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
  504. header('HTTP/1.0 503 Service Temporarily Unavailable');
  505. $this->printError($message, 'Database Error');
  506. exit;
  507. }
  508. }
  509. // Call post processing function for DB connection:
  510. if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'])) {
  511. $_params = array('pObj' => &$this);
  512. foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'] as $_funcRef) {
  513. t3lib_div::callUserFunction($_funcRef,$_params,$this);
  514. }
  515. }
  516. }
  517. /**
  518. * Looks up the value of $this->RDCT in the database and if it is found to be associated with a redirect URL then the redirection is carried out with a 'Location:' header
  519. * May exit after sending a location-header.
  520. *
  521. * @return void
  522. */
  523. function sendRedirect() {
  524. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('params', 'cache_md5params', 'md5hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->RDCT, 'cache_md5params'));
  525. if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  526. $this->updateMD5paramsRecord($this->RDCT);
  527. header('Location: '.$row['params']);
  528. exit;
  529. }
  530. }
  531. /**
  532. * Gets instance of PageRenderer
  533. *
  534. * @return t3lib_PageRenderer
  535. */
  536. public function getPageRenderer() {
  537. if (!isset($this->pageRenderer)) {
  538. $this->pageRenderer = t3lib_div::makeInstance('t3lib_PageRenderer');
  539. $this->pageRenderer->setTemplateFile(PATH_tslib . 'templates/tslib_page_frontend.html');
  540. $this->pageRenderer->setBackPath(TYPO3_mainDir);
  541. }
  542. return $this->pageRenderer;
  543. }
  544. /********************************************
  545. *
  546. * Initializing, resolving page id
  547. *
  548. ********************************************/
  549. /**
  550. * Initializes the caching system.
  551. *
  552. * @return void
  553. */
  554. protected function initCaches() {
  555. if (TYPO3_UseCachingFramework) {
  556. $GLOBALS['TT']->push('Initializing the Caching System','');
  557. $GLOBALS['typo3CacheManager'] = t3lib_div::makeInstance('t3lib_cache_Manager');
  558. $GLOBALS['typo3CacheFactory'] = t3lib_div::makeInstance('t3lib_cache_Factory');
  559. $GLOBALS['typo3CacheFactory']->setCacheManager($GLOBALS['typo3CacheManager']);
  560. try {
  561. $this->pageCache = $GLOBALS['typo3CacheManager']->getCache(
  562. 'cache_pages'
  563. );
  564. } catch(t3lib_cache_exception_NoSuchCache $e) {
  565. t3lib_cache::initPageCache();
  566. $this->pageCache = $GLOBALS['typo3CacheManager']->getCache(
  567. 'cache_pages'
  568. );
  569. }
  570. t3lib_cache::initPageSectionCache();
  571. t3lib_cache::initContentHashCache();
  572. $GLOBALS['TT']->pull();
  573. }
  574. }
  575. /**
  576. * Initializes the front-end login user.
  577. *
  578. * @return void
  579. */
  580. function initFEuser() {
  581. $this->fe_user = t3lib_div::makeInstance('tslib_feUserAuth');
  582. $this->fe_user->lockIP = $this->TYPO3_CONF_VARS['FE']['lockIP'];
  583. $this->fe_user->lockHashKeyWords = $this->TYPO3_CONF_VARS['FE']['lockHashKeyWords'];
  584. $this->fe_user->checkPid = $this->TYPO3_CONF_VARS['FE']['checkFeUserPid'];
  585. $this->fe_user->lifetime = intval($this->TYPO3_CONF_VARS['FE']['lifetime']);
  586. $this->fe_user->checkPid_value = $GLOBALS['TYPO3_DB']->cleanIntList(t3lib_div::_GP('pid')); // List of pid's acceptable
  587. // Check if a session is transferred:
  588. if (t3lib_div::_GP('FE_SESSION_KEY')) {
  589. $fe_sParts = explode('-',t3lib_div::_GP('FE_SESSION_KEY'));
  590. if (!strcmp(md5($fe_sParts[0].'/'.$this->TYPO3_CONF_VARS['SYS']['encryptionKey']), $fe_sParts[1])) { // If the session key hash check is OK:
  591. $_COOKIE[$this->fe_user->name] = $fe_sParts[0];
  592. $this->fe_user->forceSetCookie = 1;
  593. }
  594. }
  595. if ($this->TYPO3_CONF_VARS['FE']['dontSetCookie']) {
  596. $this->fe_user->dontSetCookie=1;
  597. }
  598. $this->fe_user->start();
  599. $this->fe_user->unpack_uc('');
  600. $this->fe_user->fetchSessionData(); // Gets session data
  601. $recs = t3lib_div::_GP('recs');
  602. if (is_array($recs)) { // If any record registration is submitted, register the record.
  603. $this->fe_user->record_registration($recs, $this->TYPO3_CONF_VARS['FE']['maxSessionDataSize']);
  604. }
  605. // Call hook for possible manipulation of frontend user object
  606. if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'])) {
  607. $_params = array('pObj' => &$this);
  608. foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'] as $_funcRef) {
  609. t3lib_div::callUserFunction($_funcRef,$_params,$this);
  610. }
  611. }
  612. // For every 60 seconds the is_online timestamp is updated.
  613. if (is_array($this->fe_user->user) && $this->fe_user->user['uid'] && $this->fe_user->user['is_online']<($GLOBALS['EXEC_TIME']-60)) {
  614. $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid='.intval($this->fe_user->user['uid']), array('is_online' => $GLOBALS['EXEC_TIME']));
  615. }
  616. }
  617. /**
  618. * Initializes the front-end user groups.
  619. * Sets ->loginUser and ->gr_list based on front-end user status.
  620. *
  621. * @return void
  622. */
  623. function initUserGroups() {
  624. $this->fe_user->showHiddenRecords = $this->showHiddenRecords; // This affects the hidden-flag selecting the fe_groups for the user!
  625. $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!)
  626. if (is_array($this->fe_user->user) && count($this->fe_user->groupData['uid'])) {
  627. $this->loginUser=1; // global flag!
  628. $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!
  629. $gr_array = $this->fe_user->groupData['uid'];
  630. } else {
  631. $this->loginUser=0;
  632. $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!
  633. if ($this->loginAllowedInBranch) {
  634. $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.
  635. } else {
  636. $gr_array = array(); // Set to blank since we will NOT risk any groups being set when no logins are allowed!
  637. }
  638. }
  639. // Clean up.
  640. $gr_array = array_unique($gr_array); // Make unique...
  641. sort($gr_array); // sort
  642. if (count($gr_array) && !$this->loginAllowedInBranch_mode) {
  643. $this->gr_list.=','.implode(',',$gr_array);
  644. }
  645. if ($this->fe_user->writeDevLog) t3lib_div::devLog('Valid usergroups for TSFE: '.$this->gr_list, 'tslib_fe');
  646. }
  647. /**
  648. * Checking if a user is logged in or a group constellation different from "0,-1"
  649. *
  650. * @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!)
  651. */
  652. function isUserOrGroupSet() {
  653. return is_array($this->fe_user->user) || $this->gr_list!=='0,-1';
  654. }
  655. /**
  656. * Provides ways to bypass the '?id=[xxx]&type=[xx]' format, using either PATH_INFO or virtual HTML-documents (using Apache mod_rewrite)
  657. *
  658. * Two options:
  659. * 1) Use PATH_INFO (also Apache) to extract id and type from that var. Does not require any special modules compiled with apache. (less typical)
  660. * 2) Using hook which enables features like those provided from "simulatestatic" or "realurl" extension (AKA "Speaking URLs")
  661. *
  662. * @return void
  663. * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&cHash=4ad9d7acb4
  664. */
  665. function checkAlternativeIdMethods() {
  666. $this->siteScript = t3lib_div::getIndpEnv('TYPO3_SITE_SCRIPT');
  667. // Call post processing function for custom URL methods.
  668. if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'])) {
  669. $_params = array('pObj' => &$this);
  670. foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'] as $_funcRef) {
  671. t3lib_div::callUserFunction($_funcRef,$_params,$this);
  672. }
  673. }
  674. }
  675. /**
  676. * Clears the preview-flags, sets sim_exec_time to current time.
  677. * 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.
  678. *
  679. * @return void
  680. */
  681. function clear_preview() {
  682. $this->showHiddenPage = 0;
  683. $this->showHiddenRecords = 0;
  684. $GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
  685. $GLOBALS['SIM_ACCESS_TIME'] = $GLOBALS['ACCESS_TIME'];
  686. $this->fePreview = 0;
  687. }
  688. /**
  689. * Determines the id and evaluates any preview settings
  690. * 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.
  691. *
  692. * @return void
  693. */
  694. function determineId() {
  695. // Getting ARG-v values if some
  696. $this->setIDfromArgV();
  697. // If there is a Backend login we are going to check for any preview settings:
  698. $GLOBALS['TT']->push('beUserLogin','');
  699. if ($this->beUserLogin || $this->doWorkspacePreview()) {
  700. // Backend user preview features:
  701. if ($this->beUserLogin && ($GLOBALS['BE_USER']->adminPanel instanceof tslib_AdminPanel)) {
  702. $this->fePreview = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview') ? true : false;
  703. // If admin panel preview is enabled...
  704. if ($this->fePreview) {
  705. $fe_user_OLD_USERGROUP = $this->fe_user->user['usergroup'];
  706. $this->showHiddenPage = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'showHiddenPages');
  707. $this->showHiddenRecords = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'showHiddenRecords');
  708. // simulate date
  709. $simTime = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'simulateDate');
  710. if ($simTime) {
  711. $GLOBALS['SIM_EXEC_TIME'] = $simTime;
  712. $GLOBALS['SIM_ACCESS_TIME'] = $simTime - ($simTime % 60);
  713. }
  714. // simulate user
  715. $simUserGroup = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'simulateUserGroup');
  716. $this->simUserGroup = $simUserGroup;
  717. if ($simUserGroup) $this->fe_user->user['usergroup']=$simUserGroup;
  718. if (!$simUserGroup && !$simTime && !$this->showHiddenPage && !$this->showHiddenRecords) {
  719. $this->fePreview=0;
  720. }
  721. }
  722. }
  723. if ($this->id) {
  724. // Now it's investigated if the raw page-id points to a hidden page and if so, the flag is set.
  725. // This does not require the preview flag to be set in the admin panel
  726. $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...
  727. $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'pages', $idQ . ' AND hidden!=0 AND deleted=0');
  728. if ($count) {
  729. $this->fePreview = 1; // The preview flag is set only if the current page turns out to actually be hidden!
  730. $this->showHiddenPage = 1;
  731. }
  732. // For Live workspace: Check root line for proper connection to tree root (done because of possible preview of page / branch versions)
  733. if (!$this->fePreview && $this->whichWorkspace()===0) {
  734. // Initialize the page-select functions to check rootline:
  735. $temp_sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
  736. $temp_sys_page->init($this->showHiddenPage);
  737. // If root line contained NO records and ->error_getRootLine_failPid tells us that it was because of a pid=-1 (indicating a "version" record)...:
  738. if (!count($temp_sys_page->getRootLine($this->id,$this->MP)) && $temp_sys_page->error_getRootLine_failPid==-1) {
  739. // Setting versioningPreview flag and try again:
  740. $temp_sys_page->versioningPreview = TRUE;
  741. if (count($temp_sys_page->getRootLine($this->id,$this->MP))) {
  742. // 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.
  743. $this->fePreview = 1;
  744. }
  745. }
  746. }
  747. }
  748. // The preview flag will be set if a backend user is in an offline workspace
  749. if (($GLOBALS['BE_USER']->user['workspace_preview'] || t3lib_div::_GP('ADMCMD_view') || $this->doWorkspacePreview()) && ($this->whichWorkspace()===-1 || $this->whichWorkspace()>0)) {
  750. $this->fePreview = 2; // Will show special preview message.
  751. }
  752. // If the front-end is showing a preview, caching MUST be disabled.
  753. if ($this->fePreview) {
  754. $this->disableCache();
  755. }
  756. }
  757. $GLOBALS['TT']->pull();
  758. // Now, get the id, validate access etc:
  759. $this->fetch_the_id();
  760. // Check if backend user has read access to this page. If not, recalculate the id.
  761. if ($this->beUserLogin && $this->fePreview) {
  762. if (!$GLOBALS['BE_USER']->doesUserHaveAccess($this->page,1)) {
  763. // Resetting
  764. $this->clear_preview();
  765. $this->fe_user->user['usergroup'] = $fe_user_OLD_USERGROUP;
  766. // Fetching the id again, now with the preview settings reset.
  767. $this->fetch_the_id();
  768. }
  769. }
  770. // Checks if user logins are blocked for a certain branch and if so, will unset user login and re-fetch ID.
  771. $this->loginAllowedInBranch = $this->checkIfLoginAllowedInBranch();
  772. if (!$this->loginAllowedInBranch) { // Logins are not allowed:
  773. if ($this->isUserOrGroupSet()) { // Only if there is a login will we run this...
  774. if ($this->loginAllowedInBranch_mode=='all') {
  775. // Clear out user and group:
  776. unset($this->fe_user->user);
  777. $this->gr_list = '0,-1';
  778. } else {
  779. $this->gr_list = '0,-2';
  780. }
  781. // Fetching the id again, now with the preview settings reset.
  782. $this->fetch_the_id();
  783. }
  784. }
  785. // Final cleaning.
  786. $this->id = $this->contentPid = intval($this->id); // Make sure it's an integer
  787. $this->type = intval($this->type); // Make sure it's an integer
  788. // Look for alternative content PID if page is under version preview:
  789. if ($this->fePreview) {
  790. 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:
  791. // 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!
  792. $this->contentPid = $this->page['_ORIG_uid'];
  793. }
  794. }
  795. // Call post processing function for id determination:
  796. if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'])) {
  797. $_params = array('pObj' => &$this);
  798. foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'] as $_funcRef) {
  799. t3lib_div::callUserFunction($_funcRef,$_params,$this);
  800. }
  801. }
  802. }
  803. /**
  804. * Get The Page ID
  805. * This gets the id of the page, checks if the page is in the domain and if the page is accessible
  806. * Sets variables such as $this->sys_page, $this->loginUser, $this->gr_list, $this->id, $this->type, $this->domainStartPage, $this->idParts
  807. *
  808. * @return void
  809. * @access private
  810. */
  811. function fetch_the_id() {
  812. $GLOBALS['TT']->push('fetch_the_id initialize/','');
  813. // Initialize the page-select functions.
  814. $this->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
  815. $this->sys_page->versioningPreview = ($this->fePreview===2 || intval($this->workspacePreview) || t3lib_div::_GP('ADMCMD_view')) ? TRUE : FALSE;
  816. $this->sys_page->versioningWorkspaceId = $this->whichWorkspace();
  817. $this->sys_page->init($this->showHiddenPage);
  818. // Set the valid usergroups for FE
  819. $this->initUserGroups();
  820. // Sets sys_page where-clause
  821. $this->setSysPageWhereClause();
  822. // Splitting $this->id by a period (.). First part is 'id' and second part - if exists - will overrule the &type param if given
  823. $pParts = explode('.',$this->id);
  824. $this->id = $pParts[0]; // Set it.
  825. if (isset($pParts[1])) {$this->type=$pParts[1];}
  826. // Splitting $this->id by a comma (,). First part is 'id' and other parts are just stored for use in scripts.
  827. $this->idParts = explode(',',$this->id);
  828. // Splitting by a '+' sign - used for base64/md5 methods of parameter encryption for simulate static documents.
  829. list($pgID,$SSD_p)=explode('+',$this->idParts[0],2);
  830. if ($SSD_p) { $this->idPartsAnalyze($SSD_p); }
  831. $this->id = $pgID; // Set id
  832. // If $this->id is a string, it's an alias
  833. $this->checkAndSetAlias();
  834. // The id and type is set to the integer-value - just to be sure...
  835. $this->id = intval($this->id);
  836. $this->type = intval($this->type);
  837. $GLOBALS['TT']->pull();
  838. // We find the first page belonging to the current domain
  839. $GLOBALS['TT']->push('fetch_the_id domain/','');
  840. $this->domainStartPage = $this->findDomainRecord($this->TYPO3_CONF_VARS['SYS']['recursiveDomainSearch']); // the page_id of the current domain
  841. if (!$this->id) {
  842. if ($this->domainStartPage) {
  843. $this->id = $this->domainStartPage; // If the id was not previously set, set it to the id of the domain.
  844. } else {
  845. $theFirstPage = $this->sys_page->getFirstWebPage($this->id); // Find the first 'visible' page in that domain
  846. if ($theFirstPage) {
  847. $this->id = $theFirstPage['uid'];
  848. } else {
  849. if ($this->checkPageUnavailableHandler()) {
  850. $this->pageUnavailableAndExit('No pages are found on the rootlevel!');
  851. } else {
  852. $message = 'No pages are found on the rootlevel!';
  853. t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
  854. header('HTTP/1.0 503 Service Temporarily Unavailable');
  855. $this->printError($message);
  856. exit;
  857. }
  858. }
  859. }
  860. }
  861. $GLOBALS['TT']->pull();
  862. $GLOBALS['TT']->push('fetch_the_id rootLine/','');
  863. $requestedId = $this->id; // We store the originally requested id
  864. $this->getPageAndRootlineWithDomain($this->domainStartPage);
  865. $GLOBALS['TT']->pull();
  866. if ($this->pageNotFound && $this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
  867. $pNotFoundMsg = array(
  868. 1 => 'ID was not an accessible page',
  869. 2 => 'Subsection was found and not accessible',
  870. 3 => 'ID was outside the domain',
  871. 4 => 'The requested page alias does not exist'
  872. );
  873. $this->pageNotFoundAndExit($pNotFoundMsg[$this->pageNotFound]);
  874. }
  875. // set no_cache if set
  876. if ($this->page['no_cache']) {
  877. $this->set_no_cache();
  878. }
  879. // Init SYS_LASTCHANGED
  880. $this->register['SYS_LASTCHANGED'] = intval($this->page['tstamp']);
  881. if ($this->register['SYS_LASTCHANGED'] < intval($this->page['SYS_LASTCHANGED'])) {
  882. $this->register['SYS_LASTCHANGED'] = intval($this->page['SYS_LASTCHANGED']);
  883. }
  884. }
  885. /**
  886. * Gets the page and rootline arrays based on the id, $this->id
  887. *
  888. * If the id does not correspond to a proper page, the 'previous' valid page in the rootline is found
  889. * If the page is a shortcut (doktype=4), the ->id is loaded with that id
  890. *
  891. * Whether or not the ->id is changed to the shortcut id or the previous id in rootline (eg if a page is hidden), the ->page-array and ->rootline is found and must also be valid.
  892. *
  893. * Sets or manipulates internal variables such as: $this->id, $this->page, $this->rootLine, $this->MP, $this->pageNotFound
  894. *
  895. * @return void
  896. * @access private
  897. */
  898. function getPageAndRootline() {
  899. $this->page = $this->sys_page->getPage($this->id);
  900. if (!count($this->page)) {
  901. // If no page, we try to find the page before in the rootLine.
  902. $this->pageNotFound=1; // Page is 'not found' in case the id itself was not an accessible page. code 1
  903. $this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
  904. if (count($this->rootLine)) {
  905. $c=count($this->rootLine)-1;
  906. while($c>0) {
  907. // Add to page access failure history:
  908. $this->pageAccessFailureHistory['direct_access'][] = $this->rootLine[$c];
  909. // Decrease to next page in rootline and check the access to that, if OK, set as page record and ID value.
  910. $c--;
  911. $this->id = $this->rootLine[$c]['uid'];
  912. $this->page = $this->sys_page->getPage($this->id);
  913. if (count($this->page)) { break; }
  914. }
  915. }
  916. // If still no page...
  917. if (!count($this->page)) {
  918. if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
  919. $this->pageNotFoundAndExit('The requested page does not exist!');
  920. } else {
  921. $message = 'The requested page does not exist!';
  922. header('HTTP/1.0 404 Page Not Found');
  923. t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
  924. $this->printError($message);
  925. exit;
  926. }
  927. }
  928. }
  929. // Spacer is not accessible in frontend
  930. if ($this->page['doktype'] == 199) {
  931. if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
  932. $this->pageNotFoundAndExit('The requested page does not exist!');
  933. } else {
  934. $message = 'The requested page does not exist!';
  935. header('HTTP/1.0 404 Page Not Found');
  936. t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
  937. $this->printError($message);
  938. exit;
  939. }
  940. }
  941. // Is the ID a link to another page??
  942. if ($this->page['doktype']==4) {
  943. $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.
  944. // saving the page so that we can check later - when we know
  945. // about languages - whether we took the correct shortcut or
  946. // whether a translation of the page overwrites the shortcut
  947. // target and we need to follow the new target
  948. $this->originalShortcutPage = $this->page;
  949. $this->page = $this->getPageShortcut($this->page['shortcut'],$this->page['shortcut_mode'],$this->page['uid']);
  950. $this->id = $this->page['uid'];
  951. }
  952. // Gets the rootLine
  953. $this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
  954. // If not rootline we're off...
  955. if (!count($this->rootLine)) {
  956. $ws = $this->whichWorkspace();
  957. if ($this->sys_page->error_getRootLine_failPid==-1 && $ws) {
  958. $this->sys_page->versioningPreview = TRUE;
  959. $this->versioningWorkspaceId = $ws;
  960. $this->rootLine = $this->sys_page->ge

Large files files are truncated, but you can click here to view the full file