From 6cb637e8abc94072fdae165d7a1b1af292f59685 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Nov 2017 11:31:07 +0000 Subject: [PATCH 1/3] Default features should now work with the forumwidget again --- include/features.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/include/features.php b/include/features.php index ade93a18e..f2a81fc6e 100644 --- a/include/features.php +++ b/include/features.php @@ -16,14 +16,10 @@ use Friendica\Core\PConfig; function feature_enabled($uid, $feature) { $x = Config::get('feature_lock', $feature, false); - if (!$x) { - $x = PConfig::get($uid, 'feature', $feature, false); - if (!$x) { - $x = Config::get('feature', $feature, false); - if (!$x) { - $x = get_feature_default($feature); - } - } + if ($x === false) { + $x = get_feature_default($feature); + $x = Config::get('feature', $feature, $x); + $x = PConfig::get($uid, 'feature', $feature, $x); } $arr = array('uid' => $uid, 'feature' => $feature, 'enabled' => $x); @@ -125,10 +121,9 @@ function get_features($filtered = true) { $kquantity = count($arr[$k]); for ($y = 0; $y < $kquantity; $y ++) { if (is_array($arr[$k][$y])) { - if (!$arr[$k][$y][4]) { + if ($arr[$k][$y][4] === false) { $has_items = true; - } - else { + } else { unset($arr[$k][$y]); } } From 774a7193d2e09392eb7659aa95546d1043d25776 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Nov 2017 11:43:02 +0000 Subject: [PATCH 2/3] Added clarification --- src/Core/Config.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Core/Config.php b/src/Core/Config.php index 219831ad9..a1ea5ae1f 100644 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -13,13 +13,14 @@ use dba; /** * @brief Arbitrary sytem configuration storage - * Note: - * Please do not store booleans - convert to 0/1 integer values - * The Config::get() functions return boolean false for keys that are unset, - * and this could lead to subtle bugs. * - * There are a few places in the code (such as the admin panel) where boolean - * configurations need to be fixed as of 10/08/2011. + * Note: + * If we ever would decide to return exactly the variable type as entered, + * we will have fun with the additional features. :-) + * + * The config class always returns strings but in the default features + * we use a "false" to determine if the config value isn't set. + * */ class Config { From e4995dbad569673b7e4c5bbbb06b1c34f9bae063 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Nov 2017 13:12:54 +0000 Subject: [PATCH 3/3] Good looking and better performance --- include/features.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/features.php b/include/features.php index f2a81fc6e..4e9e7d9d9 100644 --- a/include/features.php +++ b/include/features.php @@ -16,10 +16,14 @@ use Friendica\Core\PConfig; function feature_enabled($uid, $feature) { $x = Config::get('feature_lock', $feature, false); + if ($x === false) { + $x = PConfig::get($uid, 'feature', $feature, false); + } + if ($x === false) { + $x = Config::get('feature', $feature, false); + } if ($x === false) { $x = get_feature_default($feature); - $x = Config::get('feature', $feature, $x); - $x = PConfig::get($uid, 'feature', $feature, $x); } $arr = array('uid' => $uid, 'feature' => $feature, 'enabled' => $x);