]> git.mxchange.org Git - friendica.git/blob - src/Content/Feature.php
Rename to singular
[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\PConfig;
10
11 require_once 'include/plugin.php';
12
13 class Feature
14 {
15         /**
16          * @brief check if feature is enabled
17          *
18          * @return boolean
19          */
20         public static function isEnabled($uid, $feature)
21         {
22                 $x = Config::get('feature_lock', $feature, false);
23
24                 if ($x === false) {
25                         $x = PConfig::get($uid, 'feature', $feature, false);
26                 }
27                 if ($x === false) {
28                         $x = Config::get('feature', $feature, false);
29                 }
30                 if ($x === false) {
31                         $x = self::getDefault($feature);
32                 }
33
34                 $arr = array('uid' => $uid, 'feature' => $feature, 'enabled' => $x);
35                 call_hooks('isEnabled',$arr);
36                 return($arr['enabled']);
37         }
38
39         /**
40          * @brief check if feature is enabled or disabled by default
41          *
42          * @param string $feature
43          * @return boolean
44          */
45         private static function getDefault($feature)
46         {
47                 $f = self::get();
48                 foreach ($f as $cat) {
49                         foreach ($cat as $feat) {
50                                 if (is_array($feat) && $feat[0] === $feature)
51                                         return $feat[3];
52                         }
53                 }
54                 return false;
55         }
56
57         /**
58          * @brief Get a list of all available features
59          *
60          * The array includes the setting group, the setting name,
61          * explainations for the setting and if it's enabled or disabled
62          * by default
63          *
64          * @param bool $filtered True removes any locked features
65          *
66          * @return array
67          */
68         public static function get($filtered = true)
69         {
70                 $arr = array(
71
72                         // General
73                         'general' => array(
74                                 t('General Features'),
75                                 //array('expire',         t('Content Expiration'),              t('Remove old posts/comments after a period of time')),
76                                 array('multi_profiles', t('Multiple Profiles'),                 t('Ability to create multiple profiles'), false, Config::get('feature_lock','multi_profiles', false)),
77                                 array('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)),
78                                 array('export_calendar', t('Export Public Calendar'),           t('Ability for visitors to download the public calendar'), false, Config::get('feature_lock','export_calendar', false)),
79                         ),
80
81                         // Post composition
82                         'composition' => array(
83                                 t('Post Composition Features'),
84                                 array('preview',        t('Post Preview'),                      t('Allow previewing posts and comments before publishing them'), false, Config::get('feature_lock','preview', false)),
85                                 array('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)),
86                         ),
87
88                         // Network sidebar widgets
89                         'widgets' => array(
90                                 t('Network Sidebar Widgets'),
91                                 array('archives',       t('Search by Date'),                    t('Ability to select posts by date ranges'), false, Config::get('feature_lock','archives', false)),
92                                 array('forumlist_widget', t('List Forums'),                     t('Enable widget to display the forums your are connected with'), true, Config::get('feature_lock','forumlist_widget', false)),
93                                 array('groups',         t('Group Filter'),                      t('Enable widget to display Network posts only from selected group'), false, Config::get('feature_lock','groups', false)),
94                                 array('networks',       t('Network Filter'),                    t('Enable widget to display Network posts only from selected network'), false, Config::get('feature_lock','networks', false)),
95                                 array('savedsearch',    t('Saved Searches'),                    t('Save search terms for re-use'), false, Config::get('feature_lock','savedsearch', false)),
96                         ),
97
98                         // Network tabs
99                         'net_tabs' => array(
100                                 t('Network Tabs'),
101                                 array('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)),
102                                 array('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)),
103                                 array('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)),
104                         ),
105
106                         // Item tools
107                         'tools' => array(
108                                 t('Post/Comment Tools'),
109                                 array('multi_delete',   t('Multiple Deletion'),                 t('Select and delete multiple posts/comments at once'), false, Config::get('feature_lock','multi_delete', false)),
110                                 array('edit_posts',     t('Edit Sent Posts'),                   t('Edit and correct posts and comments after sending'), false, Config::get('feature_lock','edit_posts', false)),
111                                 array('commtag',        t('Tagging'),                           t('Ability to tag existing posts'), false, Config::get('feature_lock','commtag', false)),
112                                 array('categories',     t('Post Categories'),                   t('Add categories to your posts'), false, Config::get('feature_lock','categories', false)),
113                                 array('filing',         t('Saved Folders'),                     t('Ability to file posts under folders'), false, Config::get('feature_lock','filing', false)),
114                                 array('dislike',        t('Dislike Posts'),                     t('Ability to dislike posts/comments'), false, Config::get('feature_lock','dislike', false)),
115                                 array('star_posts',     t('Star Posts'),                        t('Ability to mark special posts with a star indicator'), false, Config::get('feature_lock','star_posts', false)),
116                                 array('ignore_posts',   t('Mute Post Notifications'),           t('Ability to mute notifications for a thread'), false, Config::get('feature_lock','ignore_posts', false)),
117                         ),
118
119                         // Advanced Profile Settings
120                         'advanced_profile' => array(
121                                 t('Advanced Profile Settings'),
122                                 array('forumlist_profile', t('List Forums'),                    t('Show visitors public community forums at the Advanced Profile Page'), false, Config::get('feature_lock','forumlist_profile', false)),
123                                 array('tagadelic',      t('Tag Cloud'),                         t('Provide a personal tag cloud on your profile page'), false, Config::get('feature_lock', 'tagadelic', 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                 call_hooks('get', $arr);
149                 return $arr;
150         }
151 }