Changed require to require_once to fix bug #958.
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / index_ts.php
index 83cf54c..90ec490 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -38,7 +38,7 @@
  * $Id$
  * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage tslib
  */
@@ -55,7 +55,7 @@ error_reporting (E_ALL ^ E_NOTICE);
 $TYPO3_MISC['microtime_start'] = microtime();
 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
 define('TYPO3_MODE','FE');
-define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', (php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ||php_sapi_name()=='cgi-fcgi')&&($HTTP_SERVER_VARS['ORIG_PATH_TRANSLATED']?$HTTP_SERVER_VARS['ORIG_PATH_TRANSLATED']:$HTTP_SERVER_VARS['PATH_TRANSLATED'])? ($HTTP_SERVER_VARS['ORIG_PATH_TRANSLATED']?$HTTP_SERVER_VARS['ORIG_PATH_TRANSLATED']:$HTTP_SERVER_VARS['PATH_TRANSLATED']):($HTTP_SERVER_VARS['ORIG_SCRIPT_FILENAME']?$HTTP_SERVER_VARS['ORIG_SCRIPT_FILENAME']:$HTTP_SERVER_VARS['SCRIPT_FILENAME']))));
+define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', (php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ||php_sapi_name()=='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']))));
 
 define('PATH_site', dirname(PATH_thisScript).'/');
 define('PATH_t3lib', PATH_site.'t3lib/');
@@ -75,11 +75,11 @@ $TT->push('','Script start');
 
 
 // *********************
-// DIV Library included
+// Mandatory libraries included
 // *********************
 $TT->push('Include class t3lib_db, t3lib_div, t3lib_extmgm','');
-       require(PATH_t3lib.'class.t3lib_div.php');
-       require(PATH_t3lib.'class.t3lib_extmgm.php');
+       require_once(PATH_t3lib.'class.t3lib_div.php');
+       require_once(PATH_t3lib.'class.t3lib_extmgm.php');
 $TT->pull();
 
 
@@ -88,14 +88,14 @@ $TT->pull();
 // Include configuration
 // **********************
 $TT->push('Include config files','');
-require(PATH_t3lib.'config_default.php');
+require_once(PATH_t3lib.'config_default.php');
 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.
 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.');
 
-require(PATH_t3lib.'class.t3lib_db.php');
+require_once(PATH_t3lib.'class.t3lib_db.php');
 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
 
-$CLIENT=t3lib_div::clientInfo();                               // Set to the browser: net / msie if 4+ browsers
+$CLIENT = t3lib_div::clientInfo();                             // Set to the browser: net / msie if 4+ browsers
 $TT->pull();
 
 
@@ -115,15 +115,15 @@ $TT->pull();
 // *******************************
 // Checking environment
 // *******************************
-if (t3lib_div::int_from_ver(phpversion())<4000006)     die ('TYPO3 runs with PHP4.0.6+ only');
+if (t3lib_div::int_from_ver(phpversion())<4001000)     die ('TYPO3 runs with PHP4.1.0+ only');
 
-if (isset($HTTP_POST_VARS['GLOBALS']) || isset($HTTP_GET_VARS['GLOBALS']))     die('You cannot set the GLOBALS-array from outside the script.');
+if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS']))       die('You cannot set the GLOBALS-array from outside the script.');
 if (!get_magic_quotes_gpc())   {
        $TT->push('Add slashes to GET/POST arrays','');
-       t3lib_div::addSlashesOnArray($HTTP_GET_VARS);
-       t3lib_div::addSlashesOnArray($HTTP_POST_VARS);
-       $_GET = $HTTP_GET_VARS;
-       $_POST = $HTTP_POST_VARS;
+       t3lib_div::addSlashesOnArray($_GET);
+       t3lib_div::addSlashesOnArray($_POST);
+       $HTTP_GET_VARS = $_GET;
+       $HTTP_POST_VARS = $_POST;
        $TT->pull();
 }
 
@@ -131,7 +131,7 @@ if (!get_magic_quotes_gpc())        {
 // Create $TSFE object (TSFE = TypoScript Front End)
 // Connecting to database
 // ***********************************
-$temp_TSFEclassName=t3lib_div::makeInstanceClassName('tslib_fe');
+$temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
 $TSFE = new $temp_TSFEclassName(
                $TYPO3_CONF_VARS,
                t3lib_div::_GP('id'),
@@ -142,7 +142,7 @@ $TSFE = new $temp_TSFEclassName(
                t3lib_div::_GP('MP'),
                t3lib_div::_GP('RDCT')
        );
-$TSFE->connectToMySQL();
+$TSFE->connectToDB();
 if ($TSFE->RDCT)       {$TSFE->sendRedirect();}
 
 
@@ -161,11 +161,21 @@ $TT->push('Front End user initialized','');
        $TSFE->initFEuser();
 $TT->pull();
 
+// ****************
+// PRE BE_USER HOOK
+// ****************
+if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'])) {
+       foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'] as $_funcRef) {
+               $_params = array();
+               t3lib_div::callUserFunction($_funcRef, $_params ,$this);
+       }
+}
+
 // *********
 // BE_USER
 // *********
 $BE_USER='';
-if ($HTTP_COOKIE_VARS['be_typo_user']) {               // If the backend cookie is set, we proceed and checks if a backend user is logged in.
+if ($_COOKIE['be_typo_user']) {                // If the backend cookie is set, we proceed and checks if a backend user is logged in.
        $TYPO3_MISC['microtime_BE_USER_start'] = microtime();
        $TT->push('Back End user initialized','');
                require_once (PATH_t3lib.'class.t3lib_befunc.php');
@@ -208,8 +218,8 @@ if ($HTTP_COOKIE_VARS['be_typo_user']) {            // If the backend cookie is set, we pr
                                        $BE_USER->ext_forcePreview=1;
                                }
 
-                                       // Include classes for editing IF editing module in Admin Panel is open (it is assumed that $TSFE->displayEditIcons is set only if the Edit module is open in the Admin Panel)
-                               if ($BE_USER->extAdmModuleEnabled('edit') && $BE_USER->extIsAdmMenuOpen('edit'))        {
+                                       // Include classes for editing IF editing module in Admin Panel is open
+                               if (($BE_USER->extAdmModuleEnabled('edit') && $BE_USER->extIsAdmMenuOpen('edit')) || $TSFE->displayEditIcons == 1)      {
                                        $TSFE->includeTCA();
                                        if ($BE_USER->extIsEditAction())        {
                                                require_once (PATH_t3lib.'class.t3lib_tcemain.php');
@@ -262,6 +272,13 @@ $TT->push('Process ID','');
 $TT->pull();
 
 
+// *******************************************
+// Get compressed $TCA-Array();
+// After this, we should now have a valid $TCA, though minimized
+// *******************************************
+$TSFE->getCompressedTCarray();
+
+
 // ********************************
 // Starts the template
 // *******************************
@@ -285,11 +302,10 @@ $TT->pull();
 $TSFE->getConfigArray();
 
 
-// *******************************************
-// Get compressed $TCA-Array();
-// After this, we should now have a valid $TCA, though minimized
-// *******************************************
-$TSFE->getCompressedTCarray();
+// ********************************
+// Convert POST data to internal "renderCharset" if different from the metaCharset:
+// *******************************
+$TSFE->convPOSTCharset();
 
 
 // *******************************************
@@ -342,10 +358,6 @@ if ($TSFE->isGeneratePage())       {
                        require_once(PATH_tslib.'class.tslib_pagegen.php');
                        include(PATH_tslib.'pagegen.php');
                }
-               if ($TSFE->isSearchIndexPage()) {
-                       if ($TSFE->config['config']['index_externals']) {require_once(PATH_t3lib.'class.t3lib_htmlmail.php');}
-                       require_once(t3lib_extMgm::extPath('indexed_search','class.indexer.php'));
-               }
                $TSFE->generatePage_postProcessing();
 } elseif ($TSFE->isINTincScript())     {
        require_once(PATH_tslib.'class.tslib_pagegen.php');
@@ -363,14 +375,13 @@ if ($TSFE->isINTincScript())              {
 
                        // Special feature: Include libraries
                $TT->push('Include libraries');
-               reset($INTiS_config);
-               while(list(,$INTiS_cPart)=each($INTiS_config))  {
+               foreach($INTiS_config as $INTiS_cPart)  {
                        if ($INTiS_cPart['conf']['includeLibs'])        {
                                $INTiS_resourceList = t3lib_div::trimExplode(',',$INTiS_cPart['conf']['includeLibs'],1);
                                $GLOBALS['TT']->setTSlogMessage('Files for inclusion: "'.implode(', ',$INTiS_resourceList).'"');
-                               reset($INTiS_resourceList);
-                               while(list(,$INTiS_theLib)=each($INTiS_resourceList))   {
-                                       $INTiS_incFile=$GLOBALS['TSFE']->tmpl->getFileName($INTiS_theLib);
+
+                               foreach($INTiS_resourceList as $INTiS_theLib)   {
+                                       $INTiS_incFile = $GLOBALS['TSFE']->tmpl->getFileName($INTiS_theLib);
                                        if ($INTiS_incFile)     {
                                                require_once('./'.$INTiS_incFile);
                                        } else {
@@ -483,6 +494,12 @@ if (is_object($BE_USER))   {
 }
 
 
+// ******************
+// Hook for end-of-frontend
+// ******************
+$TSFE->hook_eofe();
+
+
 // ********************
 // Finish timetracking
 // ********************