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