]> git.mxchange.org Git - friendica.git/blob - src/Content/Feature.php
Remove require
[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\Addon;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11
12 class Feature
13 {
14         /**
15          * @brief check if feature is enabled
16          *
17          * @param integer $uid     user id
18          * @param string  $feature feature
19          * @return boolean
20          */
21         public static function isEnabled($uid, $feature)
22         {
23                 $x = Config::get('feature_lock', $feature, false);
24
25                 if ($x === false) {
26                         $x = PConfig::get($uid, 'feature', $feature, false);
27                 }
28
29                 if ($x === false) {
30                         $x = 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                 Addon::callHooks('isEnabled', $arr);
39                 return($arr['enabled']);
40         }
41
42         /**
43          * @brief check if feature is enabled or disabled by default
44          *
45          * @param string $feature feature
46          * @return boolean
47          */
48         private static function getDefault($feature)
49         {
50                 $f = self::get();
51                 foreach ($f as $cat) {
52                         foreach ($cat as $feat) {
53                                 if (is_array($feat) && $feat[0] === $feature) {
54                                         return $feat[3];
55                                 }
56                         }
57                 }
58                 return false;
59         }
60
61         /**
62          * @brief Get a list of all available features
63          *
64          * The array includes the setting group, the setting name,
65          * explainations for the setting and if it's enabled or disabled
66          * by default
67          *
68          * @param bool $filtered True removes any locked features
69          *
70          * @return array
71          */
72         public static function get($filtered = true)
73         {
74                 $arr = [
75
76                         // General
77                         'general' => [
78                                 t('General Features'),
79                                 //array('expire',         t('Content Expiration'),              t('Remove old posts/comments after a period of time')),
80                                 ['multi_profiles', t('Multiple Profiles'),                      t('Ability to create multiple profiles'), false, Config::get('feature_lock', 'multi_profiles', false)],
81                                 ['photo_location', t('Photo Location'),                 t('Photo metadata is normally stripped. This extracts the location (if present) prior to stripping metadata and links it to a map.'), false, Config::get('feature_lock', 'photo_location', false)],
82                                 ['export_calendar', t('Export Public Calendar'),                t('Ability for visitors to download the public calendar'), false, Config::get('feature_lock', 'export_calendar', false)],
83                         ],
84
85                         // Post composition
86                         'composition' => [
87                                 t('Post Composition Features'),
88                                 ['preview',     t('Post Preview'),                      t('Allow previewing posts and comments before publishing them'), false, Config::get('feature_lock', 'preview', false)],
89                                 ['aclautomention',      t('Auto-mention Forums'),               t('Add/remove mention when a forum page is selected/deselected in ACL window.'), false, Config::get('feature_lock', 'aclautomention', false)],
90                         ],
91
92                         // Network sidebar widgets
93                         'widgets' => [
94                                 t('Network Sidebar Widgets'),
95                                 ['archives',    t('Search by Date'),                    t('Ability to select posts by date ranges'), false, Config::get('feature_lock', 'archives', false)],
96                                 ['forumlist_widget', t('List Forums'),                  t('Enable widget to display the forums your are connected with'), true, Config::get('feature_lock', 'forumlist_widget', false)],
97                                 ['groups',              t('Group Filter'),                      t('Enable widget to display Network posts only from selected group'), false, Config::get('feature_lock', 'groups', false)],
98                                 ['networks',    t('Network Filter'),                    t('Enable widget to display Network posts only from selected network'), false, Config::get('feature_lock', 'networks', false)],
99                                 ['savedsearch', t('Saved Searches'),                    t('Save search terms for re-use'), false, Config::get('feature_lock', 'savedsearch', false)],
100                         ],
101
102                         // Network tabs
103                         'net_tabs' => [
104                                 t('Network Tabs'),
105                                 ['personal_tab',        t('Network Personal Tab'),              t('Enable tab to display only Network posts that you\'ve interacted on'), false, Config::get('feature_lock', 'personal_tab', false)],
106                                 ['new_tab',     t('Network New Tab'),                   t('Enable tab to display only new Network posts (from the last 12 hours)'), false, Config::get('feature_lock', 'new_tab', false)],
107                                 ['link_tab',    t('Network Shared Links Tab'),          t('Enable tab to display only Network posts with links in them'), false, Config::get('feature_lock', 'link_tab', false)],
108                         ],
109
110                         // Item tools
111                         'tools' => [
112                                 t('Post/Comment Tools'),
113                                 ['multi_delete',        t('Multiple Deletion'),                 t('Select and delete multiple posts/comments at once'), false, Config::get('feature_lock', 'multi_delete', false)],
114                                 ['edit_posts',  t('Edit Sent Posts'),                   t('Edit and correct posts and comments after sending'), false, Config::get('feature_lock', 'edit_posts', false)],
115                                 ['commtag',     t('Tagging'),                           t('Ability to tag existing posts'), false, Config::get('feature_lock', 'commtag', false)],
116                                 ['categories',  t('Post Categories'),                   t('Add categories to your posts'), false, Config::get('feature_lock', 'categories', false)],
117                                 ['filing',              t('Saved Folders'),                     t('Ability to file posts under folders'), false, Config::get('feature_lock', 'filing', false)],
118                                 ['dislike',     t('Dislike Posts'),                     t('Ability to dislike posts/comments'), false, Config::get('feature_lock', 'dislike', false)],
119                                 ['star_posts',  t('Star Posts'),                        t('Ability to mark special posts with a star indicator'), false, Config::get('feature_lock', 'star_posts', false)],
120                                 ['ignore_posts',        t('Mute Post Notifications'),           t('Ability to mute notifications for a thread'), false, Config::get('feature_lock', 'ignore_posts', false)],
121                         ],
122
123                         // Advanced Profile Settings
124                         'advanced_profile' => [
125                                 t('Advanced Profile Settings'),
126                                 ['forumlist_profile', t('List Forums'),                 t('Show visitors public community forums at the Advanced Profile Page'), false, Config::get('feature_lock', 'forumlist_profile', false)],
127                                 ['tagadelic',   t('Tag Cloud'),                         t('Provide a personal tag cloud on your profile page'), false, Config::get('feature_lock', 'tagadelic', false)],
128                         ],
129                 ];
130
131                 // removed any locked features and remove the entire category if this makes it empty
132
133                 if ($filtered) {
134                         foreach ($arr as $k => $x) {
135                                 $has_items = false;
136                                 $kquantity = count($arr[$k]);
137                                 for ($y = 0; $y < $kquantity; $y ++) {
138                                         if (is_array($arr[$k][$y])) {
139                                                 if ($arr[$k][$y][4] === false) {
140                                                         $has_items = true;
141                                                 } else {
142                                                         unset($arr[$k][$y]);
143                                                 }
144                                         }
145                                 }
146                                 if (! $has_items) {
147                                         unset($arr[$k]);
148                                 }
149                         }
150                 }
151
152                 Addon::callHooks('get', $arr);
153                 return $arr;
154         }
155 }