Passed
Push — dependabot/composer/doctrine/d... ( bc1a80...bcc5a8 )
by
unknown
47:19 queued 41:28
created

Index   C

Complexity

Total Complexity 53

Size/Duplication

Total Lines 662
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 390
c 2
b 0
f 0
dl 0
loc 662
rs 6.96
wmc 53

5 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 18 1
A parseWarnings() 0 7 1
F validateForm() 0 321 33
F loadForm() 0 264 14
A parse() 0 20 4

How to fix   Complexity   

Complex Class

Complex classes like Index often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Index, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Backend\Modules\Settings\Actions;
4
5
use TijsVerkoyen\Akismet\Akismet;
6
use Backend\Core\Engine\Base\ActionIndex as BackendBaseActionIndex;
7
use Backend\Core\Engine\Form as BackendForm;
8
use Backend\Core\Language\Language as BL;
9
use Backend\Core\Engine\Model as BackendModel;
10
use Backend\Modules\Extensions\Engine\Model as BackendExtensionsModel;
11
use Backend\Modules\Settings\Engine\Model as BackendSettingsModel;
12
13
/**
14
 * This is the index-action (default), it will display the setting-overview
15
 */
16
class Index extends BackendBaseActionIndex
17
{
18
    /**
19
     * The form instance
20
     *
21
     * @var BackendForm
22
     */
23
    private $form;
24
25
    /**
26
     * Should we show boxes for their API keys
27
     *
28
     * @var bool
29
     */
30
    private $needsAkismet;
31
    private $needsGoogleMaps;
32
    private $needsGoogleRecaptcha;
33
34
    public function execute(): void
35
    {
36
        parent::execute();
37
38
        // get some data
39
        $modulesThatRequireAkismet = BackendExtensionsModel::getModulesThatRequireAkismet();
40
        $modulesThatRequireGoogleMaps = BackendExtensionsModel::getModulesThatRequireGoogleMaps();
41
        $modulesThatRequireGoogleRecaptcha = BackendExtensionsModel::getModulesThatRequireGoogleRecaptcha();
42
43
        // set properties
44
        $this->needsAkismet = (!empty($modulesThatRequireAkismet));
45
        $this->needsGoogleMaps = (!empty($modulesThatRequireGoogleMaps));
46
        $this->needsGoogleRecaptcha = !empty($modulesThatRequireGoogleRecaptcha);
47
48
        $this->loadForm();
49
        $this->validateForm();
50
        $this->parse();
51
        $this->display();
52
    }
53
54
    private function loadForm(): void
55
    {
56
        // list of default domains
57
        $defaultDomains = [str_replace(['http://', 'www.', 'https://'], '', SITE_URL)];
58
59
        // create form
60
        $this->form = new BackendForm('settingsIndex');
61
62
        // general settings
63
        $this->form->addText(
64
            'site_title',
65
            $this->get('fork.settings')->get('Core', 'site_title_' . BL::getWorkingLanguage(), SITE_DEFAULT_TITLE)
66
        );
67
68
        // Google tracking settings
69
        $googleTrackingAnalyticsTrackingId = $this->get('fork.settings')->get(
70
            'Core',
71
            'google_tracking_google_analytics_tracking_id',
72
            $this->get('fork.settings')->get('Analytics', 'web_property_id', '')
73
        );
74
        $this->form->addCheckbox(
75
            'google_tracking_google_analytics_tracking_id_enabled',
76
            ($googleTrackingAnalyticsTrackingId !== '')
77
        );
78
        $googleTrackingAnalyticsTrackingIdField = $this->form->addText(
79
            'google_tracking_google_analytics_tracking_id',
80
            $googleTrackingAnalyticsTrackingId
81
        );
82
        if ($googleTrackingAnalyticsTrackingId === '') {
83
            $googleTrackingAnalyticsTrackingIdField->setAttribute('disabled', 'disabled');
84
        }
85
86
        $googleTrackingTagManagerContainerId = $this->get('fork.settings')->get(
87
            'Core',
88
            'google_tracking_google_tag_manager_container_id',
89
            ''
90
        );
91
        $this->form->addCheckbox(
92
            'google_tracking_google_tag_manager_container_id_enabled',
93
            ($googleTrackingTagManagerContainerId !== '')
94
        );
95
        $googleTrackingTagManagerContainerIdField = $this->form->addText(
96
            'google_tracking_google_tag_manager_container_id',
97
            $googleTrackingTagManagerContainerId
98
        );
99
        if ($googleTrackingTagManagerContainerId === '') {
100
            $googleTrackingTagManagerContainerIdField->setAttribute('disabled', 'disabled');
101
        }
102
103
        // @deprecated fallback to site_html_header as this was used in the past.
104
        $siteHtmlHeadValue = $this->get('fork.settings')->get(
105
            'Core',
106
            'site_html_head',
107
            $this->get('fork.settings')->get('Core', 'site_html_header', null)
108
        );
109
        $this->form->addTextarea(
110
            'site_html_head',
111
            $siteHtmlHeadValue,
112
            'form-control code',
113
            'form-control danger code',
114
            true
115
        );
116
        $siteHtmlStartOfBodyValue = $this->get('fork.settings')->get(
117
            'Core',
118
            'site_html_start_of_body',
119
            $this->get('fork.settings')->get('Core', 'site_start_of_body_scripts', null)
120
        );
121
        $this->form->addTextarea(
122
            'site_html_start_of_body',
123
            $siteHtmlStartOfBodyValue,
124
            'form-control code',
125
            'form-control danger code',
126
            true
127
        );
128
        $siteHtmlEndOfBodyValue = $this->get('fork.settings')->get(
129
            'Core',
130
            'site_html_end_of_body',
131
            $this->get('fork.settings')->get('Core', 'site_html_footer', null)
132
        );
133
        $this->form->addTextarea(
134
            'site_html_end_of_body',
135
            $siteHtmlEndOfBodyValue,
136
            'form-control code',
137
            'form-control danger code',
138
            true
139
        );
140
        $this->form->addTextarea(
141
            'site_domains',
142
            implode("\n", (array) $this->get('fork.settings')->get('Core', 'site_domains', $defaultDomains)),
143
            'form-control code',
144
            'form-control danger code'
145
        );
146
147
        // facebook settings
148
        // @deprecated remove this in Fork 6, facebook_admin_ids / facebook_app_id / facebook_app_secret should be removed
149
        $this->form->addText('facebook_admin_ids', $this->get('fork.settings')->get('Core', 'facebook_admin_ids', null));
150
        $this->form->addText('facebook_application_id', $this->get('fork.settings')->get('Core', 'facebook_app_id', null));
151
        $this->form->addText(
152
            'facebook_application_secret',
153
            $this->get('fork.settings')->get('Core', 'facebook_app_secret', null)
154
        );
155
156
        // twitter settings
157
        $this->form->addText(
158
            'twitter_site_name',
159
            ltrim($this->get('fork.settings')->get('Core', 'twitter_site_name', null), '@')
160
        );
161
162
        // ckfinder
163
        $this->form->addText(
164
            'ckfinder_license_name',
165
            $this->get('fork.settings')->get('Core', 'ckfinder_license_name', null)
166
        );
167
        $this->form->addText(
168
            'ckfinder_license_key',
169
            $this->get('fork.settings')->get('Core', 'ckfinder_license_key', null)
170
        );
171
        $this->form->addText(
172
            'ckfinder_image_max_width',
173
            $this->get('fork.settings')->get('Core', 'ckfinder_image_max_width', 1600)
174
        );
175
        $this->form->addText(
176
            'ckfinder_image_max_height',
177
            $this->get('fork.settings')->get('Core', 'ckfinder_image_max_height', 1200)
178
        );
179
180
        // date & time formats
181
        $this->form->addDropdown(
182
            'time_format',
183
            BackendModel::getTimeFormats(),
184
            $this->get('fork.settings')->get('Core', 'time_format')
185
        );
186
        $this->form->addDropdown(
187
            'date_format_short',
188
            BackendModel::getDateFormatsShort(),
189
            $this->get('fork.settings')->get('Core', 'date_format_short')
190
        );
191
        $this->form->addDropdown(
192
            'date_format_long',
193
            BackendModel::getDateFormatsLong(),
194
            $this->get('fork.settings')->get('Core', 'date_format_long')
195
        );
196
197
        // number formats
198
        $this->form->addDropdown(
199
            'number_format',
200
            BackendModel::getNumberFormats(),
201
            $this->get('fork.settings')->get('Core', 'number_format')
202
        );
203
204
        $activeLanguages = [];
205
        $redirectLanguages = [];
206
207
        // create a list of the languages
208
        foreach ($this->get('fork.settings')->get('Core', 'languages', ['en']) as $abbreviation) {
209
            // is this the default language
210
            $defaultLanguage = $abbreviation === SITE_DEFAULT_LANGUAGE;
211
212
            // attributes
213
            $activeAttributes = [];
214
            $activeAttributes['id'] = 'active_language_' . $abbreviation;
215
            $redirectAttributes = [];
216
            $redirectAttributes['id'] = 'redirect_language_' . $abbreviation;
217
218
            // fetch label
219
            $label = BL::lbl(mb_strtoupper($abbreviation), 'Core');
220
221
            // default may not be unselected
222
            if ($defaultLanguage) {
223
                // add to attributes
224
                $activeAttributes['disabled'] = 'disabled';
225
                $redirectAttributes['disabled'] = 'disabled';
226
227
                // overrule in $_POST
228
                if (!isset($_POST['active_languages']) || !is_array($_POST['active_languages'])) {
229
                    $_POST['active_languages'] = [SITE_DEFAULT_LANGUAGE];
230
                } elseif (!in_array(
231
                    $abbreviation,
232
                    $_POST['active_languages']
233
                )
234
                ) {
235
                    $_POST['active_languages'][] = $abbreviation;
236
                }
237
                if (!isset($_POST['redirect_languages']) || !is_array($_POST['redirect_languages'])) {
238
                    $_POST['redirect_languages'] = [SITE_DEFAULT_LANGUAGE];
239
                } elseif (!in_array(
240
                    $abbreviation,
241
                    $_POST['redirect_languages']
242
                )
243
                ) {
244
                    $_POST['redirect_languages'][] = $abbreviation;
245
                }
246
            }
247
248
            // add to the list
249
            $activeLanguages[] = [
250
                'label' => $label,
251
                'value' => $abbreviation,
252
                'attributes' => $activeAttributes,
253
                'variables' => ['default' => $defaultLanguage],
254
            ];
255
            $redirectLanguages[] = [
256
                'label' => $label,
257
                'value' => $abbreviation,
258
                'attributes' => $redirectAttributes,
259
                'variables' => ['default' => $defaultLanguage],
260
            ];
261
        }
262
263
        $hasMultipleLanguages = BackendModel::getContainer()->getParameter('site.multilanguage');
264
265
        // create multilanguage checkbox
266
        $this->form->addMultiCheckbox(
267
            'active_languages',
268
            $activeLanguages,
269
            $this->get('fork.settings')->get('Core', 'active_languages', [$hasMultipleLanguages])
270
        );
271
        $this->form->addMultiCheckbox(
272
            'redirect_languages',
273
            $redirectLanguages,
274
            $this->get('fork.settings')->get('Core', 'redirect_languages', [$hasMultipleLanguages])
275
        );
276
277
        // api keys are not required for every module
278
        if ($this->needsAkismet) {
279
            $this->form->addText(
280
                'akismet_key',
281
                $this->get('fork.settings')->get('Core', 'akismet_key', null)
282
            );
283
        }
284
        if ($this->needsGoogleMaps) {
285
            $this->form->addText(
286
                'google_maps_key',
287
                $this->get('fork.settings')->get('Core', 'google_maps_key', null)
288
            );
289
        }
290
        if ($this->needsGoogleRecaptcha) {
291
            $this->form->addText(
292
                'google_recaptcha_site_key',
293
                $this->get('fork.settings')->get('Core', 'google_recaptcha_site_key', null)
294
            );
295
            $this->form->addText(
296
                'google_recaptcha_secret_key',
297
                $this->get('fork.settings')->get('Core', 'google_recaptcha_secret_key', null)
298
            );
299
        }
300
301
        // cookies
302
        // @deprecated remove this in Fork 6, the privacy consent dialog should be used
303
        $this->form->addCheckbox('show_cookie_bar', $this->get('fork.settings')->get('Core', 'show_cookie_bar', false));
304
305
        // privacy
306
        $this->form->addCheckbox(
307
            'show_consent_dialog',
308
            $this->get('fork.settings')->get('Core', 'show_consent_dialog', false)
309
        );
310
        $this->form->addText(
311
            'privacy_consent_levels',
312
            implode(
313
                ',',
314
                $this->get('fork.settings')->get(
315
                    'Core',
316
                    'privacy_consent_levels',
317
                    []
318
                )
319
            )
320
        );
321
    }
322
323
    protected function parse(): void
324
    {
325
        parent::parse();
326
327
        // show options
328
        if ($this->needsAkismet) {
329
            $this->template->assign('needsAkismet', true);
330
        }
331
        if ($this->needsGoogleMaps) {
332
            $this->template->assign('needsGoogleMaps', true);
333
        }
334
        if ($this->needsGoogleRecaptcha) {
335
            $this->template->assign('needsGoogleRecaptcha', true);
336
        }
337
338
        // parse the form
339
        $this->form->parse($this->template);
340
341
        // parse the warnings
342
        $this->parseWarnings();
343
    }
344
345
    /**
346
     * Show the warnings based on the active modules & configured settings
347
     */
348
    private function parseWarnings(): void
349
    {
350
        // get warnings
351
        $warnings = BackendSettingsModel::getWarnings();
352
353
        // assign warnings
354
        $this->template->assign('warnings', $warnings);
355
    }
356
357
    private function validateForm(): void
358
    {
359
        // is the form submitted?
360
        if ($this->form->isSubmitted()) {
361
            // validate required fields
362
            $this->form->getField('site_title')->isFilled(BL::err('FieldIsRequired'));
363
364
            // Google Tracking options
365
            if ($this->form->getField('google_tracking_google_analytics_tracking_id_enabled')->getChecked()) {
366
                $this->form->getField('google_tracking_google_analytics_tracking_id')->isFilled(
367
                    BL::err('FieldIsRequired')
368
                );
369
            }
370
            if ($this->form->getField('google_tracking_google_tag_manager_container_id_enabled')->getChecked()) {
371
                $this->form->getField('google_tracking_google_tag_manager_container_id')->isFilled(
372
                    BL::err('FieldIsRequired')
373
                );
374
            }
375
376
            // date & time
377
            $this->form->getField('time_format')->isFilled(BL::err('FieldIsRequired'));
378
            $this->form->getField('date_format_short')->isFilled(BL::err('FieldIsRequired'));
379
            $this->form->getField('date_format_long')->isFilled(BL::err('FieldIsRequired'));
380
381
            // number
382
            $this->form->getField('number_format')->isFilled(BL::err('FieldIsRequired'));
383
384
            // akismet key may be filled in
385
            if ($this->needsAkismet && $this->form->getField('akismet_key')->isFilled()) {
386
                // key has changed
387
                if ($this->form->getField('akismet_key')->getValue() != $this->get('fork.settings')->get('Core', 'akismet_key', null)) {
388
                    // create instance
389
                    $akismet = new Akismet($this->form->getField('akismet_key')->getValue(), SITE_URL);
390
391
                    // invalid key
392
                    if (!$akismet->verifyKey()) {
393
                        $this->form->getField('akismet_key')->setError(BL::err('InvalidAPIKey'));
394
                    }
395
                }
396
            }
397
398
            // domains filled in
399
            if ($this->form->getField('site_domains')->isFilled()) {
400
                // split on newlines
401
                $domains = explode("\n", trim($this->form->getField('site_domains')->getValue()));
402
403
                // loop domains
404
                foreach ($domains as $domain) {
405
                    // strip funky stuff
406
                    $domain = trim(str_replace(['www.', 'http://', 'https://'], '', $domain));
407
408
                    // invalid URL
409
                    if (!\SpoonFilter::isURL('http://' . $domain)) {
410
                        // set error
411
                        $this->form->getField('site_domains')->setError(BL::err('InvalidDomain'));
412
413
                        // stop looping domains
414
                        break;
415
                    }
416
                }
417
            }
418
419
            if ($this->form->getField('ckfinder_image_max_width')->isFilled()) {
420
                $this->form->getField(
421
                    'ckfinder_image_max_width'
422
                )->isInteger(BL::err('InvalidInteger'));
423
            }
424
            if ($this->form->getField('ckfinder_image_max_height')->isFilled()) {
425
                $this->form->getField(
426
                    'ckfinder_image_max_height'
427
                )->isInteger(BL::err('InvalidInteger'));
428
            }
429
430
            $privacyConsentLevelsField = $this->form->getField('privacy_consent_levels');
431
            if ($privacyConsentLevelsField->isFilled()) {
432
                $levels = explode(',', $privacyConsentLevelsField->getValue());
433
                foreach ($levels as $level) {
434
                    if (!preg_match('/^[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]*$/i', $level)) {
435
                        $privacyConsentLevelsField->setError(sprintf(BL::err('InvalidVariableName'), $level));
436
                        break;
437
                    }
438
                }
439
            }
440
441
442
            // no errors ?
443
            if ($this->form->isCorrect()) {
444
                // general settings
445
                $this->get('fork.settings')->set(
446
                    'Core',
447
                    'site_title_' . BL::getWorkingLanguage(),
448
                    $this->form->getField('site_title')->getValue()
449
                );
450
451
                if ($this->form->getField('google_tracking_google_analytics_tracking_id_enabled')->isChecked()) {
452
                    $googleTrackingAnalyticsTrackingId = $this->form->getField('google_tracking_google_analytics_tracking_id')->getValue();
453
                } else {
454
                    $googleTrackingAnalyticsTrackingId = '';
455
                }
456
                $this->get('fork.settings')->set(
457
                    'Core',
458
                    'google_tracking_google_analytics_tracking_id',
459
                    $googleTrackingAnalyticsTrackingId
460
                );
461
462
                if ($this->form->getField('google_tracking_google_tag_manager_container_id_enabled')->isChecked()) {
463
                    $googleTrackingTagManagerContainerId = $this->form->getField('google_tracking_google_tag_manager_container_id')->getValue();
464
                } else {
465
                    $googleTrackingTagManagerContainerId = '';
466
                }
467
                $this->get('fork.settings')->set(
468
                    'Core',
469
                    'google_tracking_google_tag_manager_container_id',
470
                    $googleTrackingTagManagerContainerId
471
                );
472
473
                $this->get('fork.settings')->set(
474
                    'Core',
475
                    'site_html_head',
476
                    $this->form->getField('site_html_head')->getValue()
477
                );
478
                $this->get('fork.settings')->set(
479
                    'Core',
480
                    'site_html_start_of_body',
481
                    $this->form->getField('site_html_start_of_body')->getValue()
482
                );
483
                // @deprecated remove this in Fork 6, use site_html_start_of_body
484
                $this->get('fork.settings')->set(
485
                    'Core',
486
                    'site_start_of_body_scripts',
487
                    $this->form->getField('site_html_start_of_body')->getValue()
488
                );
489
                $this->get('fork.settings')->set(
490
                    'Core',
491
                    'site_html_end_of_body',
492
                    $this->form->getField('site_html_end_of_body')->getValue()
493
                );
494
                // @deprecated remove this in Fork 6, use site_html_end_of_body
495
                $this->get('fork.settings')->set(
496
                    'Core',
497
                    'site_html_footer',
498
                    $this->form->getField('site_html_end_of_body')->getValue()
499
                );
500
501
                // facebook settings
502
                $this->get('fork.settings')->set(
503
                    'Core',
504
                    'facebook_admin_ids',
505
                    ($this->form->getField('facebook_admin_ids')->isFilled()) ? $this->form->getField(
506
                        'facebook_admin_ids'
507
                    )->getValue() : null
508
                );
509
                $this->get('fork.settings')->set(
510
                    'Core',
511
                    'facebook_app_id',
512
                    ($this->form->getField('facebook_application_id')->isFilled()) ? $this->form->getField(
513
                        'facebook_application_id'
514
                    )->getValue() : null
515
                );
516
                $this->get('fork.settings')->set(
517
                    'Core',
518
                    'facebook_app_secret',
519
                    ($this->form->getField('facebook_application_secret')->isFilled()) ? $this->form->getField(
520
                        'facebook_application_secret'
521
                    )->getValue() : null
522
                );
523
524
                // twitter settings
525
                /** @var \SpoonFormText $txtTwitterSiteName */
526
                $txtTwitterSiteName = $this->form->getField('twitter_site_name');
527
                if ($txtTwitterSiteName->isFilled()) {
528
                    $this->get('fork.settings')->set(
529
                        'Core',
530
                        'twitter_site_name',
531
                        '@' . ltrim($txtTwitterSiteName->getValue(), '@')
532
                    );
533
                }
534
535
                // ckfinder settings
536
                $this->get('fork.settings')->set(
537
                    'Core',
538
                    'ckfinder_license_name',
539
                    ($this->form->getField('ckfinder_license_name')->isFilled()) ? $this->form->getField(
540
                        'ckfinder_license_name'
541
                    )->getValue() : null
542
                );
543
                $this->get('fork.settings')->set(
544
                    'Core',
545
                    'ckfinder_license_key',
546
                    ($this->form->getField('ckfinder_license_key')->isFilled()) ? $this->form->getField(
547
                        'ckfinder_license_key'
548
                    )->getValue() : null
549
                );
550
                $this->get('fork.settings')->set(
551
                    'Core',
552
                    'ckfinder_image_max_width',
553
                    ($this->form->getField('ckfinder_image_max_width')->isFilled()) ? $this->form->getField(
554
                        'ckfinder_image_max_width'
555
                    )->getValue() : 1600
556
                );
557
                $this->get('fork.settings')->set(
558
                    'Core',
559
                    'ckfinder_image_max_height',
560
                    ($this->form->getField('ckfinder_image_max_height')->isFilled()) ? $this->form->getField(
561
                        'ckfinder_image_max_height'
562
                    )->getValue() : 1200
563
                );
564
565
                // api keys
566
                if ($this->needsAkismet) {
567
                    $this->get('fork.settings')->set(
568
                        'Core',
569
                        'akismet_key',
570
                        $this->form->getField('akismet_key')->getValue()
571
                    );
572
                }
573
                if ($this->needsGoogleMaps) {
574
                    $this->get('fork.settings')->set(
575
                        'Core',
576
                        'google_maps_key',
577
                        $this->form->getField('google_maps_key')->getValue()
578
                    );
579
                }
580
                if ($this->needsGoogleRecaptcha) {
581
                    $this->get('fork.settings')->set(
582
                        'Core',
583
                        'google_recaptcha_site_key',
584
                        $this->form->getField('google_recaptcha_site_key')->getValue()
585
                    );
586
                    $this->get('fork.settings')->set(
587
                        'Core',
588
                        'google_recaptcha_secret_key',
589
                        $this->form->getField('google_recaptcha_secret_key')->getValue()
590
                    );
591
                }
592
593
                // date & time formats
594
                $this->get('fork.settings')->set(
595
                    'Core',
596
                    'time_format',
597
                    $this->form->getField('time_format')->getValue()
598
                );
599
                $this->get('fork.settings')->set(
600
                    'Core',
601
                    'date_format_short',
602
                    $this->form->getField('date_format_short')->getValue()
603
                );
604
                $this->get('fork.settings')->set(
605
                    'Core',
606
                    'date_format_long',
607
                    $this->form->getField('date_format_long')->getValue()
608
                );
609
610
                // date & time formats
611
                $this->get('fork.settings')->set(
612
                    'Core',
613
                    'number_format',
614
                    $this->form->getField('number_format')->getValue()
615
                );
616
617
                // before we save the languages, we need to ensure that each language actually exists and may be chosen.
618
                $languages = [SITE_DEFAULT_LANGUAGE];
619
                $activeLanguages = array_unique(
620
                    array_merge($languages, $this->form->getField('active_languages')->getValue())
621
                );
622
                $redirectLanguages = array_unique(
623
                    array_merge($languages, $this->form->getField('redirect_languages')->getValue())
624
                );
625
626
                // cleanup redirect-languages, by removing the values that aren't present in the active languages
627
                $redirectLanguages = array_intersect($redirectLanguages, $activeLanguages);
628
629
                // save active languages
630
                $this->get('fork.settings')->set('Core', 'active_languages', $activeLanguages);
631
                $this->get('fork.settings')->set('Core', 'redirect_languages', $redirectLanguages);
632
633
                // domains may not contain www, http or https. Therefor we must loop and create the list of domains.
634
                $siteDomains = [];
635
636
                // domains filled in
637
                if ($this->form->getField('site_domains')->isFilled()) {
638
                    // split on newlines
639
                    $domains = explode("\n", trim($this->form->getField('site_domains')->getValue()));
640
641
                    // loop domains
642
                    foreach ($domains as $domain) {
643
                        // strip funky stuff
644
                        $siteDomains[] = trim(str_replace(['www.', 'http://', 'https://'], '', $domain));
645
                    }
646
                }
647
648
                // save domains
649
                $this->get('fork.settings')->set('Core', 'site_domains', $siteDomains);
650
651
                // cookies
652
                // @deprecated remove this in Fork 6, the privacy consent dialog should be used
653
                $this->get('fork.settings')->set(
654
                    'Core',
655
                    'show_cookie_bar',
656
                    $this->form->getField('show_cookie_bar')->getChecked()
657
                );
658
659
                // privacy
660
                $this->get('fork.settings')->set(
661
                    'Core',
662
                    'show_consent_dialog',
663
                    $this->form->getField('show_consent_dialog')->getChecked()
664
                );
665
                $privacyConsentLevels = [];
666
                if ($privacyConsentLevelsField->isFilled()) {
667
                    $privacyConsentLevels = explode(',', $privacyConsentLevelsField->getValue());
668
                }
669
                $this->get('fork.settings')->set(
670
                    'Core',
671
                    'privacy_consent_levels',
672
                    $privacyConsentLevels
673
                );
674
675
                // assign report
676
                $this->template->assign('report', true);
677
                $this->template->assign('reportMessage', BL::msg('Saved'));
678
            }
679
        }
680
    }
681
}
682