mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 16:48:49 +01:00
replace (slower and ugly) create_function with closures
This commit is contained in:
parent
b345ea6c31
commit
0b71dd2756
@ -703,8 +703,10 @@ abstract class Merge
|
||||
}
|
||||
// alternative syntax using double curly brackets (eg. {{cat_id}} instead $$cat_id$$),
|
||||
// agressivly removing all xml-tags eg. Word adds within placeholders
|
||||
$content = preg_replace_callback('/{{[^}]+}}/i',create_function('$p','return \'$$\'.strip_tags(substr($p[0],2,-2)).\'$$\';'),$_content);
|
||||
|
||||
$content = preg_replace_callback('/{{[^}]+}}/i', function($matches)
|
||||
{
|
||||
return '$$'.strip_tags(substr($matches[0], 2, -2)).'$$';
|
||||
}, $_content);
|
||||
// Handle escaped placeholder markers in RTF, they won't match when escaped
|
||||
if($mimetype == 'application/rtf')
|
||||
{
|
||||
|
@ -570,14 +570,11 @@ class Vfs extends Vfs\StreamWrapper
|
||||
self::_check_add($options,$path,$result);
|
||||
}
|
||||
}
|
||||
// sort code, to place directories before files, if $dirsontop enabled
|
||||
$dirsfirst = $dirsontop ? '($a[mime]==\''.self::DIR_MIME_TYPE.'\')!==($b[mime]==\''.self::DIR_MIME_TYPE.'\')?'.
|
||||
'($a[mime]==\''.self::DIR_MIME_TYPE.'\'?-1:1):' : '';
|
||||
// ordering of the rows
|
||||
if (isset($options['order']))
|
||||
{
|
||||
$sort = strtolower($options['sort']) == 'desc' ? '-' : '';
|
||||
switch($options['order'])
|
||||
$sort_desc = strtolower($options['sort']) == 'desc';
|
||||
switch($order = $options['order'])
|
||||
{
|
||||
// sort numerical
|
||||
case 'size':
|
||||
@ -586,32 +583,46 @@ class Vfs extends Vfs\StreamWrapper
|
||||
case 'mode':
|
||||
case 'ctime':
|
||||
case 'mtime':
|
||||
$code = $dirsfirst.$sort.'($a[\''.$options['order'].'\']-$b[\''.$options['order'].'\']);';
|
||||
$ok = uasort($result, function($a, $b) use ($dirsontop, $sort_desc, $order)
|
||||
{
|
||||
$cmp = $a[$order] - $b[$order];
|
||||
// sort code, to place directories before files, if $dirsontop enabled
|
||||
if ($dirsontop && ($a['mime'] == self::DIR_MIME_TYPE) !== ($b['mime'] == self::DIR_MIME_TYPE))
|
||||
{
|
||||
$cmp = $a['mime' ] == self::DIR_MIME_TYPE ? -1 : 1;
|
||||
$sort_desc = false;
|
||||
}
|
||||
// reverse sort for descending
|
||||
if ($sort_desc) $cmp *= -1;
|
||||
// always use name as second sort criteria
|
||||
$code = '$cmp = '.$code.' return $cmp ? $cmp : strcasecmp($a[\'name\'],$b[\'name\']);';
|
||||
$ok = uasort($result,create_function('$a,$b',$code));
|
||||
if (!$cmp) $cmp = strcasecmp($a['name'], $b['name']);
|
||||
return $cmp;
|
||||
});
|
||||
break;
|
||||
|
||||
// sort alphanumerical
|
||||
default:
|
||||
$options['order'] = 'name';
|
||||
$order = 'name';
|
||||
// fall throught
|
||||
case 'name':
|
||||
case 'mime':
|
||||
$code = $dirsfirst.$sort.'strcasecmp($a[\''.$options['order'].'\'],$b[\''.$options['order'].'\']);';
|
||||
if ($options['order'] != 'name')
|
||||
$ok = uasort($result, function($a, $b) use ($dirsontop, $order, $sort_desc)
|
||||
{
|
||||
$cmp = strcasecmp($a[$order], $b[$order]);
|
||||
// sort code, to place directories before files, if $dirsontop enabled
|
||||
if ($dirsontop && ($a['mime'] == self::DIR_MIME_TYPE) !== ($b['mime'] == self::DIR_MIME_TYPE))
|
||||
{
|
||||
$cmp = $a['mime' ] == self::DIR_MIME_TYPE ? -1 : 1;
|
||||
$sort_desc = false;
|
||||
}
|
||||
// reverse sort for descending
|
||||
if ($sort_desc) $cmp *= -1;
|
||||
// always use name as second sort criteria
|
||||
$code = '$cmp = '.$code.' return $cmp ? $cmp : strcasecmp($a[\'name\'],$b[\'name\']);';
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = 'return '.$code;
|
||||
}
|
||||
$ok = uasort($result,create_function('$a,$b',$code));
|
||||
if (!$cmp && $order != 'name') $cmp = strcasecmp($a['name'], $b['name']);
|
||||
return $cmp;
|
||||
});
|
||||
break;
|
||||
}
|
||||
//echo "<p>order='$options[order]', sort='$options[sort]' --> uasort($result,create_function(,'$code'))=".array2string($ok)."</p>>\n";
|
||||
}
|
||||
// limit resultset
|
||||
self::$find_total = count($result);
|
||||
|
@ -1854,7 +1854,12 @@ class calendar_bo
|
||||
if ($bdays)
|
||||
{
|
||||
// sort by month and day only
|
||||
usort($bdays,create_function('$a,$b','return (int) $a[\'bday\'] == (int) $b[\'bday\'] ? strcmp($a[\'bday\'],$b[\'bday\']) : (int) $a[\'bday\'] - (int) $b[\'bday\'];'));
|
||||
usort($bdays, function($a, $b)
|
||||
{
|
||||
return (int) $a['bday'] == (int) $b['bday'] ?
|
||||
strcmp($a['bday'], $b['bday']) :
|
||||
(int) $a['bday'] - (int) $b['bday'];
|
||||
});
|
||||
foreach($bdays as $pers)
|
||||
{
|
||||
if (empty($pers['bday']) || $pers['bday']=='0000-00-00 0' || $pers['bday']=='0000-00-00' || $pers['bday']=='0.0.00')
|
||||
|
@ -603,7 +603,11 @@ class calendar_so
|
||||
if ($cat_id)
|
||||
{
|
||||
$cats = $GLOBALS['egw']->categories->return_all_children($cat_id);
|
||||
array_walk($cats,create_function('&$val,$key','$val = (int) $val;'));
|
||||
array_walk($cats, function(&$val, $key)
|
||||
{
|
||||
unset($key); // not used, but required by function signature
|
||||
$val = (int) $val;
|
||||
});
|
||||
if (is_array($cat_id) && count($cat_id)==1) $cat_id = $cat_id[0];
|
||||
$sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '='.$this->db->quote((int)$cat_id));
|
||||
foreach($cats as $cat)
|
||||
|
@ -850,7 +850,10 @@ class mail_compose
|
||||
if ($contacts && $accounts)
|
||||
{
|
||||
$contacts = array_merge($contacts,$accounts);
|
||||
usort($contacts,create_function('$a,$b','return strcasecmp($a["n_fn"],$b["n_fn"]);'));
|
||||
usort($contacts, function($a, $b)
|
||||
{
|
||||
return strcasecmp($a['n_fn'], $b['n_fn']);
|
||||
});
|
||||
}
|
||||
elseif($accounts)
|
||||
{
|
||||
|
@ -141,7 +141,10 @@ class setup_translation
|
||||
}
|
||||
}
|
||||
$d->close();
|
||||
uasort($languages,create_function('$a,$b','return strcmp(@$a[\'descr\'],@$b[\'descr\']);'));
|
||||
uasort($languages, function($a, $b)
|
||||
{
|
||||
return strcmp(@$a['descr'], @$b['descr']);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user