Project

General

Profile

Bug #18480 » public-static-t3lib_extMgm-rev2.patch

Administrator Admin, 2008-03-19 14:11

View differences:

t3lib/class.t3lib_extmgm.php (working copy)
* @package TYPO3
* @subpackage t3lib
*/
class t3lib_extMgm {
final class t3lib_extMgm {
/**************************************
......
* @param boolean If $exitOnError is true and the extension is not loaded the function will die with an error message
* @return boolean
*/
function isLoaded($key,$exitOnError=0) {
public static function isLoaded($key,$exitOnError=0) {
global $TYPO3_LOADED_EXT;
if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key])) die('Fatal Error: Extension "'.$key.'" was not loaded.');
return isset($TYPO3_LOADED_EXT[$key]);
......
* @param string $script is appended to the output if set.
* @return string
*/
function extPath($key,$script='') {
public static function extPath($key,$script='') {
global $TYPO3_LOADED_EXT;
if (!isset($TYPO3_LOADED_EXT[$key])) {
if (!isset($TYPO3_LOADED_EXT[$key])) {
#debug(array(debug_backtrace()));
die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extPath)');
}
......
* @param string Extension key
* @return string
*/
function extRelPath($key) {
public static function extRelPath($key) {
global $TYPO3_LOADED_EXT;
if (!isset($TYPO3_LOADED_EXT[$key])) {
if (!isset($TYPO3_LOADED_EXT[$key])) {
die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded! (t3lib_extMgm::extRelPath)');
}
return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
......
* @param string Extension key
* @return string
*/
function siteRelPath($key) {
public static function siteRelPath($key) {
return substr(t3lib_extMgm::extPath($key),strlen(PATH_site));
}
......
* @return string
* @internal
*/
function getCN($key) {
public static function getCN($key) {
return substr($key,0,5)=='user_' ? 'user_'.str_replace('_','',substr($key,5)) : 'tx_'.str_replace('_','',$key);
}
......
* @param boolean If $addTofeInterface is true the list of fields are also added to the fe_admin_fieldList.
* @return void
*/
function addTCAcolumns($table,$columnArray,$addTofeInterface=0) {
public static function addTCAcolumns($table,$columnArray,$addTofeInterface=0) {
global $TCA;
t3lib_div::loadTCA($table);
if (is_array($columnArray) && is_array($TCA[$table]) && is_array($TCA[$table]['columns'])) {
if (is_array($columnArray) && is_array($TCA[$table]) && is_array($TCA[$table]['columns'])) {
$TCA[$table]['columns'] = array_merge($TCA[$table]['columns'],$columnArray); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
if ($addTofeInterface) $TCA[$table]['feInterface']['fe_admin_fieldList'].=','.implode(',',array_keys($columnArray));
}
......
* @param string Insert fields before (default) or after one of this fields (commalist with "before:" or "after:" commands). Example: "before:keywords,--palette--;;4,after:description". Palettes must be passed like in the example no matter how the palette definition looks like in TCA.
* @return void
*/
function addToAllTCAtypes($table,$str,$specificTypesList='',$position='') {
public static function addToAllTCAtypes($table,$str,$specificTypesList='',$position='') {
global $TCA;
$positionArr=t3lib_div::trimExplode(',',$position,1);
......
t3lib_div::loadTCA($table);
$str = trim($str);
if ($str && is_array($TCA[$table]) && is_array($TCA[$table]['types'])) {
foreach($TCA[$table]['types'] as $k => $v) {
if ($specificTypesList === '' || t3lib_div::inList($specificTypesList,$k)) {
if ($insert) {
if ($str && is_array($TCA[$table]) && is_array($TCA[$table]['types'])) {
foreach($TCA[$table]['types'] as $k => $v) {
if ($specificTypesList === '' || t3lib_div::inList($specificTypesList,$k)) {
if ($insert) {
if (count($positionArr)) {
$append=true;
$showItem = t3lib_div::trimExplode(',',$TCA[$table]['types'][$k]['showitem'],1);
......
$palette = trim($parts[0]).';;'.trim($parts[2]);
// insert before: find exact field name or palette with number
if (in_array($theField, $positionArr) || in_array($palette, $positionArr) || in_array('before:'.$theField, $positionArr) || in_array('before:'.$palette, $positionArr)) {
if (in_array($theField, $positionArr) || in_array($palette, $positionArr) || in_array('before:'.$theField, $positionArr) || in_array('before:'.$palette, $positionArr)) {
$showItem[$key]=$str.', '.$fieldInfo;
$append=false;
break;
......
break;
}
// insert after
if (in_array('after:'.$theField, $positionArr) || in_array('after:'.$palette, $positionArr)) {
if (in_array('after:'.$theField, $positionArr) || in_array('after:'.$palette, $positionArr)) {
$showItem[$key]=$fieldInfo.', '.$str;
$append=false;
break;
......
* @param string Table name
* @return void
*/
function allowTableOnStandardPages($table) {
public static function allowTableOnStandardPages($table) {
global $PAGES_TYPES;
$PAGES_TYPES['default']['allowedTables'].=','.$table;
......
* @param string $path is the absolute path to the module. If this value is defined the path is added as an entry in $TBE_MODULES['_PATHS'][ main_sub ]=$path; and thereby tells the backend where the newly added modules is found in the system.
* @return void
*/
function addModule($main,$sub='',$position='',$path='') {
public static function addModule($main,$sub='',$position='',$path='') {
global $TBE_MODULES;
if (isset($TBE_MODULES[$main]) && $sub) { // If there is already a main module by this name:
......
// Adding the submodule to the correct position:
list($place,$modRef)=t3lib_div::trimExplode(':',$position,1);
$mods = t3lib_div::trimExplode(',',$TBE_MODULES[$main],1);
if (!in_array($sub,$mods)) {
switch(strtolower($place)) {
if (!in_array($sub,$mods)) {
switch(strtolower($place)) {
case 'after':
case 'before':
$pointer=0;
......
case 'before':
$pointer=0;
reset($mods);
while(list($k,$m)=each($mods)) {
if (!strcmp($m,$modRef)) {
while(list($k,$m)=each($mods)) {
if (!strcmp($m,$modRef)) {
$pointer=strtolower($place)=='after'?$k+1:$k;
}
}
......
);
break;
default:
if (strtolower($place)=='top') {
if (strtolower($place)=='top') {
array_unshift($mods,$sub);
} else {
array_push($mods,$sub);
......
}
// Adding path:
if ($path) {
if ($path) {
$TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')]=$path;
}
}
......
* @param string $path is the absolute path to the module directory inside of which "index.php" and "conf.php" is found.
* @return void
*/
function addModulePath($name,$path) {
public static function addModulePath($name,$path) {
global $TBE_MODULES;
$TBE_MODULES['_PATHS'][$name] = $path;
......
* @return void
* @see t3lib_SCbase::mergeExternalItems()
*/
function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='') {
public static function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='') {
global $TBE_MODULES_EXT;
$TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className]=array(
'name' => $className,
......
* @param string Page TSconfig content
* @return void
*/
function addPageTSConfig($content) {
public static function addPageTSConfig($content) {
global $TYPO3_CONF_VARS;
$TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content;
}
......
* @param string User TSconfig content
* @return void
*/
function addUserTSConfig($content) {
public static function addUserTSConfig($content) {
global $TYPO3_CONF_VARS;
$TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content;
}
......
* @param string File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php" (or ".xml")
* @return void
*/
function addLLrefForTCAdescr($tca_descr_key,$file_ref) {
public static function addLLrefForTCAdescr($tca_descr_key,$file_ref) {
global $TCA_DESCR;
if ($tca_descr_key) {
if (!is_array($TCA_DESCR[$tca_descr_key])) {
if ($tca_descr_key) {
if (!is_array($TCA_DESCR[$tca_descr_key])) {
$TCA_DESCR[$tca_descr_key]=array();
}
if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) {
if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) {
$TCA_DESCR[$tca_descr_key]['refs']=array();
}
$TCA_DESCR[$tca_descr_key]['refs'][]=$file_ref;
......
* @return void
* @author Ren� Fritz <r.fritz@colorcube.de>
*/
function addService($extKey, $serviceType, $serviceKey, $info) {
public static function addService($extKey, $serviceType, $serviceKey, $info) {
global $T3_SERVICES,$TYPO3_CONF_VARS;
// even not available services will be included to make it possible to give the admin a feedback of non-available services.
......
* @return mixed Service info array if a service was found, FLASE otherwise
* @author Ren� Fritz <r.fritz@colorcube.de>
*/
function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) {
public static function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) {
global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
$serviceKey = FALSE;
......
$excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
}
if (is_array($T3_SERVICES[$serviceType])) {
if (is_array($T3_SERVICES[$serviceType])) {
foreach($T3_SERVICES[$serviceType] as $key => $info) {
if (in_array($key, $excludeServiceKeys)) {
......
require_once(PATH_t3lib.'class.t3lib_exec.php');
$executables = t3lib_div::trimExplode(',', $info['exec'],1);
foreach($executables as $executable) {
foreach($executables as $executable) {
if(!t3lib_exec::checkCommand($executable)) {
t3lib_extMgm::deactivateService($serviceType, $key);
$info['available']=FALSE;
......
* @return void
* @author Ren� Fritz <r.fritz@colorcube.de>
*/
function deactivateService($serviceType, $serviceKey) {
public static function deactivateService($serviceType, $serviceKey) {
global $T3_SERVICES;
// ... maybe it's better to move non-available services to a different array??
......
* @param string Type (eg. "list_type") - basically a field from "tt_content" table
* @return void
*/
function addPlugin($itemArray,$type='list_type') {
public static function addPlugin($itemArray,$type='list_type') {
global $TCA;
t3lib_div::loadTCA('tt_content');
if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) {
if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) {
reset($TCA['tt_content']['columns'][$type]['config']['items']);
while(list($k,$v)=each($TCA['tt_content']['columns'][$type]['config']['items'])) {
if (!strcmp($v[1],$itemArray[1])) {
while(list($k,$v)=each($TCA['tt_content']['columns'][$type]['config']['items'])) {
if (!strcmp($v[1],$itemArray[1])) {
$TCA['tt_content']['columns'][$type]['config']['items'][$k]=$itemArray;
return;
}
......
* @return void
* @see addPlugin()
*/
function addPiFlexFormValue($piKeyToMatch, $value, $CTypeToMatch='list') {
public static function addPiFlexFormValue($piKeyToMatch, $value, $CTypeToMatch='list') {
global $TCA;
t3lib_div::loadTCA('tt_content');
if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds'])) {
if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds'])) {
$TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch.','.$CTypeToMatch] = $value;
}
}
......
* @param string Field name in the database $content_table in which $table is allowed to be added as a reference ("Insert Record")
* @return void
*/
function addToInsertRecords($table,$content_table='tt_content',$content_field='records') {
public static function addToInsertRecords($table,$content_table='tt_content',$content_field='records') {
global $TCA;
t3lib_div::loadTCA($content_table);
if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed'])) {
if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed'])) {
$TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table;
}
}
......
* @param boolean If $cached is set as USER content object (cObject) is created - otherwise a USER_INT object is created.
* @return void
*/
function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0) {
public static function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0) {
global $TYPO3_LOADED_EXT;
$classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_','',$key).$prefix.'.php';
$cN = t3lib_extMgm::getCN($key);
......
$cN = t3lib_extMgm::getCN($key);
// General plugin:
if ($cached) {
if ($cached) {
$pluginContent = trim('
includeLibs.'.$cN.$prefix.' = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
plugin.'.$cN.$prefix.' = USER
......
'.$pluginContent);
// After ST43:
switch($type) {
switch($type) {
case 'list_type':
$addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
break;
......
$addLine = '';
break;
}
if ($addLine) {
if ($addLine) {
t3lib_extMgm::addTypoScript($key,'setup','
# Setting '.$key.' plugin TypoScript
'.$addLine.'
......
* @return void
* @see addTypoScript()
*/
function addStaticFile($extKey,$path,$title) {
public static function addStaticFile($extKey,$path,$title) {
global $TCA;
t3lib_div::loadTCA('sys_template');
if ($extKey && $path && is_array($TCA['sys_template']['columns'])) {
if ($extKey && $path && is_array($TCA['sys_template']['columns'])) {
$value = str_replace(',','','EXT:'.$extKey.'/'.$path);
$itemArray=array(trim($title.' ('.$extKey.')'),$value);
$TCA['sys_template']['columns']['include_static_file']['config']['items'][]=$itemArray;
......
* @param string TypoScript Setup string
* @return void
*/
function addTypoScriptSetup($content) {
public static function addTypoScriptSetup($content) {
global $TYPO3_CONF_VARS;
$TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
}
......
* @param string TypoScript Constants string
* @return void
*/
function addTypoScriptConstants($content) {
public static function addTypoScriptConstants($content) {
global $TYPO3_CONF_VARS;
$TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
}
......
* @param string $afterStaticUid is either an integer pointing to a uid of a static_template or a string pointing to the "key" of a static_file template ([reduced extension_key]/[local path]). The points is that the TypoScript you add is included only IF that static template is included (and in that case, right after). So effectively the TypoScript you set can specifically overrule settings from those static templates.
* @return void
*/
function addTypoScript($key,$type,$content,$afterStaticUid=0) {
public static function addTypoScript($key,$type,$content,$afterStaticUid=0) {
global $TYPO3_CONF_VARS;
if ($type=='setup' || $type=='editorcfg' || $type=='constants') {
......
#############################################
'.$content;
if ($afterStaticUid) {
if ($afterStaticUid) {
$TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
if ($afterStaticUid==43) { // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
$TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.']['cssstyledcontent/static/'].=$content;
......
* @return array Extension Array
* @internal
*/
function typo3_loadExtensions() {
public static function typo3_loadExtensions() {
global $TYPO3_CONF_VARS;
// Full list of extensions includes both required and extList:
......
$extensions = array();
//
if ($rawExtList) {
if ($rawExtList) {
// The cached File prefix.
$cacheFilePrefix = 'temp_CACHED';
// Setting the name for the cache files:
......
if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2) $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
// If cache files available, set cache file prefix and return:
if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix)) {
if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix)) {
// Return cache file prefix:
$extensions['_CACHEFILE'] = $cacheFilePrefix;
} else { // ... but if not, configure...
......
// Traverse extensions and check their existence:
clearstatcache(); // Clear file state cache to make sure we get good results from is_dir()
$temp_extensions = array_unique(t3lib_div::trimExplode(',',$rawExtList,1));
foreach($temp_extensions as $temp_extKey) {
foreach($temp_extensions as $temp_extKey) {
// Check local, global and system locations:
if (@is_dir(PATH_typo3conf.'ext/'.$temp_extKey.'/')) {
if (@is_dir(PATH_typo3conf.'ext/'.$temp_extKey.'/')) {
$extensions[$temp_extKey] = array('type'=>'L', 'siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/', 'typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
} elseif (@is_dir(PATH_typo3.'ext/'.$temp_extKey.'/')) {
} elseif (@is_dir(PATH_typo3.'ext/'.$temp_extKey.'/')) {
$extensions[$temp_extKey] = array('type'=>'G', 'siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/', 'typo3RelPath'=>'ext/'.$temp_extKey.'/');
} elseif (@is_dir(PATH_typo3.'sysext/'.$temp_extKey.'/')) {
} elseif (@is_dir(PATH_typo3.'sysext/'.$temp_extKey.'/')) {
$extensions[$temp_extKey] = array('type'=>'S', 'siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/', 'typo3RelPath'=>'sysext/'.$temp_extKey.'/');
}
......
}
// If extension was found, check for reserved filenames:
if (isset($extensions[$temp_extKey])) {
if (isset($extensions[$temp_extKey])) {
foreach($files as $fName) {
$temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName);
if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename)) {
if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename)) {
$extensions[$temp_extKey][$fName] = $temp_filename;
}
}
......
@is_dir(PATH_typo3.'sysext/') &&
@is_dir(PATH_typo3.'ext/')) { // Must also find global and system extension directories to exist, otherwise caching cannot be allowed (since it is most likely a temporary server problem). This might fix a rare, unrepeatable bug where global/system extensions are not loaded resulting in fatal errors if that is cached!
$wrError = t3lib_extMgm::cannotCacheFilesWritable($cacheFilePrefix);
if ($wrError) {
if ($wrError) {
$TYPO3_CONF_VARS['EXT']['extCache']=0;
} else {
// Write cache files:
......
* @return string
* @internal
*/
function _makeIncludeHeader($key,$file) {
public static function _makeIncludeHeader($key,$file) {
return '<?php
###########################
## EXTENSION: '.$key.'
......
* @return boolean
* @internal
*/
function isCacheFilesAvailable($cacheFilePrefix) {
public static function isCacheFilesAvailable($cacheFilePrefix) {
return
@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php');
......
* @return boolean
* @internal
*/
function isLocalconfWritable() {
public static function isLocalconfWritable() {
return @is_writable(PATH_typo3conf) && @is_writable(PATH_typo3conf.'localconf.php');
}
......
* @return string
* @internal
*/
function cannotCacheFilesWritable($cacheFilePrefix) {
public static function cannotCacheFilesWritable($cacheFilePrefix) {
$error=array();
if (!@is_writable(PATH_typo3conf)) {
if (!@is_writable(PATH_typo3conf)) {
$error[]=PATH_typo3conf;
}
if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
!@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php')) {
!@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php')) {
$error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
}
if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php') &&
!@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php')) {
!@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php')) {
$error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
}
return implode(', ',$error);
......
* @return array
* @internal
*/
function currentCacheFiles() {
public static function currentCacheFiles() {
global $TYPO3_LOADED_EXT;
if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
if (t3lib_extMgm::isCacheFilesAvailable($TYPO3_LOADED_EXT['_CACHEFILE'])) {
if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
if (t3lib_extMgm::isCacheFilesAvailable($TYPO3_LOADED_EXT['_CACHEFILE'])) {
return array(
PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_localconf.php',
PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php'
......
* @return array
* @internal
*/
function writeCacheFiles($extensions,$cacheFilePrefix) {
public static function writeCacheFiles($extensions,$cacheFilePrefix) {
// Making cache files:
$extensions['_CACHEFILE'] = $cacheFilePrefix;
$cFiles=array();
......
?>';
reset($extensions);
while(list($key,$conf)=each($extensions)) {
if (is_array($conf)) {
if ($conf['ext_localconf.php']) {
while(list($key,$conf)=each($extensions)) {
if (is_array($conf)) {
if ($conf['ext_localconf.php']) {
$cFiles['ext_localconf'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_localconf.php']);
$cFiles['ext_localconf'].=trim(t3lib_div::getUrl($conf['ext_localconf.php']));
}
if ($conf['ext_tables.php']) {
if ($conf['ext_tables.php']) {
$cFiles['ext_tables'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_tables.php']);
$cFiles['ext_tables'].=trim(t3lib_div::getUrl($conf['ext_tables.php']));
}
......
*
* @return integer Number of deleted files.
*/
function removeCacheFiles() {
public static function removeCacheFiles() {
$cacheFiles = t3lib_extMgm::currentCacheFiles();
$out = 0;
if (is_array($cacheFiles)) {
if (is_array($cacheFiles)) {
reset($cacheFiles);
foreach($cacheFiles as $cfile) {
foreach($cacheFiles as $cfile) {
@unlink($cfile);
clearstatcache();
$out++;
(2-2/4)