]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Features.php
Added type hints
[friendica.git] / src / Module / Admin / Features.php
1 <?php
2
3 namespace Friendica\Module\Admin;
4
5 use Friendica\Content\Feature;
6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Renderer;
9 use Friendica\DI;
10 use Friendica\Module\BaseAdminModule;
11
12 class Features extends BaseAdminModule
13 {
14         public static function post(array $parameters = [])
15         {
16                 parent::post($parameters);
17
18                 parent::checkFormSecurityTokenRedirectOnError('/admin/features', 'admin_manage_features');
19
20                 $features = Feature::get(false);
21
22                 foreach ($features as $fname => $fdata) {
23                         foreach (array_slice($fdata, 1) as $f) {
24                                 $feature = $f[0];
25                                 $feature_state = 'feature_' . $feature;
26                                 $featurelock = 'featurelock_' . $feature;
27
28                                 if (!empty($_POST[$feature_state])) {
29                                         $val = intval($_POST[$feature_state]);
30                                 } else {
31                                         $val = 0;
32                                 }
33                                 Config::set('feature', $feature, $val);
34
35                                 if (!empty($_POST[$featurelock])) {
36                                         Config::set('feature_lock', $feature, $val);
37                                 } else {
38                                         Config::delete('feature_lock', $feature);
39                                 }
40                         }
41                 }
42
43                 DI::baseUrl()->redirect('admin/features');
44         }
45
46         public static function content(array $parameters = [])
47         {
48                 parent::content($parameters);
49
50                 $arr = [];
51                 $features = Feature::get(false);
52
53                 foreach ($features as $fname => $fdata) {
54                         $arr[$fname] = [];
55                         $arr[$fname][0] = $fdata[0];
56                         foreach (array_slice($fdata, 1) as $f) {
57                                 $set = Config::get('feature', $f[0], $f[3]);
58                                 $arr[$fname][1][] = [
59                                         ['feature_' . $f[0], $f[1], $set, $f[2], [L10n::t('Off'), L10n::t('On')]],
60                                         ['featurelock_' . $f[0], L10n::t('Lock feature %s', $f[1]), (($f[4] !== false) ? "1" : ''), '', [L10n::t('Off'), L10n::t('On')]]
61                                 ];
62                         }
63                 }
64
65                 $tpl = Renderer::getMarkupTemplate('admin/features.tpl');
66                 $o = Renderer::replaceMacros($tpl, [
67                         '$form_security_token' => parent::getFormSecurityToken("admin_manage_features"),
68                         '$title' => L10n::t('Manage Additional Features'),
69                         '$features' => $arr,
70                         '$submit' => L10n::t('Save Settings'),
71                 ]);
72
73                 return $o;
74         }
75 }