Merge pull request #14038 from annando/feature-constants

Constants for features
This commit is contained in:
Hypolite Petovan 2024-03-24 19:37:39 +00:00 committed by GitHub
commit b21604a720
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 273 additions and 274 deletions

View file

@ -388,7 +388,7 @@ class Conversation
'$title' => $x['title'] ?? '', '$title' => $x['title'] ?? '',
'$placeholdertitle' => $this->l10n->t('Set title'), '$placeholdertitle' => $this->l10n->t('Set title'),
'$category' => $x['category'] ?? '', '$category' => $x['category'] ?? '',
'$placeholdercategory' => Feature::isEnabled($this->session->getLocalUserId(), 'categories') ? $this->l10n->t("Categories \x28comma-separated list\x29") : '', '$placeholdercategory' => Feature::isEnabled($this->session->getLocalUserId(), Feature::CATEGORIES) ? $this->l10n->t("Categories \x28comma-separated list\x29") : '',
'$scheduled_at' => Temporal::getDateTimeField( '$scheduled_at' => Temporal::getDateTimeField(
new \DateTime(), new \DateTime(),
new \DateTime('now + 6 months'), new \DateTime('now + 6 months'),

View file

@ -26,6 +26,16 @@ use Friendica\DI;
class Feature class Feature
{ {
const ADD_ABSTRACT = 'add_abstract';
const CATEGORIES = 'categories';
const EXPLICIT_MENTIONS = 'explicit_mentions';
const GROUPS = 'forumlist_profile';
const MEMBER_SINCE = 'profile_membersince';
const PHOTO_LOCATION = 'photo_location';
const PUBLIC_CALENDAR = 'public_calendar';
const TAGCLOUD = 'tagadelic';
const TRENDING_TAGS = 'trending_tags';
/** /**
* check if feature is enabled * check if feature is enabled
* *
@ -34,7 +44,7 @@ class Feature
* @return boolean * @return boolean
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function isEnabled(int $uid, $feature) public static function isEnabled(int $uid, $feature): bool
{ {
$x = DI::config()->get('feature_lock', $feature, false); $x = DI::config()->get('feature_lock', $feature, false);
@ -52,7 +62,7 @@ class Feature
$arr = ['uid' => $uid, 'feature' => $feature, 'enabled' => $x]; $arr = ['uid' => $uid, 'feature' => $feature, 'enabled' => $x];
Hook::callAll('isEnabled', $arr); Hook::callAll('isEnabled', $arr);
return($arr['enabled']); return (bool)$arr['enabled'];
} }
/** /**
@ -95,36 +105,35 @@ class Feature
'general' => [ 'general' => [
DI::l10n()->t('General Features'), DI::l10n()->t('General Features'),
//array('expire', DI::l10n()->t('Content Expiration'), DI::l10n()->t('Remove old posts/comments after a period of time')), //array('expire', DI::l10n()->t('Content Expiration'), DI::l10n()->t('Remove old posts/comments after a period of time')),
['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)], [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)],
['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)], [self::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', self::TRENDING_TAGS, false)],
], ],
// Post composition // Post composition
'composition' => [ 'composition' => [
DI::l10n()->t('Post Composition Features'), DI::l10n()->t('Post Composition Features'),
['aclautomention', DI::l10n()->t('Auto-mention Groups'), DI::l10n()->t('Add/remove mention when a group page is selected/deselected in ACL window.'), false, DI::config()->get('feature_lock', 'aclautomention', false)], [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)],
['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)], [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)],
['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)],
], ],
// Item tools // Item tools
'tools' => [ 'tools' => [
DI::l10n()->t('Post/Comment Tools'), DI::l10n()->t('Post/Comment Tools'),
['categories', DI::l10n()->t('Post Categories'), DI::l10n()->t('Add categories to your posts'), false, DI::config()->get('feature_lock', 'categories', false)], [self::CATEGORIES, DI::l10n()->t('Post Categories'), DI::l10n()->t('Add categories to your posts'), false, DI::config()->get('feature_lock', self::CATEGORIES, false)],
], ],
// Advanced Profile Settings // Advanced Profile Settings
'advanced_profile' => [ 'advanced_profile' => [
DI::l10n()->t('Advanced Profile Settings'), DI::l10n()->t('Advanced Profile Settings'),
['forumlist_profile', DI::l10n()->t('List Groups'), DI::l10n()->t('Show visitors public groups at the Advanced Profile Page'), false, DI::config()->get('feature_lock', 'forumlist_profile', false)], [self::GROUPS, DI::l10n()->t('List Groups'), DI::l10n()->t('Show visitors public groups at the Advanced Profile Page'), false, DI::config()->get('feature_lock', 'forumlist_profile', false)],
['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)], [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)],
['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)], [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)],
], ],
//Advanced Calendar Settings //Advanced Calendar Settings
'advanced_calendar' => [ 'advanced_calendar' => [
DI::l10n()->t('Advanced Calendar Settings'), DI::l10n()->t('Advanced Calendar Settings'),
['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)], [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)],
] ]
]; ];

View file

@ -172,8 +172,7 @@ class GroupManager
*/ */
public static function profileAdvanced($uid) public static function profileAdvanced($uid)
{ {
$profile = intval(Feature::isEnabled($uid, 'forumlist_profile')); if (!Feature::isEnabled($uid, Feature::GROUPS)) {
if (!$profile) {
return ''; return '';
} }

View file

@ -1045,7 +1045,7 @@ class Item
public function postProcessPost(array $post, array $recipients = []) public function postProcessPost(array $post, array $recipients = [])
{ {
if (!\Friendica\Content\Feature::isEnabled($post['uid'], 'explicit_mentions') && ($post['gravity'] == ItemModel::GRAVITY_COMMENT)) { if (!Feature::isEnabled($post['uid'], Feature::EXPLICIT_MENTIONS) && ($post['gravity'] == ItemModel::GRAVITY_COMMENT)) {
Tag::createImplicitMentions($post['uri-id'], $post['thr-parent-id']); Tag::createImplicitMentions($post['uri-id'], $post['thr-parent-id']);
} }

View file

@ -336,7 +336,7 @@ class Widget
*/ */
public static function categories(int $uid, string $baseurl, string $selected = ''): string public static function categories(int $uid, string $baseurl, string $selected = ''): string
{ {
if (!Feature::isEnabled($uid, 'categories')) { if (!Feature::isEnabled($uid, Feature::CATEGORIES)) {
return ''; return '';
} }
@ -428,7 +428,7 @@ class Widget
return ''; return '';
} }
if (Feature::isEnabled($uid, 'tagadelic')) { if (Feature::isEnabled($uid, Feature::TAGCLOUD)) {
$owner_id = Contact::getPublicIdByUserId($uid); $owner_id = Contact::getPublicIdByUserId($uid);
if (!$owner_id) { if (!$owner_id) {
@ -598,4 +598,4 @@ class Widget
$channelname $channelname
); );
} }
} }

View file

@ -516,7 +516,7 @@ class Event
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Access to this profile has been restricted.')); throw new HTTPException\UnauthorizedException(DI::l10n()->t('Access to this profile has been restricted.'));
} }
if (!DI::userSession()->isAuthenticated() && !Feature::isEnabled($owner['uid'], 'public_calendar')) { if (!DI::userSession()->isAuthenticated() && !Feature::isEnabled($owner['uid'], Feature::PUBLIC_CALENDAR)) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.')); throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
} }

View file

@ -91,7 +91,7 @@ class BaseProfile extends BaseModule
]; ];
} else { } else {
$owner = User::getByNickname($nickname, ['uid']); $owner = User::getByNickname($nickname, ['uid']);
if(DI::userSession()->isAuthenticated() || $owner && Feature::isEnabled($owner['uid'], 'public_calendar')) { if(DI::userSession()->isAuthenticated() || $owner && Feature::isEnabled($owner['uid'], Feature::PUBLIC_CALENDAR)) {
$tabs[] = [ $tabs[] = [
'label' => DI::l10n()->t('Calendar'), 'label' => DI::l10n()->t('Calendar'),
'url' => DI::baseUrl() . '/calendar/show/' . $nickname, 'url' => DI::baseUrl() . '/calendar/show/' . $nickname,

View file

@ -78,7 +78,7 @@ class Export extends BaseModule
$this->baseUrl->redirect('profile/' . $nickname . '/restricted'); $this->baseUrl->redirect('profile/' . $nickname . '/restricted');
} }
if (!$this->session->isAuthenticated() && !Feature::isEnabled($owner['uid'], 'public_calendar')) { if (!$this->session->isAuthenticated() && !Feature::isEnabled($owner['uid'], Feature::PUBLIC_CALENDAR)) {
$this->sysMessages->addNotice($this->t('Permission denied.')); $this->sysMessages->addNotice($this->t('Permission denied.'));
$this->baseUrl->redirect('profile/' . $nickname); $this->baseUrl->redirect('profile/' . $nickname);
} }

View file

@ -78,7 +78,7 @@ class Show extends BaseModule
$this->baseUrl->redirect('profile/' . $nickname . '/restricted'); $this->baseUrl->redirect('profile/' . $nickname . '/restricted');
} }
if (!$this->session->isAuthenticated() && !Feature::isEnabled($owner['uid'], 'public_calendar')) { if (!$this->session->isAuthenticated() && !Feature::isEnabled($owner['uid'], Feature::PUBLIC_CALENDAR)) {
$this->sysMessages->addNotice($this->t('Permission denied.')); $this->sysMessages->addNotice($this->t('Permission denied.'));
return Login::form(); return Login::form();
} }

View file

@ -119,7 +119,7 @@ class Channel extends Timeline
$this->page['aside'] .= $this->getNoSharerWidget('channel'); $this->page['aside'] .= $this->getNoSharerWidget('channel');
} }
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) { if (Feature::isEnabled($this->session->getLocalUserId(), Feature::TRENDING_TAGS)) {
$this->page['aside'] .= TrendingTags::getHTML($this->selectedTab); $this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
} }

View file

@ -110,7 +110,7 @@ class Community extends Timeline
$this->page['aside'] .= $this->getNoSharerWidget('community'); $this->page['aside'] .= $this->getNoSharerWidget('community');
} }
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) { if (Feature::isEnabled($this->session->getLocalUserId(), Feature::TRENDING_TAGS)) {
$this->page['aside'] .= TrendingTags::getHTML($this->selectedTab); $this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
} }

View file

@ -144,7 +144,7 @@ class Network extends Timeline
$this->page['aside'] .= $this->getNoSharerWidget('network'); $this->page['aside'] .= $this->getNoSharerWidget('network');
} }
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) { if (Feature::isEnabled($this->session->getLocalUserId(), Feature::TRENDING_TAGS)) {
$this->page['aside'] .= TrendingTags::getHTML($this->selectedTab); $this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
} }

View file

@ -205,7 +205,7 @@ class Compose extends BaseModule
'location_disabled' => $this->l10n->t('Location services are disabled. Please check the website\'s permissions on your device'), 'location_disabled' => $this->l10n->t('Location services are disabled. Please check the website\'s permissions on your device'),
'wait' => $this->l10n->t('Please wait'), 'wait' => $this->l10n->t('Please wait'),
'placeholdertitle' => $this->l10n->t('Set title'), 'placeholdertitle' => $this->l10n->t('Set title'),
'placeholdercategory' => Feature::isEnabled(DI::userSession()->getLocalUserId(),'categories') ? $this->l10n->t('Categories (comma-separated list)') : '', 'placeholdercategory' => Feature::isEnabled(DI::userSession()->getLocalUserId(), Feature::CATEGORIES) ? $this->l10n->t('Categories (comma-separated list)') : '',
'always_open_compose' => $this->pConfig->get(DI::userSession()->getLocalUserId(), 'frio', 'always_open_compose', 'always_open_compose' => $this->pConfig->get(DI::userSession()->getLocalUserId(), 'frio', 'always_open_compose',
$this->config->get('frio', 'always_open_compose', false)) ? '' : $this->config->get('frio', 'always_open_compose', false)) ? '' :
$this->l10n->t('You can make this page always open when you use the New Post button in the <a href="/settings/display">Theme Customization settings</a>.'), $this->l10n->t('You can make this page always open when you use the New Post button in the <a href="/settings/display">Theme Customization settings</a>.'),

View file

@ -156,7 +156,7 @@ class Edit extends BaseModule
'$title' => $item['title'], '$title' => $item['title'],
'$placeholdertitle' => $this->t('Set title'), '$placeholdertitle' => $this->t('Set title'),
'$category' => Post\Category::getCSVByURIId($item['uri-id'], $this->session->getLocalUserId(), Post\Category::CATEGORY), '$category' => Post\Category::getCSVByURIId($item['uri-id'], $this->session->getLocalUserId(), Post\Category::CATEGORY),
'$placeholdercategory' => (Feature::isEnabled($this->session->getLocalUserId(), 'categories') ? $this->t("Categories \x28comma-separated list\x29") : ''), '$placeholdercategory' => (Feature::isEnabled($this->session->getLocalUserId(), Feature::CATEGORIES) ? $this->t("Categories \x28comma-separated list\x29") : ''),
'$emtitle' => $this->t('Example: bob@example.com, mary@example.com'), '$emtitle' => $this->t('Example: bob@example.com, mary@example.com'),
'$lockstate' => $lockstate, '$lockstate' => $lockstate,
'$acl' => '', '$acl' => '',

View file

@ -240,7 +240,7 @@ class Photos extends \Friendica\Module\BaseProfile
// Create item container // Create item container
$lat = $lon = null; $lat = $lon = null;
if (!empty($exif['GPS']) && Feature::isEnabled($this->owner['uid'], 'photo_location')) { if (!empty($exif['GPS']) && Feature::isEnabled($this->owner['uid'], Feature::PHOTO_LOCATION)) {
$lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']); $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
$lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']); $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
} }

View file

@ -166,7 +166,7 @@ class Profile extends BaseProfile
$basic_fields += self::buildField('fullname', $this->t('Full Name:'), $profile['name']); $basic_fields += self::buildField('fullname', $this->t('Full Name:'), $profile['name']);
if (Feature::isEnabled($profile['uid'], 'profile_membersince')) { if (Feature::isEnabled($profile['uid'], Feature::MEMBER_SINCE)) {
$basic_fields += self::buildField( $basic_fields += self::buildField(
'membersince', 'membersince',
$this->t('Member since:'), $this->t('Member since:'),
@ -255,7 +255,7 @@ class Profile extends BaseProfile
} }
//show subscribed group if it is enabled in the usersettings //show subscribed group if it is enabled in the usersettings
if (Feature::isEnabled($profile['uid'], 'forumlist_profile')) { if (Feature::isEnabled($profile['uid'], Feature::GROUPS)) {
$custom_fields += self::buildField( $custom_fields += self::buildField(
'group_list', 'group_list',
$this->t('Groups:'), $this->t('Groups:'),

View file

@ -1079,13 +1079,13 @@ class Post
$owner = User::getOwnerDataById($a->getLoggedInUserId()); $owner = User::getOwnerDataById($a->getLoggedInUserId());
$item = $this->getData(); $item = $this->getData();
if (!empty($item['content-warning']) && Feature::isEnabled(DI::userSession()->getLocalUserId(), 'add_abstract')) { if (!empty($item['content-warning']) && Feature::isEnabled(DI::userSession()->getLocalUserId(), Feature::ADD_ABSTRACT)) {
$text = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $item['content-warning'] . "[/abstract]\n"; $text = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $item['content-warning'] . "[/abstract]\n";
} else { } else {
$text = ''; $text = '';
} }
if (!Feature::isEnabled(DI::userSession()->getLocalUserId(), 'explicit_mentions')) { if (!Feature::isEnabled(DI::userSession()->getLocalUserId(), Feature::EXPLICIT_MENTIONS)) {
return $text; return $text;
} }

View file

@ -1836,7 +1836,7 @@ class Transmitter
* } * }
*/ */
if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) { if (empty($item['uid']) || !Feature::isEnabled($item['uid'], Feature::EXPLICIT_MENTIONS)) {
$body = self::prependMentions($body, $item['uri-id'], $item['author-link']); $body = self::prependMentions($body, $item['uri-id'], $item['author-link']);
} }

View file

@ -3618,7 +3618,7 @@ class Diaspora
if ( if (
$item['author-id'] != $thread_parent_item['author-id'] $item['author-id'] != $thread_parent_item['author-id']
&& ($thread_parent_item['gravity'] != Item::GRAVITY_PARENT) && ($thread_parent_item['gravity'] != Item::GRAVITY_PARENT)
&& (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) && (empty($item['uid']) || !Feature::isEnabled($item['uid'], Feature::EXPLICIT_MENTIONS))
&& !DI::config()->get('system', 'disable_implicit_mentions') && !DI::config()->get('system', 'disable_implicit_mentions')
) { ) {
$body = self::prependParentAuthorMention($body, $thread_parent_item['author-link']); $body = self::prependParentAuthorMention($body, $thread_parent_item['author-link']);

File diff suppressed because it is too large Load diff