From fe82d751808e4f0ede157e22e6c1e4b7402e2022 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 27 Jan 2013 20:15:25 +0000 Subject: sp. --- inc/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/search.php b/inc/search.php index 53bd240e8..5c70b0305 100644 --- a/inc/search.php +++ b/inc/search.php @@ -16,7 +16,7 @@ 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 * @author Andreas Gohr -- cgit v1.2.3 From 155e63c930bf2fdc260994a62baa80fe5f5ab764 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 27 Jan 2013 20:32:41 +0000 Subject: add documentation for sort parameter, change false to 'natural' --- inc/search.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/search.php b/inc/search.php index 5c70b0305..6590d7342 100644 --- a/inc/search.php +++ b/inc/search.php @@ -19,9 +19,10 @@ if(!defined('DOKU_INC')) die('meh.'); * @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. * @author Andreas Gohr */ -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(); -- cgit v1.2.3 From 5514a5a77e2d38cf763ed922b727ab305c8c8bb9 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 27 Jan 2013 20:33:25 +0000 Subject: ensure parameter is passed down during recursion --- inc/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/search.php b/inc/search.php index 6590d7342..6fd7e9ae6 100644 --- a/inc/search.php +++ b/inc/search.php @@ -50,7 +50,7 @@ function search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort='natural'){ //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 -- cgit v1.2.3 From 1dc5d48b104c5676df02e6bf0090e13b0e26508b Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 27 Jan 2013 20:33:38 +0000 Subject: change to use natural order sorting --- inc/search.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/search.php b/inc/search.php index 6fd7e9ae6..277b17d39 100644 --- a/inc/search.php +++ b/inc/search.php @@ -42,10 +42,10 @@ function search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort='natural'){ closedir($dh); if ($sort == 'date') { @array_multisort(array_map('filemtime', $filepaths), SORT_NUMERIC, SORT_DESC, $files); - } else { - sort($files); + } else /* natural */ { + natsort($files); } - sort($dirs); + natsort($dirs); //give directories to userfunction then recurse foreach($dirs as $dir){ -- cgit v1.2.3 From ec24a2df21bc25730b6d807a6930867e09f2aa58 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Tue, 29 Jan 2013 19:40:23 +0100 Subject: search: pass empty $sort to skip sorting --- inc/search.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/search.php b/inc/search.php index 277b17d39..cc3e79006 100644 --- a/inc/search.php +++ b/inc/search.php @@ -19,7 +19,7 @@ if(!defined('DOKU_INC')) die('meh.'); * @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. + * @param mixed $sort 'natural' to use natural order sorting (default); 'date' to sort by filemtime; leave empty to skip sorting. * @author Andreas Gohr */ function search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort='natural'){ @@ -40,12 +40,14 @@ function search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort='natural'){ $filepaths[] = $base.'/'.$dir.'/'.$file; } closedir($dh); - if ($sort == 'date') { - @array_multisort(array_map('filemtime', $filepaths), SORT_NUMERIC, SORT_DESC, $files); - } else /* natural */ { - natsort($files); + if (!empty($sort)) { + if ($sort == 'date') { + @array_multisort(array_map('filemtime', $filepaths), SORT_NUMERIC, SORT_DESC, $files); + } else /* natural */ { + natsort($files); + } + natsort($dirs); } - natsort($dirs); //give directories to userfunction then recurse foreach($dirs as $dir){ -- cgit v1.2.3