Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author ExpressionEngine Dev Team |
Derek Jones | 7f3719f | 2010-01-05 13:35:37 +0000 | [diff] [blame^] | 9 | * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html |
| 11 | * @link http://codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * CodeIgniter Directory Helpers |
| 20 | * |
| 21 | * @package CodeIgniter |
| 22 | * @subpackage Helpers |
| 23 | * @category Helpers |
| 24 | * @author ExpressionEngine Dev Team |
| 25 | * @link http://codeigniter.com/user_guide/helpers/directory_helper.html |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * Create a Directory Map |
| 32 | * |
| 33 | * Reads the specified directory and builds an array |
| 34 | * representation of it. Sub-folders contained with the |
| 35 | * directory will be mapped as well. |
| 36 | * |
| 37 | * @access public |
| 38 | * @param string path to source |
| 39 | * @param bool whether to limit the result to the top level only |
| 40 | * @return array |
| 41 | */ |
| 42 | if ( ! function_exists('directory_map')) |
| 43 | { |
Robin Sowell | 96dafa8 | 2009-05-26 21:45:54 +0000 | [diff] [blame] | 44 | function directory_map($source_dir, $top_level_only = FALSE, $hidden = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 45 | { |
| 46 | if ($fp = @opendir($source_dir)) |
| 47 | { |
| 48 | $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
| 49 | $filedata = array(); |
| 50 | |
| 51 | while (FALSE !== ($file = readdir($fp))) |
| 52 | { |
Robin Sowell | 96dafa8 | 2009-05-26 21:45:54 +0000 | [diff] [blame] | 53 | if (($hidden == FALSE && strncmp($file, '.', 1) == 0) OR ($file == '.' OR $file == '..')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 54 | { |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | if ($top_level_only == FALSE && @is_dir($source_dir.$file)) |
| 59 | { |
| 60 | $temp_array = array(); |
| 61 | |
Robin Sowell | 96dafa8 | 2009-05-26 21:45:54 +0000 | [diff] [blame] | 62 | $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, $hidden); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 63 | |
| 64 | $filedata[$file] = $temp_array; |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | $filedata[] = $file; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | closedir($fp); |
| 73 | return $filedata; |
| 74 | } |
Derek Jones | 94026d9 | 2009-07-15 15:56:58 +0000 | [diff] [blame] | 75 | else |
| 76 | { |
| 77 | return FALSE; |
| 78 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /* End of file directory_helper.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 84 | /* Location: ./system/helpers/directory_helper.php */ |