diff options
author | Pascal Kriete <pascal.kriete@ellislab.com> | 2010-01-07 19:14:28 +0100 |
---|---|---|
committer | Pascal Kriete <pascal.kriete@ellislab.com> | 2010-01-07 19:14:28 +0100 |
commit | 98a447ac363d00d856c18f34ffbd4d14cad51eb3 (patch) | |
tree | 782d1942ca26f4f7e53168a370739ca6fae80cd5 /system/helpers | |
parent | 8c4b5e78a8f3a87e30ffc3b09b897153ffe86193 (diff) |
changing the second parameter in directory_map to an integer that controls recursion depth.
A depth of 0 is fully recursive to maintain backward compatibility with the boolean values.
Diffstat (limited to 'system/helpers')
-rw-r--r-- | system/helpers/directory_helper.php | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 791cf0d10..7de6a3c51 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -36,32 +36,30 @@ * * @access public * @param string path to source - * @param bool whether to limit the result to the top level only + * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) * @return array */ if ( ! function_exists('directory_map')) { - function directory_map($source_dir, $top_level_only = FALSE, $hidden = FALSE) - { + function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) + { if ($fp = @opendir($source_dir)) { - $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; - $filedata = array(); - + $filedata = array(); + $new_depth = $directory_depth - 1; + $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + while (FALSE !== ($file = readdir($fp))) { - if (($hidden == FALSE && strncmp($file, '.', 1) == 0) OR ($file == '.' OR $file == '..')) + // Remove '.', '..', and hidden files [optional] + if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] == '.')) { continue; } - - if ($top_level_only == FALSE && @is_dir($source_dir.$file)) + + if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file)) { - $temp_array = array(); - - $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, $hidden); - - $filedata[$file] = $temp_array; + $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden); } else { @@ -72,10 +70,8 @@ if ( ! function_exists('directory_map')) closedir($fp); return $filedata; } - else - { - return FALSE; - } + + return FALSE; } } |