]> git.mxchange.org Git - friendica.git/blob - src/Content/Feature.php
Merge pull request #11265 from k-alin/6606-k-alin-mysql-unix-socket
[friendica.git] / src / Content / Feature.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Content;
23
24 use Friendica\Core\Hook;
25 use Friendica\DI;
26
27 class Feature
28 {
29         /**
30          * check if feature is enabled
31          *
32          * @param integer $uid     user id
33          * @param string  $feature feature
34          * @return boolean
35          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
36          */
37         public static function isEnabled(int $uid, $feature)
38         {
39                 $x = DI::config()->get('feature_lock', $feature, false);
40
41                 if ($x === false) {
42                         $x = DI::pConfig()->get($uid, 'feature', $feature, false);
43                 }
44
45                 if ($x === false) {
46                         $x = DI::config()->get('feature', $feature, false);
47                 }
48
49                 if ($x === false) {
50                         $x = self::getDefault($feature);
51                 }
52
53                 $arr = ['uid' => $uid, 'feature' => $feature, 'enabled' => $x];
54                 Hook::callAll('isEnabled', $arr);
55                 return($arr['enabled']);
56         }
57
58         /**
59          * check if feature is enabled or disabled by default
60          *
61          * @param string $feature feature
62          * @return boolean
63          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
64          */
65         private static function getDefault($feature)
66         {
67                 $f = self::get();
68                 foreach ($f as $cat) {
69                         foreach ($cat as $feat) {
70                                 if (is_array($feat) && $feat[0] === $feature) {
71                                         return $feat[3];
72                                 }
73                         }
74                 }
75                 return false;
76         }
77
78         /**
79          * Get a list of all available features
80          *
81          * The array includes the setting group, the setting name,
82          * explainations for the setting and if it's enabled or disabled
83          * by default
84          *
85          * @param bool $filtered True removes any locked features
86          *
87          * @return array
88          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
89          */
90         public static function get($filtered = true)
91         {
92                 $arr = [
93
94                         // General
95                         'general' => [
96                                 DI::l10n()->t('General Features'),
97                                 //array('expire',         DI::l10n()->t('Content Expiration'),          DI::l10n()->t('Remove old posts/comments after a period of time')),
98                                 ['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)],
99                                 ['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)],
100                         ],
101
102                         // Post composition
103                         'composition' => [
104                                 DI::l10n()->t('Post Composition Features'),
105                                 ['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)],
106                                 ['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)],
107                         ],
108
109                         // Item tools
110                         'tools' => [
111                                 DI::l10n()->t('Post/Comment Tools'),
112                                 ['categories',   DI::l10n()->t('Post Categories'),         DI::l10n()->t('Add categories to your posts'), false, DI::config()->get('feature_lock', 'categories', false)],
113                         ],
114
115                         // Advanced Profile Settings
116                         'advanced_profile' => [
117                                 DI::l10n()->t('Advanced Profile Settings'),
118                                 ['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)],
119                                 ['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)],
120                                 ['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)],
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                 Hook::callAll('get', $arr);
146                 return $arr;
147         }
148 }