Removed the tree filter toggle
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_extmgm.php
index 81a51fb..e5f49e2 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+*  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * $Id$
  * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  *
- *  113: class t3lib_extMgm
+ *  114: class t3lib_extMgm
  *
  *              SECTION: PATHS and other evaluation
- *  130:     function isLoaded($key,$exitOnError=0)
- *  146:     function extPath($key,$script='')
- *  161:     function extRelPath($key)
- *  176:     function siteRelPath($key)
- *  188:     function getCN($key)
+ *  131:     function isLoaded($key,$exitOnError=0)
+ *  147:     function extPath($key,$script='')
+ *  165:     function extRelPath($key)
+ *  182:     function siteRelPath($key)
+ *  194:     function getCN($key)
  *
  *              SECTION: Adding BACKEND features
- *  221:     function addTCAcolumns($table,$columnArray,$addTofeInterface=0)
- *  245:     function addToAllTCAtypes($table,$str,$specificTypesList='',$beforeList='')
- *  297:     function allowTableOnStandardPages($table)
- *  314:     function addModule($main,$sub='',$position='',$path='')
- *  376:     function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function')
- *  394:     function addPageTSConfig($content)
- *  408:     function addUserTSConfig($content)
- *  423:     function addLLrefForTCAdescr($tca_descr_key,$file_ref)
+ *  227:     function addTCAcolumns($table,$columnArray,$addTofeInterface=0)
+ *  251:     function addToAllTCAtypes($table,$str,$specificTypesList='',$position='')
+ *  309:     function allowTableOnStandardPages($table)
+ *  326:     function addModule($main,$sub='',$position='',$path='')
+ *  389:     function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='')
+ *  408:     function addPageTSConfig($content)
+ *  422:     function addUserTSConfig($content)
+ *  437:     function addLLrefForTCAdescr($tca_descr_key,$file_ref)
  *
  *              SECTION: Adding SERVICES features
- *  465:     function addService($extKey, $serviceType, $serviceKey, $info)
- *  530:     function findService($serviceType, $serviceSubType='', $excludeServiceKeys='')
- *  597:     function deactivateService($serviceType, $serviceKey)
+ *  479:     function addService($extKey, $serviceType, $serviceKey, $info)
+ *  547:     function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array())
+ *  618:     function deactivateService($serviceType, $serviceKey)
  *
  *              SECTION: Adding FRONTEND features
- *  636:     function addPlugin($itemArray,$type='list_type')
- *  661:     function addPiFlexFormValue($piKeyToMatch,$value)
- *  681:     function addToInsertRecords($table,$content_table='tt_content',$content_field='records')
- *  712:     function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0)
- *  787:     function addStaticFile($extKey,$path,$title)
- *  806:     function addTypoScriptSetup($content)
- *  820:     function addTypoScriptConstants($content)
- *  837:     function addTypoScript($key,$type,$content,$afterStaticUid=0)
+ *  657:     function addPlugin($itemArray,$type='list_type')
+ *  682:     function addPiFlexFormValue($piKeyToMatch,$value)
+ *  702:     function addToInsertRecords($table,$content_table='tt_content',$content_field='records')
+ *  733:     function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0)
+ *  808:     function addStaticFile($extKey,$path,$title)
+ *  827:     function addTypoScriptSetup($content)
+ *  841:     function addTypoScriptConstants($content)
+ *  858:     function addTypoScript($key,$type,$content,$afterStaticUid=0)
  *
  *              SECTION: INTERNAL EXTENSION MANAGEMENT:
- *  900:     function typo3_loadExtensions()
- *  979:     function _makeIncludeHeader($key,$file)
- * 1000:     function isCacheFilesAvailable($cacheFilePrefix)
- * 1013:     function isLocalconfWritable()
- * 1026:     function cannotCacheFilesWritable($cacheFilePrefix)
- * 1050:     function currentCacheFiles()
- * 1073:     function writeCacheFiles($extensions,$cacheFilePrefix)
+ *  921:     function typo3_loadExtensions()
+ *  998:     function _makeIncludeHeader($key,$file)
+ * 1019:     function isCacheFilesAvailable($cacheFilePrefix)
+ * 1032:     function isLocalconfWritable()
+ * 1045:     function cannotCacheFilesWritable($cacheFilePrefix)
+ * 1069:     function currentCacheFiles()
+ * 1092:     function writeCacheFiles($extensions,$cacheFilePrefix)
+ * 1130:     function removeCacheFiles()
  *
- * TOTAL FUNCTIONS: 31
+ * TOTAL FUNCTIONS: 32
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
  * This class is never instantiated, rather the methods inside is called as functions like
  *             t3lib_extMgm::isLoaded('my_extension');
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage t3lib
  */
@@ -115,7 +116,7 @@ class t3lib_extMgm {
 
        /**************************************
         *
-        *       PATHS and other evaluation
+        * PATHS and other evaluation
         *
         ***************************************/
 
@@ -145,7 +146,10 @@ class t3lib_extMgm {
         */
        function extPath($key,$script='')       {
                global $TYPO3_LOADED_EXT;
-               if (!isset($TYPO3_LOADED_EXT[$key]))    die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!');
+               if (!isset($TYPO3_LOADED_EXT[$key]))    {
+                       #debug(array(debug_backtrace()));
+                       die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extPath)');
+               }
                return PATH_site.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$script;
        }
 
@@ -160,7 +164,9 @@ class t3lib_extMgm {
         */
        function extRelPath($key)       {
                global $TYPO3_LOADED_EXT;
-               if (!isset($TYPO3_LOADED_EXT[$key]))    die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!');
+               if (!isset($TYPO3_LOADED_EXT[$key]))    {
+                       die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extRelPath)');
+               }
                return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
        }
 
@@ -239,45 +245,57 @@ class t3lib_extMgm {
         * @param       string          Table name
         * @param       string          Field list to add.
         * @param       string          List of specific types to add the field list to. (If empty, all type entries are affected)
-        * @param       string          Insert fields before one of this fields (commalist). Example: "keywords,--palette--;;4,description". Palettes must be passed like in the example no matter how the palette definition looks like in TCA.
+        * @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.
         * @return      void
         */
-       function addToAllTCAtypes($table,$str,$specificTypesList='',$beforeList='')     {
+       function addToAllTCAtypes($table,$str,$specificTypesList='',$position='')       {
                global $TCA;
 
-               $beforeFields=t3lib_div::trimExplode(',',$beforeList,1);
-               $before=count($beforeFields);
+               $positionArr=t3lib_div::trimExplode(',',$position,1);
+               $insert=count($position);
 
                t3lib_div::loadTCA($table);
-               if (trim($str) && is_array($TCA[$table]) && is_array($TCA[$table]['types']))    {
+               $str = trim($str);
+               if ($str && is_array($TCA[$table]) && is_array($TCA[$table]['types']))  {
                        foreach($TCA[$table]['types'] as $k => $v)      {
-                               if (!$specificTypesList || t3lib_div::inList($specificTypesList,$k))    {
-
-                                       if ($before) {
-                                               $append=true;
-                                               $showItem = t3lib_div::trimExplode(',',$TCA[$table]['types'][$k]['showitem'],1);
-                                               foreach($showItem as $key => $fieldInfo) {
-
-                                                       $parts = explode(';',$fieldInfo);
-                                                       $theField = trim($parts[0]);
-                                                       $palette = trim($parts[0]).';;'.trim($parts[2]);
-                                                               // find exact field name or palette with number
-                                                       if (in_array($theField,$beforeFields) OR in_array($palette,$beforeFields))      {
-                                                               $showItem[$key]=trim($str).', '.$fieldInfo;
-                                                               $append=false;
-                                                               break;
+                               if ($specificTypesList === '' || t3lib_div::inList($specificTypesList,$k))      {
+                                       if ($insert)    {
+                                               if (count($positionArr)) {
+                                                       $append=true;
+                                                       $showItem = t3lib_div::trimExplode(',',$TCA[$table]['types'][$k]['showitem'],1);
+                                                       foreach($showItem as $key => $fieldInfo)        {
+       
+                                                               $parts = explode(';',$fieldInfo);
+                                                               $theField = trim($parts[0]);
+                                                               $palette = trim($parts[0]).';;'.trim($parts[2]);
+       
+                                                                       // insert before: find exact field name or palette with number
+                                                               if (in_array($theField, $positionArr) || in_array($palette, $positionArr) || in_array('before:'.$theField, $positionArr) || in_array('before:'.$palette, $positionArr)) {
+                                                                       $showItem[$key]=$str.', '.$fieldInfo;
+                                                                       $append=false;
+                                                                       break;
+                                                               }
+                                                                       // insert after
+                                                               if (in_array('after:'.$theField, $positionArr) || in_array('after:'.$palette, $positionArr))    {
+                                                                       $showItem[$key]=$fieldInfo.', '.$str;
+                                                                       $append=false;
+                                                                       break;
+                                                               }
                                                        }
+       
+                                                               // Not found? Then append.
+                                                       if($append) {
+                                                               $showItem[]=$str;
+                                                       }
+       
+                                                       $TCA[$table]['types'][$k]['showitem']=implode(', ', $showItem);
                                                }
-
-                                                       // Not found? Then append.
-                                               if($append) {
-                                                       $showItem[]=trim($str);
+                                               else {
+                                                       $TCA[$table]['types'][$k]['showitem'] .= ', ' . $str;
                                                }
 
-                                               $TCA[$table]['types'][$k]['showitem']=implode(', ', $showItem);
-
                                        } else {
-                                               $TCA[$table]['types'][$k]['showitem'].=', '.trim($str);
+                                               $TCA[$table]['types'][$k]['showitem'].=', ' . $str;
                                        }
                                }
                        }
@@ -359,6 +377,41 @@ class t3lib_extMgm {
        }
 
        /**
+        * Adds a module path to TBE_MODULES for used with the module dispatcher, mod.php
+        * Used only for modules that are not placed in the main/sub menu hierarchy by the traditional mechanism of addModule()
+        * Examples for this is context menu functionality (like import/export) which runs as an independent module through mod.php
+        * FOR USE IN ext_tables.php FILES
+        * Example:  t3lib_extMgm::addModulePath('xMOD_tximpexp',t3lib_extMgm::extPath($_EXTKEY).'app/');
+        *
+        * @param       string          $name is the name of the module, refer to conf.php of the module.
+        * @param       string          $path is the absolute path to the module directory inside of which "index.php" and "conf.php" is found.
+        * @return      void
+        */
+       function addModulePath($name,$path)     {
+               global $TBE_MODULES;
+
+               $TBE_MODULES['_PATHS'][$name] = $path;
+       }
+
+       /**
+        * Adding an application for the top menu. These are regular modules but is required to respond with Ajax content in case of certain parameters sent to them.
+        *
+        * @param       string          $name is the name of the module, refer to conf.php of the module.
+        * @param       string          $path is the absolute path to the module directory inside of which "index.php" and "conf.php" is found.
+        * @param       boolean         If set, the application is placed in the shortcut bar below the menu bar.
+        * @param       array           Options
+        * @return      void
+        */
+       function addTopApp($name,$path,$iconPane=FALSE,$options=array())        {
+               global $TBE_MODULES,$TYPO3_CONF_VARS;
+
+               $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['topApps'][$iconPane?'icons':'menu'][$name] = $options;
+
+                       // Set path for TBE-modules:
+               $TBE_MODULES['_PATHS'][$name] = $path;
+       }
+
+       /**
         * Adds a "Function menu module" ('third level module') to an existing function menu for some other backend module
         * The arguments values are generally determined by which function menu this is supposed to interact with
         * See Inside TYPO3 for information on how to use this function.
@@ -370,15 +423,17 @@ class t3lib_extMgm {
         * @param       string          Class path
         * @param       string          Title of module
         * @param       string          Menu array key - default is "function"
+        * @param       string          Workspace conditions. Blank means all workspaces, any other string can be a comma list of "online", "offline" and "custom"
         * @return      void
         * @see t3lib_SCbase::mergeExternalItems()
         */
-       function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function') {
+       function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='')  {
                global $TBE_MODULES_EXT;
                $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className]=array(
                        'name' => $className,
                        'path' => $classPath,
                        'title' => $title,
+                       'ws' => $WS
                );
        }
 
@@ -413,11 +468,11 @@ class t3lib_extMgm {
        /**
         * Adds a reference to a locallang file with TCA_DESCR labels
         * FOR USE IN ext_tables.php FILES
-        * eg. t3lib_extMgm::addLLrefForTCAdescr('pages','EXT:lang/locallang_csh_pages.php'); for the pages table or t3lib_extMgm::addLLrefForTCAdescr('_MOD_web_layout','EXT:cms/locallang_csh_weblayout.php'); for the Web > Page module.
+        * 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.
         * Usage: 31
         *
         * @param       string          Description key. Typically a database table (like "pages") but for applications can be other strings, but prefixed with "_MOD_")
-        * @param       string          File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php"
+        * @param       string          File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php" (or ".xml")
         * @return      void
         */
        function addLLrefForTCAdescr($tca_descr_key,$file_ref)  {
@@ -456,8 +511,8 @@ class t3lib_extMgm {
         * Adds a service to the global services array
         *
         * @param       string          Extension key
-        * @param       string          Service type
-        * @param       string          Service key
+        * @param       string          Service type, cannot be prefixed "tx_"
+        * @param       string          Service key, must be prefixed "tx_" or "user_"
         * @param       array           Service description array
         * @return      void
         * @author      RenĂ© Fritz <r.fritz@colorcube.de>
@@ -468,7 +523,10 @@ class t3lib_extMgm {
                // even not available services will be included to make it possible to give the admin a feedback of non-available services.
                // but maybe it's better to move non-available services to a different array??
 
-               if ($serviceType AND substr($serviceType,0,3)!='tx_' AND substr($serviceKey,0,3)=='tx_' AND is_array($info))    {
+               if ($serviceType &&
+                       !t3lib_div::isFirstPartOfStr($serviceType, 'tx_') &&
+                       (t3lib_div::isFirstPartOfStr($serviceKey, 'tx_') || t3lib_div::isFirstPartOfStr($serviceKey, 'user_')) &&
+                       is_array($info))        {
 
                        $info['priority'] = max(0,min(100,$info['priority']));
 
@@ -497,7 +555,7 @@ class t3lib_extMgm {
 
                                // OS check
                                // empty $os means 'not limited to one OS', therefore a check is not needed
-                       if ($T3_SERVICES[$serviceType][$serviceKey]['available'] AND $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
+                       if ($T3_SERVICES[$serviceType][$serviceKey]['available'] && $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
 
                                        // TYPO3_OS is not yet defined
                                $os_type = stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'UNIX';
@@ -523,22 +581,26 @@ class t3lib_extMgm {
         *
         * @param       string          Service type
         * @param       string          Service sub type
-        * @param       string          Service key that should be excluded in the search for a service
+        * @param       mixed           Service keys that should be excluded in the search for a service. Array or comma list.
         * @return      mixed           Service info array if a service was found, FLASE otherwise
         * @author      RenĂ© Fritz <r.fritz@colorcube.de>
         */
-       function findService($serviceType, $serviceSubType='', $excludeServiceKeys='') {
-               global $T3_SERVICES;
+       function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) {
+               global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
 
                $serviceKey = FALSE;
                $serviceInfo = FALSE;
                $priority = 0;
                $quality = 0;
 
+               if (!is_array($excludeServiceKeys) ) {
+                       $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
+               }
+
                if (is_array($T3_SERVICES[$serviceType]))       {
                        foreach($T3_SERVICES[$serviceType] as $key => $info)    {
 
-                               if (t3lib_div::inList($excludeServiceKeys,$key)) {
+                               if (in_array($key, $excludeServiceKeys)) {
                                        continue;
                                }
 
@@ -549,10 +611,10 @@ class t3lib_extMgm {
                                }
 
                                        // this matches empty subtype too
-                               if( $info['available'] AND ($info['subtype']==$serviceSubType OR $info['serviceSubTypes'][$serviceSubType]) AND $info['priority']>=$priority ) {
+                               if ($info['available'] && ($info['subtype']==$serviceSubType || $info['serviceSubTypes'][$serviceSubType]) && $info['priority']>=$priority )    {
 
                                                // has a lower quality than the already found, therefore we skip this service
-                                       if($info['priority']==$priority AND $info['quality']<$quality) {
+                                       if($info['priority']==$priority && $info['quality']<$quality) {
                                                continue;
                                        }
 
@@ -650,20 +712,21 @@ class t3lib_extMgm {
 
        /**
         * Adds an entry to the "ds" array of the tt_content field "pi_flexform".
-        * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin.
+        * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin or content element.
         * Usage: 0
         *
-        * @param       string          The same value as the key for the plugin
+        * @param       string          Plugin key as used in the list_type field. Use the asterisk * to match all list_type values.
         * @param       string          Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
+        * @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.
         * @return      void
         * @see addPlugin()
         */
-       function addPiFlexFormValue($piKeyToMatch,$value)       {
+       function addPiFlexFormValue($piKeyToMatch, $value, $CTypeToMatch='list')        {
                global $TCA;
                t3lib_div::loadTCA('tt_content');
 
                if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds']))  {
-                       $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch] = $value;
+                       $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch.','.$CTypeToMatch] = $value;
                }
        }
 
@@ -779,7 +842,7 @@ tt_content.'.$key.$prefix.' {
         * Usage: 3
         *
         * @param       string          $extKey is of course the extension key
-        * @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 and editorcfg.txt is found (relative to extPath, eg. 'static/')
+        * @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/
         * @param       string          $title is the title in the selector box.
         * @return      void
         * @see addTypoScript()
@@ -918,53 +981,51 @@ tt_content.'.$key.$prefix.' {
                        if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix))       {
                                        // Return cache file prefix:
                                $extensions['_CACHEFILE'] = $cacheFilePrefix;
-                       } else {
-                               // ... but if not, configure...
+                       } else {        // ... but if not, configure...
+
+                                       // Prepare reserved filenames:
+                               $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);
+
+                                       // Traverse extensions and check their existence:
+                               clearstatcache();       // Clear file state cache to make sure we get good results from is_dir()
                                $temp_extensions = array_unique(t3lib_div::trimExplode(',',$rawExtList,1));
-                               while(list(,$temp_extKey)=each($temp_extensions))       {
-                                       if (@is_dir(PATH_site.'typo3conf/ext/'.$temp_extKey))   {
-                                               $extensions[$temp_extKey]=array('type'=>'L','siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/','typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
-                                       } elseif (@is_dir(PATH_site.TYPO3_mainDir.'ext/'.$temp_extKey)) {
-                                               $extensions[$temp_extKey]=array('type'=>'G','siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/','typo3RelPath'=>'ext/'.$temp_extKey.'/');
-                                       } elseif (@is_dir(PATH_site.TYPO3_mainDir.'sysext/'.$temp_extKey))      {
-                                               $extensions[$temp_extKey]=array('type'=>'S','siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/','typo3RelPath'=>'sysext/'.$temp_extKey.'/');
+                               foreach($temp_extensions as $temp_extKey)       {
+                                               // Check local, global and system locations:
+                                       if (@is_dir(PATH_typo3conf.'ext/'.$temp_extKey.'/'))    {
+                                               $extensions[$temp_extKey] = array('type'=>'L', 'siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/', 'typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
+                                       } elseif (@is_dir(PATH_typo3.'ext/'.$temp_extKey.'/'))  {
+                                               $extensions[$temp_extKey] = array('type'=>'G', 'siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/', 'typo3RelPath'=>'ext/'.$temp_extKey.'/');
+                                       } elseif (@is_dir(PATH_typo3.'sysext/'.$temp_extKey.'/'))       {
+                                               $extensions[$temp_extKey] = array('type'=>'S', 'siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/', 'typo3RelPath'=>'sysext/'.$temp_extKey.'/');
                                        }
 
-                                       $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);
-                                       reset($files);
-                                       while(list(,$fName)=each($files))       {
-                                               $temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName);
-                                               if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename))    {
-                                                       $extensions[$temp_extKey][$fName]=$temp_filename;
+                                               // If extension was found, check for reserved filenames:
+                                       if (isset($extensions[$temp_extKey]))   {
+                                               foreach($files as $fName)       {
+                                                       $temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName);
+                                                       if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename))    {
+                                                               $extensions[$temp_extKey][$fName] = $temp_filename;
+                                                       }
                                                }
                                        }
                                }
                                unset($extensions['_CACHEFILE']);
 
-
-                               // write cache?
-                               if ($TYPO3_CONF_VARS['EXT']['extCache'])        {
+                                       // write cache?
+                               if ($TYPO3_CONF_VARS['EXT']['extCache'] &&
+                                               @is_dir(PATH_typo3.'sysext/') &&
+                                               @is_dir(PATH_typo3.'ext/'))     {       // Must also find global and system extension directories to exist, otherwise caching cannot be allowed (since it is most likely a temporary server problem). This might fix a rare, unrepeatable bug where global/system extensions are not loaded resulting in fatal errors if that is cached!
                                        $wrError = t3lib_extMgm::cannotCacheFilesWritable($cacheFilePrefix);
                                        if ($wrError)   {
-//debug('Cannot write cache files: '.$wrError.'. Disabling the cache...');
                                                $TYPO3_CONF_VARS['EXT']['extCache']=0;
                                        } else {
-                                               // Write cache files:
+                                                       // Write cache files:
                                                $extensions = t3lib_extMgm::writeCacheFiles($extensions,$cacheFilePrefix);
                                        }
                                }
                        }
                }
 
-#debug($extensions);
                return $extensions;
        }
 
@@ -1011,7 +1072,7 @@ $_EXTCONF = $TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][$_EXTKEY];
         * @internal
         */
        function isLocalconfWritable()  {
-               return is_writeable(PATH_typo3conf) && is_writeable(PATH_typo3conf.'localconf.php');
+               return @is_writable(PATH_typo3conf) && @is_writable(PATH_typo3conf.'localconf.php');
        }
 
        /**
@@ -1025,15 +1086,15 @@ $_EXTCONF = $TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][$_EXTKEY];
         */
        function cannotCacheFilesWritable($cacheFilePrefix)     {
                $error=array();
-               if (!@is_writeable(PATH_typo3conf))     {
+               if (!@is_writable(PATH_typo3conf))      {
                        $error[]=PATH_typo3conf;
                }
                if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
-                       !@is_writeable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php'))   {
+                       !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php'))    {
                                $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
                }
                if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php') &&
-                       !@is_writeable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php'))      {
+                       !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php'))       {
                                $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
                }
                return implode(', ',$error);
@@ -1093,7 +1154,10 @@ $TYPO3_LOADED_EXT = unserialize(stripslashes(\''.addslashes(serialize($extension
                                }
                        }
                }
-
+               
+               $cFiles['ext_localconf'] = "<?php\n" . preg_replace('/<\?php|\?>/is', '', $cFiles['ext_localconf']) . "?>\n";
+               $cFiles['ext_tables'] = "<?php\n" . preg_replace('/<\?php|\?>/is', '', $cFiles['ext_tables']) . "?>\n";
+               
                t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php',$cFiles['ext_localconf']);
                t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php',$cFiles['ext_tables']);
 
@@ -1102,6 +1166,25 @@ $TYPO3_LOADED_EXT = unserialize(stripslashes(\''.addslashes(serialize($extension
 
                return $extensions;
        }
+
+       /**
+        * Unlink (delete) cache files
+        *
+        * @return      integer         Number of deleted files.
+        */
+       function removeCacheFiles()     {
+               $cacheFiles = t3lib_extMgm::currentCacheFiles();
+               $out = 0;
+               if (is_array($cacheFiles))      {
+                       reset($cacheFiles);
+                       foreach($cacheFiles as $cfile)  {
+                               @unlink($cfile);
+                               clearstatcache();
+                               $out++;
+                       }
+               }
+               return $out;
+       }
 }
 
 ?>