diff options
author | Andreas Gohr <andi@splitbrain.org> | 2013-02-03 11:19:44 -0800 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2013-02-03 11:19:44 -0800 |
commit | d363222d425e29f6cb8dabab772944b126356427 (patch) | |
tree | 0cada34c2617a1cc7130a201a8836d654f93c5e4 | |
parent | 3bcae82d222952f2653babf77001a17532f94656 (diff) | |
parent | 540fe9b0cccdfe29a5ea49f6016c9915c9a04ac0 (diff) | |
download | rpg-d363222d425e29f6cb8dabab772944b126356427.tar.gz rpg-d363222d425e29f6cb8dabab772944b126356427.tar.bz2 |
Merge pull request #168 from Chris--S/FS#2245
Natural sorting - FS#2245
-rw-r--r-- | inc/search.php | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/inc/search.php b/inc/search.php index 53bd240e8..cc3e79006 100644 --- a/inc/search.php +++ b/inc/search.php @@ -16,12 +16,13 @@ if(!defined('DOKU_INC')) die('meh.'); * * @param array ref $data The results of the search are stored here * @param string $base Where to start the search - * @param callback $func Callback (function name or arayy with object,method) + * @param callback $func Callback (function name or array with object,method) * @param string $dir Current directory beyond $base * @param int $lvl Recursion Level + * @param mixed $sort 'natural' to use natural order sorting (default); 'date' to sort by filemtime; leave empty to skip sorting. * @author Andreas Gohr <andi@splitbrain.org> */ -function search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort=false){ +function search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort='natural'){ $dirs = array(); $files = array(); $filepaths = array(); @@ -39,17 +40,19 @@ function search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort=false){ $filepaths[] = $base.'/'.$dir.'/'.$file; } closedir($dh); - if ($sort == 'date') { - @array_multisort(array_map('filemtime', $filepaths), SORT_NUMERIC, SORT_DESC, $files); - } else { - sort($files); + if (!empty($sort)) { + if ($sort == 'date') { + @array_multisort(array_map('filemtime', $filepaths), SORT_NUMERIC, SORT_DESC, $files); + } else /* natural */ { + natsort($files); + } + natsort($dirs); } - sort($dirs); //give directories to userfunction then recurse foreach($dirs as $dir){ if (call_user_func_array($func, array(&$data,$base,$dir,'d',$lvl,$opts))){ - search($data,$base,$func,$opts,$dir,$lvl+1); + search($data,$base,$func,$opts,$dir,$lvl+1,$sort); } } //now handle the files |