Documentation TYPO3 par Ameos |
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 if (trim($str) && is_array($TCA[$table]) && is_array($TCA[$table]['types'])) { 00259 foreach($TCA[$table]['types'] as $k => $v) { 00260 if (!$specificTypesList || t3lib_div::inList($specificTypesList,$k)) { 00261 if ($insert) { 00262 $append=true; 00263 $showItem = t3lib_div::trimExplode(',',$TCA[$table]['types'][$k]['showitem'],1); 00264 foreach($showItem as $key => $fieldInfo) { 00265 00266 $parts = explode(';',$fieldInfo); 00267 $theField = trim($parts[0]); 00268 $palette = trim($parts[0]).';;'.trim($parts[2]); 00269 00270 // insert before: find exact field name or palette with number 00271 if (in_array($theField, $positionArr) || in_array($palette, $positionArr) || in_array('before:'.$theField, $positionArr) || in_array('before:'.$palette, $positionArr)) { 00272 $showItem[$key]=trim($str).', '.$fieldInfo; 00273 $append=false; 00274 break; 00275 } 00276 // insert after 00277 if (in_array('after:'.$theField, $positionArr) || in_array('after:'.$palette, $positionArr)) { 00278 $showItem[$key]=$fieldInfo.', '.trim($str); 00279 $append=false; 00280 break; 00281 } 00282 } 00283 00284 // Not found? Then append. 00285 if($append) { 00286 $showItem[]=trim($str); 00287 } 00288 00289 $TCA[$table]['types'][$k]['showitem']=implode(', ', $showItem); 00290 00291 } else { 00292 $TCA[$table]['types'][$k]['showitem'].=', '.trim($str); 00293 } 00294 } 00295 } 00296 } 00297 } 00298 00299 00309 function allowTableOnStandardPages($table) { 00310 global $PAGES_TYPES; 00311 00312 $PAGES_TYPES['default']['allowedTables'].=','.$table; 00313 } 00314 00326 function addModule($main,$sub='',$position='',$path='') { 00327 global $TBE_MODULES; 00328 00329 if (isset($TBE_MODULES[$main]) && $sub) { // If there is already a main module by this name: 00330 00331 // Adding the submodule to the correct position: 00332 list($place,$modRef)=t3lib_div::trimExplode(':',$position,1); 00333 $mods = t3lib_div::trimExplode(',',$TBE_MODULES[$main],1); 00334 if (!in_array($sub,$mods)) { 00335 switch(strtolower($place)) { 00336 case 'after': 00337 case 'before': 00338 $pointer=0; 00339 reset($mods); 00340 while(list($k,$m)=each($mods)) { 00341 if (!strcmp($m,$modRef)) { 00342 $pointer=strtolower($place)=='after'?$k+1:$k; 00343 } 00344 } 00345 array_splice( 00346 $mods, // The modules array 00347 $pointer, // To insert one position from the end of the list 00348 0, // Don't remove any items, just insert 00349 $sub // Module to insert 00350 ); 00351 break; 00352 default: 00353 if (strtolower($place)=='top') { 00354 array_unshift($mods,$sub); 00355 } else { 00356 array_push($mods,$sub); 00357 } 00358 break; 00359 } 00360 } 00361 // Re-inserting the submodule list: 00362 $TBE_MODULES[$main]=implode(',',$mods); 00363 } else { // Create new main modules with only one submodule, $sub (or none if $sub is blank) 00364 $TBE_MODULES[$main]=$sub; 00365 } 00366 00367 // Adding path: 00368 if ($path) { 00369 $TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')]=$path; 00370 } 00371 } 00372 00384 function addModulePath($name,$path) { 00385 global $TBE_MODULES; 00386 00387 $TBE_MODULES['_PATHS'][$name] = $path; 00388 } 00389 00399 function addTopApp($name,$path,$iconPane=FALSE,$options=array()) { 00400 global $TBE_MODULES,$TYPO3_CONF_VARS; 00401 00402 $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['topApps'][$iconPane?'icons':'menu'][$name] = $options; 00403 00404 // Set path for TBE-modules: 00405 $TBE_MODULES['_PATHS'][$name] = $path; 00406 } 00407 00424 function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='') { 00425 global $TBE_MODULES_EXT; 00426 $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className]=array( 00427 'name' => $className, 00428 'path' => $classPath, 00429 'title' => $title, 00430 'ws' => $WS 00431 ); 00432 } 00433 00443 function addPageTSConfig($content) { 00444 global $TYPO3_CONF_VARS; 00445 $TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content; 00446 } 00447 00457 function addUserTSConfig($content) { 00458 global $TYPO3_CONF_VARS; 00459 $TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content; 00460 } 00461 00472 function addLLrefForTCAdescr($tca_descr_key,$file_ref) { 00473 global $TCA_DESCR; 00474 if ($tca_descr_key) { 00475 if (!is_array($TCA_DESCR[$tca_descr_key])) { 00476 $TCA_DESCR[$tca_descr_key]=array(); 00477 } 00478 if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) { 00479 $TCA_DESCR[$tca_descr_key]['refs']=array(); 00480 } 00481 $TCA_DESCR[$tca_descr_key]['refs'][]=$file_ref; 00482 } 00483 } 00484 00485 00486 00487 00488 00489 00490 00491 00492 00493 00494 00495 00496 /************************************** 00497 * 00498 * Adding SERVICES features 00499 * 00500 * @author René Fritz <r.fritz@colorcube.de> 00501 * 00502 ***************************************/ 00503 00514 function addService($extKey, $serviceType, $serviceKey, $info) { 00515 global $T3_SERVICES,$TYPO3_CONF_VARS; 00516 00517 // even not available services will be included to make it possible to give the admin a feedback of non-available services. 00518 // but maybe it's better to move non-available services to a different array?? 00519 00520 if ($serviceType && 00521 !t3lib_div::isFirstPartOfStr($serviceType, 'tx_') && 00522 (t3lib_div::isFirstPartOfStr($serviceKey, 'tx_') || t3lib_div::isFirstPartOfStr($serviceKey, 'user_')) && 00523 is_array($info)) { 00524 00525 $info['priority'] = max(0,min(100,$info['priority'])); 00526 00527 $T3_SERVICES[$serviceType][$serviceKey]=$info; 00528 00529 $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey; 00530 $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey; 00531 $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType; 00532 00533 00534 // mapping a service key to a service type 00535 // all service keys begin with tx_ - service types don't 00536 // this way a selection of a special service key as service type is easy 00537 $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey]; 00538 00539 00540 // change the priority (and other values) from TYPO3_CONF_VARS 00541 // $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]['priority'] 00542 // even the activation is possible (a unix service might be possible on windows for some reasons) 00543 if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) { 00544 00545 // no check is done here - there might be configuration values only the service type knows about, so we pass everything 00546 $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey],$TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]); 00547 } 00548 00549 00550 // OS check 00551 // empty $os means 'not limited to one OS', therefore a check is not needed 00552 if ($T3_SERVICES[$serviceType][$serviceKey]['available'] && $T3_SERVICES[$serviceType][$serviceKey]['os']!='') { 00553 00554 // TYPO3_OS is not yet defined 00555 $os_type = stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'UNIX'; 00556 00557 $os = t3lib_div::trimExplode(',',strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os'])); 00558 00559 if (!in_array($os_type,$os)) { 00560 t3lib_extMgm::deactivateService($serviceType, $serviceKey); 00561 } 00562 } 00563 00564 // convert subtype list to array for quicker access 00565 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array(); 00566 $serviceSubTypes = t3lib_div::trimExplode(',',$info['subtype']); 00567 foreach ($serviceSubTypes as $subtype) { 00568 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype; 00569 } 00570 } 00571 } 00572 00582 function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) { 00583 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS; 00584 00585 $serviceKey = FALSE; 00586 $serviceInfo = FALSE; 00587 $priority = 0; 00588 $quality = 0; 00589 00590 if (!is_array($excludeServiceKeys) ) { 00591 $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1); 00592 } 00593 00594 if (is_array($T3_SERVICES[$serviceType])) { 00595 foreach($T3_SERVICES[$serviceType] as $key => $info) { 00596 00597 if (in_array($key, $excludeServiceKeys)) { 00598 continue; 00599 } 00600 00601 // select a subtype randomly 00602 // usefull to start a service by service key without knowing his subtypes - for testing purposes 00603 if ($serviceSubType=='*') { 00604 $serviceSubType = key($info['serviceSubTypes']); 00605 } 00606 00607 // this matches empty subtype too 00608 if ($info['available'] && ($info['subtype']==$serviceSubType || $info['serviceSubTypes'][$serviceSubType]) && $info['priority']>=$priority ) { 00609 00610 // has a lower quality than the already found, therefore we skip this service 00611 if($info['priority']==$priority && $info['quality']<$quality) { 00612 continue; 00613 } 00614 00615 // service depends on external programs - check if they exists 00616 if(trim($info['exec'])) { 00617 require_once(PATH_t3lib.'class.t3lib_exec.php'); 00618 00619 $executables = t3lib_div::trimExplode(',', $info['exec'],1); 00620 foreach($executables as $executable) { 00621 if(!t3lib_exec::checkCommand($executable)) { 00622 t3lib_extMgm::deactivateService($serviceType, $key); 00623 $info['available']=FALSE; 00624 break; 00625 } 00626 } 00627 } 00628 00629 // still available after exec check? 00630 if($info['available']) { 00631 $serviceKey = $key; 00632 $priority = $info['priority']; 00633 $quality = $info['quality']; 00634 } 00635 } 00636 } 00637 } 00638 00639 if ($serviceKey) { 00640 $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey]; 00641 } 00642 return $serviceInfo; 00643 } 00644 00653 function deactivateService($serviceType, $serviceKey) { 00654 global $T3_SERVICES; 00655 00656 // ... maybe it's better to move non-available services to a different array?? 00657 $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE; 00658 } 00659 00660 00661 00662 00663 00664 00665 00666 00667 00668 00669 00670 00671 00672 00673 /************************************** 00674 * 00675 * Adding FRONTEND features 00676 * (related specifically to "cms" extension) 00677 * 00678 ***************************************/ 00679 00692 function addPlugin($itemArray,$type='list_type') { 00693 global $TCA; 00694 t3lib_div::loadTCA('tt_content'); 00695 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) { 00696 reset($TCA['tt_content']['columns'][$type]['config']['items']); 00697 while(list($k,$v)=each($TCA['tt_content']['columns'][$type]['config']['items'])) { 00698 if (!strcmp($v[1],$itemArray[1])) { 00699 $TCA['tt_content']['columns'][$type]['config']['items'][$k]=$itemArray; 00700 return; 00701 } 00702 } 00703 $TCA['tt_content']['columns'][$type]['config']['items'][]=$itemArray; 00704 } 00705 } 00706 00717 function addPiFlexFormValue($piKeyToMatch,$value) { 00718 global $TCA; 00719 t3lib_div::loadTCA('tt_content'); 00720 00721 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds'])) { 00722 $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch] = $value; 00723 } 00724 } 00725 00737 function addToInsertRecords($table,$content_table='tt_content',$content_field='records') { 00738 global $TCA; 00739 t3lib_div::loadTCA($content_table); 00740 if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed'])) { 00741 $TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table; 00742 } 00743 } 00744 00768 function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0) { 00769 global $TYPO3_LOADED_EXT; 00770 $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_','',$key).$prefix.'.php'; 00771 $cN = t3lib_extMgm::getCN($key); 00772 00773 // General plugin: 00774 if ($cached) { 00775 $pluginContent = trim(' 00776 includeLibs.'.$cN.$prefix.' = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.' 00777 plugin.'.$cN.$prefix.' = USER 00778 plugin.'.$cN.$prefix.' { 00779 userFunc = '.$cN.$prefix.'->main 00780 }'); 00781 } else { 00782 $pluginContent = trim(' 00783 plugin.'.$cN.$prefix.' = USER_INT 00784 plugin.'.$cN.$prefix.' { 00785 includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.' 00786 userFunc = '.$cN.$prefix.'->main 00787 }'); 00788 } 00789 t3lib_extMgm::addTypoScript($key,'setup',' 00790 # Setting '.$key.' plugin TypoScript 00791 '.$pluginContent); 00792 00793 // After ST43: 00794 switch($type) { 00795 case 'list_type': 00796 $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix; 00797 break; 00798 case 'menu_type': 00799 $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix; 00800 break; 00801 case 'splash_layout': 00802 $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix; 00803 break; 00804 case 'CType': 00805 $addLine = trim(' 00806 tt_content.'.$key.$prefix.' = COA 00807 tt_content.'.$key.$prefix.' { 00808 10 = < lib.stdheader 00809 20 = < plugin.'.$cN.$prefix.' 00810 } 00811 '); 00812 break; 00813 case 'header_layout': 00814 $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix; 00815 break; 00816 case 'includeLib': 00817 $addLine = 'page.1000 = < plugin.'.$cN.$prefix; 00818 break; 00819 default: 00820 $addLine = ''; 00821 break; 00822 } 00823 if ($addLine) { 00824 t3lib_extMgm::addTypoScript($key,'setup',' 00825 # Setting '.$key.' plugin TypoScript 00826 '.$addLine.' 00827 ',43); 00828 } 00829 } 00830 00843 function addStaticFile($extKey,$path,$title) { 00844 global $TCA; 00845 t3lib_div::loadTCA('sys_template'); 00846 if ($extKey && $path && is_array($TCA['sys_template']['columns'])) { 00847 $value = str_replace(',','','EXT:'.$extKey.'/'.$path); 00848 $itemArray=array(trim($title.' ('.$extKey.')'),$value); 00849 $TCA['sys_template']['columns']['include_static_file']['config']['items'][]=$itemArray; 00850 } 00851 } 00852 00862 function addTypoScriptSetup($content) { 00863 global $TYPO3_CONF_VARS; 00864 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content; 00865 } 00866 00876 function addTypoScriptConstants($content) { 00877 global $TYPO3_CONF_VARS; 00878 $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content; 00879 } 00880 00893 function addTypoScript($key,$type,$content,$afterStaticUid=0) { 00894 global $TYPO3_CONF_VARS; 00895 00896 if ($type=='setup' || $type=='editorcfg' || $type=='constants') { 00897 $content = ' 00898 00899 [GLOBAL] 00900 ############################################# 00901 ## TypoScript added by extension "'.$key.'" 00902 ############################################# 00903 00904 '.$content; 00905 if ($afterStaticUid) { 00906 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content; 00907 if ($afterStaticUid==43) { // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content 00908 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.']['cssstyledcontent/static/'].=$content; 00909 } 00910 } else { 00911 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content; 00912 } 00913 } 00914 } 00915 00916 00917 00918 00919 00920 00921 00922 00923 00924 00925 00926 00927 00928 00929 00930 00931 00932 00933 /************************************** 00934 * 00935 * INTERNAL EXTENSION MANAGEMENT: 00936 * 00937 ***************************************/ 00938 00956 function typo3_loadExtensions() { 00957 global $TYPO3_CONF_VARS; 00958 00959 // Full list of extensions includes both required and extList: 00960 $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'].','.$TYPO3_CONF_VARS['EXT']['extList']; 00961 00962 // Empty array as a start. 00963 $extensions = array(); 00964 00965 // 00966 if ($rawExtList) { 00967 // The cached File prefix. 00968 $cacheFilePrefix = 'temp_CACHED'; 00969 // Setting the name for the cache files: 00970 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1) $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']),0,4); 00971 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2) $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList); 00972 00973 // If cache files available, set cache file prefix and return: 00974 if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix)) { 00975 // Return cache file prefix: 00976 $extensions['_CACHEFILE'] = $cacheFilePrefix; 00977 } else { // ... but if not, configure... 00978 00979 // Prepare reserved filenames: 00980 $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); 00981 00982 // Traverse extensions and check their existence: 00983 clearstatcache(); // Clear file state cache to make sure we get good results from is_dir() 00984 $temp_extensions = array_unique(t3lib_div::trimExplode(',',$rawExtList,1)); 00985 foreach($temp_extensions as $temp_extKey) { 00986 // Check local, global and system locations: 00987 if (@is_dir(PATH_typo3conf.'ext/'.$temp_extKey.'/')) { 00988 $extensions[$temp_extKey] = array('type'=>'L', 'siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/', 'typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/'); 00989 } elseif (@is_dir(PATH_typo3.'ext/'.$temp_extKey.'/')) { 00990 $extensions[$temp_extKey] = array('type'=>'G', 'siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/', 'typo3RelPath'=>'ext/'.$temp_extKey.'/'); 00991 } elseif (@is_dir(PATH_typo3.'sysext/'.$temp_extKey.'/')) { 00992 $extensions[$temp_extKey] = array('type'=>'S', 'siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/', 'typo3RelPath'=>'sysext/'.$temp_extKey.'/'); 00993 } 00994 00995 // If extension was found, check for reserved filenames: 00996 if (isset($extensions[$temp_extKey])) { 00997 foreach($files as $fName) { 00998 $temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName); 00999 if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename)) { 01000 $extensions[$temp_extKey][$fName] = $temp_filename; 01001 } 01002 } 01003 } 01004 } 01005 unset($extensions['_CACHEFILE']); 01006 01007 // write cache? 01008 if ($TYPO3_CONF_VARS['EXT']['extCache'] && 01009 @is_dir(PATH_typo3.'sysext/') && 01010 @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! 01011 $wrError = t3lib_extMgm::cannotCacheFilesWritable($cacheFilePrefix); 01012 if ($wrError) { 01013 $TYPO3_CONF_VARS['EXT']['extCache']=0; 01014 } else { 01015 // Write cache files: 01016 $extensions = t3lib_extMgm::writeCacheFiles($extensions,$cacheFilePrefix); 01017 } 01018 } 01019 } 01020 } 01021 01022 return $extensions; 01023 } 01024 01033 function _makeIncludeHeader($key,$file) { 01034 return '<?php 01035 ########################### 01036 ## EXTENSION: '.$key.' 01037 ## FILE: '.$file.' 01038 ########################### 01039 01040 $_EXTKEY = \''.$key.'\'; 01041 $_EXTCONF = $TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][$_EXTKEY]; 01042 01043 ?>'; 01044 } 01045 01054 function isCacheFilesAvailable($cacheFilePrefix) { 01055 return 01056 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') && 01057 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php'); 01058 } 01059 01067 function isLocalconfWritable() { 01068 return @is_writable(PATH_typo3conf) && @is_writable(PATH_typo3conf.'localconf.php'); 01069 } 01070 01080 function cannotCacheFilesWritable($cacheFilePrefix) { 01081 $error=array(); 01082 if (!@is_writable(PATH_typo3conf)) { 01083 $error[]=PATH_typo3conf; 01084 } 01085 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') && 01086 !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php')) { 01087 $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php'; 01088 } 01089 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php') && 01090 !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php')) { 01091 $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php'; 01092 } 01093 return implode(', ',$error); 01094 } 01095 01104 function currentCacheFiles() { 01105 global $TYPO3_LOADED_EXT; 01106 01107 if ($TYPO3_LOADED_EXT['_CACHEFILE']) { 01108 if (t3lib_extMgm::isCacheFilesAvailable($TYPO3_LOADED_EXT['_CACHEFILE'])) { 01109 return array( 01110 PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_localconf.php', 01111 PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php' 01112 ); 01113 } 01114 } 01115 } 01116 01127 function writeCacheFiles($extensions,$cacheFilePrefix) { 01128 // Making cache files: 01129 $extensions['_CACHEFILE'] = $cacheFilePrefix; 01130 $cFiles=array(); 01131 $cFiles['ext_localconf'].='<?php 01132 01133 $TYPO3_LOADED_EXT = unserialize(stripslashes(\''.addslashes(serialize($extensions)).'\')); 01134 01135 ?>'; 01136 01137 reset($extensions); 01138 while(list($key,$conf)=each($extensions)) { 01139 if (is_array($conf)) { 01140 if ($conf['ext_localconf.php']) { 01141 $cFiles['ext_localconf'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_localconf.php']); 01142 $cFiles['ext_localconf'].=trim(t3lib_div::getUrl($conf['ext_localconf.php'])); 01143 } 01144 if ($conf['ext_tables.php']) { 01145 $cFiles['ext_tables'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_tables.php']); 01146 $cFiles['ext_tables'].=trim(t3lib_div::getUrl($conf['ext_tables.php'])); 01147 } 01148 } 01149 } 01150 01151 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php',$cFiles['ext_localconf']); 01152 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php',$cFiles['ext_tables']); 01153 01154 $extensions=array(); 01155 $extensions['_CACHEFILE'] = $cacheFilePrefix; 01156 01157 return $extensions; 01158 } 01159 01165 function removeCacheFiles() { 01166 $cacheFiles = t3lib_extMgm::currentCacheFiles(); 01167 $out = 0; 01168 if (is_array($cacheFiles)) { 01169 reset($cacheFiles); 01170 foreach($cacheFiles as $cfile) { 01171 @unlink($cfile); 01172 clearstatcache(); 01173 $out++; 01174 } 01175 } 01176 return $out; 01177 } 01178 } 01179 01180 ?>