summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/helpers/directory_helper.php32
-rw-r--r--user_guide/changelog.html1
-rw-r--r--user_guide/helpers/directory_helper.html6
3 files changed, 18 insertions, 21 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;
}
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 93a7025f0..4758d49bc 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -81,6 +81,7 @@ SVN Revision: </p>
<li>Deprecated the <kbd>dohash()</kbd> function in favour of <kbd>do_hash()</kbd> for naming consistency.</li>
<li>Non-backwards compatible change made to <kbd>get_dir_file_info()</kbd> in the <a href="helpers/file_helper.html">File Helper</a>. No longer recurses
by default so as to encourage responsible use (this function can cause server performance issues when used without caution).</li>
+ <li>Modified the second parameter of <kbd>directory_map()</kbd> in the <a href="helpers/directory_helper.html">Directory Helper</a> to accept an integer to specify recursion depth.</li>
</ul>
</li>
</ul>
diff --git a/user_guide/helpers/directory_helper.html b/user_guide/helpers/directory_helper.html
index eae2c52ec..3b70799d0 100644
--- a/user_guide/helpers/directory_helper.html
+++ b/user_guide/helpers/directory_helper.html
@@ -78,10 +78,10 @@ and builds an array representation of it and all its contained files. Example:</
<p class="important"><strong>Note:</strong> Paths are almost always relative to your main index.php file.</p>
-<p>Sub-folders contained within the directory will be mapped as well. If you wish to map
-only the top level directory set the second parameter to <var>true</var> (boolean):</p>
+<p>Sub-folders contained within the directory will be mapped as well. If you wish to control the recursion depth,
+you can do so using the second parameter (integer). A depth of 1 will only map the top level directory:</p>
-<code>$map = directory_map('./mydirectory/', TRUE);</code>
+<code>$map = directory_map('./mydirectory/', 1);</code>
<p>By default, hidden files will not be included in the returned array. To override this behavior,
you may set a third parameter to <var>true</var> (boolean):</p>