]> git.mxchange.org Git - friendica.git/blob - include/features.php
Merge remote-tracking branch 'upstream/develop' into 1607-performance
[friendica.git] / include / features.php
1 <?php
2
3 /**
4  * @file include/features.php
5  * @brief Features management
6  */
7
8 /**
9  * @brief check if feature is enabled
10  *
11  * @return boolean
12  */
13 function feature_enabled($uid, $feature) {
14
15         if (($feature == 'richtext') AND !get_app()->theme_richtext_editor) {
16                 return false;
17         }
18
19         $x = get_config('feature_lock', $feature);
20
21         if ($x === false) {
22                 $x = get_pconfig($uid, 'feature', $feature);
23                 if ($x === false) {
24                         $x = get_config('feature', $feature);
25                         if ($x === false) {
26                                 $x = get_feature_default($feature);
27                         }
28                 }
29         }
30
31         $arr = array('uid' => $uid, 'feature' => $feature, 'enabled' => $x);
32         call_hooks('feature_enabled',$arr);
33         return($arr['enabled']);
34 }
35
36 /**
37  * @brief check if feature is enabled or disabled by default
38  * 
39  * @param string $feature
40  * @return boolean
41  */
42 function get_feature_default($feature) {
43         $f = get_features();
44         foreach($f as $cat) {
45                 foreach($cat as $feat) {
46                         if(is_array($feat) && $feat[0] === $feature)
47                                 return $feat[3];
48                 }
49         }
50         return false;
51 }
52
53 /**
54  * @brief Get a list of all available features
55  * 
56  * The array includes the setting group, the setting name,
57  * explainations for the setting and if it's enabled or disabled
58  * by default
59  * 
60  * @param bool $filtered True removes any locked features
61  * 
62  * @return array
63  */
64 function get_features($filtered = true) {
65
66         $arr = array(
67
68                 // General
69                 'general' => array(
70                         t('General Features'),
71                         //array('expire',         t('Content Expiration'),              t('Remove old posts/comments after a period of time')),
72                         array('multi_profiles', t('Multiple Profiles'),                 t('Ability to create multiple profiles'), false, get_config('feature_lock','multi_profiles')),
73                         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, get_config('feature_lock','photo_location')),
74                         array('export_calendar', t('Export Public Calendar'),           t('Ability for visitors to download the public calendar'), false, get_config('feature_lock','export_calendar')),
75                 ),
76
77                 // Post composition
78                 'composition' => array(
79                         t('Post Composition Features'),
80                         array('richtext',       t('Richtext Editor'),                   t('Enable richtext editor'), false, get_config('feature_lock','richtext')),
81                         array('preview',        t('Post Preview'),                      t('Allow previewing posts and comments before publishing them'), false, get_config('feature_lock','preview')),
82                         array('aclautomention', t('Auto-mention Forums'),               t('Add/remove mention when a forum page is selected/deselected in ACL window.'), false, get_config('feature_lock','aclautomention')),
83                 ),
84
85                 // Network sidebar widgets
86                 'widgets' => array(
87                         t('Network Sidebar Widgets'),
88                         array('archives',       t('Search by Date'),                    t('Ability to select posts by date ranges'), false, get_config('feature_lock','archives')),
89                         array('forumlist_widget', t('List Forums'),                     t('Enable widget to display the forums your are connected with'), true, get_config('feature_lock','forumlist_widget')),
90                         array('groups',         t('Group Filter'),                      t('Enable widget to display Network posts only from selected group'), false, get_config('feature_lock','groups')),
91                         array('networks',       t('Network Filter'),                    t('Enable widget to display Network posts only from selected network'), false, get_config('feature_lock','networks')),
92                         array('savedsearch',    t('Saved Searches'),                    t('Save search terms for re-use'), false, get_config('feature_lock','savedsearch')),
93                 ),
94
95                 // Network tabs
96                 'net_tabs' => array(
97                         t('Network Tabs'),
98                         array('personal_tab',   t('Network Personal Tab'),              t('Enable tab to display only Network posts that you\'ve interacted on'), false, get_config('feature_lock','personal_tab')),
99                         array('new_tab',        t('Network New Tab'),                   t('Enable tab to display only new Network posts (from the last 12 hours)'), false, get_config('feature_lock','new_tab')),
100                         array('link_tab',       t('Network Shared Links Tab'),          t('Enable tab to display only Network posts with links in them'), false, get_config('feature_lock','link_tab')),
101                 ),
102
103                 // Item tools
104                 'tools' => array(
105                         t('Post/Comment Tools'),
106                         array('multi_delete',   t('Multiple Deletion'),                 t('Select and delete multiple posts/comments at once'), false, get_config('feature_lock','multi_delete')),
107                         array('edit_posts',     t('Edit Sent Posts'),                   t('Edit and correct posts and comments after sending'), false, get_config('feature_lock','edit_posts')),
108                         array('commtag',        t('Tagging'),                           t('Ability to tag existing posts'), false, get_config('feature_lock','commtag')),
109                         array('categories',     t('Post Categories'),                   t('Add categories to your posts'), false, get_config('feature_lock','categories')),
110                         array('filing',         t('Saved Folders'),                     t('Ability to file posts under folders'), false, get_config('feature_lock','filing')),
111                         array('dislike',        t('Dislike Posts'),                     t('Ability to dislike posts/comments'), false, get_config('feature_lock','dislike')),
112                         array('star_posts',     t('Star Posts'),                        t('Ability to mark special posts with a star indicator'), false, get_config('feature_lock','star_posts')),
113                         array('ignore_posts',   t('Mute Post Notifications'),           t('Ability to mute notifications for a thread'), false, get_config('feature_lock','ignore_posts')),
114                 ),
115
116                 // Advanced Profile Settings
117                 'advanced_profile' => array(
118                         t('Advanced Profile Settings'),
119                         array('forumlist_profile', t('List Forums'),                    t('Show visitors public community forums at the Advanced Profile Page'), false, get_config('feature_lock','forumlist_profile')),
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                                         }
134                                         else {
135                                                 unset($arr[$k][$y]);
136                                         }
137                                 }
138                         }
139                         if(! $has_items) {
140                                 unset($arr[$k]);
141                         }
142                 }
143         }
144
145         // Remove the richtext editor setting if the theme doesn't support it
146         if (!get_app()->theme_richtext_editor) {
147                 unset($arr['composition'][1]);
148         }
149
150         call_hooks('get_features',$arr);
151         return $arr;
152 }