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