PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/typo3/sysext/cms/tslib/index_ts.php

https://bitbucket.org/linxpinx/mercurial
PHP | 584 lines | 481 code | 26 blank | 77 comment | 21 complexity | 92dd00e1fd4d3ec5fc7e37e1549e5b6c MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0
  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. * This is the MAIN DOCUMENT of the TypoScript driven standard front-end (from the "cms" extension)
  29. * Basically put this is the "index.php" script which all requests for TYPO3 delivered pages goes to in the frontend (the website)
  30. * The script configures constants, includes libraries and does a little logic here and there in order to instantiate the right classes to create the webpage.
  31. * All the real data processing goes on in the "tslib/" classes which this script will include and use as needed.
  32. *
  33. * $Id: index_ts.php 7905 2010-06-13 14:42:33Z ohader $
  34. * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
  35. *
  36. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  37. * @package TYPO3
  38. * @subpackage tslib
  39. */
  40. // *******************************
  41. // Checking PHP version
  42. // *******************************
  43. if (version_compare(phpversion(), '5.2', '<')) die ('TYPO3 requires PHP 5.2.0 or higher.');
  44. // *******************************
  45. // Set error reporting
  46. // *******************************
  47. if (defined('E_DEPRECATED')) {
  48. error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
  49. } else {
  50. error_reporting(E_ALL ^ E_NOTICE);
  51. }
  52. // ******************
  53. // Constants defined
  54. // ******************
  55. $TYPO3_MISC['microtime_start'] = microtime(true);
  56. define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
  57. define('TYPO3_MODE','FE');
  58. if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', (PHP_SAPI=='cgi'||PHP_SAPI=='isapi' ||PHP_SAPI=='cgi-fcgi')&&($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED'])? ($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED']):($_SERVER['ORIG_SCRIPT_FILENAME']?$_SERVER['ORIG_SCRIPT_FILENAME']:$_SERVER['SCRIPT_FILENAME']))));
  59. if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/');
  60. if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
  61. define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
  62. define('PATH_typo3', PATH_site.TYPO3_mainDir);
  63. define('PATH_typo3conf', PATH_site.'typo3conf/');
  64. if (!defined('PATH_tslib')) {
  65. if (@is_dir(PATH_site.TYPO3_mainDir.'sysext/cms/tslib/')) {
  66. define('PATH_tslib', PATH_site.TYPO3_mainDir.'sysext/cms/tslib/');
  67. } elseif (@is_dir(PATH_site.'tslib/')) {
  68. define('PATH_tslib', PATH_site.'tslib/');
  69. }
  70. }
  71. if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
  72. // *********************
  73. // Unset variable(s) in global scope (fixes #13959)
  74. // *********************
  75. unset($error);
  76. // *********************
  77. // Prevent any output until AJAX/compression is initialized to stop
  78. // AJAX/compression data corruption
  79. // *********************
  80. ob_start();
  81. // *********************
  82. // Timetracking started
  83. // *********************
  84. if ($_COOKIE['be_typo_user']) {
  85. require_once(PATH_t3lib.'class.t3lib_timetrack.php');
  86. $TT = new t3lib_timeTrack;
  87. } else {
  88. require_once(PATH_t3lib.'class.t3lib_timetracknull.php');
  89. $TT = new t3lib_timeTrackNull;
  90. }
  91. $TT->start();
  92. $TT->push('','Script start');
  93. // *********************
  94. // Mandatory libraries included
  95. // *********************
  96. $TT->push('Include class t3lib_db, t3lib_div, t3lib_extmgm','');
  97. require_once(PATH_t3lib.'class.t3lib_div.php');
  98. require_once(PATH_t3lib.'class.t3lib_extmgm.php');
  99. $TT->pull();
  100. // **********************
  101. // Include configuration
  102. // **********************
  103. $TT->push('Include config files','');
  104. require(PATH_t3lib.'config_default.php');
  105. if (!defined ('TYPO3_db')) die ('The configuration file was not included.'); // the name of the TYPO3 database is stored in this constant. Here the inclusion of the config-file is verified by checking if this var is set.
  106. if (!t3lib_extMgm::isLoaded('cms')) die('<strong>Error:</strong> The main frontend extension "cms" was not loaded. Enable it in the extension manager in the backend.');
  107. if (!defined('PATH_tslib')) {
  108. define('PATH_tslib', t3lib_extMgm::extPath('cms').'tslib/');
  109. }
  110. // *********************
  111. // Error & Exception handling
  112. // *********************
  113. if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
  114. $TT->push('Register Exceptionhandler', '');
  115. if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
  116. // register an error handler for the given errorHandlerErrors
  117. $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
  118. // set errors which will be converted in an exception
  119. $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
  120. }
  121. $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
  122. $TT->pull();
  123. }
  124. $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
  125. $TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
  126. $CLIENT = t3lib_div::clientInfo(); // Set to the browser: net / msie if 4+ browsers
  127. $TT->pull();
  128. // *******************************
  129. // Checking environment
  130. // *******************************
  131. if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) die('You cannot set the GLOBALS-array from outside the script.');
  132. if (!get_magic_quotes_gpc()) {
  133. $TT->push('Add slashes to GET/POST arrays','');
  134. t3lib_div::addSlashesOnArray($_GET);
  135. t3lib_div::addSlashesOnArray($_POST);
  136. $HTTP_GET_VARS = $_GET;
  137. $HTTP_POST_VARS = $_POST;
  138. $TT->pull();
  139. }
  140. // Hook to preprocess the current request:
  141. if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
  142. foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
  143. $hookParameters = array();
  144. t3lib_div::callUserFunction($hookFunction, $hookParameters, $hookParameters);
  145. }
  146. unset($hookFunction);
  147. unset($hookParameters);
  148. }
  149. // *********************
  150. // Look for extension ID which will launch alternative output engine
  151. // *********************
  152. if ($temp_extId = t3lib_div::_GP('eID')) {
  153. if ($classPath = t3lib_div::getFileAbsFileName($TYPO3_CONF_VARS['FE']['eID_include'][$temp_extId])) {
  154. // Remove any output produced until now
  155. ob_clean();
  156. require($classPath);
  157. }
  158. exit;
  159. }
  160. // ***********************************
  161. // Create $TSFE object (TSFE = TypoScript Front End)
  162. // Connecting to database
  163. // ***********************************
  164. $TSFE = t3lib_div::makeInstance('tslib_fe',
  165. $TYPO3_CONF_VARS,
  166. t3lib_div::_GP('id'),
  167. t3lib_div::_GP('type'),
  168. t3lib_div::_GP('no_cache'),
  169. t3lib_div::_GP('cHash'),
  170. t3lib_div::_GP('jumpurl'),
  171. t3lib_div::_GP('MP'),
  172. t3lib_div::_GP('RDCT')
  173. );
  174. /* @var $TSFE tslib_fe */
  175. if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
  176. !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
  177. $TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
  178. }
  179. $TSFE->connectToDB();
  180. // In case of a keyword-authenticated preview, re-initialize the TSFE object:
  181. if ($temp_previewConfig = $TSFE->ADMCMD_preview()) {
  182. $TSFE = t3lib_div::makeInstance('tslib_fe',
  183. $TYPO3_CONF_VARS,
  184. t3lib_div::_GP('id'),
  185. t3lib_div::_GP('type'),
  186. t3lib_div::_GP('no_cache'),
  187. t3lib_div::_GP('cHash'),
  188. t3lib_div::_GP('jumpurl'),
  189. t3lib_div::_GP('MP'),
  190. t3lib_div::_GP('RDCT')
  191. );
  192. $TSFE->ADMCMD_preview_postInit($temp_previewConfig);
  193. }
  194. if ($TSFE->RDCT) {$TSFE->sendRedirect();}
  195. // *******************
  196. // Output compression
  197. // *******************
  198. // Remove any output produced until now
  199. ob_clean();
  200. if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
  201. if (t3lib_div::testInt($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
  202. // Prevent errors if ini_set() is unavailable (safe mode)
  203. @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
  204. }
  205. ob_start(array(t3lib_div::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
  206. }
  207. // *********
  208. // FE_USER
  209. // *********
  210. $TT->push('Front End user initialized','');
  211. /* @var $TSFE tslib_fe */
  212. $TSFE->initFEuser();
  213. $TT->pull();
  214. // ****************
  215. // PRE BE_USER HOOK
  216. // ****************
  217. if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'])) {
  218. foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'] as $_funcRef) {
  219. $_params = array();
  220. t3lib_div::callUserFunction($_funcRef, $_params , $_params);
  221. }
  222. }
  223. // *********
  224. // BE_USER
  225. // *********
  226. $BE_USER = NULL;
  227. if ($_COOKIE['be_typo_user']) { // If the backend cookie is set, we proceed and checks if a backend user is logged in.
  228. $TYPO3_MISC['microtime_BE_USER_start'] = microtime(true);
  229. $TT->push('Back End user initialized','');
  230. // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
  231. $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
  232. $BE_USER->OS = TYPO3_OS;
  233. $BE_USER->lockIP = $TYPO3_CONF_VARS['BE']['lockIP'];
  234. $BE_USER->start(); // Object is initialized
  235. $BE_USER->unpack_uc('');
  236. if ($BE_USER->user['uid']) {
  237. $BE_USER->fetchGroupData();
  238. $TSFE->beUserLogin = 1;
  239. }
  240. // Unset the user initialization.
  241. if (!$BE_USER->checkLockToIP() || !$BE_USER->checkBackendAccessSettingsFromInitPhp() || !$BE_USER->user['uid']) {
  242. $BE_USER = NULL;
  243. $TSFE->beUserLogin=0;
  244. }
  245. $TT->pull();
  246. $TYPO3_MISC['microtime_BE_USER_end'] = microtime(true);
  247. } elseif ($TSFE->ADMCMD_preview_BEUSER_uid) {
  248. // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
  249. $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
  250. $BE_USER->userTS_dontGetCached = 1;
  251. $BE_USER->OS = TYPO3_OS;
  252. $BE_USER->setBeUserByUid($TSFE->ADMCMD_preview_BEUSER_uid);
  253. $BE_USER->unpack_uc('');
  254. if ($BE_USER->user['uid']) {
  255. $BE_USER->fetchGroupData();
  256. $TSFE->beUserLogin = 1;
  257. } else {
  258. $BE_USER = NULL;
  259. $TSFE->beUserLogin = 0;
  260. }
  261. }
  262. // ********************
  263. // Workspace preview:
  264. // ********************
  265. $TSFE->workspacePreviewInit();
  266. // *****************************************
  267. // Process the ID, type and other parameters
  268. // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
  269. // *****************************************
  270. $TT->push('Process ID','');
  271. // Initialize admin panel since simulation settings are required here:
  272. if ($TSFE->beUserLogin) {
  273. $BE_USER->initializeAdminPanel();
  274. }
  275. $TSFE->checkAlternativeIdMethods();
  276. $TSFE->clear_preview();
  277. $TSFE->determineId();
  278. // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
  279. if ($TSFE->beUserLogin && (!$BE_USER->extPageReadAccess($TSFE->page) || t3lib_div::_GP('ADMCMD_noBeUser'))) { // t3lib_div::_GP('ADMCMD_noBeUser') is placed here because workspacePreviewInit() might need to know if a backend user is logged in!
  280. // Remove user
  281. unset($BE_USER);
  282. $TSFE->beUserLogin = 0;
  283. // Re-evaluate the page-id.
  284. $TSFE->checkAlternativeIdMethods();
  285. $TSFE->clear_preview();
  286. $TSFE->determineId();
  287. }
  288. $TSFE->makeCacheHash();
  289. $TT->pull();
  290. // *****************************************
  291. // Admin Panel & Frontend editing
  292. // *****************************************
  293. if ($TSFE->beUserLogin) {
  294. // if a BE User is present load, the sprite manager for frontend-editing
  295. $spriteManager = t3lib_div::makeInstance('t3lib_SpriteManager', FALSE);
  296. $spriteManager->loadCacheFile();
  297. $BE_USER->initializeFrontendEdit();
  298. if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
  299. $LANG = t3lib_div::makeInstance('language');
  300. $LANG->init($BE_USER->uc['lang']);
  301. }
  302. if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
  303. $BE_USER->frontendEdit->initConfigOptions();
  304. }
  305. }
  306. // *******************************************
  307. // Get compressed $TCA-Array();
  308. // After this, we should now have a valid $TCA, though minimized
  309. // *******************************************
  310. $TSFE->getCompressedTCarray();
  311. // ********************************
  312. // Starts the template
  313. // *******************************
  314. $TT->push('Start Template','');
  315. $TSFE->initTemplate();
  316. $TT->pull();
  317. // ********************************
  318. // Get from cache
  319. // *******************************
  320. $TT->push('Get Page from cache','');
  321. $TSFE->getFromCache();
  322. $TT->pull();
  323. // ******************************************************
  324. // Get config if not already gotten
  325. // After this, we should have a valid config-array ready
  326. // ******************************************************
  327. $TSFE->getConfigArray();
  328. // ********************************
  329. // Convert POST data to internal "renderCharset" if different from the metaCharset
  330. // *******************************
  331. $TSFE->convPOSTCharset();
  332. // *******************************************
  333. // Setting language and locale
  334. // *******************************************
  335. $TT->push('Setting language and locale','');
  336. $TSFE->settingLanguage();
  337. $TSFE->settingLocale();
  338. $TT->pull();
  339. // ********************************
  340. // Check JumpUrl
  341. // *******************************
  342. $TSFE->setExternalJumpUrl();
  343. $TSFE->checkJumpUrlReferer();
  344. // ********************************
  345. // Check Submission of data.
  346. // This is done at this point, because we need the config values
  347. // *******************************
  348. switch($TSFE->checkDataSubmission()) {
  349. case 'email':
  350. $TSFE->sendFormmail();
  351. break;
  352. case 'fe_tce':
  353. $TSFE->includeTCA();
  354. $TT->push('fe_tce','');
  355. $TSFE->fe_tce();
  356. $TT->pull();
  357. break;
  358. }
  359. // ********************************
  360. // Generate page
  361. // *******************************
  362. $TSFE->setUrlIdToken();
  363. $TT->push('Page generation','');
  364. if ($TSFE->isGeneratePage()) {
  365. $TSFE->generatePage_preProcessing();
  366. $temp_theScript=$TSFE->generatePage_whichScript();
  367. if ($temp_theScript) {
  368. include($temp_theScript);
  369. } else {
  370. include(PATH_tslib.'pagegen.php');
  371. }
  372. $TSFE->generatePage_postProcessing();
  373. } elseif ($TSFE->isINTincScript()) {
  374. include(PATH_tslib.'pagegen.php');
  375. }
  376. $TT->pull();
  377. // ********************************
  378. // $TSFE->config['INTincScript']
  379. // *******************************
  380. if ($TSFE->isINTincScript()) {
  381. $TT->push('Non-cached objects','');
  382. $TSFE->INTincScript();
  383. $TT->pull();
  384. }
  385. // ***************
  386. // Output content
  387. // ***************
  388. if ($TSFE->isOutputting()) {
  389. $TT->push('Print Content','');
  390. $TSFE->processOutput();
  391. // ***************************************
  392. // Outputs content / Includes EXT scripts
  393. // ***************************************
  394. if ($TSFE->isEXTincScript()) {
  395. $TT->push('External PHP-script','');
  396. // Important global variables here are $EXTiS_*, they must not be overridden in include-scripts!!!
  397. $EXTiS_config = $TSFE->config['EXTincScript'];
  398. $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$TSFE->content); // Splits content with the key
  399. // Special feature: Include libraries
  400. foreach ($EXTiS_config as $EXTiS_cPart) {
  401. if (isset($EXTiS_cPart['conf']['includeLibs']) && $EXTiS_cPart['conf']['includeLibs']) {
  402. $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'], true);
  403. $TSFE->includeLibraries($EXTiS_resourceList);
  404. }
  405. }
  406. foreach ($EXTiS_splitC as $EXTiS_c => $EXTiS_cPart) {
  407. if (substr($EXTiS_cPart,32,3)=='-->') { // If the split had a comment-end after 32 characters it's probably a split-string
  408. $EXTiS_key = 'EXT_SCRIPT.'.substr($EXTiS_cPart,0,32);
  409. if (is_array($EXTiS_config[$EXTiS_key])) {
  410. $REC = $EXTiS_config[$EXTiS_key]['data'];
  411. $CONF = $EXTiS_config[$EXTiS_key]['conf'];
  412. $content = '';
  413. include($EXTiS_config[$EXTiS_key]['file']);
  414. echo $content; // The script MAY return content in $content or the script may just output the result directly!
  415. }
  416. echo substr($EXTiS_cPart,35);
  417. } else {
  418. echo ($c?'<!--EXT_SCRIPT.':'').$EXTiS_cPart;
  419. }
  420. }
  421. $TT->pull();
  422. } else {
  423. echo $TSFE->content;
  424. }
  425. $TT->pull();
  426. }
  427. // ********************************
  428. // Store session data for fe_users
  429. // ********************************
  430. $TSFE->storeSessionData();
  431. // ***********
  432. // Statistics
  433. // ***********
  434. $TYPO3_MISC['microtime_end'] = microtime(true);
  435. $TSFE->setParseTime();
  436. if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS['FE']['debug']) || !empty($TSFE->config['config']['debug']))) {
  437. echo '
  438. <!-- Parsetime: '.$TSFE->scriptParseTime.' ms-->';
  439. }
  440. $TSFE->statistics();
  441. // ***************
  442. // Check JumpUrl
  443. // ***************
  444. $TSFE->jumpurl();
  445. // *************
  446. // Preview info
  447. // *************
  448. $TSFE->previewInfo();
  449. // ******************
  450. // Publishing static
  451. // ******************
  452. if (is_object($BE_USER) && ($BE_USER->adminPanel instanceof tslib_AdminPanel)) {
  453. if ($BE_USER->adminPanel->isAdminModuleEnabled('publish') && $BE_USER->adminPanel->getExtPublishList()) {
  454. include_once(PATH_tslib.'publish.php');
  455. }
  456. }
  457. // ******************
  458. // Hook for end-of-frontend
  459. // ******************
  460. $TSFE->hook_eofe();
  461. // ********************
  462. // Finish timetracking
  463. // ********************
  464. $TT->pull();
  465. // ******************
  466. // beLoginLinkIPList
  467. // ******************
  468. echo $TSFE->beLoginLinkIPList();
  469. // *************
  470. // Admin panel
  471. // *************
  472. if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->beUserLogin) {
  473. echo $BE_USER->displayAdminPanel();
  474. }
  475. // *************
  476. // Debugging Output
  477. // *************
  478. if(isset($error) && is_object($error) && @is_callable(array($error,'debugOutput'))) {
  479. $error->debugOutput();
  480. }
  481. if (TYPO3_DLOG) {
  482. t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
  483. }
  484. ?>