-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
executable file
·120 lines (115 loc) · 4.86 KB
/
index.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
<?php
Kirby::plugin('flokosiol/translations', [
'sections' => [
'translations' => [
'props' => [
'deletable' => function (bool $deletable = true) {
return $deletable;
},
'revertable' => function (bool $revertable = true) {
return $revertable;
}
],
'computed' => [
'id' => function () {
return $this->model()->id();
},
'translations' => function () {
$translatedContent = [];
if ($translations = $this->model()->translations()) {
foreach ($translations as $translation) {
if ($translation->exists() && $translation->code() != kirby()->defaultLanguage()->code()) {
$translatedContent[] = $translation->code();
}
}
}
return $translatedContent;
}
]
]
],
'api' => [
'routes' => [
[
'pattern' => 'flokosiol/translations/delete',
'method' => 'POST',
'action' => function () {
$id = get('id');
$languageCode = get('languageCode');
if (kirby()->defaultLanguage()->code() == $languageCode) {
return [
'code' => 403,
'text' => 'Default language textfile can not be deleted.'
];
}
if ($page = page($id)) {
$fileName = $page->contentFileName($languageCode) . '.' . $languageCode . '.' . $page->contentFileExtension();
$filePath = $page->root() . DS .$fileName;
if (F::exists($filePath)) {
if (F::remove($filePath)) {
return [
'code' => 200,
'text' => 'Textfile ' . str::upper($languageCode) . ' deleted.'
];
}
else {
return [
'code' => 500,
'text' => 'Textfile ' . $filePath . ' could not be removed.'
];
}
}
else {
return [
'code' => 404,
'text' => 'Textfile ' . $filePath . ' does not exist.'
];
}
}
return [
'code' => 404,
'text' => 'Page not found'
];
}
],
[
'pattern' => 'flokosiol/translations/revert',
'method' => 'POST',
'action' => function () {
$id = get('id');
$languageCode = get('languageCode');
$defaultLanguageCode = kirby()->defaultLanguage()->code();
if ($languageCode == $defaultLanguageCode) {
return [
'code' => 403,
'text' => 'Default language textfile can not be deleted.'
];
}
if ($page = page($id)) {
$data = $page->readContent($defaultLanguageCode);
if ($page->save($data, $languageCode, true)) {
return [
'code' => 200,
'text' => $languageCode . ' reverted.'
];
}
}
return [
'code' => 500,
'text' => $languageCode . ' could not be reverted.'
];
}
]
]
],
'translations' => [
'en' => [
'flokosiol.translations.delete.confirm' => 'Do you really want to delete the content of this language ({code})?',
'flokosiol.translations.revert.confirm' => 'Do you really want to revert the content to the current state of the default language?',
],
'de' => [
'flokosiol.translations.delete.confirm' => 'Möchtest Du wirklich den Inhalt dieser Sprache ({code}) löschen?',
'flokosiol.translations.revert.confirm' => 'Möchtest Du wirklich den Inhalt auf den aktuellen Stand der Standardsprache zurücksetzen?',
]
]
]);