1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Sites;
13
14 use Brickrouge\Element;
15 use Brickrouge\Form;
16 use Brickrouge\Text;
17 use Brickrouge\Widget;
18
19 class EditBlock extends \Icybee\EditBlock
20 {
21 protected function lazy_get_attributes()
22 {
23 return \ICanBoogie\array_merge_recursive
24 (
25 parent::lazy_get_attributes(), array
26 (
27 Element::GROUPS => array
28 (
29 'location' => array
30 (
31 'title' => 'Emplacement',
32 'class' => 'location'
33 ),
34
35 'i18n' => array
36 (
37 'title' => 'Internationalisation'
38 ),
39
40 'advanced' => array
41 (
42 'title' => 'Advanced parameters'
43 )
44 )
45 )
46 );
47 }
48
49 protected function lazy_get_children()
50 {
51 global $core;
52
53 $core->document->css->add(DIR . 'public/admin.css');
54
55 $languages = $core->locale['languages'];
56
57 asort($languages);
58
59 $tz = ini_get('date.timezone');
60
61
62
63 $placeholder_tld = null;
64 $placeholder_domain = null;
65 $placeholder_subdomain = null;
66
67 $parts = explode('.', $_SERVER['SERVER_NAME']);
68 $parts = array_reverse($parts);
69
70 $values = $this->values;
71
72 if (!$values['tld'] && isset($parts[0]))
73 {
74 $placeholder_tld = $parts[0];
75 }
76
77 if (!$values['domain'] && isset($parts[1]))
78 {
79 $placeholder_domain = $parts[1];
80 }
81
82 if (!$values['subdomain'] && isset($parts[2]))
83 {
84 $placeholder_subdomain = $parts[2];
85 }
86
87 return array_merge
88 (
89 parent::lazy_get_children(), array
90 (
91 'title' => new Text
92 (
93 array
94 (
95 Form::LABEL => 'Title',
96 Element::REQUIRED => true
97 )
98 ),
99
100 'admin_title' => new Text
101 (
102 array
103 (
104 Form::LABEL => 'Admin title',
105 Element::DESCRIPTION => "Il s'agit du titre utilisé par l'interface d'administration."
106 )
107 ),
108
109 'email' => new Text
110 (
111 array
112 (
113 Form::LABEL => 'Email',
114 Element::REQUIRED => true,
115 Element::VALIDATOR => array('Brickrouge\Form::validate_email'),
116 Element::DESCRIPTION => "The site's email is usually used as default sender email,
117 but can also be used as a contact address."
118 )
119 ),
120
121 'subdomain' => new Text
122 (
123 array
124 (
125 Form::LABEL => 'Sous-domaine',
126 Element::GROUP => 'location',
127
128 'size' => 16,
129 'placeholder' => $placeholder_subdomain
130 )
131 ),
132
133 'domain' => new Text
134 (
135 array
136 (
137 Form::LABEL => 'Domaine',
138 Text::ADDON => '.',
139 Text::ADDON_POSITION => 'before',
140 Element::GROUP => 'location',
141
142 'placeholder' => $placeholder_domain
143 )
144 ),
145
146 'tld' => new Text
147 (
148 array
149 (
150 Form::LABEL => 'TLD',
151 Text::ADDON => '.',
152 Text::ADDON_POSITION => 'before',
153 Element::GROUP => 'location',
154
155 'size' => 8,
156 'placeholder' => $placeholder_tld
157 )
158 ),
159
160 'path' => new Text
161 (
162 array
163 (
164 Form::LABEL => 'Chemin',
165 Text::ADDON => '/',
166 Text::ADDON_POSITION => 'before',
167 Element::GROUP => 'location',
168
169 'value' => trim($values['path'], '/')
170 )
171 ),
172
173 'language' => new Element
174 (
175 'select', array
176 (
177 Form::LABEL => 'Langue',
178 Element::REQUIRED => true,
179 Element::GROUP => 'i18n',
180 Element::OPTIONS => array(null => '') + $languages
181 )
182 ),
183
184 'nativeid' => $this->get_control_translation_sources($values),
185
186 'timezone' => new Widget\TimeZone
187 (
188 array
189 (
190 Form::LABEL => 'Fuseau horaire',
191 Element::GROUP => 'i18n',
192 Element::DESCRIPTION => "Par défaut, le fuseau horaire du serveur est
193 utilisé (actuellement : <q>" . ($tz ? $tz : 'non défini') . "</q>)."
194 )
195 ),
196
197 'status' => new Element
198 (
199 'select', array
200 (
201 Form::LABEL => 'Status',
202 Element::GROUP => 'advanced',
203 Element::OPTIONS => array
204 (
205 Site::STATUS_OK => 'Ok (online)',
206 Site::STATUS_UNAUTHORIZED => 'Unauthorized',
207 Site::STATUS_NOT_FOUND => 'Not found (offline)',
208 Site::STATUS_UNAVAILABLE => 'Unavailable'
209 )
210 )
211 )212 213 214 215 216 217 218 219 220 221
222 )
223 );
224 }
225
226 private function get_site_models()
227 {
228 $models = array();
229
230 $dh = opendir(\ICanBoogie\DOCUMENT_ROOT . 'protected');
231
232 while ($file = readdir($dh))
233 {
234 if ($file[0] == '.' || $file == 'all' || $file == 'default')
235 {
236 continue;
237 }
238
239 $models[] = $file;
240 }
241
242 if (!$models)
243 {
244 return $models;
245 }
246
247 sort($models);
248
249 return array_combine($models, $models);
250 }
251
252 protected function get_control_translation_sources(array $values)
253 {
254 $options = $this->module->model
255 ->select('siteid, concat(title, ":", language) title')
256 ->where('siteid != ?', (int) $values['siteid'])
257 ->pairs;
258
259 if (!$options)
260 {
261 return;
262 }
263
264 return new Element
265 (
266 'select', array
267 (
268 Form::LABEL => 'Traduction source',
269 Element::GROUP => 'i18n',
270 Element::OPTIONS => array(0 => '<none>') + $options
271 )
272 );
273 }
274 }