]> git.mxchange.org Git - friendica.git/blob - src/Content/Feature.php
Fix namespace issue with posix function in Worker\Repository\Process
[friendica.git] / src / Content / Feature.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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          * explanations 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                                 ['add_abstract', DI::l10n()->t('Add an abstract from ActivityPub content warnings'), DI::l10n()->t('Add an abstract when commenting on ActivityPub posts with a content warning. Abstracts are displayed as content warning on systems like Mastodon or Pleroma.'), false, DI::config()->get('feature_lock', 'add_abstract', false)],
108                         ],
109
110                         // Item tools
111                         'tools' => [
112                                 DI::l10n()->t('Post/Comment Tools'),
113                                 ['categories',   DI::l10n()->t('Post Categories'),         DI::l10n()->t('Add categories to your posts'), false, DI::config()->get('feature_lock', 'categories', false)],
114                         ],
115
116                         // Advanced Profile Settings
117                         'advanced_profile' => [
118                                 DI::l10n()->t('Advanced Profile Settings'),
119                                 ['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)],
120                                 ['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)],
121                                 ['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)],
122                         ],
123
124                         //Advanced Calendar Settings
125                         'advanced_calendar' => [
126                                 DI::l10n()->t('Advanced Calendar Settings'),
127                                 ['public_calendar',     DI::l10n()->t('Allow anonymous access to your calendar'), DI::l10n()->t('Allows anonymous visitors to consult your calendar and your public events. Contact birthday events are private to you.'), false, DI::config()->get('feature_lock', 'public_calendar', 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                 Hook::callAll('get', $arr);
153                 return $arr;
154         }
155 }