Login / Status
developer.Resource
Home . Documentation . Document Library . Core Documentation
Sponsors
hosted by punkt.deTYPO3 and Open Source Magazine

Chapter 3. Core Architecture

3.1. Backend

Backend interface

The backend interface is (typically) found in the typo3/ directory (constant TYPO3_mainDir).

Visually it is divided by a frameset into these sections:

  1. alt_main.php: This script is redirected to after login from index.php. It will generate the frameset and include a minor set of JavaScript functions and variables which will be used by the other backend scripts with reference to the "top" JavaScript object. (JS reference: "top")

  2. alt_toplogo.php: Simply creates the logo in the upper left corner of the backend. (JS reference: "top.toplogo")

  3. alt_topmenu_dummy.php: By default it displays nothing. But when users click an icon of a file or database record and a context sensitive menu is displayed, then it is loaded into this frame. Then - depending on the capabilities of the client browser - the menu is either shown in this frame or the frame will remain blank and just write the menu content back to the calling frame where a DIV-layer will be created with the menu content dynamically. Depending on user configuration (User > Setup: Select navigation mode = "Icons in top frame") you might also see a list of menu icons in this bar as the default document (see below). (JS reference: "top.topmenuFrame")

  4. alt_menu.php: Displays the vertical menu of backend modules. (JS reference: "top.menu")

  5. alt_intro.php: By default the "About modules" content is shown here. However users might be shown the task center right away if they set that option in the User > Setup screen (if the "taskcenter" extension is installed). Otherwise this frame will contain module scripts depending on selections in the menu of course. One special instance of this is "Frameset modules" like the Web and File main modules since they will display a frameset with a page/directory tree and a record/file list (see below). (JS reference: "top.content")

  6. alt_shortcut.php: This frame is optionally displayed depending on user configuration. For "admin" users it's always shown. For other users it must be specifically enabled (User TSconfig: "options.shortcutFrame"). (JS reference: "top.shortcutFrame")

Finally the backend can be configured for "condensed mode" and there are also a few alternative options for how the menu is displayed.

Alternative menu: Selectorbox

One of those alternative options include having a selector box shown in a third frame in the "top-bar". That frame will have the JavaScript reference "top.menu" in substitute for the left menu and is made by the script "alt_menu_sel.php".

So setting the user profile like this...

... will yield this result for backend menu navigation:

  1. (alt_toplogo.php)

  2. alt_menu_sel.php: Basically a simple document with a selectorbox. An "onchange" event is fired when an item is selected. The onchange-event will simply call the function "top.goToModule('module_name')" in order to change module - so in reality it's all handled in the main frameset as with the other types of menus which also call the function in the frameset.

  3. (alt_topmenu_dummy.php)

Alternative menu: Icons in top frame

You can also have the menu as a list of icons in the top frame. This obviously requires you to know the menu items by heart so you can recognize the items on their icons only without the descriptive labels:

... and the menu will look like:

Main- and sub modules

Basically there are two types of modules, main modules and sub modules. Normally we refer to them just as "modules" or "backend modules".

The term "modules" is used within TYPO3 specifically for these backend modules. For the frontend we might also like to call a message board or guest book for "a module". However to distinguish between the two worlds we use another term, "plugins", for frontend applications such as message boards, shops, guest books etc.

Modules are discussed in detail later in this document. For now just observe the distinction between main- and submodules:

Main modules are those on the "first level" in the menu. Most of them are not linking directly to any script but are merely "headlines" for the submodules under them. One exception is the "Doc" module which is linked to the alt_doc.php script.

Sub modules are those on the second level in the menu. As such they don't have to have any technical relationship with the main module. The main module might simply act as a category for the module. However for "Frameset modules" it's a little different (see next section). Sub-modules may be named "Web>List" or "User>Setup" but we encourage unambiguous naming of modules so any module can be referred to by its own name only, eg. "List module" (Web>List) or "Filelist module" (File>Filelist) - it turns out to be much easier to say in words "The filelist module" than "The File-Filelist module".

Finally "Function menus" are what you get when you create backend modules "on the third level" - basically a module which inserts itself into a menu of an existing main- or sub-module. This of course requires the host module to supply an API for that, but that is in fact the case with both the "Info" and "Functions" modules!

In this example the extension "info_pagetsconfig" has been loaded in the EM (Extension Manager) and thus the Info module will show this item in the menu:

Frameset Modules

Main modules can be configured to load a frameset into the content frame instead of the modules default script. This is the case of the Web and File main modules. In itself that might sound trivial but the point is that "Frameset modules" are more than just a "category" for submodules - they are offering additional features:

In the case of frameset modules the idea becomes clear when you observe the usage; Both the Web and File main modules offers a two-split window with a page/folder tree on the left and a sub-module script loaded in the right frame. The point is that a click in the left frame will load the sub-module script in the right frame with an &id= parameter! In the case of the Web module this "id" is of course the page id, for the File module it's the path to the directory that should be shown.

Still this could be achieved by a local frameset made by the module itself, but the main point is that even if you switch between the sub-modules in the menu the id-value is passed along to the other sub-module and further will the id be restored and sent to the script when a totally other module has been accessed in the meantime and the user goes back to one of the sub-modules within the frameset module.

For instance you might click the page "A page title" below, the List module will show the records for that page id, then you go the the Extension Manager and when you later click on the List, Info, Access or Functions sub-module the last page id displayed will be shown again.

That is what a Frameset module does.

(See the module section for details on how to configure such a module)

A Frameset Module consists of these scripts:

  1. alt_mod_frameset.php: The frameset is constructed by this script for all frameset modules. This script will receive information about the scripts to load in the frames inside.

  2. [frameset module specific script name]: Navigation script as specified in the module configuration of the Frameset Module. (JS reference: top.content.nav_frame)

  3. border.html: A simple vertical bar separating the two main frames. (JS reference: top.content.border_frame)

  4. [module specific script name]: Sub-module script as specified in the module configuration of the sub-module. (JS reference: top.content.list_frame)

Certain requirements are put on the function of the navigation and sub-module scripts in order to ensure complete compatibility with the concept of Frameset Modules. This is basically about updating some JavaScript variables in the main frameset. See the module section for more details.

Condensed Mode

If Condensed Mode is enabled for the user it has an impact on how Frameset Modules handles the splitting of the screen into navigation and list frame. Basically the frameset is not used and the communication goes always from menu -> navigation frame -> list frame:

This mode is designed to help people with small screen resolutions to keep all the information on the screen without having to scroll horizontally (too much). In default mode TYPO3 runs best at resolutions of 1024x768 or above.

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:

  1. init.php: Included to provide database access, configuration values, class inclusions and user authentication etc.

  2. 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.

  3. Other classes: Then further classes needed by the script depending on the function will be included.

  4. 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:

  1. Global variable $BACK_PATH must point back to the TYPO3_mainDir (relative from the current script), eg. "../../" or "../../../typo3/"

  2. 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:

<?phpdefine('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:

  1. A set of constants and global variables are defined.

  2. A set of classes are included.

  3. PHP environment is checked and set.

  4. Local configuration is included ("localconf.php").

  5. Table definitions are set ("tables.php").

  6. Connection to database established.

  7. Backend user is authenticated.

  8. 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")

  1. Error reporting is set to

    error_reporting (E_ALL ^ E_NOTICE);

  2. Constants TYPO3_OS, TYPO3_MODE, PATH_thisScript and TYPO3_mainDir are defined.

  3. 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!

  4. Constants  PATH_typo3, PATH_typo3_mod, PATH_site, PATH_t3lib, PATH_typo3conf are defined.

  5. Classes t3lib_div and t3lib_extMgm are included.

  6. 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:
    1. $TYPO3_CONF_VARS is initialized with the default set of values.

    2. $typo_db* database variables are reset to blank.

    3. PATH_typo3conf.'localconf.php' is included. If not found, script exits with error message.

      localconf.php:

      1. 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]:

    4. Constants TYPO3_db, TYPO3_db_username, TYPO3_db_password, TYPO3_db_host, TYPO3_tables_script, TYPO3_extTableDef_script and TYPO3_languages is defined

    5. $typo_db* variables are unset.

    6. Certain $GLOBALS['TYPO3_CONF_VARS']['GFX'] values are manipulated.

    7. debug() function is defined (only function outside a class!)

    8. "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.

    9. 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).

    10. Global vars $EXEC_TIME, $SIM_EXEC_TIME and $TYPO_VERSION are set

    [Back in init.php]:

  7. Database Abstraction Layer foundation class is included and global object, $TYPO3_DB, is created.

  8. Global vars $CLIENT and $PARSETIME_START are set.

  9. 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.

  10. IP masking is performed (based on $TYPO3_CONF_VARS['BE']['IPmaskList']). Exits if criterias are not met.

  11. SSL locking is checked ($TYPO3_CONF_VARS['BE']['lockSSL']).  Exits if criterias are not met.

  12. Checking PHP environment. Exits if PHP version is not supported or if HTTP_GET_VARS[GLOBALS] is set.

  13. 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.

  14. Database connection. Exits if database connection fails.

  15. Checking browser. Must be 4+ browser. Exits if criterias are not met.

  16. 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:
    1. global variables $PAGES_TYPES, $ICON_TYPES, $LANG_GENERAL_LABELS, $TCA, $TBE_MODULES, $TBE_STYLES, $FILEICONS are defined.

    [Back in init.php]

  17. "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)

  18. If the constant TYPO3_extTableDef_script is defined then that script is included.

  19. 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!)

  20. The global variables $WEBMOUNTS and $FILEMOUNTS are set (based on the BE_USERS permissions)

  21. Optional output compression initialized

So that is what happens in init.php!

Global variables, Constants and Classes

After init.php has been included there is a set of variables, constants and classes available to the parent script. In the document "TYPO3 Core API" you can see two tables listing these constants and variables.

The column "Avail. in FE" is an indicator that tells you if the constant, variable or class mentioned is also available to scripts running under the frontend of the "cms" extension. Strictly this is not a part of the core (which is what we deal with in this document), but since the "cms" extension is practically always a part of a TYPO3 setup it's included here as a service to you.

Classes

This is the classes already included after having included "init.php":

Class

Included in

Description

Avail. in FE

t3lib_div

init.php

YES

t3lib_extMgm

init.php

YES

t3lib_db

init.php

YES

t3lib_userauth

init.php

YES

t3lib_userauthgroup

init.php

-

t3lib_beuserauth

init.php

-

t3lib_iconworks

init.php

-

t3lib_befunc

init.php

-

t3lib_cs

init.php

YES

gzip_encode

init.php

Output compression class by Sandy McArthur, Jr. Included if option is set in TYPO3_CONF_VARS.

(YES)

Possibly other classes could have been included in "ext_tables.php" files or "ext_localconf.php" files. This is OK for the "localconf.php" file, but not necessarily for extensions. Please see the Extension API description for guidelines on this.

System/PHP Variables

A short notice on system variables:

Don't use any system-global vars, except these:

HTTP_GET_VARS, HTTP_POST_VARS, HTTP_COOKIE_VARS

Any other variables may not be accessible if php.ini-optimized is used!

Environment / Server variables are also very critical! Since different servers and platforms offer different values in the environment and server variables, TYPO3 features an abstraction function you should always use if you need to get the REQUEST_URI, HTTP_HOST or something like that. At least never use the PHP function "getenv()" or take the values directly from HTTP_SERVER_VARS - rather call t3lib_div::getIndpEnv("name_of_sys_variable") to get the value (if it is supported by that function). You can rely on that function will deliver a consistent value independently of the server OS and webserver software.

You should refer to the TYPO3 Coding Guidelines or TYPO3 Core API for more information about this or go directly to the source of class.t3lib_div.php.

The template class (template.php)

Most backend scripts include another core script than "init.php". That is "template.php".

require ('init.php');

require ('template.php');

"template.php" contains a class "template". This class is used to output HTML-header, footer and page content in the backend.

template.php does this:

  1. Initially an obsolete function, fw($str), is defined. This just returns the input string un-altered. May be removed in the future as it's obsolete and here for backwards compatibility only. If you use this function in your modules, then stop doing that!

  2. Defines the class "template" which contains the HTML output related methods for creating backend documents.

  3. Defines four extension classes of the template class: bigDoc, noDoc, smallDoc, mediumDoc. Each of them presets a certain width of the outputted page by specifying a class for a wrapping DIV-tag.

  4. Includes sysext/lang/lang.php which contains the class "language" for management of localized labels in the backend. It also contains an instance of the character set conversion class, "t3lib_cs".

  5. Creates the global variables $TBE_TEMPLATE and $LANG as instances of the classes "template" and "language" respectively.

"template.php" requires init.php to have been included on beforehand.

This is the variables and classes available in addition after inclusion of "template.php":

Variables

Global variable

Defined in

Description

Avail. in FE

$TBE_TEMPLATE

template.php

Global backend template object for HTML-output in backend modules

$LANG

template.php

Localization object which returns the correct localized labels for various parts in the backend.

It also contains an instance of the "t3lib_cs" class in $LANG->csConvObj

$LOCAL_LANG

Optionally included "locallang" file.

Stores language specific labels and messages. Requires a "local_lang" file to have been included in the global space.

Notice: This variable is unset in "config_default .php" for your convenience. So don't set the $LOCAL_LANG array prior to "init.php".

-

$TCA_DESCR

[on-the-fly]

Could be set to contain help descriptions for fields and modules.  Is set by API function in the "language" class.

Unset in "config_default.php"

Classes

Class

Included in

Description

Avail. in FE

template

[optionally  included after init.php, see next section]

Global backend template class for HTML-output in backend modules, instantiated inside template.php as $TBE_TEMPLATE

-

language

template.php

Localization class which returns the correct localized labels for various parts in the backend. Instantiated as $LANG

-

Example: A dummy backend script

As an good example of how backend scripts (modules) should be constructed, please look at the dummy.php file:

/**  * Dummy document - displays nothing but background color. *  * @author    Kasper Skårhøj <kasper@typo3.com> * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj * XHTML compliant content */require ('init.php');require ('template.php');// ***************************// Script Classes// ***************************class SC_dummy {    var $content;        /**     * Create content     */    function main()    {        global $TBE_TEMPLATE;            // Start page        $TBE_TEMPLATE->docType = 'xhtml_trans';        $this->content.=$TBE_TEMPLATE->startPage('Dummy document');            // End page:        $this->content.=$TBE_TEMPLATE->endPage();    }        /**     * Print output     */    function printContent()    {        echo $this->content;    }}// Include extension?if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/dummy.php'])    {    include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/dummy.php']);}// Make instance:$SOBE = t3lib_div::makeInstance('SC_dummy');$SOBE->main();$SOBE->printContent();

(In addition a script must include opening and closing tags for php (<?php ... ?>) and a copyright header defining the author and GNU/GPL license. See almost any script in the backend for an example)

In this example you see the following important elements:

  1. init.php is included by require(): We can now know that a backend user is authenticated, that there is a database connection etc.

  2. template.php is included by require(): We can now create backend HTML-output and localized labels.

  3. Script class is defined (here: "SC_dummy", typically named "SC_" + script name). All processing should take place inside this class

  4. Possible inclusion of an extension class for the "SC_dummy" (this is what happens in the lines after "// Include extension?"

  5. Finally the script class is instantiated and the relevant functions are called - here main() and printContent(). Which functions needs to be called from the global space depends on what you have put into your class!

Inside the script class these basic steps for HTML output is taken:

  1. The method $TBE_TEMPLATE->startPage('Dummy document') is called: This returns the header section of the output HTML page with the page title set to "Dummy document". Prior to this function call the docType is set to XHTML Transitional (optional). You can also specify other optional values like additional CSS styles, JavaScript etc.

  2. The method $TBE_TEMPLATE->endPage() is called: This returns the page footer.

  3. In between the two function calls you can basically output any HTML you like as the page content. <body> tags have been set and typically the whole page is wrapped in a DIV tag as well.

The HTML output of dummy.php will look like this:

<?xml version="1.0" encoding="iso-8859-1"?>

<?xml-stylesheet href="#internalStyle" type="text/css"?>

<!DOCTYPE html

     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

<meta name="GENERATOR" content="TYPO3 3.6.0-dev, http://typo3.com, &#169; Kasper Sk&#197;rh&#248;j 1998-2003, extensions are copyright of their respective owners." />

<title>Dummy document</title>

<link rel="stylesheet" type="text/css" href="stylesheet.css"/>

<style type="text/css" id="internalStyle">

/*<![CDATA[*/

A:hover {color: #254D7B}

H2 {background-color: #9BA1A8;}

H3 {background-color: #E7DBA8;}

BODY {background-color: #F7F3EF;}

/*]]>*/

</style>

</head>

<body>

<!-- Wrapping DIV-section for whole page BEGIN -->

<div class="typo3-def">

... [additional content between startPage() and endPage() will be inserted here!] ...

<script type="text/javascript">

 /*<![CDATA[*/

if (top.busy && top.busy.loginRefreshed) {

top.busy.loginRefreshed();

}

/*]]>*/

</script>

<!-- Wrapping DIV-section for whole page END -->

</div>

</body>

</html>

The maroon coloured content is created by startPage()

The teal coloured content is created by endPage()

The green/bold line represents the position where your custom output will be placed in the document.

API documentation

There is a host of methods inside the template class which can be used. Some of these are documented in "TYPO3 Core API" and others by examples in various Extension Programming Tutorials.

Other reserved global variables

In addition to the global variables declared in "init.php" there are a number of other reserved global variables which has a recognized importance. These are always defined outside "init.php" either prior to or after the inclusion of "init.php".

Global variable

Defined in

Description

Avail. in FE

$MLANG

[prior to init.php / conf.php of modules]

Contains a limited amount of language labels: The title, icon and description of the module.

-

$MCONF

[prior to init.php / conf.php of modules]

Contains a few module-cofiguration informations like the name, access and which script to use. Primarily used by access control and the class t3lib_loadmodules.

-

$BACK_PATH

[prior to init.php / conf.php of modules]

Possibly set in the parent script including "init.php" pointing back to the "TYPO3_mainDir" from wherever the parent script is located. Used primarily for images and links. See discussion on "TYPO3_MOD_PATH" and modules in general.

-

$LOCKED_RECORDS

t3lib_BEfunc

Locking of records is cached in this variable.



TYPO3 Core API

TSRef

TYPO3 Coding Guidelines