-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathLanguageMultilingualismForm.class.php
More file actions
168 lines (142 loc) · 4.12 KB
/
LanguageMultilingualismForm.class.php
File metadata and controls
168 lines (142 loc) · 4.12 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
namespace wcf\acp\form;
use wcf\data\language\Language;
use wcf\data\language\LanguageEditor;
use wcf\form\AbstractForm;
use wcf\system\cache\eager\LanguageCache;
use wcf\system\exception\UserInputException;
use wcf\system\language\LanguageFactory;
use wcf\system\WCF;
use wcf\util\ArrayUtil;
/**
* Shows the language multilingualism form.
*
* @author Jean-Marc Licht
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
class LanguageMultilingualismForm extends AbstractForm
{
/**
* @inheritDoc
*/
public $activeMenuItem = 'wcf.acp.menu.link.language.multilingualism';
/**
* @inheritDoc
*/
public $neededPermissions = ['admin.language.canManageLanguage'];
/**
* indicates if multilingualism is enabled
* @var int
*/
public $enable = 0;
/**
* ids of selected available languages
* @var int[]
*/
public $languageIDs = [];
/**
* list of available content languages
* @var Language[]
*/
public $languages = [];
/**
* indicates that this page is only accessible to owners in enterprise mode
*/
const BLACKLISTED_IN_ENTERPRISE_MODE = true;
/**
* @inheritDoc
*/
public function readParameters()
{
parent::readParameters();
$this->languages = LanguageFactory::getInstance()->getLanguages();
}
/**
* @inheritDoc
*/
public function readFormParameters()
{
parent::readFormParameters();
if (isset($_POST['enable'])) {
$this->enable = \intval($_POST['enable']);
}
if (isset($_POST['languageIDs']) && \is_array($_POST['languageIDs'])) {
$this->languageIDs = ArrayUtil::toIntegerArray($_POST['languageIDs']);
}
}
/**
* @inheritDoc
*/
public function validate()
{
parent::validate();
if ($this->enable == 1) {
// add default language
if (!\in_array(LanguageFactory::getInstance()->getDefaultLanguageID(), $this->languageIDs)) {
$this->languageIDs[] = LanguageFactory::getInstance()->getDefaultLanguageID();
}
// validate language ids
$contentLanguages = 0;
foreach ($this->languageIDs as $languageID) {
if (isset($this->languages[$languageID])) {
$contentLanguages++;
}
}
if ($contentLanguages < 2) {
throw new UserInputException('languageIDs');
}
}
}
/**
* @inheritDoc
*/
public function save()
{
parent::save();
// save
LanguageEditor::enableMultilingualism(($this->enable == 1 ? $this->languageIDs : []));
// clear cache
(new LanguageCache())->rebuild();
$this->saved();
// show success message
WCF::getTPL()->assign('success', true);
}
/**
* @inheritDoc
*/
public function readData()
{
parent::readData();
if (empty($_POST)) {
// default values
$contentLanguages = 0;
foreach ($this->languages as $languageID => $language) {
if ($language->hasContent) {
$contentLanguages++;
$this->languageIDs[] = $languageID;
}
}
// add default language
if (!\in_array(LanguageFactory::getInstance()->getDefaultLanguageID(), $this->languageIDs)) {
$this->languageIDs[] = LanguageFactory::getInstance()->getDefaultLanguageID();
}
if ($contentLanguages > 1) {
$this->enable = 1;
}
}
}
/**
* @inheritDoc
*/
public function assignVariables()
{
parent::assignVariables();
WCF::getTPL()->assign([
'defaultLanguageID' => LanguageFactory::getInstance()->getDefaultLanguageID(),
'enable' => $this->enable,
'languageIDs' => $this->languageIDs,
'languages' => $this->languages,
]);
}
}