Return an associative array of files within one or more modules.
public static files ( $module_name = NULL, $module_folder = NULL ) : array | ||
$module_name | string If not null, will return only files from that module. | |
$module_folder | string If not null, will return only files within that sub-folder of each module (ie 'views'). | |
return | array | An associative array, like:
array(
'module_name' => array(
'folder' => array('file1', 'file2')
)
) |
/** * List all language files for the specified language * * Searches the application/languages folder as well as all core modules * for folders matching the language name. * * @param string $language The language * * @return array An array of files. */ function list_lang_files($language = 'english') { $ci =& get_instance(); $lang_files = array(); // Base language files. $lang_files['core'] = find_lang_files(APPPATH . "language/{$language}/"); // Module directories $modules = Modules::list_modules(); // Application Module directories only $custom_modules = Modules::list_modules(true); foreach ($modules as $module) { $module_langs = Modules::files($module, 'language'); $type = 'core'; if (isset($module_langs[$module]['language'][$language])) { $path = implode('/', array(Modules::path($module, 'language'), $language)); $files = find_lang_files($path . '/'); if (in_array($module, $custom_modules)) { $type = 'custom'; } if (is_array($files)) { foreach ($files as $file) { $lang_files[$type][] = $file; } } } } return $lang_files; }
/** * List all language files for the specified language * * Searches the application/languages folder as well as all core modules * for folders matching the language name. * * @param string $language The language. * * @return array The filenames. */ function list_lang_files($language = 'english') { // Base language files. $langFiles = array(); $langFiles['core'] = find_lang_files(APPPATH . "language/{$language}/"); // Build the 'core' and 'custom' module lists. $modules = Modules::list_modules(); $appModules = Modules::list_modules(true); foreach ($modules as $module) { $moduleLangs = Modules::files($module, 'language'); $type = 'core'; if (isset($moduleLangs[$module]['language'][$language])) { $path = implode('/', array(Modules::path($module, 'language'), $language)); $files = find_lang_files($path . '/'); // 'core' modules will only be found in $modules, while 'custom' // modules will be found in both $modules and $appModules. if (in_array($module, $appModules)) { $type = 'custom'; } if (is_array($files)) { foreach ($files as $file) { $langFiles[$type][] = $file; } } } } return $langFiles; }
/** * Get all versions available for the modules * * @return array Array of available versions for each module */ private function get_module_versions() { $modules = Modules::files(null, 'migrations'); if ($modules === false) { return false; } // Sort modules by key (module directory name) ksort($modules); // Get the installed version of all of the modules (modules which have // not been installed will not be included) $installedVersions = $this->migrations->getModuleVersions(); $modVersions = array(); // Add the migration data for each module foreach ($modules as $module => &$mod) { if (!array_key_exists('migrations', $mod)) { continue; } // Sort module migrations in reverse order arsort($mod['migrations']); /** * @internal Calculating the latest version from the migration list * saves ~20% of the load time when a lot of modules (tested with > * 50) are listed. However, it requires the controller to know more * about the format of the migration filenames than may be desirable. * If that is the case, the 'latest_version' key below can be * populated with the result of: * $this->migrations->getVersion("{$module}_", true) */ // Add the installed version, latest version, and list of migrations $modVersions[$module] = array('installed_version' => isset($installedVersions["{$module}_"]) ? $installedVersions["{$module}_"] : 0, 'latest_version' => intval(substr(current($mod['migrations']), 0, 3), 10), 'migrations' => $mod['migrations']); } return $modVersions; }
/** * Get the versions of the modules. * * @return array The installed/latest versions of each module. */ private function get_module_versions() { $modules = Modules::files(null, 'migrations'); if ($modules === false) { return false; } // Sort modules by key (module directory name) ksort($modules); // Get the installed version of all of the modules (modules which have // not been installed will not be included) $installedVersions = $this->ci->migrations->getModuleVersions(); $modVersions = array(); // Add the migration data for each module foreach ($modules as $module => &$mod) { if (!array_key_exists('migrations', $mod)) { continue; } // Sort module migrations in reverse order arsort($mod['migrations']); // Add the installed version, latest version, and list of migrations $modVersions[$module] = array('installed_version' => isset($installedVersions["{$module}_"]) ? $installedVersions["{$module}_"] : 0, 'latest_version' => intval(substr(current($mod['migrations']), 0, 3), 10), 'migrations' => $mod['migrations']); } return $modVersions; }
/** * Returns an associative array of files within one or more modules. * * @deprecated since 0.7.1 Use Modules::files() instead. * * @param $module_name string If not NULL, will return only files from that module. * @param $module_folder string If not NULL, will return only files within that folder of each module (ie 'views') * @param $exclude_core boolean Whether we should ignore all core modules. * * @return array An associative array, like: array('module_name' => array('folder' => array('file1', 'file2'))) */ function module_files($module_name = null, $module_folder = null, $exclude_core = false) { return Modules::files($module_name, $module_folder, $exclude_core); }
/** * Delete existing language folder. * * @param string $language The language to delete. * * @return bool */ function delete_language($language = NULL) { if (empty($language)) { return FALSE; } if (!function_exists('delete_files')) { get_instance()->load->helper('file'); } // Delete the specified admin and main language folder. foreach (array(MAINDIR, ADMINDIR) as $domain) { $path = ROOTPATH . "{$domain}/language/{$language}"; if (is_dir($path)) { delete_files($path, TRUE); rmdir($path); } } // Clone then specified module language files. $modules = Modules::list_modules(); foreach ($modules as $module) { $moduleLangs = Modules::files($module, 'language'); if (isset($moduleLangs[$module]['language'][$language])) { $path = Modules::path($module, 'language'); delete_files("{$path}/{$language}", TRUE); rmdir("{$path}/{$language}"); } } return FALSE; }
/** * Clone a single existing language. * * @param string $filename The name for the newly cloned language. * @param string $language The language to clone. * * @return mixed The $lang array from the file or false if not found. Returns * null if $filename is empty. */ function clone_language($filename = NULL, $language = 'english') { if (empty($filename)) { return FALSE; } // Clone the specified admin and main language files. foreach (array(MAINDIR, ADMINDIR) as $domain) { copy_language_files(ROOTPATH . "{$domain}/language/{$language}", ROOTPATH . "{$domain}/language/{$filename}"); } // Clone then specified module language files. $modules = Modules::list_modules(); foreach ($modules as $module) { $moduleLangs = Modules::files($module, 'language'); if (isset($moduleLangs[$module]['language'][$language])) { $path = Modules::path($module, 'language'); copy_language_files("{$path}/{$language}", "{$path}/{$filename}"); } } return TRUE; }