Ejemplo n.º 1
0
 /**
  * List existing languages in the system
  *
  * Lists the existing languages in the system by examining the core
  * language folders in bonfire/application/language.
  *
  * @return array The names of the language directories.
  */
 function list_languages()
 {
     if (!function_exists('bcDirectoryMap')) {
         get_instance()->load->helper('directory');
     }
     return bcDirectoryMap(APPPATH . 'language', 1);
 }
Ejemplo n.º 2
0
 /**
  * Create a Directory Map
  *
  * Reads the specified directory and builds an array
  * representation of it. Sub-folders contained with the
  * directory will be mapped as well.
  *
  * @param   string  $source_dir     Path to source
  * @param   int $directory_depth    Depth of directories to traverse
  *                      (0 = fully recursive, 1 = current dir, etc)
  * @param   bool    $hidden         Whether to show hidden files
  * @return  array
  */
 function bcDirectoryMap($source_dir, $directory_depth = 0, $hidden = false)
 {
     if ($fp = @opendir($source_dir)) {
         $filedata = array();
         $new_depth = $directory_depth - 1;
         $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
         while (false !== ($file = readdir($fp))) {
             // Remove '.', '..', and hidden files [optional]
             if ($file === '.' || $file === '..' || $hidden === false && $file[0] === '.') {
                 continue;
             }
             if (($directory_depth < 1 || $new_depth > 0) && is_dir($source_dir . $file)) {
                 $filedata[$file] = bcDirectoryMap($source_dir . $file . DIRECTORY_SEPARATOR, $new_depth, $hidden);
             } else {
                 $filedata[] = $file;
             }
         }
         closedir($fp);
         return $filedata;
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Returns a list of all modules in the system.
  *
  * @param bool $exclude_core Whether to exclude the Bonfire core modules.
  *
  * @return array A list of all modules in the system.
  */
 public static function list_modules($exclude_core = false)
 {
     // Ensure the bcDirectoryMap function is available.
     if (!function_exists('bcDirectoryMap')) {
         get_instance()->load->helper('directory');
     }
     $map = array();
     foreach (Modules::folders() as $folder) {
         // If excluding core modules, skip the core module folder.
         if ($exclude_core && stripos($folder, 'bonfire/modules') !== false) {
             continue;
         }
         $dirs = bcDirectoryMap($folder, 1);
         if (is_array($dirs)) {
             $map = array_merge($map, $dirs);
         }
     }
     $count = count($map);
     if (!$count) {
         return $map;
     }
     // Clean out any html or php files.
     for ($i = 0; $i < $count; $i++) {
         if (stripos($map[$i], '.html') !== false || stripos($map[$i], '.php') !== false) {
             unset($map[$i]);
         }
     }
     return $map;
 }
Ejemplo n.º 4
0
 /**
  * Retrieves the list of files in a folder and preps the name and filename
  * so it's ready for creating the HTML.
  *
  * @param  String $folder The path to the folder to retrieve.
  * @param  String $type   The type of documentation being retrieved
  * ('application', 'bonfire', or the name of the module).
  * @param  Array  $ignoredFolders   A list of sub-folders we should ignore.
  *
  * @return Array  An associative array @see parse_ini_file for format
  * details.
  */
 private function get_folder_files($folder, $type, $ignoredFolders = array())
 {
     if (!is_dir($folder)) {
         return array();
     }
     // If the toc file exists in the folder, use it to build the links.
     if (is_file("{$folder}/{$this->tocFile}")) {
         return parse_ini_file("{$folder}/{$this->tocFile}", true);
     }
     // If the toc file does not exist, build the links by listing the files
     // in the directory (and any sub-directories)
     $this->load->helper('directory');
     $map = bcDirectoryMap($folder);
     // If directory_map can not open the directory or find any files inside
     // the directory, return an empty array.
     if (empty($map)) {
         return array();
     }
     // If these docs are located in the /application/docs or /bonfire/docs
     // directory, just use $this->docsGroup for the root.
     // Module docs need $this->docsGroup and $type.
     $tocRoot = $this->docsGroup;
     if ($this->docsGroup != strtolower($type)) {
         $tocRoot .= '/' . strtolower($type);
     }
     $toc = array();
     foreach ($map as $new_folder => $files) {
         // Is this a folder that should be ignored?
         if (is_string($new_folder) && in_array($new_folder, $ignoredFolders)) {
             continue;
         }
         // If $files isn't an array, then make it one so that all situations
         // may be dealt with cleanly.
         if (!is_array($files)) {
             $files = array($files);
         }
         foreach ($files as $file) {
             if (in_array($file, $this->ignoreFiles)) {
                 continue;
             }
             // The title for the index is the passed $type. Otherwise,
             // build the title from the file's name.
             if (strpos($file, 'index') === false) {
                 $title = str_replace($this->docsExt, '', $file);
                 $title = str_replace('_', ' ', $title);
                 $title = ucwords($title);
                 $toc["{$tocRoot}/{$file}"] = $title;
             } else {
                 $toc[$tocRoot] = $type;
             }
         }
     }
     return $toc;
 }