/src/typo3_src-4.2.0alpha1/t3lib/class.t3lib_extmgm.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 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 ***************************************************************/
00114 class t3lib_extMgm {
00115 
00116 
00117         /**************************************
00118          *
00119          * PATHS and other evaluation
00120          *
00121          ***************************************/
00122 
00131         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 
00147         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 
00165         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 
00182         function siteRelPath($key)      {
00183                 return substr(t3lib_extMgm::extPath($key),strlen(PATH_site));
00184         }
00185 
00194         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 
00227         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 
00251         function addToAllTCAtypes($table,$str,$specificTypesList='',$position='')       {
00252                 global $TCA;
00253 
00254                 $positionArr=t3lib_div::trimExplode(',',$position,1);
00255                 $insert=count($position);
00256 
00257                 t3lib_div::loadTCA($table);
00258                 $str = trim($str);
00259                 if ($str && is_array($TCA[$table]) && is_array($TCA[$table]['types']))  {
00260                         foreach($TCA[$table]['types'] as $k => $v)      {
00261                                 if (!$specificTypesList || t3lib_div::inList($specificTypesList,$k))    {
00262                                         if ($insert)    {
00263                                                 if (count($positionArr)) {
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) || in_array($palette, $positionArr) || in_array('before:'.$theField, $positionArr) || in_array('before:'.$palette, $positionArr)) {
00274                                                                         $showItem[$key]=$str.', '.$fieldInfo;
00275                                                                         $append=false;
00276                                                                         break;
00277                                                                 }
00278                                                                         // insert after
00279                                                                 if (in_array('after:'.$theField, $positionArr) || in_array('after:'.$palette, $positionArr))    {
00280                                                                         $showItem[$key]=$fieldInfo.', '.$str;
00281                                                                         $append=false;
00282                                                                         break;
00283                                                                 }
00284                                                         }
00285         
00286                                                                 // Not found? Then append.
00287                                                         if($append) {
00288                                                                 $showItem[]=$str;
00289                                                         }
00290         
00291                                                         $TCA[$table]['types'][$k]['showitem']=implode(', ', $showItem);
00292                                                 }
00293                                                 else {
00294                                                         $TCA[$table]['types'][$k]['showitem'] .= ', ' . $str;
00295                                                 }
00296 
00297                                         } else {
00298                                                 $TCA[$table]['types'][$k]['showitem'].=', ' . $str;
00299                                         }
00300                                 }
00301                         }
00302                 }
00303         }
00304 
00305 
00315         function allowTableOnStandardPages($table)      {
00316                 global $PAGES_TYPES;
00317 
00318                 $PAGES_TYPES['default']['allowedTables'].=','.$table;
00319         }
00320 
00332         function addModule($main,$sub='',$position='',$path='') {
00333                 global $TBE_MODULES;
00334 
00335                 if (isset($TBE_MODULES[$main]) && $sub) {       // If there is already a main module by this name:
00336 
00337                                 // Adding the submodule to the correct position:
00338                         list($place,$modRef)=t3lib_div::trimExplode(':',$position,1);
00339                         $mods = t3lib_div::trimExplode(',',$TBE_MODULES[$main],1);
00340                         if (!in_array($sub,$mods))      {
00341                                 switch(strtolower($place))      {
00342                                         case 'after':
00343                                         case 'before':
00344                                                 $pointer=0;
00345                                                 reset($mods);
00346                                                 while(list($k,$m)=each($mods))  {
00347                                                         if (!strcmp($m,$modRef))        {
00348                                                                 $pointer=strtolower($place)=='after'?$k+1:$k;
00349                                                         }
00350                                                 }
00351                                                 array_splice(
00352                                                         $mods,  // The modules array
00353                                                         $pointer,               // To insert one position from the end of the list
00354                                                         0,              // Don't remove any items, just insert
00355                                                         $sub    // Module to insert
00356                                                 );
00357                                         break;
00358                                         default:
00359                                                 if (strtolower($place)=='top')  {
00360                                                         array_unshift($mods,$sub);
00361                                                 } else {
00362                                                         array_push($mods,$sub);
00363                                                 }
00364                                         break;
00365                                 }
00366                         }
00367                                 // Re-inserting the submodule list:
00368                         $TBE_MODULES[$main]=implode(',',$mods);
00369                 } else {        // Create new main modules with only one submodule, $sub (or none if $sub is blank)
00370                         $TBE_MODULES[$main]=$sub;
00371                 }
00372 
00373                         // Adding path:
00374                 if ($path)      {
00375                         $TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')]=$path;
00376                 }
00377         }
00378 
00390         function addModulePath($name,$path)     {
00391                 global $TBE_MODULES;
00392 
00393                 $TBE_MODULES['_PATHS'][$name] = $path;
00394         }
00395 
00405         function addTopApp($name,$path,$iconPane=FALSE,$options=array())        {
00406                 global $TBE_MODULES,$TYPO3_CONF_VARS;
00407 
00408                 $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['topApps'][$iconPane?'icons':'menu'][$name] = $options;
00409 
00410                         // Set path for TBE-modules:
00411                 $TBE_MODULES['_PATHS'][$name] = $path;
00412         }
00413 
00430         function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='')  {
00431                 global $TBE_MODULES_EXT;
00432                 $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className]=array(
00433                         'name' => $className,
00434                         'path' => $classPath,
00435                         'title' => $title,
00436                         'ws' => $WS
00437                 );
00438         }
00439 
00449         function addPageTSConfig($content)      {
00450                 global $TYPO3_CONF_VARS;
00451                 $TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content;
00452         }
00453 
00463         function addUserTSConfig($content)      {
00464                 global $TYPO3_CONF_VARS;
00465                 $TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content;
00466         }
00467 
00478         function addLLrefForTCAdescr($tca_descr_key,$file_ref)  {
00479                 global $TCA_DESCR;
00480                 if ($tca_descr_key)     {
00481                         if (!is_array($TCA_DESCR[$tca_descr_key]))      {
00482                                 $TCA_DESCR[$tca_descr_key]=array();
00483                         }
00484                         if (!is_array($TCA_DESCR[$tca_descr_key]['refs']))      {
00485                                 $TCA_DESCR[$tca_descr_key]['refs']=array();
00486                         }
00487                         $TCA_DESCR[$tca_descr_key]['refs'][]=$file_ref;
00488                 }
00489         }
00490 
00491 
00492 
00493 
00494 
00495 
00496 
00497 
00498 
00499 
00500 
00501 
00502         /**************************************
00503          *
00504          *       Adding SERVICES features
00505          *
00506          *   @author    René Fritz <r.fritz@colorcube.de>
00507          *
00508          ***************************************/
00509 
00520         function addService($extKey, $serviceType, $serviceKey, $info)  {
00521                 global $T3_SERVICES,$TYPO3_CONF_VARS;
00522 
00523                 // even not available services will be included to make it possible to give the admin a feedback of non-available services.
00524                 // but maybe it's better to move non-available services to a different array??
00525 
00526                 if ($serviceType &&
00527                         !t3lib_div::isFirstPartOfStr($serviceType, 'tx_') &&
00528                         (t3lib_div::isFirstPartOfStr($serviceKey, 'tx_') || t3lib_div::isFirstPartOfStr($serviceKey, 'user_')) &&
00529                         is_array($info))        {
00530 
00531                         $info['priority'] = max(0,min(100,$info['priority']));
00532 
00533                         $T3_SERVICES[$serviceType][$serviceKey]=$info;
00534 
00535                         $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey;
00536                         $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
00537                         $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType;
00538 
00539 
00540                                 // mapping a service key to a service type
00541                                 // all service keys begin with tx_ - service types don't
00542                                 // this way a selection of a special service key as service type is easy
00543                         $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey];
00544 
00545 
00546                                 // change the priority (and other values) from TYPO3_CONF_VARS
00547                                 // $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]['priority']
00548                                 // even the activation is possible (a unix service might be possible on windows for some reasons)
00549                         if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) {
00550 
00551                                         // no check is done here - there might be configuration values only the service type knows about, so we pass everything
00552                                 $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey],$TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]);
00553                         }
00554 
00555 
00556                                 // OS check
00557                                 // empty $os means 'not limited to one OS', therefore a check is not needed
00558                         if ($T3_SERVICES[$serviceType][$serviceKey]['available'] && $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
00559 
00560                                         // TYPO3_OS is not yet defined
00561                                 $os_type = stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'UNIX';
00562 
00563                                 $os = t3lib_div::trimExplode(',',strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os']));
00564 
00565                                 if (!in_array($os_type,$os)) {
00566                                         t3lib_extMgm::deactivateService($serviceType, $serviceKey);
00567                                 }
00568                         }
00569 
00570                                 // convert subtype list to array for quicker access
00571                         $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array();
00572                         $serviceSubTypes = t3lib_div::trimExplode(',',$info['subtype']);
00573                         foreach ($serviceSubTypes as $subtype) {
00574                                 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
00575                         }
00576                 }
00577         }
00578 
00588         function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) {
00589                 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
00590 
00591                 $serviceKey = FALSE;
00592                 $serviceInfo = FALSE;
00593                 $priority = 0;
00594                 $quality = 0;
00595 
00596                 if (!is_array($excludeServiceKeys) ) {
00597                         $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
00598                 }
00599 
00600                 if (is_array($T3_SERVICES[$serviceType]))       {
00601                         foreach($T3_SERVICES[$serviceType] as $key => $info)    {
00602 
00603                                 if (in_array($key, $excludeServiceKeys)) {
00604                                         continue;
00605                                 }
00606 
00607                                         // select a subtype randomly
00608                                         // usefull to start a service by service key without knowing his subtypes - for testing purposes
00609                                 if ($serviceSubType=='*') {
00610                                         $serviceSubType = key($info['serviceSubTypes']);
00611                                 }
00612 
00613                                         // this matches empty subtype too
00614                                 if ($info['available'] && ($info['subtype']==$serviceSubType || $info['serviceSubTypes'][$serviceSubType]) && $info['priority']>=$priority )    {
00615 
00616                                                 // has a lower quality than the already found, therefore we skip this service
00617                                         if($info['priority']==$priority && $info['quality']<$quality) {
00618                                                 continue;
00619                                         }
00620 
00621                                                 // service depends on external programs - check if they exists
00622                                         if(trim($info['exec'])) {
00623                                                 require_once(PATH_t3lib.'class.t3lib_exec.php');
00624 
00625                                                 $executables = t3lib_div::trimExplode(',', $info['exec'],1);
00626                                                 foreach($executables as $executable)    {
00627                                                         if(!t3lib_exec::checkCommand($executable)) {
00628                                                                 t3lib_extMgm::deactivateService($serviceType, $key);
00629                                                                 $info['available']=FALSE;
00630                                                                 break;
00631                                                         }
00632                                                 }
00633                                         }
00634 
00635                                                 // still available after exec check?
00636                                         if($info['available']) {
00637                                                 $serviceKey = $key;
00638                                                 $priority = $info['priority'];
00639                                                 $quality = $info['quality'];
00640                                         }
00641                                 }
00642                         }
00643                 }
00644 
00645                 if ($serviceKey) {
00646                         $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey];
00647                 }
00648                 return $serviceInfo;
00649         }
00650 
00659         function deactivateService($serviceType, $serviceKey) {
00660                 global $T3_SERVICES;
00661 
00662                         // ... maybe it's better to move non-available services to a different array??
00663                 $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE;
00664         }
00665 
00666 
00667 
00668 
00669 
00670 
00671 
00672 
00673 
00674 
00675 
00676 
00677 
00678 
00679         /**************************************
00680          *
00681          *       Adding FRONTEND features
00682          *       (related specifically to "cms" extension)
00683          *
00684          ***************************************/
00685 
00698         function addPlugin($itemArray,$type='list_type')        {
00699                 global $TCA;
00700                 t3lib_div::loadTCA('tt_content');
00701                 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items']))       {
00702                         reset($TCA['tt_content']['columns'][$type]['config']['items']);
00703                         while(list($k,$v)=each($TCA['tt_content']['columns'][$type]['config']['items']))        {
00704                                 if (!strcmp($v[1],$itemArray[1]))       {
00705                                         $TCA['tt_content']['columns'][$type]['config']['items'][$k]=$itemArray;
00706                                         return;
00707                                 }
00708                         }
00709                         $TCA['tt_content']['columns'][$type]['config']['items'][]=$itemArray;
00710                 }
00711         }
00712 
00723         function addPiFlexFormValue($piKeyToMatch,$value)       {
00724                 global $TCA;
00725                 t3lib_div::loadTCA('tt_content');
00726 
00727                 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds']))  {
00728                         $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch] = $value;
00729                 }
00730         }
00731 
00743         function addToInsertRecords($table,$content_table='tt_content',$content_field='records')        {
00744                 global $TCA;
00745                 t3lib_div::loadTCA($content_table);
00746                 if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed']))   {
00747                         $TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table;
00748                 }
00749         }
00750 
00774         function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0) {
00775                 global $TYPO3_LOADED_EXT;
00776                 $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_','',$key).$prefix.'.php';
00777                 $cN = t3lib_extMgm::getCN($key);
00778 
00779                         // General plugin:
00780                 if ($cached)    {
00781                         $pluginContent = trim('
00782 includeLibs.'.$cN.$prefix.' = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
00783 plugin.'.$cN.$prefix.' = USER
00784 plugin.'.$cN.$prefix.' {
00785   userFunc = '.$cN.$prefix.'->main
00786 }');
00787                 } else {
00788                         $pluginContent = trim('
00789 plugin.'.$cN.$prefix.' = USER_INT
00790 plugin.'.$cN.$prefix.' {
00791   includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
00792   userFunc = '.$cN.$prefix.'->main
00793 }');
00794                 }
00795                 t3lib_extMgm::addTypoScript($key,'setup','
00796 # Setting '.$key.' plugin TypoScript
00797 '.$pluginContent);
00798 
00799                         // After ST43:
00800                 switch($type)   {
00801                         case 'list_type':
00802                                 $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00803                         break;
00804                         case 'menu_type':
00805                                 $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00806                         break;
00807                         case 'splash_layout':
00808                                 $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00809                         break;
00810                         case 'CType':
00811                                 $addLine = trim('
00812 tt_content.'.$key.$prefix.' = COA
00813 tt_content.'.$key.$prefix.' {
00814         10 = < lib.stdheader
00815         20 = < plugin.'.$cN.$prefix.'
00816 }
00817                                 ');
00818                         break;
00819                         case 'header_layout':
00820                                 $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00821                         break;
00822                         case 'includeLib':
00823                                 $addLine = 'page.1000 = < plugin.'.$cN.$prefix;
00824                         break;
00825                         default:
00826                                 $addLine = '';
00827                         break;
00828                 }
00829                 if ($addLine)   {
00830                         t3lib_extMgm::addTypoScript($key,'setup','
00831 # Setting '.$key.' plugin TypoScript
00832 '.$addLine.'
00833 ',43);
00834                 }
00835         }
00836 
00849         function addStaticFile($extKey,$path,$title)    {
00850                 global $TCA;
00851                 t3lib_div::loadTCA('sys_template');
00852                 if ($extKey && $path && is_array($TCA['sys_template']['columns']))      {
00853                         $value = str_replace(',','','EXT:'.$extKey.'/'.$path);
00854                         $itemArray=array(trim($title.' ('.$extKey.')'),$value);
00855                         $TCA['sys_template']['columns']['include_static_file']['config']['items'][]=$itemArray;
00856                 }
00857         }
00858 
00868         function addTypoScriptSetup($content)   {
00869                 global $TYPO3_CONF_VARS;
00870                 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
00871         }
00872 
00882         function addTypoScriptConstants($content)       {
00883                 global $TYPO3_CONF_VARS;
00884                 $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
00885         }
00886 
00899         function addTypoScript($key,$type,$content,$afterStaticUid=0)   {
00900                 global $TYPO3_CONF_VARS;
00901 
00902                 if ($type=='setup' || $type=='editorcfg' || $type=='constants')         {
00903                         $content = '
00904 
00905 [GLOBAL]
00906 #############################################
00907 ## TypoScript added by extension "'.$key.'"
00908 #############################################
00909 
00910 '.$content;
00911                         if ($afterStaticUid)    {
00912                                 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
00913                                 if ($afterStaticUid==43)        {       // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
00914                                         $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.']['cssstyledcontent/static/'].=$content;
00915                                 }
00916                         } else {
00917                                 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content;
00918                         }
00919                 }
00920         }
00921 
00922 
00923 
00924 
00925 
00926 
00927 
00928 
00929 
00930 
00931 
00932 
00933 
00934 
00935 
00936 
00937 
00938 
00939         /**************************************
00940          *
00941          *       INTERNAL EXTENSION MANAGEMENT:
00942          *
00943          ***************************************/
00944 
00962         function typo3_loadExtensions() {
00963                 global $TYPO3_CONF_VARS;
00964 
00965                         // Full list of extensions includes both required and extList:
00966                 $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'].','.$TYPO3_CONF_VARS['EXT']['extList'];
00967 
00968                         // Empty array as a start.
00969                 $extensions = array();
00970 
00971                         //
00972                 if ($rawExtList)        {
00973                                 // The cached File prefix.
00974                         $cacheFilePrefix = 'temp_CACHED';
00975                                 // Setting the name for the cache files:
00976                         if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1)     $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']),0,4);
00977                         if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2)     $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
00978 
00979                                 // If cache files available, set cache file prefix and return:
00980                         if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix))       {
00981                                         // Return cache file prefix:
00982                                 $extensions['_CACHEFILE'] = $cacheFilePrefix;
00983                         } else {        // ... but if not, configure...
00984 
00985                                         // Prepare reserved filenames:
00986                                 $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);
00987 
00988                                         // Traverse extensions and check their existence:
00989                                 clearstatcache();       // Clear file state cache to make sure we get good results from is_dir()
00990                                 $temp_extensions = array_unique(t3lib_div::trimExplode(',',$rawExtList,1));
00991                                 foreach($temp_extensions as $temp_extKey)       {
00992                                                 // Check local, global and system locations:
00993                                         if (@is_dir(PATH_typo3conf.'ext/'.$temp_extKey.'/'))    {
00994                                                 $extensions[$temp_extKey] = array('type'=>'L', 'siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/', 'typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
00995                                         } elseif (@is_dir(PATH_typo3.'ext/'.$temp_extKey.'/'))  {
00996                                                 $extensions[$temp_extKey] = array('type'=>'G', 'siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/', 'typo3RelPath'=>'ext/'.$temp_extKey.'/');
00997                                         } elseif (@is_dir(PATH_typo3.'sysext/'.$temp_extKey.'/'))       {
00998                                                 $extensions[$temp_extKey] = array('type'=>'S', 'siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/', 'typo3RelPath'=>'sysext/'.$temp_extKey.'/');
00999                                         }
01000 
01001                                                 // If extension was found, check for reserved filenames:
01002                                         if (isset($extensions[$temp_extKey]))   {
01003                                                 foreach($files as $fName)       {
01004                                                         $temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName);
01005                                                         if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename))    {
01006                                                                 $extensions[$temp_extKey][$fName] = $temp_filename;
01007                                                         }
01008                                                 }
01009                                         }
01010                                 }
01011                                 unset($extensions['_CACHEFILE']);
01012 
01013                                         // write cache?
01014                                 if ($TYPO3_CONF_VARS['EXT']['extCache'] &&
01015                                                 @is_dir(PATH_typo3.'sysext/') &&
01016                                                 @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!
01017                                         $wrError = t3lib_extMgm::cannotCacheFilesWritable($cacheFilePrefix);
01018                                         if ($wrError)   {
01019                                                 $TYPO3_CONF_VARS['EXT']['extCache']=0;
01020                                         } else {
01021                                                         // Write cache files:
01022                                                 $extensions = t3lib_extMgm::writeCacheFiles($extensions,$cacheFilePrefix);
01023                                         }
01024                                 }
01025                         }
01026                 }
01027 
01028                 return $extensions;
01029         }
01030 
01039         function _makeIncludeHeader($key,$file) {
01040                 return '<?php
01041 ###########################
01042 ## EXTENSION: '.$key.'
01043 ## FILE:      '.$file.'
01044 ###########################
01045 
01046 $_EXTKEY = \''.$key.'\';
01047 $_EXTCONF = $TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][$_EXTKEY];
01048 
01049 ?>';
01050         }
01051 
01060         function isCacheFilesAvailable($cacheFilePrefix)        {
01061                 return
01062                         @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
01063                         @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php');
01064         }
01065 
01073         function isLocalconfWritable()  {
01074                 return @is_writable(PATH_typo3conf) && @is_writable(PATH_typo3conf.'localconf.php');
01075         }
01076 
01086         function cannotCacheFilesWritable($cacheFilePrefix)     {
01087                 $error=array();
01088                 if (!@is_writable(PATH_typo3conf))      {
01089                         $error[]=PATH_typo3conf;
01090                 }
01091                 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
01092                         !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php'))    {
01093                                 $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
01094                 }
01095                 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php') &&
01096                         !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php'))       {
01097                                 $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
01098                 }
01099                 return implode(', ',$error);
01100         }
01101 
01110         function currentCacheFiles()    {
01111                 global $TYPO3_LOADED_EXT;
01112 
01113                 if ($TYPO3_LOADED_EXT['_CACHEFILE'])    {
01114                         if (t3lib_extMgm::isCacheFilesAvailable($TYPO3_LOADED_EXT['_CACHEFILE']))       {
01115                                 return array(
01116                                         PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_localconf.php',
01117                                         PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php'
01118                                 );
01119                         }
01120                 }
01121         }
01122 
01133         function writeCacheFiles($extensions,$cacheFilePrefix)  {
01134                         // Making cache files:
01135                 $extensions['_CACHEFILE'] = $cacheFilePrefix;
01136                 $cFiles=array();
01137                 $cFiles['ext_localconf'].='<?php
01138 
01139 $TYPO3_LOADED_EXT = unserialize(stripslashes(\''.addslashes(serialize($extensions)).'\'));
01140 
01141 ?>';
01142 
01143                 reset($extensions);
01144                 while(list($key,$conf)=each($extensions))       {
01145                         if (is_array($conf))    {
01146                                 if ($conf['ext_localconf.php']) {
01147                                         $cFiles['ext_localconf'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_localconf.php']);
01148                                         $cFiles['ext_localconf'].=trim(t3lib_div::getUrl($conf['ext_localconf.php']));
01149                                 }
01150                                 if ($conf['ext_tables.php'])    {
01151                                         $cFiles['ext_tables'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_tables.php']);
01152                                         $cFiles['ext_tables'].=trim(t3lib_div::getUrl($conf['ext_tables.php']));
01153                                 }
01154                         }
01155                 }
01156 
01157                 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php',$cFiles['ext_localconf']);
01158                 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php',$cFiles['ext_tables']);
01159 
01160                 $extensions=array();
01161                 $extensions['_CACHEFILE'] = $cacheFilePrefix;
01162 
01163                 return $extensions;
01164         }
01165 
01171         function removeCacheFiles()     {
01172                 $cacheFiles = t3lib_extMgm::currentCacheFiles();
01173                 $out = 0;
01174                 if (is_array($cacheFiles))      {
01175                         reset($cacheFiles);
01176                         foreach($cacheFiles as $cfile)  {
01177                                 @unlink($cfile);
01178                                 clearstatcache();
01179                                 $out++;
01180                         }
01181                 }
01182                 return $out;
01183         }
01184 }
01185 
01186 ?>

This documentation has been generated automatically from TYPO3 source code using Doxygen and is provided as is by Cast Iron Coding as a courtesy to other TYPO3 developers and users. Please consider Cast Iron Coding — a full-service web development agency in Portland, Oregon specializing in TYPO3 extension development — for all of your TYPO3 development and consulting needs!