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