Removed the tree filter toggle
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_extmgm.php
index aaf40eb..e5f49e2 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@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
  *
  *
  *
- *  113: class t3lib_extMgm
+ *  114: class t3lib_extMgm
  *
  *              SECTION: PATHS and other evaluation
- *  130:     function isLoaded($key,$exitOnError=0)
- *  146:     function extPath($key,$script='')
- *  164:     function extRelPath($key)
- *  181:     function siteRelPath($key)
- *  193:     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
- *  226:     function addTCAcolumns($table,$columnArray,$addTofeInterface=0)
- *  250:     function addToAllTCAtypes($table,$str,$specificTypesList='',$position='')
- *  312:     function allowTableOnStandardPages($table)
- *  329:     function addModule($main,$sub='',$position='',$path='')
- *  391:     function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function')
- *  409:     function addPageTSConfig($content)
- *  423:     function addUserTSConfig($content)
- *  438:     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
- *  480:     function addService($extKey, $serviceType, $serviceKey, $info)
- *  545:     function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array())
- *  616:     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
- *  655:     function addPlugin($itemArray,$type='list_type')
- *  680:     function addPiFlexFormValue($piKeyToMatch,$value)
- *  700:     function addToInsertRecords($table,$content_table='tt_content',$content_field='records')
- *  731:     function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0)
- *  806:     function addStaticFile($extKey,$path,$title)
- *  825:     function addTypoScriptSetup($content)
- *  839:     function addTypoScriptConstants($content)
- *  856:     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:
- *  919:     function typo3_loadExtensions()
+ *  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")
  *
  */
@@ -254,45 +255,47 @@ class t3lib_extMgm {
                $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 ($insert) {
-                                               $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) OR in_array($palette, $positionArr) OR
-                                                               in_array('before:'.$theField, $positionArr) OR in_array('before:'.$palette, $positionArr))      {
-                                                               $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;
+                                                               }
                                                        }
-                                                               // insert after
-                                                       if (in_array('after:'.$theField, $positionArr) OR in_array('after:'.$palette, $positionArr))    {
-                                                               $showItem[$key]=$fieldInfo.', '.trim($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;
                                        }
                                }
                        }
@@ -374,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.
@@ -485,9 +523,9 @@ 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
-                       !t3lib_div::isFirstPartOfStr($serviceType, 'tx_') AND
-                       (t3lib_div::isFirstPartOfStr($serviceKey, 'tx_') OR t3lib_div::isFirstPartOfStr($serviceKey, 'user_')) AND
+               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']));
@@ -517,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';
@@ -573,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;
                                        }
 
@@ -674,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;
                }
        }
 
@@ -943,6 +982,7 @@ tt_content.'.$key.$prefix.' {
                                        // Return cache file prefix:
                                $extensions['_CACHEFILE'] = $cacheFilePrefix;
                        } 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);
 
@@ -951,11 +991,11 @@ tt_content.'.$key.$prefix.' {
                                $temp_extensions = array_unique(t3lib_div::trimExplode(',',$rawExtList,1));
                                foreach($temp_extensions as $temp_extKey)       {
                                                // Check local, global and system locations:
-                                       if (@is_dir(PATH_site.'typo3conf/ext/'.$temp_extKey.'/'))       {
+                                       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_site.TYPO3_mainDir.'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_site.TYPO3_mainDir.'sysext/'.$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.'/');
                                        }
 
@@ -973,8 +1013,8 @@ tt_content.'.$key.$prefix.' {
 
                                        // write cache?
                                if ($TYPO3_CONF_VARS['EXT']['extCache'] &&
-                                               @is_dir(PATH_site.TYPO3_mainDir.'sysext/') &&
-                                               @is_dir(PATH_site.TYPO3_mainDir.'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!
+                                               @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)   {
                                                $TYPO3_CONF_VARS['EXT']['extCache']=0;
@@ -1114,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']);
 
@@ -1123,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;
+       }
 }
 
 ?>