Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

151 lines
5.5 KiB

  1. <?php
  2. /**
  3. * @file src/Content/Feature.php
  4. * @brief Features management
  5. */
  6. namespace Friendica\Content;
  7. use Friendica\Core\Config;
  8. use Friendica\Core\Hook;
  9. use Friendica\Core\L10n;
  10. use Friendica\DI;
  11. class Feature
  12. {
  13. /**
  14. * @brief check if feature is enabled
  15. *
  16. * @param integer $uid user id
  17. * @param string $feature feature
  18. * @return boolean
  19. * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  20. */
  21. public static function isEnabled(int $uid, $feature)
  22. {
  23. $x = Config::get('feature_lock', $feature, false);
  24. if ($x === false) {
  25. $x = DI::pConfig()->get($uid, 'feature', $feature, false);
  26. }
  27. if ($x === false) {
  28. $x = Config::get('feature', $feature, false);
  29. }
  30. if ($x === false) {
  31. $x = self::getDefault($feature);
  32. }
  33. $arr = ['uid' => $uid, 'feature' => $feature, 'enabled' => $x];
  34. Hook::callAll('isEnabled', $arr);
  35. return($arr['enabled']);
  36. }
  37. /**
  38. * @brief check if feature is enabled or disabled by default
  39. *
  40. * @param string $feature feature
  41. * @return boolean
  42. * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  43. */
  44. private static function getDefault($feature)
  45. {
  46. $f = self::get();
  47. foreach ($f as $cat) {
  48. foreach ($cat as $feat) {
  49. if (is_array($feat) && $feat[0] === $feature) {
  50. return $feat[3];
  51. }
  52. }
  53. }
  54. return false;
  55. }
  56. /**
  57. * @brief Get a list of all available features
  58. *
  59. * The array includes the setting group, the setting name,
  60. * explainations for the setting and if it's enabled or disabled
  61. * by default
  62. *
  63. * @param bool $filtered True removes any locked features
  64. *
  65. * @return array
  66. * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  67. */
  68. public static function get($filtered = true)
  69. {
  70. $arr = [
  71. // General
  72. 'general' => [
  73. L10n::t('General Features'),
  74. //array('expire', L10n::t('Content Expiration'), L10n::t('Remove old posts/comments after a period of time')),
  75. ['multi_profiles', L10n::t('Multiple Profiles'), L10n::t('Ability to create multiple profiles'), false, Config::get('feature_lock', 'multi_profiles', false)],
  76. ['photo_location', L10n::t('Photo Location'), 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, Config::get('feature_lock', 'photo_location', false)],
  77. ['export_calendar', L10n::t('Export Public Calendar'), L10n::t('Ability for visitors to download the public calendar'), false, Config::get('feature_lock', 'export_calendar', false)],
  78. ['trending_tags', L10n::t('Trending Tags'), L10n::t('Show a community page widget with a list of the most popular tags in recent public posts.'), false, Config::get('feature_lock', 'trending_tags', false)],
  79. ],
  80. // Post composition
  81. 'composition' => [
  82. L10n::t('Post Composition Features'),
  83. ['aclautomention', L10n::t('Auto-mention Forums'), L10n::t('Add/remove mention when a forum page is selected/deselected in ACL window.'), false, Config::get('feature_lock', 'aclautomention', false)],
  84. ['explicit_mentions', L10n::t('Explicit Mentions'), L10n::t('Add explicit mentions to comment box for manual control over who gets mentioned in replies.'), false, Config::get('feature_lock', 'explicit_mentions', false)],
  85. ],
  86. // Network sidebar widgets
  87. 'widgets' => [
  88. L10n::t('Network Sidebar'),
  89. ['archives', L10n::t('Archives'), L10n::t('Ability to select posts by date ranges'), false, Config::get('feature_lock', 'archives', false)],
  90. ['networks', L10n::t('Protocol Filter'), L10n::t('Enable widget to display Network posts only from selected protocols'), false, Config::get('feature_lock', 'networks', false)],
  91. ],
  92. // Network tabs
  93. 'net_tabs' => [
  94. L10n::t('Network Tabs'),
  95. ['new_tab', L10n::t('Network New Tab'), L10n::t("Enable tab to display only new Network posts \x28from the last 12 hours\x29"), false, Config::get('feature_lock', 'new_tab', false)],
  96. ['link_tab', L10n::t('Network Shared Links Tab'), L10n::t('Enable tab to display only Network posts with links in them'), false, Config::get('feature_lock', 'link_tab', false)],
  97. ],
  98. // Item tools
  99. 'tools' => [
  100. L10n::t('Post/Comment Tools'),
  101. ['categories', L10n::t('Post Categories'), L10n::t('Add categories to your posts'), false, Config::get('feature_lock', 'categories', false)],
  102. ],
  103. // Advanced Profile Settings
  104. 'advanced_profile' => [
  105. L10n::t('Advanced Profile Settings'),
  106. ['forumlist_profile', L10n::t('List Forums'), L10n::t('Show visitors public community forums at the Advanced Profile Page'), false, Config::get('feature_lock', 'forumlist_profile', false)],
  107. ['tagadelic', L10n::t('Tag Cloud'), L10n::t('Provide a personal tag cloud on your profile page'), false, Config::get('feature_lock', 'tagadelic', false)],
  108. ['profile_membersince', L10n::t('Display Membership Date'), L10n::t('Display membership date in profile'), false, Config::get('feature_lock', 'profile_membersince', false)],
  109. ],
  110. ];
  111. // removed any locked features and remove the entire category if this makes it empty
  112. if ($filtered) {
  113. foreach ($arr as $k => $x) {
  114. $has_items = false;
  115. $kquantity = count($arr[$k]);
  116. for ($y = 0; $y < $kquantity; $y ++) {
  117. if (is_array($arr[$k][$y])) {
  118. if ($arr[$k][$y][4] === false) {
  119. $has_items = true;
  120. } else {
  121. unset($arr[$k][$y]);
  122. }
  123. }
  124. }
  125. if (! $has_items) {
  126. unset($arr[$k]);
  127. }
  128. }
  129. }
  130. Hook::callAll('get', $arr);
  131. return $arr;
  132. }
  133. }