From 9eb826bb0bf8ad7e565e13e9d20b9c0e5f0dad7d Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 16 Jul 2020 13:51:53 +0200 Subject: [PATCH] Add support for dictionaries in sub-folders of /dictionaries --- setup/modelfactory.class.inc.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/setup/modelfactory.class.inc.php b/setup/modelfactory.class.inc.php index 2bc507c99..38dcd8919 100644 --- a/setup/modelfactory.class.inc.php +++ b/setup/modelfactory.class.inc.php @@ -464,25 +464,29 @@ class MFDictModule extends MFModule } /** + * Scan for dictionary files recursively in $sDir + * * @inheritDoc */ - public function GetDictionaryFiles() + public function GetDictionaryFiles($sDir = null) { $aDictionaries = array(); - foreach (array($this->sRootDir, $this->sRootDir.'/dictionaries') as $sRootDir) + $sDictionaryFilePattern = '*dictionary.itop.*.php'; + + if($sDir === null) { - if ($hDir = @opendir($sRootDir)) + $sDir = $this->sRootDir; + } + + if ($hDir = opendir($sDir)) + { + // Matching files + $aDictionaries = glob($sDir.'/'.$sDictionaryFilePattern); + + // Directories to scan + foreach(glob($sDir.'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $sSubDir) { - while (($sFile = readdir($hDir)) !== false) - { - $aMatches = array(); - if (preg_match("/^.*dictionary\\.itop.*.php$/i", $sFile, - $aMatches)) // Dictionary files are named like .dict..php - { - $aDictionaries[] = $sRootDir.'/'.$sFile; - } - } - closedir($hDir); + $aDictionaries = array_merge($aDictionaries, $this->GetDictionaryFiles($sSubDir)); } }