mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 00:29:38 +01:00
"fixed not working plugin cache (on tree level): callback has to be public, as it's get called static by an other class (egw_cache)"
This commit is contained in:
parent
b47b6ed7ff
commit
80a1fb5a53
@ -15,9 +15,11 @@
|
||||
* use importexport_helper_functions::method
|
||||
*/
|
||||
class importexport_helper_functions {
|
||||
|
||||
// Plugins are scanned and cached for all instances using this source path
|
||||
const CACHE_EXPIRATION = 86400;
|
||||
|
||||
/**
|
||||
* Plugins are scanned and cached for all instances using this source path for given time (in seconds)
|
||||
*/
|
||||
const CACHE_EXPIRATION = 3600;
|
||||
|
||||
/**
|
||||
* Files known to cause problems, and will be skipped in a plugin scan
|
||||
@ -31,10 +33,10 @@ class importexport_helper_functions {
|
||||
/**
|
||||
* nothing to construct here, only static functions!
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Converts a custom time string to to unix timestamp
|
||||
* The format of the time string is given by the argument $_format
|
||||
* The format of the time string is given by the argument $_format
|
||||
* which takes the same parameters as the php date() function.
|
||||
*
|
||||
* @abstract supportet formatstrings: d,m,y,Y,H,h,i,s,O,a,A
|
||||
@ -48,7 +50,7 @@ class importexport_helper_functions {
|
||||
$fparams = explode( ',', chunk_split( $_format, 1, ',' ) );
|
||||
$spos = 0;
|
||||
foreach ( $fparams as $fparam ) {
|
||||
|
||||
|
||||
switch ( $fparam ) {
|
||||
case 'd': (int)$day = substr( $_string, $spos, 2 ); $spos += 2; break;
|
||||
case 'm': (int)$mon = substr( $_string, $spos, 2 ); $spos += 2; break;
|
||||
@ -64,10 +66,10 @@ class importexport_helper_functions {
|
||||
default: $spos++; // seperator
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print_debug("hour:$hour; min:$min; sec:$sec; mon:$mon; day:$day; year:$year;\n");
|
||||
$timestamp = mktime($hour, $min, $sec, $mon, $day, $year, $_is_dst);
|
||||
|
||||
|
||||
// offset given?
|
||||
if ( isset( $offset ) && strlen( $offset == 5 ) ) {
|
||||
$operator = $offset{0};
|
||||
@ -92,7 +94,7 @@ class importexport_helper_functions {
|
||||
}
|
||||
}
|
||||
return is_array( $_account_lids ) ? $account_ids : implode( ',', (array)$account_ids );
|
||||
|
||||
|
||||
} // end of member function account_lid2id
|
||||
|
||||
/**
|
||||
@ -110,19 +112,17 @@ class importexport_helper_functions {
|
||||
}
|
||||
return is_array( $_account_id ) ? $account_lids : implode( ',', (array)$account_lids );
|
||||
} // end of member function account_id2lid
|
||||
|
||||
|
||||
/**
|
||||
* converts cat_id to a cat_name
|
||||
*
|
||||
* @param mixed _cat_ids comma seperated list or array
|
||||
* @return mixed comma seperated list or array with cat_names
|
||||
* @return mixed comma seperated list or array with cat_names
|
||||
*/
|
||||
public static function cat_id2name( $_cat_ids ) {
|
||||
$cats = &CreateObject( 'phpgwapi.categories' );
|
||||
|
||||
$cat_ids = is_array( $_cat_ids ) ? $_cat_ids : explode( ',', $_cat_ids );
|
||||
foreach ( $cat_ids as $cat_id ) {
|
||||
$cat_names[] = $cats->id2name( (int)$cat_id );
|
||||
$cat_names[] = categories::id2name( (int)$cat_id );
|
||||
}
|
||||
return is_array( $_cat_ids ) ? $cat_names : implode(',',(array)$cat_names);
|
||||
} // end of member function category_id2name
|
||||
@ -135,52 +135,51 @@ class importexport_helper_functions {
|
||||
* @return mixed comma seperated list or array with cat_ids
|
||||
*/
|
||||
public static function cat_name2id( $_cat_names ) {
|
||||
$cats = CreateObject( 'phpgwapi.categories' );
|
||||
$cats->app_name = $GLOBALS['egw_info']['flags']['currentapp'];
|
||||
|
||||
$cats = new categories(); // uses current user and app (egw_info[flags][currentapp])
|
||||
|
||||
$cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names );
|
||||
foreach ( $cat_names as $cat_name ) {
|
||||
if ( $cat_name == '' ) continue;
|
||||
if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 ) {
|
||||
$cat_id = $cats->add( array(
|
||||
'name' => $cat_name,
|
||||
'access' => 'public',
|
||||
$cat_id = $cats->add( array(
|
||||
'name' => $cat_name,
|
||||
'access' => 'public',
|
||||
'descr' => $cat_name. ' ('. lang('Automatically created by importexport'). ')'
|
||||
));
|
||||
}
|
||||
$cat_ids[] = $cat_id;
|
||||
}
|
||||
return is_array( $_cat_names ) ? $cat_ids : implode( ',', (array)$cat_ids );
|
||||
|
||||
|
||||
} // end of member function category_name2id
|
||||
|
||||
/**
|
||||
* conversion
|
||||
*
|
||||
* Conversions enable you to change / adapt the content of each _record field for your needs.
|
||||
*
|
||||
* Conversions enable you to change / adapt the content of each _record field for your needs.
|
||||
* General syntax is: pattern1 |> replacement1 || ... || patternN |> replacementN
|
||||
* If the pattern-part of a pair is ommited it will match everything ('^.*$'), which
|
||||
* If the pattern-part of a pair is ommited it will match everything ('^.*$'), which
|
||||
* is only usefull for the last pair, as they are worked from left to right.
|
||||
* Example: 1|>private||public
|
||||
* This will translate a '1' in the _record field to 'privat' and everything else to 'public'.
|
||||
*
|
||||
* In addintion to the fields assign by the pattern of the reg.exp.
|
||||
*
|
||||
* In addintion to the fields assign by the pattern of the reg.exp.
|
||||
* you can use all other _record fields, with the syntax |[FIELDINDEX].
|
||||
* Example:
|
||||
* Your record is:
|
||||
* Example:
|
||||
* Your record is:
|
||||
* array( 0 => Company, 1 => NFamily, 2 => NGiven
|
||||
* Your conversion string for field 0 (Company):
|
||||
* Your conversion string for field 0 (Company):
|
||||
* .+|>|[0]: |[1], |[2]|||[1], |[2]
|
||||
* This constructs something like
|
||||
* This constructs something like
|
||||
* Company: FamilyName, GivenName or FamilyName, GivenName if 'Company' is empty.
|
||||
*
|
||||
*
|
||||
* Moreover the two helper function cat() and account() can be used.
|
||||
* cat(Cat1,...,CatN) returns a (','-separated) list with the cat_id's. If a
|
||||
* cat(Cat1,...,CatN) returns a (','-separated) list with the cat_id's. If a
|
||||
* category isn't found, it will be automaticaly added.
|
||||
*
|
||||
* Patterns as well as the replacement can be regular expressions (the replacement is done
|
||||
* Patterns as well as the replacement can be regular expressions (the replacement is done
|
||||
* via ereg_replace).
|
||||
*
|
||||
*
|
||||
* @param array _record reference with record to do the conversion with
|
||||
* @param array _conversion array with conversion description
|
||||
* @param object &$cclass calling class to process the '@ evals' (not impelmeted yet)
|
||||
@ -188,7 +187,7 @@ class importexport_helper_functions {
|
||||
*/
|
||||
public static function conversion( $_record, $_conversion, &$_cclass = null ) {
|
||||
if (empty( $_conversion ) ) return $_record;
|
||||
|
||||
|
||||
$PSep = '||'; // Pattern-Separator, separats the pattern-replacement-pairs in conversion
|
||||
$ASep = '|>'; // Assignment-Separator, separats pattern and replacesment
|
||||
$CPre = '|['; $CPos = ']'; // |[_record-idx] is expanded to the corespondig value
|
||||
@ -199,7 +198,7 @@ class importexport_helper_functions {
|
||||
|
||||
foreach ( $_conversion as $idx => $conversion_string ) {
|
||||
if ( empty( $conversion_string ) ) continue;
|
||||
|
||||
|
||||
// fetch patterns ($rvalues)
|
||||
$pat_reps = explode( $PSep, stripslashes( $conversion_string ) );
|
||||
foreach( $pat_reps as $k => $pat_rep ) {
|
||||
@ -209,25 +208,25 @@ class importexport_helper_functions {
|
||||
}
|
||||
$rvalues[$pattern] = $replace; // replace two with only one, added by the form
|
||||
}
|
||||
|
||||
|
||||
// conversion list may be longer than $_record aka (no_csv)
|
||||
$val = array_key_exists( $idx, $_record ) ? $_record[$idx] : '';
|
||||
|
||||
foreach ( $rvalues as $pattern => $replace ) {
|
||||
if( ereg( (string)$pattern, $val) ) {
|
||||
|
||||
|
||||
$val = ereg_replace( (string)$pattern, $replace, (string)$val );
|
||||
|
||||
|
||||
$reg = '\|\[([a-zA-Z_0-9]+)\]';
|
||||
while( ereg( $reg, $val, $vars ) ) {
|
||||
// expand all _record fields
|
||||
$val = str_replace(
|
||||
$CPre . $vars[1] . $CPos,
|
||||
$_record[array_search($vars[1], array_keys($_record))],
|
||||
$CPre . $vars[1] . $CPos,
|
||||
$_record[array_search($vars[1], array_keys($_record))],
|
||||
$val
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$val = preg_replace_callback( "/(cat|account|strtotime)\(([^)]*)\)/i", array( self, 'c2_dispatcher') , $val );
|
||||
}
|
||||
}
|
||||
@ -238,10 +237,10 @@ class importexport_helper_functions {
|
||||
}
|
||||
return $_record;
|
||||
} // end of member function conversion
|
||||
|
||||
|
||||
/**
|
||||
* callback for preg_replace_callback from self::conversion.
|
||||
* This function gets called when 2nd level conversions are made,
|
||||
* This function gets called when 2nd level conversions are made,
|
||||
* like the cat() and account() statements in the conversions.
|
||||
*
|
||||
* @param array $_matches
|
||||
@ -249,7 +248,7 @@ class importexport_helper_functions {
|
||||
private static function c2_dispatcher( $_matches ) {
|
||||
$action = &$_matches[1]; // cat or account ...
|
||||
$data = &$_matches[2]; // datas for action
|
||||
|
||||
|
||||
switch ( $action ) {
|
||||
case 'strtotime' :
|
||||
list( $string, $format ) = explode( ',', $data );
|
||||
@ -259,40 +258,36 @@ class importexport_helper_functions {
|
||||
return self::$method( $data );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function strclean( $_matches ) {
|
||||
switch( $_matches[1] ) {
|
||||
case '|T{' : return trim( $_matches[2] );
|
||||
case '|TC{' : return trim( preg_replace( '/[\x01-\x1F]+/', '', $_matches[2] ) );
|
||||
case '|TCnCL{' : return trim( preg_replace( '/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2] ) );
|
||||
case '|INE{' : return preg_match( '/\^.+\^/', $_matches[2] ) ? $_matches[2] : '';
|
||||
case '|INE{' : return preg_match( '/\^.+\^/', $_matches[2] ) ? $_matches[2] : '';
|
||||
default:
|
||||
throw new Exception('Error in conversion string! "'. substr( $_matches[1], 0, -1 ). '" is not valid!');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns a list of importexport plugins
|
||||
* returns a list of importexport plugins
|
||||
*
|
||||
* @param string $_tpye {import | export | all}
|
||||
* @param string $_appname {<appname> | all}
|
||||
* @return array(<appname> => array( <type> => array(<plugin> => <title>)))
|
||||
*/
|
||||
public static function get_plugins( $_appname = 'all', $_type = 'all' ) {
|
||||
/*
|
||||
$plugins = egw_cache::getTree(
|
||||
__CLASS__,
|
||||
'plugins',
|
||||
array('importexport_helper_functions','_get_plugins'),
|
||||
__CLASS__,
|
||||
'plugins',
|
||||
array('importexport_helper_functions','_get_plugins'),
|
||||
array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')),
|
||||
self::CACHE_EXPIRATION
|
||||
);
|
||||
*/
|
||||
$plugins = self::_get_plugins(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export'));
|
||||
|
||||
$appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname;
|
||||
$types = $_type == 'all' ? array('import','export') : (array)$_type;
|
||||
|
||||
|
||||
foreach($plugins as $appname => $types) {
|
||||
if(!in_array($appname, $appnames)) unset($plugins['appname']);
|
||||
}
|
||||
@ -302,7 +297,7 @@ class importexport_helper_functions {
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
protected static function _get_plugins(Array $appnames, Array $types) {
|
||||
public static function _get_plugins(Array $appnames, Array $types) {
|
||||
$plugins = array();
|
||||
foreach ($appnames as $appname) {
|
||||
if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue;
|
||||
@ -310,7 +305,7 @@ class importexport_helper_functions {
|
||||
$appdir = EGW_INCLUDE_ROOT. "/$appname/inc";
|
||||
if(!is_dir($appdir)) continue;
|
||||
$d = dir($appdir);
|
||||
|
||||
|
||||
// step through each file in appdir
|
||||
while (false !== ($entry = $d->read())) {
|
||||
// Blacklisted?
|
||||
@ -318,12 +313,12 @@ class importexport_helper_functions {
|
||||
|
||||
list( ,$classname, ,$extension) = explode('.',$entry);
|
||||
$file = $appdir. '/'. $entry;
|
||||
|
||||
|
||||
foreach ($types as $type) {
|
||||
if( !is_file($file) || strpos($entry, $type) === false || $extension != 'php' ) continue;
|
||||
require_once($file);
|
||||
$reflectionClass = new ReflectionClass($classname);
|
||||
if($reflectionClass->IsInstantiable() &&
|
||||
if($reflectionClass->IsInstantiable() &&
|
||||
$reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) {
|
||||
try {
|
||||
$plugin_object = new $classname;
|
||||
@ -339,9 +334,9 @@ class importexport_helper_functions {
|
||||
$d->close();
|
||||
}
|
||||
//error_log(__CLASS__.__FUNCTION__.print_r($plugins,true));
|
||||
return $plugins;
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns list of apps which have plugins of given type.
|
||||
*
|
||||
@ -353,7 +348,6 @@ class importexport_helper_functions {
|
||||
}
|
||||
|
||||
public static function guess_filetype( $_file ) {
|
||||
|
||||
|
||||
}
|
||||
} // end of importexport_helper_functions
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user