2017-12-04 14:33:49 +01:00
< ? php
/**
2022-01-02 08:27:47 +01:00
* @ copyright Copyright ( C ) 2010 - 2022 , the Friendica project
2020-02-09 15:45:36 +01:00
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*
2017-12-04 14:33:49 +01:00
*/
2020-02-09 15:45:36 +01:00
2017-12-04 14:33:49 +01:00
namespace Friendica\Content ;
2018-12-26 07:06:24 +01:00
use Friendica\Core\Hook ;
2020-01-18 16:50:57 +01:00
use Friendica\DI ;
2017-12-04 14:33:49 +01:00
2017-12-04 15:01:27 +01:00
class Feature
2017-12-04 14:33:49 +01:00
{
/**
2020-01-19 07:05:23 +01:00
* check if feature is enabled
2017-12-04 14:33:49 +01:00
*
2017-12-04 15:16:15 +01:00
* @ param integer $uid user id
* @ param string $feature feature
2017-12-04 14:33:49 +01:00
* @ return boolean
2019-01-06 22:06:53 +01:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2017-12-04 14:33:49 +01:00
*/
2019-07-16 03:48:28 +02:00
public static function isEnabled ( int $uid , $feature )
2017-12-04 14:33:49 +01:00
{
2020-01-19 21:21:13 +01:00
$x = DI :: config () -> get ( 'feature_lock' , $feature , false );
2017-12-04 14:33:49 +01:00
2017-12-06 21:18:45 +01:00
if ( $x === false ) {
2020-01-18 16:50:57 +01:00
$x = DI :: pConfig () -> get ( $uid , 'feature' , $feature , false );
2017-12-04 14:33:49 +01:00
}
2017-12-06 20:57:06 +01:00
2017-12-06 21:18:45 +01:00
if ( $x === false ) {
2020-01-19 21:21:13 +01:00
$x = DI :: config () -> get ( 'feature' , $feature , false );
2017-12-04 14:33:49 +01:00
}
2017-12-06 20:57:06 +01:00
2017-12-06 21:18:45 +01:00
if ( $x === false ) {
2017-12-04 14:33:49 +01:00
$x = self :: getDefault ( $feature );
}
2018-01-15 14:05:12 +01:00
$arr = [ 'uid' => $uid , 'feature' => $feature , 'enabled' => $x ];
2018-12-26 07:06:24 +01:00
Hook :: callAll ( 'isEnabled' , $arr );
2017-12-04 14:33:49 +01:00
return ( $arr [ 'enabled' ]);
}
/**
2020-01-19 07:05:23 +01:00
* check if feature is enabled or disabled by default
2017-12-04 14:33:49 +01:00
*
2017-12-04 15:16:15 +01:00
* @ param string $feature feature
2017-12-04 14:33:49 +01:00
* @ return boolean
2019-01-06 22:06:53 +01:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2017-12-04 14:33:49 +01:00
*/
2017-12-04 15:01:27 +01:00
private static function getDefault ( $feature )
{
2017-12-04 14:33:49 +01:00
$f = self :: get ();
foreach ( $f as $cat ) {
foreach ( $cat as $feat ) {
2017-12-04 15:16:15 +01:00
if ( is_array ( $feat ) && $feat [ 0 ] === $feature ) {
2017-12-04 14:33:49 +01:00
return $feat [ 3 ];
2017-12-04 15:16:15 +01:00
}
2017-12-04 14:33:49 +01:00
}
}
return false ;
}
/**
2020-01-19 07:05:23 +01:00
* Get a list of all available features
2017-12-04 14:33:49 +01:00
*
* The array includes the setting group , the setting name ,
* explainations for the setting and if it ' s enabled or disabled
* by default
*
* @ param bool $filtered True removes any locked features
*
* @ return array
2019-01-06 22:06:53 +01:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2017-12-04 14:33:49 +01:00
*/
2017-12-04 15:01:27 +01:00
public static function get ( $filtered = true )
{
2018-01-15 14:05:12 +01:00
$arr = [
2017-12-04 14:33:49 +01:00
// General
2018-01-15 14:05:12 +01:00
'general' => [
2020-01-18 20:52:34 +01:00
DI :: l10n () -> t ( 'General Features' ),
//array('expire', DI::l10n()->t('Content Expiration'), DI::l10n()->t('Remove old posts/comments after a period of time')),
2020-01-19 21:21:13 +01:00
[ 'photo_location' , DI :: l10n () -> t ( 'Photo Location' ), DI :: l10n () -> t ( " Photo metadata is normally stripped. This extracts the location \x28 if present \x29 prior to stripping metadata and links it to a map. " ), false , DI :: config () -> get ( 'feature_lock' , '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 )],
2018-01-15 14:05:12 +01:00
],
2017-12-04 14:33:49 +01:00
// Post composition
2018-01-15 14:05:12 +01:00
'composition' => [
2020-01-18 20:52:34 +01:00
DI :: l10n () -> t ( 'Post Composition Features' ),
2020-01-19 21:21:13 +01:00
[ '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 )],
[ '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 )],
2018-01-15 14:05:12 +01:00
],
2017-12-04 14:33:49 +01:00
// Item tools
2018-01-15 14:05:12 +01:00
'tools' => [
2020-01-18 20:52:34 +01:00
DI :: l10n () -> t ( 'Post/Comment Tools' ),
2020-01-19 21:21:13 +01:00
[ 'categories' , DI :: l10n () -> t ( 'Post Categories' ), DI :: l10n () -> t ( 'Add categories to your posts' ), false , DI :: config () -> get ( 'feature_lock' , 'categories' , false )],
2018-01-15 14:05:12 +01:00
],
2017-12-04 14:33:49 +01:00
// Advanced Profile Settings
2018-01-15 14:05:12 +01:00
'advanced_profile' => [
2020-01-18 20:52:34 +01:00
DI :: l10n () -> t ( 'Advanced Profile Settings' ),
2020-01-19 21:21:13 +01:00
[ '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 )],
[ '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 )],
[ '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 )],
2018-01-15 14:05:12 +01:00
],
];
2017-12-04 14:33:49 +01:00
// removed any locked features and remove the entire category if this makes it empty
if ( $filtered ) {
foreach ( $arr as $k => $x ) {
$has_items = false ;
$kquantity = count ( $arr [ $k ]);
for ( $y = 0 ; $y < $kquantity ; $y ++ ) {
if ( is_array ( $arr [ $k ][ $y ])) {
if ( $arr [ $k ][ $y ][ 4 ] === false ) {
$has_items = true ;
} else {
unset ( $arr [ $k ][ $y ]);
}
}
}
if ( ! $has_items ) {
unset ( $arr [ $k ]);
}
}
}
2018-12-26 07:06:24 +01:00
Hook :: callAll ( 'get' , $arr );
2017-12-04 14:33:49 +01:00
return $arr ;
}
}