]> git.mxchange.org Git - friendica.git/blob - src/Content/Feature.php
Move PConfig::get() to DI::pConfig()->get()
[friendica.git] / src / Content / Feature.php
1 <?php
2 /**
3  * @file src/Content/Feature.php
4  * @brief Features management
5  */
6 namespace Friendica\Content;
7
8 use Friendica\Core\Config;
9 use Friendica\Core\Hook;
10 use Friendica\Core\L10n;
11 use Friendica\Core\PConfig;
12 use Friendica\DI;
13
14 class Feature
15 {
16         /**
17          * @brief check if feature is enabled
18          *
19          * @param integer $uid     user id
20          * @param string  $feature feature
21          * @return boolean
22          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
23          */
24         public static function isEnabled(int $uid, $feature)
25         {
26                 $x = Config::get('feature_lock', $feature, false);
27
28                 if ($x === false) {
29                         $x = DI::pConfig()->get($uid, 'feature', $feature, false);
30                 }
31
32                 if ($x === false) {
33                         $x = Config::get('feature', $feature, false);
34                 }
35
36                 if ($x === false) {
37                         $x = self::getDefault($feature);
38                 }
39
40                 $arr = ['uid' => $uid, 'feature' => $feature, 'enabled' => $x];
41                 Hook::callAll('isEnabled', $arr);
42                 return($arr['enabled']);
43         }
44
45         /**
46          * @brief check if feature is enabled or disabled by default
47          *
48          * @param string $feature feature
49          * @return boolean
50          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
51          */
52         private static function getDefault($feature)
53         {
54                 $f = self::get();
55                 foreach ($f as $cat) {
56                         foreach ($cat as $feat) {
57                                 if (is_array($feat) && $feat[0] === $feature) {
58                                         return $feat[3];
59                                 }
60                         }
61                 }
62                 return false;
63         }
64
65         /**
66          * @brief Get a list of all available features
67          *
68          * The array includes the setting group, the setting name,
69          * explainations for the setting and if it's enabled or disabled
70          * by default
71          *
72          * @param bool $filtered True removes any locked features
73          *
74          * @return array
75          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
76          */
77         public static function get($filtered = true)
78         {
79                 $arr = [
80
81                         // General
82                         'general' => [
83                                 L10n::t('General Features'),
84                                 //array('expire',         L10n::t('Content Expiration'),                L10n::t('Remove old posts/comments after a period of time')),
85                                 ['multi_profiles',  L10n::t('Multiple Profiles'),      L10n::t('Ability to create multiple profiles'), false, Config::get('feature_lock', 'multi_profiles', false)],
86                                 ['photo_location',  L10n::t('Photo Location'),         L10n::t("Photo metadata is normally stripped. This extracts the location \x28if present\x29 prior to stripping metadata and links it to a map."), false, Config::get('feature_lock', 'photo_location', false)],
87                                 ['export_calendar', L10n::t('Export Public Calendar'), L10n::t('Ability for visitors to download the public calendar'), false, Config::get('feature_lock', 'export_calendar', false)],
88                                 ['trending_tags',   L10n::t('Trending Tags'),          L10n::t('Show a community page widget with a list of the most popular tags in recent public posts.'), false, Config::get('feature_lock', 'trending_tags', false)],
89                         ],
90
91                         // Post composition
92                         'composition' => [
93                                 L10n::t('Post Composition Features'),
94                                 ['aclautomention', L10n::t('Auto-mention Forums'), L10n::t('Add/remove mention when a forum page is selected/deselected in ACL window.'), false, Config::get('feature_lock', 'aclautomention', false)],
95                                 ['explicit_mentions', L10n::t('Explicit Mentions'), L10n::t('Add explicit mentions to comment box for manual control over who gets mentioned in replies.'), false, Config::get('feature_lock', 'explicit_mentions', false)],
96                         ],
97
98                         // Network sidebar widgets
99                         'widgets' => [
100                                 L10n::t('Network Sidebar'),
101                                 ['archives',         L10n::t('Archives'), L10n::t('Ability to select posts by date ranges'), false, Config::get('feature_lock', 'archives', false)],
102                                 ['networks',         L10n::t('Protocol Filter'), L10n::t('Enable widget to display Network posts only from selected protocols'), false, Config::get('feature_lock', 'networks', false)],
103                         ],
104
105                         // Network tabs
106                         'net_tabs' => [
107                                 L10n::t('Network Tabs'),
108                                 ['new_tab',      L10n::t('Network New Tab'),          L10n::t("Enable tab to display only new Network posts \x28from the last 12 hours\x29"), false, Config::get('feature_lock', 'new_tab', false)],
109                                 ['link_tab',     L10n::t('Network Shared Links Tab'), L10n::t('Enable tab to display only Network posts with links in them'), false, Config::get('feature_lock', 'link_tab', false)],
110                         ],
111
112                         // Item tools
113                         'tools' => [
114                                 L10n::t('Post/Comment Tools'),
115                                 ['categories',   L10n::t('Post Categories'),         L10n::t('Add categories to your posts'), false, Config::get('feature_lock', 'categories', false)],
116                         ],
117
118                         // Advanced Profile Settings
119                         'advanced_profile' => [
120                                 L10n::t('Advanced Profile Settings'),
121                                 ['forumlist_profile',   L10n::t('List Forums'),             L10n::t('Show visitors public community forums at the Advanced Profile Page'), false, Config::get('feature_lock', 'forumlist_profile', false)],
122                                 ['tagadelic',           L10n::t('Tag Cloud'),               L10n::t('Provide a personal tag cloud on your profile page'), false, Config::get('feature_lock', 'tagadelic', false)],
123                                 ['profile_membersince', L10n::t('Display Membership Date'), L10n::t('Display membership date in profile'), false, Config::get('feature_lock', 'profile_membersince', false)],
124                         ],
125                 ];
126
127                 // removed any locked features and remove the entire category if this makes it empty
128
129                 if ($filtered) {
130                         foreach ($arr as $k => $x) {
131                                 $has_items = false;
132                                 $kquantity = count($arr[$k]);
133                                 for ($y = 0; $y < $kquantity; $y ++) {
134                                         if (is_array($arr[$k][$y])) {
135                                                 if ($arr[$k][$y][4] === false) {
136                                                         $has_items = true;
137                                                 } else {
138                                                         unset($arr[$k][$y]);
139                                                 }
140                                         }
141                                 }
142                                 if (! $has_items) {
143                                         unset($arr[$k]);
144                                 }
145                         }
146                 }
147
148                 Hook::callAll('get', $arr);
149                 return $arr;
150         }
151 }