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