Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 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
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 25 | * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 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 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 42 | if ( ! function_exists('directory_map'))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 43 | {
|
| 44 | function directory_map($source_dir, $top_level_only = FALSE)
|
| 45 | {
|
| 46 | if ($fp = @opendir($source_dir))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 47 | {
|
Derek Jones | 2798b50 | 2008-05-06 14:12:18 +0000 | [diff] [blame] | 48 | $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 49 | $filedata = array();
|
Derek Jones | 2798b50 | 2008-05-06 14:12:18 +0000 | [diff] [blame] | 50 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 51 | while (FALSE !== ($file = readdir($fp)))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 52 | {
|
Derek Allard | 15dcf49 | 2008-05-12 21:37:04 +0000 | [diff] [blame] | 53 | if (strncmp($file, '.', 1) == 0)
|
Derek Jones | 2798b50 | 2008-05-06 14:12:18 +0000 | [diff] [blame] | 54 | {
|
| 55 | continue;
|
| 56 | }
|
| 57 |
|
| 58 | if ($top_level_only == FALSE && @is_dir($source_dir.$file))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 59 | {
|
| 60 | $temp_array = array();
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 61 |
|
Derek Jones | 2798b50 | 2008-05-06 14:12:18 +0000 | [diff] [blame] | 62 | $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 63 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 64 | $filedata[$file] = $temp_array;
|
| 65 | }
|
Derek Jones | 2798b50 | 2008-05-06 14:12:18 +0000 | [diff] [blame] | 66 | else
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 67 | {
|
| 68 | $filedata[] = $file;
|
| 69 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 70 | }
|
Derek Jones | 2798b50 | 2008-05-06 14:12:18 +0000 | [diff] [blame] | 71 |
|
| 72 | closedir($fp);
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 73 | return $filedata;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 74 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 75 | }
|
| 76 | }
|
| 77 |
|
Derek Allard | 15dcf49 | 2008-05-12 21:37:04 +0000 | [diff] [blame] | 78 |
|
| 79 | /* End of file directory_helper.php */
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 80 | /* Location: ./system/helpers/directory_helper.php */ |