class.t3lib_extmgm.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * Contains a class with Extension Management functions
00029  *
00030  * $Id: class.t3lib_extmgm.php 4432 2008-11-07 03:52:22Z flyguide $
00031  * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
00032  *
00033  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00034  */
00035 /**
00036  * [CLASS/FUNCTION INDEX of SCRIPT]
00037  *
00038  *
00039  *
00040  *  114: class t3lib_extMgm
00041  *
00042  *              SECTION: PATHS and other evaluation
00043  *  131:     function isLoaded($key,$exitOnError = 0)
00044  *  147:     function extPath($key,$script='')
00045  *  165:     function extRelPath($key)
00046  *  182:     function siteRelPath($key)
00047  *  194:     function getCN($key)
00048  *
00049  *              SECTION: Adding BACKEND features
00050  *  227:     function addTCAcolumns($table,$columnArray,$addTofeInterface=0)
00051  *  251:     function addToAllTCAtypes($table,$str,$specificTypesList='',$position='')
00052  *  309:     function allowTableOnStandardPages($table)
00053  *  326:     function addModule($main,$sub='',$position='',$path='')
00054  *  389:     function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='')
00055  *  408:     function addPageTSConfig($content)
00056  *  422:     function addUserTSConfig($content)
00057  *  437:     function addLLrefForTCAdescr($tca_descr_key,$file_ref)
00058  *
00059  *              SECTION: Adding SERVICES features
00060  *  479:     function addService($extKey, $serviceType, $serviceKey, $info)
00061  *  547:     function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array())
00062  *  618:     function deactivateService($serviceType, $serviceKey)
00063  *
00064  *              SECTION: Adding FRONTEND features
00065  *  657:     function addPlugin($itemArray,$type='list_type')
00066  *  682:     function addPiFlexFormValue($piKeyToMatch,$value)
00067  *  702:     function addToInsertRecords($table,$content_table='tt_content',$content_field='records')
00068  *  733:     function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0)
00069  *  808:     function addStaticFile($extKey,$path,$title)
00070  *  827:     function addTypoScriptSetup($content)
00071  *  841:     function addTypoScriptConstants($content)
00072  *  858:     function addTypoScript($key,$type,$content,$afterStaticUid=0)
00073  *
00074  *              SECTION: INTERNAL EXTENSION MANAGEMENT:
00075  *  921:     function typo3_loadExtensions()
00076  *  998:     function _makeIncludeHeader($key,$file)
00077  * 1019:     function isCacheFilesAvailable($cacheFilePrefix)
00078  * 1032:     function isLocalconfWritable()
00079  * 1045:     function cannotCacheFilesWritable($cacheFilePrefix)
00080  * 1069:     function currentCacheFiles()
00081  * 1092:     function writeCacheFiles($extensions,$cacheFilePrefix)
00082  * 1130:     function removeCacheFiles()
00083  *
00084  * TOTAL FUNCTIONS: 32
00085  * (This index is automatically created/updated by the extension "extdeveval")
00086  *
00087  */
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 /**
00105  * Extension Management functions
00106  *
00107  * This class is never instantiated, rather the methods inside is called as functions like
00108  *      t3lib_extMgm::isLoaded('my_extension');
00109  *
00110  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00111  * @package TYPO3
00112  * @subpackage t3lib
00113  */
00114 final class t3lib_extMgm {
00115 
00116 
00117     /**************************************
00118      *
00119      * PATHS and other evaluation
00120      *
00121      ***************************************/
00122 
00123     /**
00124      * Returns true if the extension with extension key $key is loaded.
00125      * Usage: 109
00126      *
00127      * @param   string      Extension key to test
00128      * @param   boolean     If $exitOnError is true and the extension is not loaded the function will die with an error message
00129      * @return  boolean
00130      */
00131     public static function isLoaded($key, $exitOnError = 0) {
00132         global $TYPO3_LOADED_EXT;
00133         if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key]))    die('Fatal Error: Extension "'.$key.'" was not loaded.');
00134         return isset($TYPO3_LOADED_EXT[$key]);
00135     }
00136 
00137     /**
00138      * Returns the absolute path to the extension with extension key $key
00139      * If the extension is not loaded the function will die with an error message
00140      * Useful for internal fileoperations
00141      * Usage: 136
00142      *
00143      * @param   string      Extension key
00144      * @param   string      $script is appended to the output if set.
00145      * @return  string
00146      */
00147     public static function extPath($key, $script = '') {
00148         global $TYPO3_LOADED_EXT;
00149         if (!isset($TYPO3_LOADED_EXT[$key])) {
00150             #debug(array(debug_backtrace()));
00151             die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extPath)');
00152         }
00153         return PATH_site.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$script;
00154     }
00155 
00156     /**
00157      * Returns the relative path to the extension as measured from from the TYPO3_mainDir
00158      * If the extension is not loaded the function will die with an error message
00159      * Useful for images and links from backend
00160      * Usage: 54
00161      *
00162      * @param   string      Extension key
00163      * @return  string
00164      */
00165     public static function extRelPath($key) {
00166         global $TYPO3_LOADED_EXT;
00167         if (!isset($TYPO3_LOADED_EXT[$key])) {
00168             die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extRelPath)');
00169         }
00170         return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
00171     }
00172 
00173     /**
00174      * Returns the relative path to the extension as measured from the PATH_site (frontend)
00175      * If the extension is not loaded the function will die with an error message
00176      * Useful for images and links from the frontend
00177      * Usage: 6
00178      *
00179      * @param   string      Extension key
00180      * @return  string
00181      */
00182     public static function siteRelPath($key) {
00183         return substr(t3lib_extMgm::extPath($key), strlen(PATH_site));
00184     }
00185 
00186     /**
00187      * Returns the correct class name prefix for the extension key $key
00188      * Usage: 3
00189      *
00190      * @param   string      Extension key
00191      * @return  string
00192      * @internal
00193      */
00194     public static function getCN($key) {
00195         return substr($key, 0, 5)=='user_' ? 'user_'.str_replace('_', '', substr($key, 5)) : 'tx_'.str_replace('_', '', $key);
00196     }
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207     /**************************************
00208      *
00209      *   Adding BACKEND features
00210      *   (related to core features)
00211      *
00212      ***************************************/
00213 
00214     /**
00215      * Adding fields to an existing table definition in $TCA
00216      * Adds an array with $TCA column-configuration to the $TCA-entry for that table.
00217      * This function adds the configuration needed for rendering of the field in TCEFORMS - but it does NOT add the field names to the types lists!
00218      * So to have the fields displayed you must also call fx. addToAllTCAtypes or manually add the fields to the types list.
00219      * FOR USE IN ext_tables.php FILES
00220      * Usage: 4
00221      *
00222      * @param   string      $table is the table name of a table already present in $TCA with a columns section
00223      * @param   array       $columnArray is the array with the additional columns (typical some fields an extension wants to add)
00224      * @param   boolean     If $addTofeInterface is true the list of fields are also added to the fe_admin_fieldList.
00225      * @return  void
00226      */
00227     public static function addTCAcolumns($table, $columnArray, $addTofeInterface = 0) {
00228         global $TCA;
00229         t3lib_div::loadTCA($table);
00230         if (is_array($columnArray) && is_array($TCA[$table]) && is_array($TCA[$table]['columns'])) {
00231             $TCA[$table]['columns'] = array_merge($TCA[$table]['columns'], $columnArray);   // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
00232             if ($addTofeInterface)  $TCA[$table]['feInterface']['fe_admin_fieldList'].=','.implode(',', array_keys($columnArray));
00233         }
00234     }
00235 
00236     /**
00237      * Makes fields visible in the TCEforms, adding them to the end of (all) "types"-configurations
00238      *
00239      * Adds a string $str (comma list of field names) to all ["types"][xxx]["showitem"] entries for table $table (unless limited by $specificTypesList)
00240      * This is needed to have new fields shown automatically in the TCEFORMS of a record from $table.
00241      * Typically this function is called after having added new columns (database fields) with the addTCAcolumns function
00242      * FOR USE IN ext_tables.php FILES
00243      * Usage: 1
00244      *
00245      * @param   string      Table name
00246      * @param   string      Field list to add.
00247      * @param   string      List of specific types to add the field list to. (If empty, all type entries are affected)
00248      * @param   string      Insert fields before (default) or after one of this fields (commalist with "before:" or "after:" commands). Example: "before:keywords,--palette--;;4,after:description". Palettes must be passed like in the example no matter how the palette definition looks like in TCA.
00249      * @return  void
00250      */
00251     public static function addToAllTCAtypes($table, $str, $specificTypesList = '', $position = '') {
00252         t3lib_div::loadTCA($table);
00253         $str = trim($str);
00254 
00255         if ($str && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['types'])) {
00256             foreach($GLOBALS['TCA'][$table]['types'] as $type => &$typeDetails) {
00257                 if ($specificTypesList === '' || t3lib_div::inList($specificTypesList, $type)) {
00258                     $typeDetails['showitem'] = self::executePositionedStringInsertion(
00259                         $typeDetails['showitem'],
00260                         $str,
00261                         $position
00262                     );
00263                 }
00264             }
00265         }
00266     }
00267 
00268     /**
00269      * Adds new fields to all palettes of an existing field.
00270      * If the field does not have a palette yet, it's created automatically and
00271      * gets called "generatedFor-$field".
00272      *
00273      * @param   string      $table: Name of the table
00274      * @param   string      $field: Name of the field that has the palette to be extended
00275      * @param   string      $addFields: List of fields to be added to the palette
00276      * @param   string      $insertionPosition: Insert fields before (default) or after one
00277      *                      of this fields (commalist with "before:" or "after:" commands).
00278      *                      Example: "before:keywords,--palette--;;4,after:description".
00279      *                      Palettes must be passed like in the example no matter how the
00280      *                      palette definition looks like in TCA.
00281      * @return  void
00282      */
00283     public static function addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition = '') {
00284         $generatedPalette = '';
00285         t3lib_div::loadTCA($table);
00286 
00287         if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
00288             $types =& $GLOBALS['TCA'][$table]['types'];
00289             if (is_array($types)) {
00290                     // Iterate through all types and search for the field that defines the palette to be extended:
00291                 foreach (array_keys($types) as $type) {
00292                     $fields = self::getFieldsOfFieldList($types[$type]['showitem']);
00293                     if (isset($fields[$field])) {
00294                             // If the field already has a palette, extend it:
00295                         if ($fields[$field]['details']['palette']) {
00296                             $palette = $fields[$field]['details']['palette'];
00297                             self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
00298                             // If there's not palette yet, create one:
00299                         } else {
00300                             if ($generatedPalette) {
00301                                 $palette = $generatedPalette;
00302                             } else {
00303                                 $palette = $generatedPalette = 'generatedFor-' . $field;
00304                                 self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
00305                             }
00306                             $fields[$field]['details']['palette'] = $palette;
00307                             $types[$type]['showitem'] =  self::generateFieldList($fields);
00308                         }
00309                     }
00310                 }
00311             }
00312         }
00313     }
00314 
00315     /**
00316      * Adds new fields to a palette.
00317      * If the palette does not exist yet, it's created automatically.
00318      *
00319      * @param   string      $table: Name of the table
00320      * @param   string      $palette: Name of the palette to be extended
00321      * @param   string      $addFields: List of fields to be added to the palette
00322      * @param   string      $insertionPosition: Insert fields before (default) or after one
00323      *                      of this fields (commalist with "before:" or "after:" commands).
00324      *                      Example: "before:keywords,--palette--;;4,after:description".
00325      *                      Palettes must be passed like in the example no matter how the
00326      *                      palette definition looks like in TCA.
00327      * @return  void
00328      */
00329     public static function addFieldsToPalette($table, $palette, $addFields, $insertionPosition = '') {
00330         t3lib_div::loadTCA($table);
00331 
00332         if (isset($GLOBALS['TCA'][$table])) {
00333             $paletteData =& $GLOBALS['TCA'][$table]['palettes'][$palette];
00334                 // If palette already exists, merge the data:
00335             if (is_array($paletteData)) {
00336                 $paletteData['showitem'] = self::executePositionedStringInsertion(
00337                     $paletteData['showitem'],
00338                     $addFields,
00339                     $insertionPosition
00340                 );
00341                 // If it's a new palette, just set the data:
00342             } else {
00343                 $paletteData['showitem'] = $addFields;
00344             }
00345         }
00346     }
00347 
00348     /**
00349      * Inserts as list of data into an existing list.
00350      * The insertion position can be defined accordant before of after existing list items.
00351      *
00352      * @param   string      $list: The list of items to be extended
00353      * @param   string      $insertionList: The list of items to inserted
00354      * @param   string      $insertionPosition: Insert fields before (default) or after one
00355      *                      of this fields (commalist with "before:" or "after:" commands).
00356      *                      Example: "before:keywords,--palette--;;4,after:description".
00357      *                      Palettes must be passed like in the example no matter how the
00358      *                      palette definition looks like in TCA.
00359      * @return  string      The extended list
00360      */
00361     protected static function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') {
00362         $list = trim($list);
00363         $insertionList = self::removeDuplicatesForInsertion($list, $insertionList);
00364 
00365             // Append data to the end (default):
00366         if ($insertionPosition === '') {
00367             $list.= ($list ? ', ' : '') . $insertionList;
00368             // Insert data before or after insertion points:
00369         } else {
00370             $positions = t3lib_div::trimExplode(',', $insertionPosition, true);
00371             $fields = self::getFieldsOfFieldList($list);
00372             $isInserted = false;
00373                 // Iterate through all fields an check whether it's possible to inserte there:
00374             foreach ($fields as $field => &$fieldDetails) {
00375                 $needles = self::getInsertionNeedles($field, $fieldDetails['details']);
00376                     // Insert data before:
00377                 foreach ($needles['before'] as $needle) {
00378                     if (in_array($needle, $positions)) {
00379                         $fieldDetails['rawData'] = $insertionList . ', '  . $fieldDetails['rawData'];
00380                         $isInserted = true;
00381                         break;
00382                     }
00383                 }
00384                     // Insert data after:
00385                 foreach ($needles['after'] as $needle) {
00386                     if (in_array($needle, $positions)) {
00387                         $fieldDetails['rawData'] .= ', ' . $insertionList;
00388                         $isInserted = true;
00389                         break;
00390                     }
00391                 }
00392                     // Break if insertion was already done:
00393                 if ($isInserted) {
00394                     break;
00395                 }
00396             }
00397                 // If insertion point could not be determined, append the data:
00398             if (!$isInserted) {
00399                 $list.= ($list ? ', ' : '') . $insertionList;
00400                 // If data was correctly inserted before or after existing items, recreate the list:
00401             } else {
00402                 $list = self::generateFieldList($fields, true);
00403             }
00404         }
00405 
00406         return $list;
00407     }
00408 
00409     /**
00410      * Compares an existing list of items and a list of items to be inserted
00411      * and returns a duplicate-free variant of that insertion list.
00412      *
00413      * Example:
00414      *  + list: 'field_a, field_b;;;;2-2-2, field_c;;;;3-3-3'
00415      *  + insertion: 'field_b, field_d, field_c;;;4-4-4'
00416      * -> new insertion: 'field_d'
00417      *
00418      * @param   string      $list: The list of items to be extended
00419      * @param   string      $insertionList: The list of items to inserted
00420      * @return  string      Duplicate-free list of items to be inserted
00421      */
00422     protected static function removeDuplicatesForInsertion($list, $insertionList) {
00423         $pattern = '/(^|,)\s*\b([^;,]+)\b[^,]*/';
00424 
00425         if ($list && preg_match_all($pattern, $list, $listMatches)) {
00426             if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) {
00427                 $duplicates = array_intersect($listMatches[2], $insertionListMatches[2]);
00428                 if ($duplicates) {
00429                     foreach ($duplicates as &$duplicate) {
00430                         $duplicate = preg_quote($duplicate, '/');
00431                     }
00432                     $insertionList = preg_replace(
00433                         array('/(^|,)\s*\b(' . implode('|', $duplicates) . ')\b[^,]*(,|$)/', '/,$/'),
00434                         array('\3', ''),
00435                         $insertionList
00436                     );
00437                 }
00438             }
00439         }
00440 
00441         return $insertionList;
00442     }
00443 
00444     /**
00445      * Generates search needles that are used for inserting fields/items into an existing list.
00446      *
00447      * @see     executePositionedStringInsertion
00448      * @param   string      $field: The name of the field/item
00449      * @param   array       $fieldDetails: Additional details of the field like e.g. palette information
00450      *                      (this array gets created by the function getFieldsOfFieldList())
00451      * @return  array       The needled to be used for inserting content before or after existing fields/items
00452      */
00453     protected static function getInsertionNeedles($field, array $fieldDetails) {
00454         $needles = array(
00455             'before' => array($field, 'before:' . $field),
00456             'after' => array('after:' . $field),
00457         );
00458 
00459         if ($fieldDetails['palette']) {
00460             $palette = $field . ';;' . $fieldDetails['palette'];
00461             $needles['before'][] = $palette;
00462             $needles['before'][] = 'before:' . $palette;
00463             $needles['afer'][] = 'after:' . $palette;
00464         }
00465 
00466         return $needles;
00467     }
00468 
00469     /**
00470      * Generates an array of fields with additional information such as e.g. the name of the palette.
00471      *
00472      * @param   string      $fieldList: List of fields/items to be splitted up
00473      *                      (this mostly reflects the data in $TCA[<table>]['types'][<type>]['showitem'])
00474      * @return  array       An array with the names of the fields as keys and additional information
00475      */
00476     protected static function getFieldsOfFieldList($fieldList) {
00477         $fields = array();
00478         $fieldParts = t3lib_div::trimExplode(',', $fieldList, true);
00479 
00480         foreach ($fieldParts as $fieldPart) {
00481             $fieldDetails = t3lib_div::trimExplode(';', $fieldPart, false, 5);
00482             if (!isset($fields[$fieldDetails[0]])) {
00483                 $fields[$fieldDetails[0]] = array(
00484                     'rawData' => $fieldPart,
00485                     'details' => array(
00486                         'field' => $fieldDetails[0],
00487                         'label' => $fieldDetails[1],
00488                         'palette' => $fieldDetails[2],
00489                         'special' => $fieldDetails[3],
00490                         'styles' => $fieldDetails[4],
00491                     ),
00492                 );
00493             }
00494         }
00495 
00496         return $fields;
00497     }
00498 
00499     /**
00500      * Generates a list of fields/items out of an array provided by the function getFieldsOfFieldList().
00501      *
00502      * @see     getFieldsOfFieldList
00503      * @param   array       $fields: The array of fields with optional additional information
00504      * @param   boolean     $useRawData: Use raw data instead of building by using the details (default: false)
00505      * @return  string      The list of fields/items which gets used for $TCA[<table>]['types'][<type>]['showitem']
00506      *                      or $TCA[<table>]['palettes'][<palette>]['showitem'] in most cases
00507      */
00508     protected static function generateFieldList(array $fields, $useRawData = false) {
00509         $fieldParts = array();
00510 
00511         foreach ($fields as $field => $fieldDetails) {
00512             if ($useRawData) {
00513                 $fieldParts[] = $fieldDetails['rawData'];
00514             } else {
00515                 $fieldParts[] = (count($fieldDetails['details']) > 1 ? implode(';', $fieldDetails['details']) : $field);
00516             }
00517         }
00518 
00519         return implode(', ', $fieldParts);
00520     }
00521 
00522     /**
00523      * Add tablename to default list of allowed tables on pages (in $PAGES_TYPES)
00524      * Will add the $table to the list of tables allowed by default on pages as setup by $PAGES_TYPES['default']['allowedTables']
00525      * FOR USE IN ext_tables.php FILES
00526      * Usage: 11
00527      *
00528      * @param   string      Table name
00529      * @return  void
00530      */
00531     public static function allowTableOnStandardPages($table) {
00532         global $PAGES_TYPES;
00533 
00534         $PAGES_TYPES['default']['allowedTables'].=','.$table;
00535     }
00536 
00537     /**
00538      * Adds a module (main or sub) to the backend interface
00539      * FOR USE IN ext_tables.php FILES
00540      * Usage: 18
00541      *
00542      * @param   string      $main is the main module key, $sub is the submodule key. So $main would be an index in the $TBE_MODULES array and $sub could be an element in the lists there.
00543      * @param   string      $sub is the submodule key. If $sub is not set a blank $main module is created.
00544      * @param   string      $position can be used to set the position of the $sub module within the list of existing submodules for the main module. $position has this syntax: [cmd]:[submodule-key]. cmd can be "after", "before" or "top" (or blank which is default). If "after"/"before" then submodule will be inserted after/before the existing submodule with [submodule-key] if found. If not found, the bottom of list. If "top" the module is inserted in the top of the submodule list.
00545      * @param   string      $path is the absolute path to the module. If this value is defined the path is added as an entry in $TBE_MODULES['_PATHS'][  main_sub  ] = $path; and thereby tells the backend where the newly added modules is found in the system.
00546      * @return  void
00547      */
00548     public static function addModule($main, $sub = '', $position = '', $path = '') {
00549         global $TBE_MODULES;
00550 
00551         if (isset($TBE_MODULES[$main]) && $sub) {   // If there is already a main module by this name:
00552 
00553                 // Adding the submodule to the correct position:
00554             list($place, $modRef) = t3lib_div::trimExplode(':', $position, 1);
00555             $mods = t3lib_div::trimExplode(',', $TBE_MODULES[$main], 1);
00556             if (!in_array($sub, $mods)) {
00557                 switch(strtolower($place)) {
00558                     case 'after':
00559                     case 'before':
00560                         $pointer = 0;
00561                         reset($mods);
00562                         while(list($k, $m) = each($mods)) {
00563                             if (!strcmp($m, $modRef)) {
00564                                 $pointer = strtolower($place)=='after'?$k+1:$k;
00565                             }
00566                         }
00567                         array_splice(
00568                             $mods,  // The modules array
00569                             $pointer,       // To insert one position from the end of the list
00570                             0,      // Don't remove any items, just insert
00571                             $sub    // Module to insert
00572                         );
00573                     break;
00574                     default:
00575                         if (strtolower($place)=='top') {
00576                             array_unshift($mods, $sub);
00577                         } else {
00578                             array_push($mods, $sub);
00579                         }
00580                     break;
00581                 }
00582             }
00583                 // Re-inserting the submodule list:
00584             $TBE_MODULES[$main] = implode(',', $mods);
00585         } else {    // Create new main modules with only one submodule, $sub (or none if $sub is blank)
00586             $TBE_MODULES[$main] = $sub;
00587         }
00588 
00589             // Adding path:
00590         if ($path) {
00591             $TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')] = $path;
00592         }
00593     }
00594 
00595     /**
00596      * Adds a module path to TBE_MODULES for used with the module dispatcher, mod.php
00597      * Used only for modules that are not placed in the main/sub menu hierarchy by the traditional mechanism of addModule()
00598      * Examples for this is context menu functionality (like import/export) which runs as an independent module through mod.php
00599      * FOR USE IN ext_tables.php FILES
00600      * Example:  t3lib_extMgm::addModulePath('xMOD_tximpexp', t3lib_extMgm::extPath($_EXTKEY).'app/');
00601      *
00602      * @param   string      $name is the name of the module, refer to conf.php of the module.
00603      * @param   string      $path is the absolute path to the module directory inside of which "index.php" and "conf.php" is found.
00604      * @return  void
00605      */
00606     public static function addModulePath($name, $path) {
00607         global $TBE_MODULES;
00608 
00609         $TBE_MODULES['_PATHS'][$name] = $path;
00610     }
00611 
00612     /**
00613      * Adds a "Function menu module" ('third level module') to an existing function menu for some other backend module
00614      * The arguments values are generally determined by which function menu this is supposed to interact with
00615      * See Inside TYPO3 for information on how to use this function.
00616      * FOR USE IN ext_tables.php FILES
00617      * Usage: 26
00618      *
00619      * @param   string      Module name
00620      * @param   string      Class name
00621      * @param   string      Class path
00622      * @param   string      Title of module
00623      * @param   string      Menu array key - default is "function"
00624      * @param   string      Workspace conditions. Blank means all workspaces, any other string can be a comma list of "online", "offline" and "custom"
00625      * @return  void
00626      * @see t3lib_SCbase::mergeExternalItems()
00627      */
00628     public static function insertModuleFunction($modname, $className, $classPath, $title, $MM_key = 'function', $WS = '') {
00629         global $TBE_MODULES_EXT;
00630         $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className] = array(
00631             'name' => $className,
00632             'path' => $classPath,
00633             'title' => $title,
00634             'ws' => $WS
00635         );
00636     }
00637 
00638     /**
00639      * Adds $content to the default Page TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultPageTSconfig']
00640      * Prefixed with a [GLOBAL] line
00641      * FOR USE IN ext_tables.php/ext_locallang.php FILES
00642      * Usage: 5
00643      *
00644      * @param   string      Page TSconfig content
00645      * @return  void
00646      */
00647     public static function addPageTSConfig($content) {
00648         global $TYPO3_CONF_VARS;
00649         $TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content;
00650     }
00651 
00652     /**
00653      * Adds $content to the default User TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultUserTSconfig']
00654      * Prefixed with a [GLOBAL] line
00655      * FOR USE IN ext_tables.php/ext_locallang.php FILES
00656      * Usage: 3
00657      *
00658      * @param   string      User TSconfig content
00659      * @return  void
00660      */
00661     public static function addUserTSConfig($content) {
00662         global $TYPO3_CONF_VARS;
00663         $TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content;
00664     }
00665 
00666     /**
00667      * Adds a reference to a locallang file with TCA_DESCR labels
00668      * FOR USE IN ext_tables.php FILES
00669      * eg. t3lib_extMgm::addLLrefForTCAdescr('pages', 'EXT:lang/locallang_csh_pages.xml'); for the pages table or t3lib_extMgm::addLLrefForTCAdescr('_MOD_web_layout', 'EXT:cms/locallang_csh_weblayout.php'); for the Web > Page module.
00670      * Usage: 31
00671      *
00672      * @param   string      Description key. Typically a database table (like "pages") but for applications can be other strings, but prefixed with "_MOD_")
00673      * @param   string      File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php" (or ".xml")
00674      * @return  void
00675      */
00676     public static function addLLrefForTCAdescr($tca_descr_key, $file_ref) {
00677         global $TCA_DESCR;
00678         if ($tca_descr_key) {
00679             if (!is_array($TCA_DESCR[$tca_descr_key])) {
00680                 $TCA_DESCR[$tca_descr_key] = array();
00681             }
00682             if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) {
00683                 $TCA_DESCR[$tca_descr_key]['refs'] = array();
00684             }
00685             $TCA_DESCR[$tca_descr_key]['refs'][] = $file_ref;
00686         }
00687     }
00688 
00689 
00690 
00691 
00692 
00693 
00694 
00695 
00696 
00697 
00698 
00699 
00700     /**************************************
00701      *
00702      *   Adding SERVICES features
00703      *
00704      *   @author    Ren� Fritz <r.fritz@colorcube.de>
00705      *
00706      ***************************************/
00707 
00708     /**
00709      * Adds a service to the global services array
00710      *
00711      * @param   string      Extension key
00712      * @param   string      Service type, cannot be prefixed "tx_"
00713      * @param   string      Service key, must be prefixed "tx_" or "user_"
00714      * @param   array       Service description array
00715      * @return  void
00716      * @author  Ren� Fritz <r.fritz@colorcube.de>
00717      */
00718     public static function addService($extKey, $serviceType, $serviceKey, $info) {
00719         global $T3_SERVICES, $TYPO3_CONF_VARS;
00720 
00721         // even not available services will be included to make it possible to give the admin a feedback of non-available services.
00722         // but maybe it's better to move non-available services to a different array??
00723 
00724         if ($serviceType &&
00725             !t3lib_div::isFirstPartOfStr($serviceType, 'tx_') &&
00726             (t3lib_div::isFirstPartOfStr($serviceKey, 'tx_') || t3lib_div::isFirstPartOfStr($serviceKey, 'user_')) &&
00727             is_array($info))    {
00728 
00729             $info['priority'] = max(0, min(100, $info['priority']));
00730 
00731             $T3_SERVICES[$serviceType][$serviceKey] = $info;
00732 
00733             $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey;
00734             $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
00735             $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType;
00736 
00737 
00738                 // mapping a service key to a service type
00739                 // all service keys begin with tx_ - service types don't
00740                 // this way a selection of a special service key as service type is easy
00741             $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey];
00742 
00743 
00744                 // change the priority (and other values) from TYPO3_CONF_VARS
00745                 // $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]['priority']
00746                 // even the activation is possible (a unix service might be possible on windows for some reasons)
00747             if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) {
00748 
00749                     // no check is done here - there might be configuration values only the service type knows about, so we pass everything
00750                 $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey], $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]);
00751             }
00752 
00753 
00754                 // OS check
00755                 // empty $os means 'not limited to one OS', therefore a check is not needed
00756             if ($T3_SERVICES[$serviceType][$serviceKey]['available'] && $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
00757 
00758                     // TYPO3_OS is not yet defined
00759                 $os_type = stristr(PHP_OS, 'win')&&!stristr(PHP_OS, 'darwin')?'WIN':'UNIX';
00760 
00761                 $os = t3lib_div::trimExplode(',', strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os']));
00762 
00763                 if (!in_array($os_type, $os)) {
00764                     t3lib_extMgm::deactivateService($serviceType, $serviceKey);
00765                 }
00766             }
00767 
00768                 // convert subtype list to array for quicker access
00769             $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array();
00770             $serviceSubTypes = t3lib_div::trimExplode(',', $info['subtype']);
00771             foreach ($serviceSubTypes as $subtype) {
00772                 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
00773             }
00774         }
00775     }
00776 
00777     /**
00778      * Find the available service with highest priority
00779      *
00780      * @param   string      Service type
00781      * @param   string      Service sub type
00782      * @param   mixed       Service keys that should be excluded in the search for a service. Array or comma list.
00783      * @return  mixed       Service info array if a service was found, FLASE otherwise
00784      * @author  Ren� Fritz <r.fritz@colorcube.de>
00785      */
00786     public static function findService($serviceType, $serviceSubType = '', $excludeServiceKeys = array()) {
00787         global $T3_SERVICES, $TYPO3_CONF_VARS;
00788 
00789         $serviceKey = FALSE;
00790         $serviceInfo = FALSE;
00791         $priority = 0;
00792         $quality = 0;
00793 
00794         if (!is_array($excludeServiceKeys) ) {
00795             $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
00796         }
00797 
00798         if (is_array($T3_SERVICES[$serviceType])) {
00799             foreach($T3_SERVICES[$serviceType] as $key => $info)    {
00800 
00801                 if (in_array($key, $excludeServiceKeys)) {
00802                     continue;
00803                 }
00804 
00805                     // select a subtype randomly
00806                     // usefull to start a service by service key without knowing his subtypes - for testing purposes
00807                 if ($serviceSubType=='*') {
00808                     $serviceSubType = key($info['serviceSubTypes']);
00809                 }
00810 
00811                     // this matches empty subtype too
00812                 if ($info['available'] && ($info['subtype']==$serviceSubType || $info['serviceSubTypes'][$serviceSubType]) && $info['priority']>=$priority )    {
00813 
00814                         // has a lower quality than the already found, therefore we skip this service
00815                     if($info['priority']==$priority && $info['quality']<$quality) {
00816                         continue;
00817                     }
00818 
00819                         // service depends on external programs - check if they exists
00820                     if(trim($info['exec'])) {
00821                         require_once(PATH_t3lib.'class.t3lib_exec.php');
00822 
00823                         $executables = t3lib_div::trimExplode(',', $info['exec'], 1);
00824                         foreach($executables as $executable) {
00825                             if(!t3lib_exec::checkCommand($executable)) {
00826                                 t3lib_extMgm::deactivateService($serviceType, $key);
00827                                 $info['available'] = FALSE;
00828                                 break;
00829                             }
00830                         }
00831                     }
00832 
00833                         // still available after exec check?
00834                     if($info['available']) {
00835                         $serviceKey = $key;
00836                         $priority = $info['priority'];
00837                         $quality = $info['quality'];
00838                     }
00839                 }
00840             }
00841         }
00842 
00843         if ($serviceKey) {
00844             $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey];
00845         }
00846         return $serviceInfo;
00847     }
00848 
00849     /**
00850      * Deactivate a service
00851      *
00852      * @param   string      Service type
00853      * @param   string      Service key
00854      * @return  void
00855      * @author  Ren� Fritz <r.fritz@colorcube.de>
00856      */
00857     public static function deactivateService($serviceType, $serviceKey) {
00858         global $T3_SERVICES;
00859 
00860             // ... maybe it's better to move non-available services to a different array??
00861         $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE;
00862     }
00863 
00864 
00865 
00866 
00867 
00868 
00869 
00870 
00871 
00872 
00873 
00874 
00875 
00876 
00877     /**************************************
00878      *
00879      *   Adding FRONTEND features
00880      *   (related specifically to "cms" extension)
00881      *
00882      ***************************************/
00883 
00884     /**
00885      * Adds an entry to the list of plugins in content elements of type "Insert plugin"
00886      * Takes the $itemArray (label, value[,icon]) and adds to the items-array of $TCA[tt_content] elements with CType "listtype" (or another field if $type points to another fieldname)
00887      * If the value (array pos. 1) is already found in that items-array, the entry is substituted, otherwise the input array is added to the bottom.
00888      * Use this function to add a frontend plugin to this list of plugin-types - or more generally use this function to add an entry to any selectorbox/radio-button set in the TCEFORMS
00889      * FOR USE IN ext_tables.php FILES
00890      * Usage: 13
00891      *
00892      * @param   array       Item Array
00893      * @param   string      Type (eg. "list_type") - basically a field from "tt_content" table
00894      * @return  void
00895      */
00896     public static function addPlugin($itemArray, $type = 'list_type') {
00897         global $TCA;
00898 
00899         $_EXTKEY = $GLOBALS['_EXTKEY'];
00900         if ($_EXTKEY && !$itemArray[2]) {
00901             $itemArray[2] = t3lib_extMgm::extRelPath($_EXTKEY) . 'ext_icon.gif';
00902         }
00903 
00904         t3lib_div::loadTCA('tt_content');
00905         if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) {
00906             reset($TCA['tt_content']['columns'][$type]['config']['items']);
00907             while(list($k, $v) = each($TCA['tt_content']['columns'][$type]['config']['items'])) {
00908                 if (!strcmp($v[1], $itemArray[1])) {
00909                     $TCA['tt_content']['columns'][$type]['config']['items'][$k] = $itemArray;
00910                     return;
00911                 }
00912             }
00913             $TCA['tt_content']['columns'][$type]['config']['items'][] = $itemArray;
00914         }
00915     }
00916 
00917     /**
00918      * Adds an entry to the "ds" array of the tt_content field "pi_flexform".
00919      * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin or content element.
00920      * Usage: 0
00921      *
00922      * @param   string      Plugin key as used in the list_type field. Use the asterisk * to match all list_type values.
00923      * @param   string      Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
00924      * @param   string      Value of tt_content.CType (Content Type) to match. The default is "list" which corresponds to the "Insert Plugin" content element.  Use the asterisk * to match all CType values.
00925      * @return  void
00926      * @see addPlugin()
00927      */
00928     public static function addPiFlexFormValue($piKeyToMatch, $value, $CTypeToMatch = 'list') {
00929         global $TCA;
00930         t3lib_div::loadTCA('tt_content');
00931 
00932         if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds'])) {
00933             $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch.','.$CTypeToMatch] = $value;
00934         }
00935     }
00936 
00937     /**
00938      * Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records"
00939      * By using $content_table and $content_field you can also use the function for other tables.
00940      * FOR USE IN ext_tables.php FILES
00941      * Usage: 9
00942      *
00943      * @param   string      Table name to allow for "insert record"
00944      * @param   string      Table name TO WHICH the $table name is applied. See $content_field as well.
00945      * @param   string      Field name in the database $content_table in which $table is allowed to be added as a reference ("Insert Record")
00946      * @return  void
00947      */
00948     public static function addToInsertRecords($table, $content_table = 'tt_content', $content_field = 'records') {
00949         global $TCA;
00950         t3lib_div::loadTCA($content_table);
00951         if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed'])) {
00952             $TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table;
00953         }
00954     }
00955 
00956     /**
00957      * Add PlugIn to Static Template #43
00958      *
00959      * When adding a frontend plugin you will have to add both an entry to the TCA definition of tt_content table AND to the TypoScript template which must initiate the rendering.
00960      * Since the static template with uid 43 is the "content.default" and practically always used for rendering the content elements it's very useful to have this function automatically adding the necessary TypoScript for calling your plugin. It will also work for the extension "css_styled_content"
00961      * $type determines the type of frontend plugin:
00962      *      "list_type" (default)   - the good old "Insert plugin" entry
00963      *      "menu_type" - a "Menu/Sitemap" entry
00964      *      "splash_layout" - a "Textbox" entry
00965      *      "CType" - a new content element type
00966      *      "header_layout" - an additional header type (added to the selection of layout1-5)
00967      *      "includeLib" - just includes the library for manual use somewhere in TypoScript.
00968      *  (Remember that your $type definition should correspond to the column/items array in $TCA[tt_content] where you added the selector item for the element! See addPlugin() function)
00969      * FOR USE IN ext_locallang.php FILES
00970      * Usage: 2
00971      *
00972      * @param   string      $key is the extension key
00973      * @param   string      $classFile is the PHP-class filename relative to the extension root directory. If set to blank a default value is chosen according to convensions.
00974      * @param   string      $prefix is used as a - yes, suffix - of the class name (fx. "_pi1")
00975      * @param   string      $type, see description above
00976      * @param   boolean     If $cached is set as USER content object (cObject) is created - otherwise a USER_INT object is created.
00977      * @return  void
00978      */
00979     public static function addPItoST43($key, $classFile = '', $prefix = '', $type = 'list_type', $cached = 0) {
00980         global $TYPO3_LOADED_EXT;
00981         $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_', '', $key).$prefix.'.php';
00982         $cN = t3lib_extMgm::getCN($key);
00983 
00984             // General plugin:
00985         $pluginContent = trim('
00986 plugin.'.$cN.$prefix.' = USER' . ($cached ? '' : '_INT') . '
00987 plugin.'.$cN.$prefix.' {
00988   includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
00989   userFunc = '.$cN.$prefix.'->main
00990 }');
00991         t3lib_extMgm::addTypoScript($key, 'setup', '
00992 # Setting '.$key.' plugin TypoScript
00993 '.$pluginContent);
00994 
00995             // After ST43:
00996         switch($type) {
00997             case 'list_type':
00998                 $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00999             break;
01000             case 'menu_type':
01001                 $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
01002             break;
01003             case 'splash_layout':
01004                 $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
01005             break;
01006             case 'CType':
01007                 $addLine = trim('
01008 tt_content.'.$key.$prefix.' = COA
01009 tt_content.'.$key.$prefix.' {
01010     10 = < lib.stdheader
01011     20 = < plugin.'.$cN.$prefix.'
01012 }
01013                 ');
01014             break;
01015             case 'header_layout':
01016                 $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
01017             break;
01018             case 'includeLib':
01019                 $addLine = 'page.1000 = < plugin.'.$cN.$prefix;
01020             break;
01021             default:
01022                 $addLine = '';
01023             break;
01024         }
01025         if ($addLine) {
01026             t3lib_extMgm::addTypoScript($key, 'setup', '
01027 # Setting '.$key.' plugin TypoScript
01028 '.$addLine.'
01029 ', 43);
01030         }
01031     }
01032 
01033     /**
01034      * Call this method to add an entry in the static template list found in sys_templates
01035      * "static template files" are the modern equalent (provided from extensions) to the traditional records in "static_templates"
01036      * FOR USE IN ext_locallang.php FILES
01037      * Usage: 3
01038      *
01039      * @param   string      $extKey is of course the extension key
01040      * @param   string      $path is the path where the template files (fixed names) include_static.txt (integer list of uids from the table "static_templates"), constants.txt, setup.txt, editorcfg.txt, and include_static_file.txt is found (relative to extPath, eg. 'static/'). The file include_static_file.txt, allows you to include other static templates defined in files, from your static template, and thus corresponds to the field 'include_static_file' in the sys_template table. The syntax for this is a commaseperated list of static templates to include, like:  EXT:css_styled_content/static/,EXT:da_newsletter_subscription/static/,EXT:cc_random_image/pi2/static/
01041      * @param   string      $title is the title in the selector box.
01042      * @return  void
01043      * @see addTypoScript()
01044      */
01045     public static function addStaticFile($extKey, $path, $title) {
01046         global $TCA;
01047         t3lib_div::loadTCA('sys_template');
01048         if ($extKey && $path && is_array($TCA['sys_template']['columns'])) {
01049             $value = str_replace(',', '', 'EXT:'.$extKey.'/'.$path);
01050             $itemArray = array(trim($title.' ('.$extKey.')'), $value);
01051             $TCA['sys_template']['columns']['include_static_file']['config']['items'][] = $itemArray;
01052         }
01053     }
01054 
01055     /**
01056      * Adds $content to the default TypoScript setup code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_setup']
01057      * Prefixed with a [GLOBAL] line
01058      * FOR USE IN ext_locallang.php FILES
01059      * Usage: 6
01060      *
01061      * @param   string      TypoScript Setup string
01062      * @return  void
01063      */
01064     public static function addTypoScriptSetup($content) {
01065         global $TYPO3_CONF_VARS;
01066         $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
01067     }
01068 
01069     /**
01070      * Adds $content to the default TypoScript constants code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_constants']
01071      * Prefixed with a [GLOBAL] line
01072      * FOR USE IN ext_locallang.php FILES
01073      * Usage: 0
01074      *
01075      * @param   string      TypoScript Constants string
01076      * @return  void
01077      */
01078     public static function addTypoScriptConstants($content) {
01079         global $TYPO3_CONF_VARS;
01080         $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
01081     }
01082 
01083     /**
01084      * Adds $content to the default TypoScript code for either setup, constants or editorcfg as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_*']
01085      * (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!)
01086      * FOR USE IN ext_locallang.php FILES
01087      * Usage: 7
01088      *
01089      * @param   string      $key is the extension key (informative only).
01090      * @param   string      $type is either "setup", "constants" or "editorcfg" and obviously determines which kind of TypoScript code we are adding.
01091      * @param   string      $content is the TS content, prefixed with a [GLOBAL] line and a comment-header.
01092      * @param   string      $afterStaticUid is either an integer pointing to a uid of a static_template or a string pointing to the "key" of a static_file template ([reduced extension_key]/[local path]). The points is that the TypoScript you add is included only IF that static template is included (and in that case, right after). So effectively the TypoScript you set can specifically overrule settings from those static templates.
01093      * @return  void
01094      */
01095     public static function addTypoScript($key, $type, $content, $afterStaticUid = 0) {
01096         global $TYPO3_CONF_VARS;
01097 
01098         if ($type=='setup' || $type=='editorcfg' || $type=='constants')     {
01099             $content = '
01100 
01101 [GLOBAL]
01102 #############################################
01103 ## TypoScript added by extension "'.$key.'"
01104 #############################################
01105 
01106 '.$content;
01107             if ($afterStaticUid) {
01108                 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
01109                 if ($afterStaticUid==43)    {   // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
01110                     $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.']['cssstyledcontent/static/'].=$content;
01111                 }
01112             } else {
01113                 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content;
01114             }
01115         }
01116     }
01117 
01118 
01119 
01120 
01121 
01122 
01123 
01124 
01125 
01126 
01127 
01128 
01129 
01130 
01131 
01132 
01133 
01134 
01135     /**************************************
01136      *
01137      *   INTERNAL EXTENSION MANAGEMENT:
01138      *
01139      ***************************************/
01140 
01141     /**
01142      * Loading extensions configured in $TYPO3_CONF_VARS['EXT']['extList']
01143      *
01144      * CACHING ON: ($TYPO3_CONF_VARS['EXT']['extCache'] = 1 or 2)
01145      *      If caching is enabled (and possible), the output will be $extensions['_CACHEFILE'] set to the cacheFilePrefix. Subsequently the cache files must be included then since those will eventually set up the extensions.
01146      *      If cachefiles are not found they will be generated
01147      * CACHING OFF: ($TYPO3_CONF_VARS['EXT']['extCache'] = 0)
01148      *      The returned value will be an array where each key is an extension key and the value is an array with filepaths for the extension.
01149      *      This array will later be set in the global var $TYPO3_LOADED_EXT
01150      *
01151      * Usages of this function can be seen in config_default.php
01152      * Extensions are always detected in the order local - global - system.
01153      * Usage: 1
01154      *
01155      * @return  array       Extension Array
01156      * @internal
01157      */
01158     public static function typo3_loadExtensions() {
01159         global $TYPO3_CONF_VARS;
01160 
01161             // Full list of extensions includes both required and extList:
01162         $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'].','.$TYPO3_CONF_VARS['EXT']['extList'];
01163 
01164             // Empty array as a start.
01165         $extensions = array();
01166 
01167             //
01168         if ($rawExtList) {
01169                 // The cached File prefix.
01170             $cacheFilePrefix = 'temp_CACHED';
01171                 // Setting the name for the cache files:
01172             if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1) $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']), 0, 4);
01173             if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2) $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
01174 
01175                 // If cache files available, set cache file prefix and return:
01176             if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix)) {
01177                     // Return cache file prefix:
01178                 $extensions['_CACHEFILE'] = $cacheFilePrefix;
01179             } else {    // ... but if not, configure...
01180 
01181                     // Prepare reserved filenames:
01182                 $files = t3lib_div::trimExplode(',', 'ext_localconf.php,ext_tables.php,ext_tables.sql,ext_tables_static+adt.sql,ext_typoscript_constants.txt,ext_typoscript_editorcfg.txt,ext_typoscript_setup.txt', 1);
01183 
01184                     // Traverse extensions and check their existence:
01185                 clearstatcache();   // Clear file state cache to make sure we get good results from is_dir()
01186                 $temp_extensions = array_unique(t3lib_div::trimExplode(',', $rawExtList, 1));
01187                 foreach($temp_extensions as $temp_extKey) {
01188                         // Check local, global and system locations:
01189                     if (@is_dir(PATH_typo3conf.'ext/'.$temp_extKey.'/')) {
01190                         $extensions[$temp_extKey] = array('type'=>'L', 'siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/', 'typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
01191                     } elseif (@is_dir(PATH_typo3.'ext/'.$temp_extKey.'/')) {
01192                         $extensions[$temp_extKey] = array('type'=>'G', 'siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/', 'typo3RelPath'=>'ext/'.$temp_extKey.'/');
01193                     } elseif (@is_dir(PATH_typo3.'sysext/'.$temp_extKey.'/'