]> git.mxchange.org Git - friendica.git/blob - src/Content/Features.php
Features to src
[friendica.git] / src / Content / Features.php
1 <?php
2 /**
3  * @file src/Content/Features.php
4  * @brief Features management
5  */
6 namespace Friendica\Content;
7
8 use Friendica\Core\Config;
9 use Friendica\Core\PConfig;
10
11 class Features
12 {
13         /**
14          * @brief check if feature is enabled
15          *
16          * @return boolean
17          */
18         public static function isEnabled($uid, $feature)
19         {
20                 $x = Config::get('feature_lock', $feature, false);
21
22                 if ($x === false) {
23                         $x = PConfig::get($uid, 'feature', $feature, false);
24                 }
25                 if ($x === false) {
26                         $x = Config::get('feature', $feature, false);
27                 }
28                 if ($x === false) {
29                         $x = self::getDefault($feature);
30                 }
31
32                 $arr = array('uid' => $uid, 'feature' => $feature, 'enabled' => $x);
33                 call_hooks('isEnabled',$arr);
34                 return($arr['enabled']);
35         }
36
37         /**
38          * @brief check if feature is enabled or disabled by default
39          *
40          * @param string $feature
41          * @return boolean
42          */
43         private static function getDefault($feature) {
44                 $f = self::get();
45                 foreach ($f as $cat) {
46                         foreach ($cat as $feat) {
47                                 if (is_array($feat) && $feat[0] === $feature)
48                                         return $feat[3];
49                         }
50                 }
51                 return false;
52         }
53
54         /**
55          * @brief Get a list of all available features
56          *
57          * The array includes the setting group, the setting name,
58          * explainations for the setting and if it's enabled or disabled
59          * by default
60          *
61          * @param bool $filtered True removes any locked features
62          *
63          * @return array
64          */
65         public static function get($filtered = true) {
66
67                 $arr = array(
68
69                         // General
70                         'general' => array(
71                                 t('General Features'),
72                                 //array('expire',         t('Content Expiration'),              t('Remove old posts/comments after a period of time')),
73                                 array('multi_profiles', t('Multiple Profiles'),                 t('Ability to create multiple profiles'), false, Config::get('feature_lock','multi_profiles', false)),
74                                 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)),
75                                 array('export_calendar', t('Export Public Calendar'),           t('Ability for visitors to download the public calendar'), false, Config::get('feature_lock','export_calendar', false)),
76                         ),
77
78                         // Post composition
79                         'composition' => array(
80                                 t('Post Composition Features'),
81                                 array('preview',        t('Post Preview'),                      t('Allow previewing posts and comments before publishing them'), false, Config::get('feature_lock','preview', false)),
82                                 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)),
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, Config::get('feature_lock','archives', false)),
89                                 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)),
90                                 array('groups',         t('Group Filter'),                      t('Enable widget to display Network posts only from selected group'), false, Config::get('feature_lock','groups', false)),
91                                 array('networks',       t('Network Filter'),                    t('Enable widget to display Network posts only from selected network'), false, Config::get('feature_lock','networks', false)),
92                                 array('savedsearch',    t('Saved Searches'),                    t('Save search terms for re-use'), false, Config::get('feature_lock','savedsearch', false)),
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, Config::get('feature_lock','personal_tab', false)),
99                                 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)),
100                                 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)),
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, Config::get('feature_lock','multi_delete', false)),
107                                 array('edit_posts',     t('Edit Sent Posts'),                   t('Edit and correct posts and comments after sending'), false, Config::get('feature_lock','edit_posts', false)),
108                                 array('commtag',        t('Tagging'),                           t('Ability to tag existing posts'), false, Config::get('feature_lock','commtag', false)),
109                                 array('categories',     t('Post Categories'),                   t('Add categories to your posts'), false, Config::get('feature_lock','categories', false)),
110                                 array('filing',         t('Saved Folders'),                     t('Ability to file posts under folders'), false, Config::get('feature_lock','filing', false)),
111                                 array('dislike',        t('Dislike Posts'),                     t('Ability to dislike posts/comments'), false, Config::get('feature_lock','dislike', false)),
112                                 array('star_posts',     t('Star Posts'),                        t('Ability to mark special posts with a star indicator'), false, Config::get('feature_lock','star_posts', false)),
113                                 array('ignore_posts',   t('Mute Post Notifications'),           t('Ability to mute notifications for a thread'), false, Config::get('feature_lock','ignore_posts', false)),
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, Config::get('feature_lock','forumlist_profile', false)),
120                                 array('tagadelic',      t('Tag Cloud'),                         t('Provide a personal tag cloud on your profile page'), false, Config::get('feature_lock', 'tagadelic', false)),
121                         ),
122                 );
123
124                 // removed any locked features and remove the entire category if this makes it empty
125
126                 if ($filtered) {
127                         foreach ($arr as $k => $x) {
128                                 $has_items = false;
129                                 $kquantity = count($arr[$k]);
130                                 for ($y = 0; $y < $kquantity; $y ++) {
131                                         if (is_array($arr[$k][$y])) {
132                                                 if ($arr[$k][$y][4] === false) {
133                                                         $has_items = true;
134                                                 } else {
135                                                         unset($arr[$k][$y]);
136                                                 }
137                                         }
138                                 }
139                                 if (! $has_items) {
140                                         unset($arr[$k]);
141                                 }
142                         }
143                 }
144
145                 call_hooks('get',$arr);
146                 return $arr;
147         }
148 }