Main Page | Directories | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages | Examples

class.t3lib_extmgm.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2004 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 ***************************************************************/
00113 class t3lib_extMgm {
00114 
00115 
00116    /**************************************
00117     *
00118     * PATHS and other evaluation
00119     *
00120     ***************************************/
00121 
00130    function isLoaded($key,$exitOnError=0) {
00131       global $TYPO3_LOADED_EXT;
00132       if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key]))  die('Fatal Error: Extension "'.$key.'" was not loaded.');
00133       return isset($TYPO3_LOADED_EXT[$key]);
00134    }
00135 
00146    function extPath($key,$script='')   {
00147       global $TYPO3_LOADED_EXT;
00148       if (!isset($TYPO3_LOADED_EXT[$key]))   {
00149          #debug(array(debug_backtrace()));
00150          die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extPath)');
00151       }
00152       return PATH_site.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$script;
00153    }
00154 
00164    function extRelPath($key)  {
00165       global $TYPO3_LOADED_EXT;
00166       if (!isset($TYPO3_LOADED_EXT[$key]))   {
00167          die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extRelPath)');
00168       }
00169       return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
00170    }
00171 
00181    function siteRelPath($key) {
00182       return substr(t3lib_extMgm::extPath($key),strlen(PATH_site));
00183    }
00184 
00193    function getCN($key) {
00194       return substr($key,0,5)=='user_' ? 'user_'.str_replace('_','',substr($key,5)) : 'tx_'.str_replace('_','',$key);
00195    }
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206    /**************************************
00207     *
00208     *  Adding BACKEND features
00209     *  (related to core features)
00210     *
00211     ***************************************/
00212 
00226    function addTCAcolumns($table,$columnArray,$addTofeInterface=0)   {
00227       global $TCA;
00228       t3lib_div::loadTCA($table);
00229       if (is_array($columnArray) && is_array($TCA[$table]) && is_array($TCA[$table]['columns']))   {
00230          $TCA[$table]['columns'] = array_merge($TCA[$table]['columns'],$columnArray);  // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
00231          if ($addTofeInterface)  $TCA[$table]['feInterface']['fe_admin_fieldList'].=','.implode(',',array_keys($columnArray));
00232       }
00233    }
00234 
00250    function addToAllTCAtypes($table,$str,$specificTypesList='',$position='')  {
00251       global $TCA;
00252 
00253       $positionArr=t3lib_div::trimExplode(',',$position,1);
00254       $insert=count($position);
00255 
00256       t3lib_div::loadTCA($table);
00257       if (trim($str) && is_array($TCA[$table]) && is_array($TCA[$table]['types']))  {
00258          foreach($TCA[$table]['types'] as $k => $v)   {
00259             if (!$specificTypesList || t3lib_div::inList($specificTypesList,$k)) {
00260 
00261 
00262 
00263                if ($insert) {
00264                   $append=true;
00265                   $showItem = t3lib_div::trimExplode(',',$TCA[$table]['types'][$k]['showitem'],1);
00266                   foreach($showItem as $key => $fieldInfo) {
00267 
00268                      $parts = explode(';',$fieldInfo);
00269                      $theField = trim($parts[0]);
00270                      $palette = trim($parts[0]).';;'.trim($parts[2]);
00271 
00272                         // insert before: find exact field name or palette with number
00273                      if (in_array($theField, $positionArr) OR in_array($palette, $positionArr) OR
00274                         in_array('before:'.$theField, $positionArr) OR in_array('before:'.$palette, $positionArr))   {
00275                         $showItem[$key]=trim($str).', '.$fieldInfo;
00276                         $append=false;
00277                         break;
00278                      }
00279                         // insert after
00280                      if (in_array('after:'.$theField, $positionArr) OR in_array('after:'.$palette, $positionArr)) {
00281                         $showItem[$key]=$fieldInfo.', '.trim($str);
00282                         $append=false;
00283                         break;
00284                      }
00285                   }
00286 
00287                      // Not found? Then append.
00288                   if($append) {
00289                      $showItem[]=trim($str);
00290                   }
00291 
00292                   $TCA[$table]['types'][$k]['showitem']=implode(', ', $showItem);
00293 
00294                } else {
00295                   $TCA[$table]['types'][$k]['showitem'].=', '.trim($str);
00296                }
00297             }
00298          }
00299       }
00300    }
00301 
00302 
00312    function allowTableOnStandardPages($table)   {
00313       global $PAGES_TYPES;
00314 
00315       $PAGES_TYPES['default']['allowedTables'].=','.$table;
00316    }
00317 
00329    function addModule($main,$sub='',$position='',$path='')  {
00330       global $TBE_MODULES;
00331 
00332       if (isset($TBE_MODULES[$main]) && $sub)   {  // If there is already a main module by this name:
00333 
00334             // Adding the submodule to the correct position:
00335          list($place,$modRef)=t3lib_div::trimExplode(':',$position,1);
00336          $mods = t3lib_div::trimExplode(',',$TBE_MODULES[$main],1);
00337          if (!in_array($sub,$mods)) {
00338             switch(strtolower($place)) {
00339                case 'after':
00340                case 'before':
00341                   $pointer=0;
00342                   reset($mods);
00343                   while(list($k,$m)=each($mods))   {
00344                      if (!strcmp($m,$modRef))   {
00345                         $pointer=strtolower($place)=='after'?$k+1:$k;
00346                      }
00347                   }
00348                   array_splice(
00349                      $mods,   // The modules array
00350                      $pointer,      // To insert one position from the end of the list
00351                      0,    // Don't remove any items, just insert
00352                      $sub  // Module to insert
00353                   );
00354                break;
00355                default:
00356                   if (strtolower($place)=='top')   {
00357                      array_unshift($mods,$sub);
00358                   } else {
00359                      array_push($mods,$sub);
00360                   }
00361                break;
00362             }
00363          }
00364             // Re-inserting the submodule list:
00365          $TBE_MODULES[$main]=implode(',',$mods);
00366       } else { // Create new main modules with only one submodule, $sub (or none if $sub is blank)
00367          $TBE_MODULES[$main]=$sub;
00368       }
00369 
00370          // Adding path:
00371       if ($path)  {
00372          $TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')]=$path;
00373       }
00374    }
00375 
00391    function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function')   {
00392       global $TBE_MODULES_EXT;
00393       $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className]=array(
00394          'name' => $className,
00395          'path' => $classPath,
00396          'title' => $title,
00397       );
00398    }
00399 
00409    function addPageTSConfig($content)  {
00410       global $TYPO3_CONF_VARS;
00411       $TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content;
00412    }
00413 
00423    function addUserTSConfig($content)  {
00424       global $TYPO3_CONF_VARS;
00425       $TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content;
00426    }
00427 
00438    function addLLrefForTCAdescr($tca_descr_key,$file_ref)   {
00439       global $TCA_DESCR;
00440       if ($tca_descr_key)  {
00441          if (!is_array($TCA_DESCR[$tca_descr_key]))   {
00442             $TCA_DESCR[$tca_descr_key]=array();
00443          }
00444          if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) {
00445             $TCA_DESCR[$tca_descr_key]['refs']=array();
00446          }
00447          $TCA_DESCR[$tca_descr_key]['refs'][]=$file_ref;
00448       }
00449    }
00450 
00451 
00452 
00453 
00454 
00455 
00456 
00457 
00458 
00459 
00460 
00461 
00462    /**************************************
00463     *
00464     *  Adding SERVICES features
00465     *
00466     *   @author   René Fritz <r.fritz@colorcube.de>
00467     *
00468     ***************************************/
00469 
00480    function addService($extKey, $serviceType, $serviceKey, $info) {
00481       global $T3_SERVICES,$TYPO3_CONF_VARS;
00482 
00483       // even not available services will be included to make it possible to give the admin a feedback of non-available services.
00484       // but maybe it's better to move non-available services to a different array??
00485 
00486       if ($serviceType AND substr($serviceType,0,3)!='tx_' AND substr($serviceKey,0,3)=='tx_' AND is_array($info))   {
00487 
00488          $info['priority'] = max(0,min(100,$info['priority']));
00489 
00490          $T3_SERVICES[$serviceType][$serviceKey]=$info;
00491 
00492          $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey;
00493          $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
00494          $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType;
00495 
00496 
00497             // mapping a service key to a service type
00498             // all service keys begin with tx_ - service types don't
00499             // this way a selection of a special service key as service type is easy
00500          $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey];
00501 
00502 
00503             // change the priority (and other values) from TYPO3_CONF_VARS
00504             // $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]['priority']
00505             // even the activation is possible (a unix service might be possible on windows for some reasons)
00506          if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) {
00507 
00508                // no check is done here - there might be configuration values only the service type knows about, so we pass everything
00509             $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey],$TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]);
00510          }
00511 
00512 
00513             // OS check
00514             // empty $os means 'not limited to one OS', therefore a check is not needed
00515          if ($T3_SERVICES[$serviceType][$serviceKey]['available'] AND $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
00516 
00517                // TYPO3_OS is not yet defined
00518             $os_type = stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'UNIX';
00519 
00520             $os = t3lib_div::trimExplode(',',strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os']));
00521 
00522             if (!in_array($os_type,$os)) {
00523                t3lib_extMgm::deactivateService($serviceType, $serviceKey);
00524             }
00525          }
00526 
00527             // convert subtype list to array for quicker access
00528          $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array();
00529          $serviceSubTypes = t3lib_div::trimExplode(',',$info['subtype']);
00530          foreach ($serviceSubTypes as $subtype) {
00531             $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
00532          }
00533       }
00534    }
00535 
00545    function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) {
00546       global $T3_SERVICES;
00547 
00548       $serviceKey = FALSE;
00549       $serviceInfo = FALSE;
00550       $priority = 0;
00551       $quality = 0;
00552 
00553       if (!is_array($excludeServiceKeys) ) {
00554          $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
00555       }
00556 
00557       if (is_array($T3_SERVICES[$serviceType])) {
00558          foreach($T3_SERVICES[$serviceType] as $key => $info)  {
00559 
00560             if (in_array($key, $excludeServiceKeys)) {
00561                continue;
00562             }
00563 
00564                // select a subtype randomly
00565                // usefull to start a service by service key without knowing his subtypes - for testing purposes
00566             if ($serviceSubType=='*') {
00567                $serviceSubType = key($info['serviceSubTypes']);
00568             }
00569 
00570                // this matches empty subtype too
00571             if( $info['available'] AND ($info['subtype']==$serviceSubType OR $info['serviceSubTypes'][$serviceSubType]) AND $info['priority']>=$priority ) {
00572 
00573                   // has a lower quality than the already found, therefore we skip this service
00574                if($info['priority']==$priority AND $info['quality']<$quality) {
00575                   continue;
00576                }
00577 
00578                   // service depends on external programs - check if they exists
00579                if(trim($info['exec'])) {
00580                   require_once(PATH_t3lib.'class.t3lib_exec.php');
00581 
00582                   $executables = t3lib_div::trimExplode(',', $info['exec'],1);
00583                   foreach($executables as $executable)   {
00584                      if(!t3lib_exec::checkCommand($executable)) {
00585                         t3lib_extMgm::deactivateService($serviceType, $key);
00586                         $info['available']=FALSE;
00587                         break;
00588                      }
00589                   }
00590                }
00591 
00592                   // still available after exec check?
00593                if($info['available']) {
00594                   $serviceKey = $key;
00595                   $priority = $info['priority'];
00596                   $quality = $info['quality'];
00597                }
00598             }
00599          }
00600       }
00601 
00602       if ($serviceKey) {
00603          $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey];
00604       }
00605       return $serviceInfo;
00606    }
00607 
00616    function deactivateService($serviceType, $serviceKey) {
00617       global $T3_SERVICES;
00618 
00619          // ... maybe it's better to move non-available services to a different array??
00620       $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE;
00621    }
00622 
00623 
00624 
00625 
00626 
00627 
00628 
00629 
00630 
00631 
00632 
00633 
00634 
00635 
00636    /**************************************
00637     *
00638     *  Adding FRONTEND features
00639     *  (related specifically to "cms" extension)
00640     *
00641     ***************************************/
00642 
00655    function addPlugin($itemArray,$type='list_type')   {
00656       global $TCA;
00657       t3lib_div::loadTCA('tt_content');
00658       if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) {
00659          reset($TCA['tt_content']['columns'][$type]['config']['items']);
00660          while(list($k,$v)=each($TCA['tt_content']['columns'][$type]['config']['items'])) {
00661             if (!strcmp($v[1],$itemArray[1]))   {
00662                $TCA['tt_content']['columns'][$type]['config']['items'][$k]=$itemArray;
00663                return;
00664             }
00665          }
00666          $TCA['tt_content']['columns'][$type]['config']['items'][]=$itemArray;
00667       }
00668    }
00669 
00680    function addPiFlexFormValue($piKeyToMatch,$value)  {
00681       global $TCA;
00682       t3lib_div::loadTCA('tt_content');
00683 
00684       if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds']))  {
00685          $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch] = $value;
00686       }
00687    }
00688 
00700    function addToInsertRecords($table,$content_table='tt_content',$content_field='records')  {
00701       global $TCA;
00702       t3lib_div::loadTCA($content_table);
00703       if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed'])) {
00704          $TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table;
00705       }
00706    }
00707 
00731    function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0)  {
00732       global $TYPO3_LOADED_EXT;
00733       $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_','',$key).$prefix.'.php';
00734       $cN = t3lib_extMgm::getCN($key);
00735 
00736          // General plugin:
00737       if ($cached)   {
00738          $pluginContent = trim('
00739 includeLibs.'.$cN.$prefix.' = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
00740 plugin.'.$cN.$prefix.' = USER
00741 plugin.'.$cN.$prefix.' {
00742   userFunc = '.$cN.$prefix.'->main
00743 }');
00744       } else {
00745          $pluginContent = trim('
00746 plugin.'.$cN.$prefix.' = USER_INT
00747 plugin.'.$cN.$prefix.' {
00748   includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
00749   userFunc = '.$cN.$prefix.'->main
00750 }');
00751       }
00752       t3lib_extMgm::addTypoScript($key,'setup','
00753 # Setting '.$key.' plugin TypoScript
00754 '.$pluginContent);
00755 
00756          // After ST43:
00757       switch($type)  {
00758          case 'list_type':
00759             $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00760          break;
00761          case 'menu_type':
00762             $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00763          break;
00764          case 'splash_layout':
00765             $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00766          break;
00767          case 'CType':
00768             $addLine = trim('
00769 tt_content.'.$key.$prefix.' = COA
00770 tt_content.'.$key.$prefix.' {
00771    10 = < lib.stdheader
00772    20 = < plugin.'.$cN.$prefix.'
00773 }
00774             ');
00775          break;
00776          case 'header_layout':
00777             $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00778          break;
00779          case 'includeLib':
00780             $addLine = 'page.1000 = < plugin.'.$cN.$prefix;
00781          break;
00782          default:
00783             $addLine = '';
00784          break;
00785       }
00786       if ($addLine)  {
00787          t3lib_extMgm::addTypoScript($key,'setup','
00788 # Setting '.$key.' plugin TypoScript
00789 '.$addLine.'
00790 ',43);
00791       }
00792    }
00793 
00806    function addStaticFile($extKey,$path,$title) {
00807       global $TCA;
00808       t3lib_div::loadTCA('sys_template');
00809       if ($extKey && $path && is_array($TCA['sys_template']['columns']))   {
00810          $value = str_replace(',','','EXT:'.$extKey.'/'.$path);
00811          $itemArray=array(trim($title.' ('.$extKey.')'),$value);
00812          $TCA['sys_template']['columns']['include_static_file']['config']['items'][]=$itemArray;
00813       }
00814    }
00815 
00825    function addTypoScriptSetup($content)  {
00826       global $TYPO3_CONF_VARS;
00827       $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
00828    }
00829 
00839    function addTypoScriptConstants($content) {
00840       global $TYPO3_CONF_VARS;
00841       $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
00842    }
00843 
00856    function addTypoScript($key,$type,$content,$afterStaticUid=0)  {
00857       global $TYPO3_CONF_VARS;
00858 
00859       if ($type=='setup' || $type=='editorcfg' || $type=='constants')      {
00860          $content = '
00861 
00862 [GLOBAL]
00863 #############################################
00864 ## TypoScript added by extension "'.$key.'"
00865 #############################################
00866 
00867 '.$content;
00868          if ($afterStaticUid) {
00869             $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
00870             if ($afterStaticUid==43)   {  // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
00871                $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.']['cssstyledcontent/static/'].=$content;
00872             }
00873          } else {
00874             $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content;
00875          }
00876       }
00877    }
00878 
00879 
00880 
00881 
00882 
00883 
00884 
00885 
00886 
00887 
00888 
00889 
00890 
00891 
00892 
00893 
00894 
00895 
00896    /**************************************
00897     *
00898     *  INTERNAL EXTENSION MANAGEMENT:
00899     *
00900     ***************************************/
00901 
00919    function typo3_loadExtensions()  {
00920       global $TYPO3_CONF_VARS;
00921 
00922          // Full list of extensions includes both required and extList:
00923       $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'].','.$TYPO3_CONF_VARS['EXT']['extList'];
00924 
00925          // Empty array as a start.
00926       $extensions = array();
00927 
00928          //
00929       if ($rawExtList)  {
00930             // The cached File prefix.
00931          $cacheFilePrefix = 'temp_CACHED';
00932             // Setting the name for the cache files:
00933          if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1)   $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']),0,4);
00934          if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2)   $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
00935 
00936             // If cache files available, set cache file prefix and return:
00937          if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix))  {
00938                // Return cache file prefix:
00939             $extensions['_CACHEFILE'] = $cacheFilePrefix;
00940          } else {
00941             // ... but if not, configure...
00942             $temp_extensions = array_unique(t3lib_div::trimExplode(',',$rawExtList,1));
00943             while(list(,$temp_extKey)=each($temp_extensions))  {
00944                if (@is_dir(PATH_site.'typo3conf/ext/'.$temp_extKey)) {
00945                   $extensions[$temp_extKey]=array('type'=>'L','siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/','typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
00946                } elseif (@is_dir(PATH_site.TYPO3_mainDir.'ext/'.$temp_extKey))   {
00947                   $extensions[$temp_extKey]=array('type'=>'G','siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/','typo3RelPath'=>'ext/'.$temp_extKey.'/');
00948                } elseif (@is_dir(PATH_site.TYPO3_mainDir.'sysext/'.$temp_extKey))   {
00949                   $extensions[$temp_extKey]=array('type'=>'S','siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/','typo3RelPath'=>'sysext/'.$temp_extKey.'/');
00950                }
00951 
00952                $files = t3lib_div::trimExplode(',','
00953                   ext_localconf.php,
00954                   ext_tables.php,
00955                   ext_tables.sql,
00956                   ext_tables_static+adt.sql,
00957                   ext_typoscript_constants.txt,
00958                   ext_typoscript_editorcfg.txt,
00959                   ext_typoscript_setup.txt
00960                ',1);
00961                reset($files);
00962                while(list(,$fName)=each($files))   {
00963                   $temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName);
00964                   if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename)) {
00965                      $extensions[$temp_extKey][$fName]=$temp_filename;
00966                   }
00967                }
00968             }
00969             unset($extensions['_CACHEFILE']);
00970 
00971 
00972             // write cache?
00973             if ($TYPO3_CONF_VARS['EXT']['extCache'])  {
00974                $wrError = t3lib_extMgm::cannotCacheFilesWritable($cacheFilePrefix);
00975                if ($wrError)  {
00976 //debug('Cannot write cache files: '.$wrError.'. Disabling the cache...');
00977                   $TYPO3_CONF_VARS['EXT']['extCache']=0;
00978                } else {
00979                   // Write cache files:
00980                   $extensions = t3lib_extMgm::writeCacheFiles($extensions,$cacheFilePrefix);
00981                }
00982             }
00983          }
00984       }
00985 
00986 #debug($extensions);
00987       return $extensions;
00988    }
00989 
00998    function _makeIncludeHeader($key,$file)   {
00999       return '<?php
01000 ###########################
01001 ## EXTENSION: '.$key.'
01002 ## FILE:      '.$file.'
01003 ###########################
01004 
01005 $_EXTKEY = \''.$key.'\';
01006 $_EXTCONF = $TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][$_EXTKEY];
01007 
01008 ?>';
01009    }
01010 
01019    function isCacheFilesAvailable($cacheFilePrefix)   {
01020       return
01021          @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
01022          @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php');
01023    }
01024 
01032    function isLocalconfWritable()   {
01033       return is_writeable(PATH_typo3conf) && is_writeable(PATH_typo3conf.'localconf.php');
01034    }
01035 
01045    function cannotCacheFilesWritable($cacheFilePrefix)   {
01046       $error=array();
01047       if (!@is_writeable(PATH_typo3conf)) {
01048          $error[]=PATH_typo3conf;
01049       }
01050       if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
01051          !@is_writeable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php'))   {
01052             $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
01053       }
01054       if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php') &&
01055          !@is_writeable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php'))   {
01056             $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
01057       }
01058       return implode(', ',$error);
01059    }
01060 
01069    function currentCacheFiles()  {
01070       global $TYPO3_LOADED_EXT;
01071 
01072       if ($TYPO3_LOADED_EXT['_CACHEFILE'])   {
01073          if (t3lib_extMgm::isCacheFilesAvailable($TYPO3_LOADED_EXT['_CACHEFILE']))  {
01074             return array(
01075                PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_localconf.php',
01076                PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php'
01077             );
01078          }
01079       }
01080    }
01081 
01092    function writeCacheFiles($extensions,$cacheFilePrefix)   {
01093          // Making cache files:
01094       $extensions['_CACHEFILE'] = $cacheFilePrefix;
01095       $cFiles=array();
01096       $cFiles['ext_localconf'].='<?php
01097 
01098 $TYPO3_LOADED_EXT = unserialize(stripslashes(\''.addslashes(serialize($extensions)).'\'));
01099 
01100 ?>';
01101 
01102       reset($extensions);
01103       while(list($key,$conf)=each($extensions)) {
01104          if (is_array($conf)) {
01105             if ($conf['ext_localconf.php'])  {
01106                $cFiles['ext_localconf'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_localconf.php']);
01107                $cFiles['ext_localconf'].=trim(t3lib_div::getUrl($conf['ext_localconf.php']));
01108             }
01109             if ($conf['ext_tables.php'])  {
01110                $cFiles['ext_tables'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_tables.php']);
01111                $cFiles['ext_tables'].=trim(t3lib_div::getUrl($conf['ext_tables.php']));
01112             }
01113          }
01114       }
01115 
01116       t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php',$cFiles['ext_localconf']);
01117       t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php',$cFiles['ext_tables']);
01118 
01119       $extensions=array();
01120       $extensions['_CACHEFILE'] = $cacheFilePrefix;
01121 
01122       return $extensions;
01123    }
01124 }
01125 
01126 ?>

Generated on Sun Oct 3 01:05:48 2004 for TYPO3core 3.7.0 dev by  doxygen 1.3.8-20040913