codes = $codes; } /** * Clean up within an installation * * @param string $dir The installation dir * * @return void */ public function cleanInstallation($dir) { $dir = rtrim($dir, '/\\'); if (is_dir("$dir/languages")) { $this->cleanLanguagesDir("$dir/languages"); } $dir = "$dir/mod"; foreach (scandir($dir) as $entry) { if ($entry[0] === '.') { continue; } $path = "$dir/$entry"; if (is_dir("$path/languages")) { $this->cleanLanguagesDir("$path/languages"); } } } /** * Clean up a languages dir * * @param string $dir Languages dir * * @return void */ public function cleanLanguagesDir($dir) { $dir = rtrim($dir, '/\\'); foreach (scandir($dir) as $entry) { if ($entry[0] === '.') { continue; } if (pathinfo($entry, PATHINFO_EXTENSION) !== 'php') { continue; } $path = "$dir/$entry"; $code = basename($entry, '.php'); if (!in_array($code, $this->codes)) { $code = Translator::normalizeLanguageCode($code); if (in_array($code, $this->codes)) { // rename file to lowercase rename($path, "$dir/$code.php"); $this->log[] = "Renamed $path to $code.php"; continue; } unlink($path); $this->log[] = "Removed $path"; } } } }