summaryrefslogtreecommitdiffstats
path: root/system/helpers/directory_helper.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@server-speed.net>2011-01-28 22:51:06 +0100
committerFlorian Pritz <bluewind@server-speed.net>2011-01-28 22:58:52 +0100
commitce2b69675075444c9e40b72bcdd42ab7edbbe633 (patch)
tree2932f13b0db14fe53dc0622d888318db638a017f /system/helpers/directory_helper.php
parentb6b8a6587c399bfd89e13e92ce04ee8486688e6e (diff)
update to CI 2.0
Signed-off-by: Florian Pritz <bluewind@server-speed.net>
Diffstat (limited to 'system/helpers/directory_helper.php')
-rwxr-xr-x[-rw-r--r--]system/helpers/directory_helper.php40
1 files changed, 18 insertions, 22 deletions
diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php
index 791cf0d10..38347fa62 100644..100755
--- a/system/helpers/directory_helper.php
+++ b/system/helpers/directory_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -36,46 +36,42 @@
*
* @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
{
$filedata[] = $file;
}
}
-
+
closedir($fp);
return $filedata;
}
- else
- {
- return FALSE;
- }
+
+ return FALSE;
}
}