From e0255c0dc45d8c670b865087336b4807d831e0fb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 8 Apr 2018 20:05:30 -0700 Subject: first cut of feature/techlevel merge --- Zotlabs/Module/Settings/Features.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Module/Settings/Features.php') diff --git a/Zotlabs/Module/Settings/Features.php b/Zotlabs/Module/Settings/Features.php index 5b642acc3..3c3205c65 100644 --- a/Zotlabs/Module/Settings/Features.php +++ b/Zotlabs/Module/Settings/Features.php @@ -11,7 +11,13 @@ class Features { // Build list of features and check which are set // We will not create any settings for features that are above our techlevel - $features = get_features(); + if(intval($_REQUEST['techlevel'])) + $level = intval($_REQUEST['techlevel']); + else { + $level = get_account_techlevel(); + } + + $features = get_features(true,$level); $all_features = array(); foreach($features as $k => $v) { foreach($v as $f) @@ -28,9 +34,21 @@ class Features { } function get() { - $arr = array(); - $features = get_features(); - + + $arr = []; + if(intval($_REQUEST['techlevel'])) + $level = intval($_REQUEST['techlevel']); + else { + $level = get_account_techlevel(); + } + + $techlevels = \Zotlabs\Lib\Techlevels::levels(); + + $def_techlevel = \App::$account['account_level']; + $techlock = get_config('system','techlevel_lock'); + + $features = get_features(true,$level); + foreach($features as $fname => $fdata) { $arr[$fname] = array(); $arr[$fname][0] = $fdata[0]; @@ -43,6 +61,8 @@ class Features { $o .= replace_macros($tpl, array( '$form_security_token' => get_form_security_token("settings_features"), '$title' => t('Additional Features'), + '$techlevel' => [ 'techlevel', t('Your technical skill level'), $def_techlevel, t('Used to provide a member experience and additional features consistent with your comfort level'), $techlevels ], + '$techlock' => $techlock, '$features' => $arr, '$submit' => t('Submit'), )); -- cgit v1.2.3 From e4ee165e296404b5ff6ed8ee252c98313f84de91 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 8 Apr 2018 22:02:48 -0700 Subject: more work merging techlevels and features --- Zotlabs/Module/Settings/Features.php | 57 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'Zotlabs/Module/Settings/Features.php') diff --git a/Zotlabs/Module/Settings/Features.php b/Zotlabs/Module/Settings/Features.php index 3c3205c65..43ca57be2 100644 --- a/Zotlabs/Module/Settings/Features.php +++ b/Zotlabs/Module/Settings/Features.php @@ -8,26 +8,16 @@ class Features { function post() { check_form_security_token_redirectOnErr('/settings/features', 'settings_features'); - // Build list of features and check which are set - // We will not create any settings for features that are above our techlevel + $features = get_features(false); - if(intval($_REQUEST['techlevel'])) - $level = intval($_REQUEST['techlevel']); - else { - $level = get_account_techlevel(); - } - - $features = get_features(true,$level); - $all_features = array(); - foreach($features as $k => $v) { - foreach($v as $f) - $all_features[] = $f[0]; - } - foreach($all_features as $k) { - if(x($_POST,"feature_$k")) - set_pconfig(local_channel(),'feature',$k, 1); - else - set_pconfig(local_channel(),'feature',$k, 0); + foreach($features as $fname => $fdata) { + foreach(array_slice($fdata,1) as $f) { + $k = $f[0]; + if(array_key_exists("feature_$k",$_POST)) + set_pconfig(local_channel(),'feature',$k, (string) $_POST["feature_$k"]); + else + set_pconfig(local_channel(),'feature', $k, ''); + } } build_sync_packet(); return; @@ -36,6 +26,8 @@ class Features { function get() { $arr = []; + $harr = []; + if(intval($_REQUEST['techlevel'])) $level = intval($_REQUEST['techlevel']); else { @@ -44,27 +36,42 @@ class Features { $techlevels = \Zotlabs\Lib\Techlevels::levels(); - $def_techlevel = \App::$account['account_level']; + unset($techlevels[0]); + + logger('techlevels: ' . print_r($techlevels,true)); + + $def_techlevel = (($level > 0) ? $level : 1); $techlock = get_config('system','techlevel_lock'); + $all_features_raw = get_features(false); + + foreach($all_features_raw as $fname => $fdata) { + foreach(array_slice($fdata,1) as $f) { + $harr[$f[0]] = ((intval(feature_enabled(local_channel(),$f[0]))) ? "1" : ''); + } + } + $features = get_features(true,$level); foreach($features as $fname => $fdata) { $arr[$fname] = array(); $arr[$fname][0] = $fdata[0]; foreach(array_slice($fdata,1) as $f) { - $arr[$fname][1][] = array('feature_' .$f[0],$f[1],((intval(feature_enabled(local_channel(),$f[0]))) ? "1" : ''),$f[2],array(t('Off'),t('On'))); + $arr[$fname][1][] = array('feature_' . $f[0],$f[1],((intval(feature_enabled(local_channel(),$f[0]))) ? "1" : ''),$f[2],array(t('Off'),t('On'))); + unset($harr[$f[0]]); } } $tpl = get_markup_template("settings_features.tpl"); $o .= replace_macros($tpl, array( '$form_security_token' => get_form_security_token("settings_features"), - '$title' => t('Additional Features'), + '$title' => t('Additional Features'), '$techlevel' => [ 'techlevel', t('Your technical skill level'), $def_techlevel, t('Used to provide a member experience and additional features consistent with your comfort level'), $techlevels ], - '$techlock' => $techlock, - '$features' => $arr, - '$submit' => t('Submit'), + '$techlock' => $techlock, + '$features' => $arr, + '$hiddens' => $harr, + '$baseurl' => z_root(), + '$submit' => t('Submit'), )); return $o; -- cgit v1.2.3 From cda3d23508430f8c2dd07fe9d5731b0ba8f4aa24 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 8 Apr 2018 22:09:08 -0700 Subject: more intelligent handling of level 0 - and remove an extraneous logging function --- Zotlabs/Module/Settings/Features.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Module/Settings/Features.php') diff --git a/Zotlabs/Module/Settings/Features.php b/Zotlabs/Module/Settings/Features.php index 43ca57be2..888032c28 100644 --- a/Zotlabs/Module/Settings/Features.php +++ b/Zotlabs/Module/Settings/Features.php @@ -34,11 +34,16 @@ class Features { $level = get_account_techlevel(); } + if(! intval($level)) { + notice( t('Permission denied.') . EOL); + return; + } + $techlevels = \Zotlabs\Lib\Techlevels::levels(); - unset($techlevels[0]); + // This page isn't accessible at techlevel 0 - logger('techlevels: ' . print_r($techlevels,true)); + unset($techlevels[0]); $def_techlevel = (($level > 0) ? $level : 1); $techlock = get_config('system','techlevel_lock'); -- cgit v1.2.3