Elgg  Version 2.3
ReleaseCleaner.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\I18n;
3 
10 
14  private $codes;
15 
19  public $log = [];
20 
26  public function __construct(array $codes = []) {
27  if (!$codes) {
29  }
30  $this->codes = $codes;
31  }
32 
40  public function cleanInstallation($dir) {
41  $dir = rtrim($dir, '/\\');
42 
43  if (is_dir("$dir/languages")) {
44  $this->cleanLanguagesDir("$dir/languages");
45  }
46 
47  $dir = "$dir/mod";
48 
49  foreach (scandir($dir) as $entry) {
50  if ($entry[0] === '.') {
51  continue;
52  }
53 
54  $path = "$dir/$entry";
55 
56  if (is_dir("$path/languages")) {
57  $this->cleanLanguagesDir("$path/languages");
58  }
59  }
60  }
61 
69  public function cleanLanguagesDir($dir) {
70  $dir = rtrim($dir, '/\\');
71 
72  foreach (scandir($dir) as $entry) {
73  if ($entry[0] === '.') {
74  continue;
75  }
76 
77  if (pathinfo($entry, PATHINFO_EXTENSION) !== 'php') {
78  continue;
79  }
80 
81  $path = "$dir/$entry";
82 
83  $code = basename($entry, '.php');
84  if (!in_array($code, $this->codes)) {
86 
87  if (in_array($code, $this->codes)) {
88  // rename file to lowercase
89  rename($path, "$dir/$code.php");
90  $this->log[] = "Renamed $path to $code.php";
91  continue;
92  }
93 
94  unlink($path);
95  $this->log[] = "Removed $path";
96  }
97  }
98  }
99 }
Removes invalid language files from an installation.
static getAllLanguageCodes()
Returns an array of language codes.
Definition: Translator.php:551
cleanInstallation($dir)
Clean up within an installation.
$path
Definition: details.php:88
cleanLanguagesDir($dir)
Clean up a languages dir.
__construct(array $codes=[])
Constructor.
static normalizeLanguageCode($code)
Normalize a language code (e.g.
Definition: Translator.php:710