3 * @copyright Copyright (C) 2010-2024, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Content;
24 use Friendica\Core\Hook;
29 const ACCOUNTS = 'accounts';
30 const ADD_ABSTRACT = 'add_abstract';
31 const ARCHIVE = 'archive';
32 const CATEGORIES = 'categories';
33 const CHANNELS = 'channels';
34 const CIRCLES = 'circles';
35 const COMMUNITY = 'community';
36 const EXPLICIT_MENTIONS = 'explicit_mentions';
37 const FOLDERS = 'folders';
38 const GROUPS = 'forumlist_profile';
39 const MEMBER_SINCE = 'profile_membersince';
40 const NETWORKS = 'networks';
41 const NOSHARER = 'nosharer';
42 const PHOTO_LOCATION = 'photo_location';
43 const PUBLIC_CALENDAR = 'public_calendar';
44 const SEARCHES = 'searches';
45 const TAGCLOUD = 'tagadelic';
46 const TRENDING_TAGS = 'trending_tags';
49 * check if feature is enabled
51 * @param integer $uid user id
52 * @param string $feature feature
54 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
56 public static function isEnabled(int $uid, $feature): bool
58 if (!DI::config()->get('feature_lock', $feature, false)) {
59 $enabled = DI::config()->get('feature', $feature) ?? self::getDefault($feature);
60 $enabled = DI::pConfig()->get($uid, 'feature', $feature) ?? $enabled;
65 $arr = ['uid' => $uid, 'feature' => $feature, 'enabled' => $enabled];
66 Hook::callAll('isEnabled', $arr);
67 return (bool)$arr['enabled'];
71 * check if feature is enabled or disabled by default
73 * @param string $feature feature
75 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
77 private static function getDefault($feature)
79 foreach (self::get() as $cat) {
80 foreach ($cat as $feat) {
81 if (is_array($feat) && $feat[0] === $feature) {
90 * Get a list of all available features
92 * The array includes the setting group, the setting name,
93 * explanations for the setting and if it's enabled or disabled
96 * @param bool $filtered True removes any locked features
99 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
101 public static function get($filtered = true)
107 DI::l10n()->t('General Features'),
108 //array('expire', DI::l10n()->t('Content Expiration'), DI::l10n()->t('Remove old posts/comments after a period of time')),
109 [self::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', self::PHOTO_LOCATION, false)],
110 [self::COMMUNITY, DI::l10n()->t('Display the community in the navigation'), DI::l10n()->t('If enabled, the community can be accessed via the navigation menu. Independant from this setting, the community timelines can always be accessed via the channels.'), true, DI::config()->get('feature_lock', self::COMMUNITY, false)],
115 DI::l10n()->t('Post Composition Features'),
116 [self::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', Feature::EXPLICIT_MENTIONS, false)],
117 [self::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', self::ADD_ABSTRACT, false)],
122 DI::l10n()->t('Post/Comment Tools'),
123 [self::CATEGORIES, DI::l10n()->t('Post Categories'), DI::l10n()->t('Add categories to your posts'), false, DI::config()->get('feature_lock', self::CATEGORIES, false)],
126 // Widget visibility on the network stream
128 DI::l10n()->t('Network Widgets'),
129 [self::CIRCLES, DI::l10n()->t('Circles'), DI::l10n()->t('Display posts that have been created by accounts of the selected circle.'), true, DI::config()->get('feature_lock', self::CIRCLES, false)],
130 [self::GROUPS, DI::l10n()->t('Groups'), DI::l10n()->t('Display posts that have been distributed by the selected group.'), true, DI::config()->get('feature_lock', self::GROUPS, false)],
131 [self::ARCHIVE, DI::l10n()->t('Archives'), DI::l10n()->t('Display an archive where posts can be selected by month and year.'), true, DI::config()->get('feature_lock', self::ARCHIVE, false)],
132 [self::NETWORKS, DI::l10n()->t('Protocols'), DI::l10n()->t('Display posts with the selected protocols.'), true, DI::config()->get('feature_lock', self::NETWORKS, false)],
133 [self::ACCOUNTS, DI::l10n()->t('Account Types'), DI::l10n()->t('Display posts done by accounts with the selected account type.'), true, DI::config()->get('feature_lock', self::ACCOUNTS, false)],
134 [self::CHANNELS, DI::l10n()->t('Channels'), DI::l10n()->t('Display posts in the system channels and user defined channels.'), true, DI::config()->get('feature_lock', self::CHANNELS, false)],
135 [self::SEARCHES, DI::l10n()->t('Saved Searches'), DI::l10n()->t('Display posts that contain subscribed hashtags.'), true, DI::config()->get('feature_lock', self::SEARCHES, false)],
136 [self::FOLDERS, DI::l10n()->t('Saved Folders'), DI::l10n()->t('Display a list of folders in which posts are stored.'), true, DI::config()->get('feature_lock', self::FOLDERS, false)],
137 [self::NOSHARER, DI::l10n()->t('Own Contacts'), DI::l10n()->t('Include or exclude posts from subscribed accounts. This widget is not visible on all channels.'), true, DI::config()->get('feature_lock', self::NOSHARER, false)],
138 [self::TRENDING_TAGS, DI::l10n()->t('Trending Tags'), DI::l10n()->t('Display a list of the most popular tags in recent public posts.'), false, DI::config()->get('feature_lock', self::TRENDING_TAGS, false)],
141 // Advanced Profile Settings
142 'advanced_profile' => [
143 DI::l10n()->t('Advanced Profile Settings'),
144 [self::TAGCLOUD, DI::l10n()->t('Tag Cloud'), DI::l10n()->t('Provide a personal tag cloud on your profile page'), false, DI::config()->get('feature_lock', self::TAGCLOUD, false)],
145 [self::MEMBER_SINCE, DI::l10n()->t('Display Membership Date'), DI::l10n()->t('Display membership date in profile'), false, DI::config()->get('feature_lock', self::MEMBER_SINCE, false)],
148 //Advanced Calendar Settings
149 'advanced_calendar' => [
150 DI::l10n()->t('Advanced Calendar Settings'),
151 [self::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', self::PUBLIC_CALENDAR, false)],
155 // removed any locked features and remove the entire category if this makes it empty
158 foreach ($arr as $k => $x) {
160 $kquantity = count($arr[$k]);
161 for ($y = 0; $y < $kquantity; $y ++) {
162 if (is_array($arr[$k][$y])) {
163 if ($arr[$k][$y][4] === false) {
176 Hook::callAll('get', $arr);