/halogy/helpers/directory_helper.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 84 lines · 35 code · 11 blank · 38 comment · 13 complexity · b47a61f5cdeb793859aefd9e9e0a256b MD5 · raw file

  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
  9. * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
  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. * CodeIgniter Directory Helpers
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Helpers
  21. * @category Helpers
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
  24. */
  25. // ------------------------------------------------------------------------
  26. /**
  27. * Create a Directory Map
  28. *
  29. * Reads the specified directory and builds an array
  30. * representation of it. Sub-folders contained with the
  31. * directory will be mapped as well.
  32. *
  33. * @access public
  34. * @param string path to source
  35. * @param bool whether to limit the result to the top level only
  36. * @return array
  37. */
  38. if ( ! function_exists('directory_map'))
  39. {
  40. function directory_map($source_dir, $top_level_only = FALSE, $hidden = FALSE)
  41. {
  42. if ($fp = @opendir($source_dir))
  43. {
  44. $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
  45. $filedata = array();
  46. while (FALSE !== ($file = readdir($fp)))
  47. {
  48. if (($hidden == FALSE && strncmp($file, '.', 1) == 0) OR ($file == '.' OR $file == '..'))
  49. {
  50. continue;
  51. }
  52. if ($top_level_only == FALSE && @is_dir($source_dir.$file))
  53. {
  54. $temp_array = array();
  55. $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, $hidden);
  56. $filedata[$file] = $temp_array;
  57. }
  58. else
  59. {
  60. $filedata[] = $file;
  61. }
  62. }
  63. closedir($fp);
  64. return $filedata;
  65. }
  66. else
  67. {
  68. return FALSE;
  69. }
  70. }
  71. }
  72. /* End of file directory_helper.php */
  73. /* Location: ./system/helpers/directory_helper.php */