Documentation TYPO3 par Ameos

class.t3lib_extmgm.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 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
00487                         !t3lib_div::isFirstPartOfStr($serviceType, 'tx_') AND
00488                         (t3lib_div::isFirstPartOfStr($serviceKey, 'tx_') OR t3lib_div::isFirstPartOfStr($serviceKey, 'user_')) AND
00489                         is_array($info))        {
00490 
00491                         $info['priority'] = max(0,min(100,$info['priority']));
00492 
00493                         $T3_SERVICES[$serviceType][$serviceKey]=$info;
00494 
00495                         $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey;
00496                         $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
00497                         $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType;
00498 
00499 
00500                                 // mapping a service key to a service type
00501                                 // all service keys begin with tx_ - service types don't
00502                                 // this way a selection of a special service key as service type is easy
00503                         $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey];
00504 
00505 
00506                                 // change the priority (and other values) from TYPO3_CONF_VARS
00507                                 // $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]['priority']
00508                                 // even the activation is possible (a unix service might be possible on windows for some reasons)
00509                         if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) {
00510 
00511                                         // no check is done here - there might be configuration values only the service type knows about, so we pass everything
00512                                 $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey],$TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]);
00513                         }
00514 
00515 
00516                                 // OS check
00517                                 // empty $os means 'not limited to one OS', therefore a check is not needed
00518                         if ($T3_SERVICES[$serviceType][$serviceKey]['available'] AND $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
00519 
00520                                         // TYPO3_OS is not yet defined
00521                                 $os_type = stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'UNIX';
00522 
00523                                 $os = t3lib_div::trimExplode(',',strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os']));
00524 
00525                                 if (!in_array($os_type,$os)) {
00526                                         t3lib_extMgm::deactivateService($serviceType, $serviceKey);
00527                                 }
00528                         }
00529 
00530                                 // convert subtype list to array for quicker access
00531                         $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array();
00532                         $serviceSubTypes = t3lib_div::trimExplode(',',$info['subtype']);
00533                         foreach ($serviceSubTypes as $subtype) {
00534                                 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
00535                         }
00536                 }
00537         }
00538 
00548         function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) {
00549                 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
00550 
00551                 $serviceKey = FALSE;
00552                 $serviceInfo = FALSE;
00553                 $priority = 0;
00554                 $quality = 0;
00555 
00556                 if (!is_array($excludeServiceKeys) ) {
00557                         $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
00558                 }
00559 
00560                 if (is_array($T3_SERVICES[$serviceType]))       {
00561                         foreach($T3_SERVICES[$serviceType] as $key => $info)    {
00562 
00563                                 if (in_array($key, $excludeServiceKeys)) {
00564                                         continue;
00565                                 }
00566 
00567                                         // select a subtype randomly
00568                                         // usefull to start a service by service key without knowing his subtypes - for testing purposes
00569                                 if ($serviceSubType=='*') {
00570                                         $serviceSubType = key($info['serviceSubTypes']);
00571                                 }
00572 
00573                                         // this matches empty subtype too
00574                                 if( $info['available'] AND ($info['subtype']==$serviceSubType OR $info['serviceSubTypes'][$serviceSubType]) AND $info['priority']>=$priority ) {
00575 
00576                                                 // has a lower quality than the already found, therefore we skip this service
00577                                         if($info['priority']==$priority AND $info['quality']<$quality) {
00578                                                 continue;
00579                                         }
00580 
00581                                                 // service depends on external programs - check if they exists
00582                                         if(trim($info['exec'])) {
00583                                                 require_once(PATH_t3lib.'class.t3lib_exec.php');
00584 
00585                                                 $executables = t3lib_div::trimExplode(',', $info['exec'],1);
00586                                                 foreach($executables as $executable)    {
00587                                                         if(!t3lib_exec::checkCommand($executable)) {
00588                                                                 t3lib_extMgm::deactivateService($serviceType, $key);
00589                                                                 $info['available']=FALSE;
00590                                                                 break;
00591                                                         }
00592                                                 }
00593                                         }
00594 
00595                                                 // still available after exec check?
00596                                         if($info['available']) {
00597                                                 $serviceKey = $key;
00598                                                 $priority = $info['priority'];
00599                                                 $quality = $info['quality'];
00600                                         }
00601                                 }
00602                         }
00603                 }
00604 
00605                 if ($serviceKey) {
00606                         $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey];
00607                 }
00608                 return $serviceInfo;
00609         }
00610 
00619         function deactivateService($serviceType, $serviceKey) {
00620                 global $T3_SERVICES;
00621 
00622                         // ... maybe it's better to move non-available services to a different array??
00623                 $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE;
00624         }
00625 
00626 
00627 
00628 
00629 
00630 
00631 
00632 
00633 
00634 
00635 
00636 
00637 
00638 
00639         /**************************************
00640          *
00641          *       Adding FRONTEND features
00642          *       (related specifically to "cms" extension)
00643          *
00644          ***************************************/
00645 
00658         function addPlugin($itemArray,$type='list_type')        {
00659                 global $TCA;
00660                 t3lib_div::loadTCA('tt_content');
00661                 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items']))       {
00662                         reset($TCA['tt_content']['columns'][$type]['config']['items']);
00663                         while(list($k,$v)=each($TCA['tt_content']['columns'][$type]['config']['items']))        {
00664                                 if (!strcmp($v[1],$itemArray[1]))       {
00665                                         $TCA['tt_content']['columns'][$type]['config']['items'][$k]=$itemArray;
00666                                         return;
00667                                 }
00668                         }
00669                         $TCA['tt_content']['columns'][$type]['config']['items'][]=$itemArray;
00670                 }
00671         }
00672 
00683         function addPiFlexFormValue($piKeyToMatch,$value)       {
00684                 global $TCA;
00685                 t3lib_div::loadTCA('tt_content');
00686 
00687                 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds']))  {
00688                         $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch] = $value;
00689                 }
00690         }
00691 
00703         function addToInsertRecords($table,$content_table='tt_content',$content_field='records')        {
00704                 global $TCA;
00705                 t3lib_div::loadTCA($content_table);
00706                 if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed']))   {
00707                         $TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table;
00708                 }
00709         }
00710 
00734         function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0) {
00735                 global $TYPO3_LOADED_EXT;
00736                 $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_','',$key).$prefix.'.php';
00737                 $cN = t3lib_extMgm::getCN($key);
00738 
00739                         // General plugin:
00740                 if ($cached)    {
00741                         $pluginContent = trim('
00742 includeLibs.'.$cN.$prefix.' = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
00743 plugin.'.$cN.$prefix.' = USER
00744 plugin.'.$cN.$prefix.' {
00745   userFunc = '.$cN.$prefix.'->main
00746 }');
00747                 } else {
00748                         $pluginContent = trim('
00749 plugin.'.$cN.$prefix.' = USER_INT
00750 plugin.'.$cN.$prefix.' {
00751   includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
00752   userFunc = '.$cN.$prefix.'->main
00753 }');
00754                 }
00755                 t3lib_extMgm::addTypoScript($key,'setup','
00756 # Setting '.$key.' plugin TypoScript
00757 '.$pluginContent);
00758 
00759                         // After ST43:
00760                 switch($type)   {
00761                         case 'list_type':
00762                                 $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00763                         break;
00764                         case 'menu_type':
00765                                 $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00766                         break;
00767                         case 'splash_layout':
00768                                 $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00769                         break;
00770                         case 'CType':
00771                                 $addLine = trim('
00772 tt_content.'.$key.$prefix.' = COA
00773 tt_content.'.$key.$prefix.' {
00774         10 = < lib.stdheader
00775         20 = < plugin.'.$cN.$prefix.'
00776 }
00777                                 ');
00778                         break;
00779                         case 'header_layout':
00780                                 $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
00781                         break;
00782                         case 'includeLib':
00783                                 $addLine = 'page.1000 = < plugin.'.$cN.$prefix;
00784                         break;
00785                         default:
00786                                 $addLine = '';
00787                         break;
00788                 }
00789                 if ($addLine)   {
00790                         t3lib_extMgm::addTypoScript($key,'setup','
00791 # Setting '.$key.' plugin TypoScript
00792 '.$addLine.'
00793 ',43);
00794                 }
00795         }
00796 
00809         function addStaticFile($extKey,$path,$title)    {
00810                 global $TCA;
00811                 t3lib_div::loadTCA('sys_template');
00812                 if ($extKey && $path && is_array($TCA['sys_template']['columns']))      {
00813                         $value = str_replace(',','','EXT:'.$extKey.'/'.$path);
00814                         $itemArray=array(trim($title.' ('.$extKey.')'),$value);
00815                         $TCA['sys_template']['columns']['include_static_file']['config']['items'][]=$itemArray;
00816                 }
00817         }
00818 
00828         function addTypoScriptSetup($content)   {
00829                 global $TYPO3_CONF_VARS;
00830                 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
00831         }
00832 
00842         function addTypoScriptConstants($content)       {
00843                 global $TYPO3_CONF_VARS;
00844                 $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
00845         }
00846 
00859         function addTypoScript($key,$type,$content,$afterStaticUid=0)   {
00860                 global $TYPO3_CONF_VARS;
00861 
00862                 if ($type=='setup' || $type=='editorcfg' || $type=='constants')         {
00863                         $content = '
00864 
00865 [GLOBAL]
00866 #############################################
00867 ## TypoScript added by extension "'.$key.'"
00868 #############################################
00869 
00870 '.$content;
00871                         if ($afterStaticUid)    {
00872                                 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
00873                                 if ($afterStaticUid==43)        {       // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
00874                                         $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.']['cssstyledcontent/static/'].=$content;
00875                                 }
00876                         } else {
00877                                 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content;
00878                         }
00879                 }
00880         }
00881 
00882 
00883 
00884 
00885 
00886 
00887 
00888 
00889 
00890 
00891 
00892 
00893 
00894 
00895 
00896 
00897 
00898 
00899         /**************************************
00900          *
00901          *       INTERNAL EXTENSION MANAGEMENT:
00902          *
00903          ***************************************/
00904 
00922         function typo3_loadExtensions() {
00923                 global $TYPO3_CONF_VARS;
00924 
00925                         // Full list of extensions includes both required and extList:
00926                 $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'].','.$TYPO3_CONF_VARS['EXT']['extList'];
00927 
00928                         // Empty array as a start.
00929                 $extensions = array();
00930 
00931                         //
00932                 if ($rawExtList)        {
00933                                 // The cached File prefix.
00934                         $cacheFilePrefix = 'temp_CACHED';
00935                                 // Setting the name for the cache files:
00936                         if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1)     $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']),0,4);
00937                         if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2)     $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
00938 
00939                                 // If cache files available, set cache file prefix and return:
00940                         if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix))       {
00941                                         // Return cache file prefix:
00942                                 $extensions['_CACHEFILE'] = $cacheFilePrefix;
00943                         } else {        // ... but if not, configure...
00944                                         // Prepare reserved filenames:
00945                                 $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);
00946 
00947                                         // Traverse extensions and check their existence:
00948                                 clearstatcache();       // Clear file state cache to make sure we get good results from is_dir()
00949                                 $temp_extensions = array_unique(t3lib_div::trimExplode(',',$rawExtList,1));
00950                                 foreach($temp_extensions as $temp_extKey)       {
00951                                                 // Check local, global and system locations:
00952                                         if (@is_dir(PATH_site.'typo3conf/ext/'.$temp_extKey.'/'))       {
00953                                                 $extensions[$temp_extKey] = array('type'=>'L', 'siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/', 'typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
00954                                         } elseif (@is_dir(PATH_site.TYPO3_mainDir.'ext/'.$temp_extKey.'/'))     {
00955                                                 $extensions[$temp_extKey] = array('type'=>'G', 'siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/', 'typo3RelPath'=>'ext/'.$temp_extKey.'/');
00956                                         } elseif (@is_dir(PATH_site.TYPO3_mainDir.'sysext/'.$temp_extKey.'/'))  {
00957                                                 $extensions[$temp_extKey] = array('type'=>'S', 'siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/', 'typo3RelPath'=>'sysext/'.$temp_extKey.'/');
00958                                         }
00959 
00960                                                 // If extension was found, check for reserved filenames:
00961                                         if (isset($extensions[$temp_extKey]))   {
00962                                                 foreach($files as $fName)       {
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                                 }
00970                                 unset($extensions['_CACHEFILE']);
00971 
00972                                         // write cache?
00973                                 if ($TYPO3_CONF_VARS['EXT']['extCache'] &&
00974                                                 @is_dir(PATH_site.TYPO3_mainDir.'sysext/') &&
00975                                                 @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!
00976                                         $wrError = t3lib_extMgm::cannotCacheFilesWritable($cacheFilePrefix);
00977                                         if ($wrError)   {
00978                                                 $TYPO3_CONF_VARS['EXT']['extCache']=0;
00979                                         } else {
00980                                                         // Write cache files:
00981                                                 $extensions = t3lib_extMgm::writeCacheFiles($extensions,$cacheFilePrefix);
00982                                         }
00983                                 }
00984                         }
00985                 }
00986 
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_writable(PATH_typo3conf) && @is_writable(PATH_typo3conf.'localconf.php');
01034         }
01035 
01045         function cannotCacheFilesWritable($cacheFilePrefix)     {
01046                 $error=array();
01047                 if (!@is_writable(PATH_typo3conf))      {
01048                         $error[]=PATH_typo3conf;
01049                 }
01050                 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
01051                         !@is_writable(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_writable(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 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6