Inside TYPO3
3.1.2. Initialization (init.php)
Scripts in TYPO3_mainDir
Each script in the backend is required to include the init.php file. For core scripts this is done as the first code line in the script:
require ('init.php');
An example could be the alt_main.php script (the backend frameset):
/**
* Main frameset of the TYPO3 backend
*
* @author Kasper Skårhøj <kasper@typo3.com>
* Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
*/
require (
'init.php'
);
require (
'template.php'
);
require_once (
PATH_t3lib
.
'class.t3lib_loadmodules.php'
);
require_once (
PATH_t3lib
.
'class.t3lib_basicfilefunc.php'
);
require_once (
'class.alt_menu_functions.inc'
);
// ***************************
// Script Class
// ***************************
class
SC_alt_main
{
var
$content
;
var
$mainJScode
;
var
$loadModules
;
var
$alt_menuObj
;
These are comments on the various parts of the above source code:
-
init.php: Included to provide database access, configuration values, class inclusions and user authentication etc.
-
template.php: As you can see also the template.php script is included (which provides a class for backend HTML-output and processing of system languages/labels). The template.php script is typically included by all scripts which has some HTML-output for the backend interface.
-
Other classes: Then further classes needed by the script depending on the function will be included.
-
Script Class: Then a "script-class" (prefixed SC_) is defined. This performs ALL processing done in the script. In the end of the script this class is instantiated and the output is written to the browser. That's it.
Scripts outside of TYPO3_mainDir
For modules (located elsewhere than in the TYPO3_mainDir) the following initialization must be done prior to inclusion of init.php:
-
Global variable $BACK_PATH must point back to the TYPO3_mainDir (relative from the current script), eg. "../../" or "../../../typo3/"
-
Constant TYPO3_MOD_PATH must point forth to the location of the script (relative from the TYPO3_mainDir), eg. "ext/myextension/" or "../typo3conf/ext/myextension/"
An example is seen in the install/index.php file:
define('TYPO3_MOD_PATH', 'install/');
$BACK_PATH='../';
require ($BACK_PATH.'init.php');
If a script is positioned outside of the TYPO3_mainDir it must be in the typo3conf/ directory. In that case the initial lines could look like this:
define('TYPO3_MOD_PATH', '../typo3conf/my_backend_script/');
$BACK_PATH='../../typo3/';
require ($BACK_PATH.'init.php');
Modules
Modules will typically initiate with basic lines like these:
unset($MCONF);
require ('conf.php');
require ($BACK_PATH.'init.php');
So before init.php is called the local "conf.php" file is included. That file must define the TYPO3_MOD_PATH constant and $BACK_PATH global variable. The modules section will describe this in detail.
We could take mod/web/perms/index.php as an example. Here the conf.php file looks like this:
<?php
define
('
TYPO3_MOD_PATH'
, '
mod/web/perm/'
);
$BACK_PATH
=
'../../../'
;
//... (additional configuration of module)...
?>
Modules in typo3conf/
Another example is from a conf.php file of a locally installed extension (such are located in the "typo3conf/ext/" directory) with a backend module:
<?php
// DO NOT REMOVE OR CHANGE THESE 3 LINES:
define
(
'TYPO3_MOD_PATH'
,
'../typo3conf/ext/charsettool/mod1/'
);
$BACK_PATH
=
'../../../../typo3/'
;
//... (additional configuration of module)...
?>
init.php
So what happens in init.php?
The short version is this:
-
A set of constants and global variables are defined.
-
A set of classes are included.
-
PHP environment is checked and set.
-
Local configuration is included ("localconf.php").
-
Table definitions are set ("tables.php").
-
Connection to database established.
-
Backend user is authenticated.
-
Missing backend user authentication and other errors will make the script exit with an error message.
The verbose version is this:
(All global variables and constants referred to here are described in "TYPO3 Core API")
-
Error reporting is set to
error_reporting (E_ALL ^ E_NOTICE);
-
Constants TYPO3_OS, TYPO3_MODE, PATH_thisScript and TYPO3_mainDir are defined.
-
If TYPO3_MOD_PATH is defined the path is evaluated: The script must be found below either TYPO3_mainDir or PATH_site."typo3conf/". Otherwise the init.php script halts with an error message. Further the script will exit at this point if it was not able to get a correct absolute path for the installation. TYPO3 requires to know the absolute position of the directory from where the script is executed!
-
Constants PATH_typo3, PATH_typo3_mod, PATH_site, PATH_t3lib, PATH_typo3conf are defined.
-
Classes t3lib_div and t3lib_extMgm are included.
-
t3lib/config_default.php is included (shared with frontend as well). If no TYPO3_db constant is defined after the inclusion of config_default.php then the script exits with an error message.
This is what happens inside config_default.php:-
t3lib/config_default.php:
-
$TYPO3_CONF_VARS is initialized with the default set of values.
-
$typo_db* database variables are reset to blank.
-
PATH_typo3conf.'localconf.php' is included. If not found, script exits with error message.
-
localconf.php:
-
localconf.php is allowed to override any variable from $TYPO3_CONF_VARS and further set the database variables with database username, password, database name, host.
[Back in t3lib_config_default.php]: -
-
Constants TYPO3_db, TYPO3_db_username, TYPO3_db_password, TYPO3_db_host, TYPO3_tables_script, TYPO3_extTableDef_script and TYPO3_languages is defined
-
$typo_db* variables are unset.
-
Certain $GLOBALS['TYPO3_CONF_VARS']['GFX'] values are manipulated.
-
debug() function is defined (only function outside a class!)
-
"ext_localconf.php" files from installed extensions are included either as a cached file (ex. "typo3conf/temp_CACHED_ps5cb2_ext_localconf.php") or as individual files (depends on configuration of TYPO3_CONF_VARS['EXT']['extCache'].
"ext_localconf.php" files are allowed to override $TYPO3_CONF_VARS values! They cannot modify the database connection information though. (See the definition of the Extension API for details)
$TYPO3_LOADED_EXT is set. -
Unsetting most of the reserved global variables ($PAGES_TYPES, $ICON_TYPES, $LANG_GENERAL_LABELS, $TCA, $TBE_MODULES, $TBE_STYLES, $FILEICONS, $WEBMOUNTS, $FILEMOUNTS, $BE_USER, $TBE_MODULES_EXT, $TCA_DESCR, $TCA_DESCR, $LOCAL_LANG) except $TYPO3_CONF_VARS (so from localconf.php files you cannot set values in these variables - you must use "tables.php" files).
-
Global vars $EXEC_TIME, $SIM_EXEC_TIME and $TYPO_VERSION are set
[Back in init.php]: -
-
Database Abstraction Layer foundation class is included and global object, $TYPO3_DB, is created.
-
Global vars $CLIENT and $PARSETIME_START are set.
-
Classes for user authentication are included plus class for icon manipulation and the t3lib_BEfunc (backend functions) class. Also the class "t3lib_cs" for character set conversion is included.
-
IP masking is performed (based on $TYPO3_CONF_VARS['BE']['IPmaskList']). Exits if criterias are not met.
-
SSL locking is checked ($TYPO3_CONF_VARS['BE']['lockSSL']). Exits if criterias are not met.
-
Checking PHP environment. Exits if PHP version is not supported or if HTTP_GET_VARS[GLOBALS] is set.
-
Checking for Install Tool call: If constant TYPO3_enterInstallScript is set, then the Install Tool is launched! Notice that the Install Tool is launched before any connection is made to the database! Thus the Install Tool will run even if the database configuration is not complete or existing.
-
Database connection. Exits if database connection fails.
-
Checking browser. Must be 4+ browser. Exits if criterias are not met.
-
Default tables are defined; PATH_t3lib.'stddb/tables.php' is included! (Alternatively the constant TYPO3_tables_script could have defined another filename relative to "PATH_typo3conf" which will be included instead. Deprecated since it spoils backwards compatibility and extensions should be used to override the default $TCA instead. So consider this obsolete.)
-
t3lib/stddb/tables.php:
-
global variables $PAGES_TYPES, $ICON_TYPES, $LANG_GENERAL_LABELS, $TCA, $TBE_MODULES, $TBE_STYLES, $FILEICONS are defined.
[Back in init.php]
-
-
"ext_tables.php" files are included either as a cached file (ex. "typo3conf/temp_CACHED_ps5cb2_ext_tables.php") or as individual files (depends on configuration of TYPO3_CONF_VARS['EXT']['extCache']).
"ext_tables.php" files are allowed to override the global variables defined in "stddb/tables.php"! (See the definition of the Extension API for details) -
If the constant TYPO3_extTableDef_script is defined then that script is included.
-
Backend user authenticated: Global variable $BE_USER is instantiated and initialized. If no backend user is authenticated the script will exit (UNLESS the constant TYPO3_PROCEED_IF_NO_USER has been defined and set true prior to inclusion of init.php!)
-
The global variables $WEBMOUNTS and $FILEMOUNTS are set (based on the BE_USERS permissions)
-
Optional output compression initialized
So that is what happens in init.php!