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