-
Notifications
You must be signed in to change notification settings - Fork 5
/
bootstrap.php
135 lines (99 loc) · 3.64 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
include(__DIR__.'/vendor/autoload.php');
$this->module("lokalize")->extend([
'languages' => function() {
static $languages;
if (is_null($languages)) {
$languages = [
'af' => 'Afrikaans',
'ar' => 'Arabic',
'bs' => 'Bosnian',
'zh' => 'Chinese',
'hr' => 'Croatian',
'da' => 'Danish',
'nl' => 'Dutch',
'en' => 'English',
'fi' => 'Finnish',
'fr' => 'French',
'de' => 'German',
'he' => 'Hebrew',
'hi' => 'Hindi',
'hu' => 'Hungarian',
'is' => 'Icelandic',
'it' => 'Italian',
'id' => 'Indonesian',
'ja' => 'Japanese',
'no' => 'Norwegian',
'pl' => 'Polish',
'pt' => 'Portuguese',
'ru' => 'Russian',
'es' => 'Spanish',
'sv' => 'Swedish',
'tr' => 'Turkish',
];
foreach ($this->app->retrieve('config/languages', []) as $code => $label) {
if (!isset($languages[$code])) {
$languages[$code] = $label;
}
}
foreach ($this->app->retrieve('config/lokalize/languages', []) as $code => $label) {
if (!isset($languages[$code])) {
$languages[$code] = $label;
}
}
}
return $languages;
},
'projects' => function() {
return $this->app->storage->find('lokalize/projects', [
'sort' => ['name' => 1]
])->toArray();
},
'project' => function($id) {
$project = $this->app->storage->findOne('lokalize/projects', [
'_id' => $id
]);
if ($project && $this->app->retrieve('config/lokalize/persistKeys') && $keyspath = $this->app->path("#storage:lokalize/keys/{$project['name']}.php")) {
$project['keys'] = array_merge(include($keyspath), $project['keys']);
}
return $project;
},
'saveProject' => function($project) {
$this->app->storage->save('lokalize/projects', $project);
if ($this->app->retrieve('config/lokalize/persistKeys')) {
$this->app->helper('fs')->write('#storage:lokalize/keys/'.$project['name'].'.php', "<?php\n return ".var_export($project['keys'], true).";");
}
return $project;
},
'removeProject' => function($project) {
$id = is_string($project) ? $project : $project['_id'];
if ($this->app->retrieve('config/lokalize/persistKeys') && isset($project['name'])) {
$this->app->helper('fs')->delete('#storage:lokalize/keys/'.$project['name'].'.php');
}
return $this->app->storage->remove('lokalize/projects', ['_id' => $id]);
}
]);
// CLI
if (COCKPIT_CLI) {
$this->path('#cli', __DIR__.'/cli');
}
// ACL
$app('acl')->addResource('lokalize', ['manage']);
// ADMIN
if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) {
include_once(__DIR__.'/admin.php');
}
// REST
if (COCKPIT_API_REQUEST) {
$app->on('cockpit.rest.init', function($routes) {
$routes['lokalize'] = 'Lokalize\\Controller\\RestApi';
});
// allow access to public collections
$app->on('cockpit.api.authenticate', function($data) {
if ($data['user'] || $data['resource'] != 'lokalize') return;
if ($this->retrieve('config/lokalize/publicAccess', false)) {
$data['authenticated'] = true;
$data['user'] = ['_id' => null, 'group' => 'public'];
}
});
}