From 446cb905e472817a807a230b028399cf13df6c2e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 21 Apr 2019 20:32:02 -0400 Subject: [PATCH] Move admin/features to src/Module - Add Module\Admin\Features class - Add route for admin/features - Add features admin aside menu entry - Move templates/admin/settings_features.tpl to templates/admin/features.tpl - Remove admin_page_features and admin_page_features_post from mod/admin.php --- mod/admin.php | 90 ------------------- src/App/Router.php | 1 + src/Module/Admin/Features.php | 79 ++++++++++++++++ src/Module/BaseAdminModule.php | 1 + .../{settings_features.tpl => features.tpl} | 0 5 files changed, 81 insertions(+), 90 deletions(-) create mode 100644 src/Module/Admin/Features.php rename view/templates/admin/{settings_features.tpl => features.tpl} (100%) diff --git a/mod/admin.php b/mod/admin.php index d6b447c79..2b9a90b54 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -111,9 +111,6 @@ function admin_post(App $a) } $return_path = 'admin/themes/' . $theme . (!empty($_GET['mode']) ? '?mode=' . $_GET['mode'] : ''); break; - case 'features': - admin_page_features_post($a); - break; case 'logs': admin_page_logs_post($a); break; @@ -228,9 +225,6 @@ function admin_content(App $a) case 'themes': $o = admin_page_themes($a); break; - case 'features': - $o = admin_page_features($a); - break; case 'logs': $o = admin_page_logs($a); break; @@ -1672,90 +1666,6 @@ function admin_page_viewlogs(App $a) ]); } -/** - * @brief Prosesses data send by the features admin page - * - * @param App $a - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - */ -function admin_page_features_post(App $a) -{ - BaseModule::checkFormSecurityTokenRedirectOnError('/admin/features', 'admin_manage_features'); - - Logger::log('postvars: ' . print_r($_POST, true), Logger::DATA); - - $features = Feature::get(false); - - foreach ($features as $fname => $fdata) { - foreach (array_slice($fdata, 1) as $f) { - $feature = $f[0]; - $feature_state = 'feature_' . $feature; - $featurelock = 'featurelock_' . $feature; - - if (!empty($_POST[$feature_state])) { - $val = intval($_POST[$feature_state]); - } else { - $val = 0; - } - Config::set('feature', $feature, $val); - - if (!empty($_POST[$featurelock])) { - Config::set('feature_lock', $feature, $val); - } else { - Config::delete('feature_lock', $feature); - } - } - } - - $a->internalRedirect('admin/features'); - return; // NOTREACHED -} - -/** - * @brief Subpage for global additional feature management - * - * This functin generates the subpage 'Manage Additional Features' - * for the admin panel. At this page the admin can set preferences - * for the user settings of the 'additional features'. If needed this - * preferences can be locked through the admin. - * - * The returned string contains the HTML code of the subpage 'Manage - * Additional Features' - * - * @param App $a - * @return string - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - */ -function admin_page_features(App $a) -{ - if (($a->argc > 1) && ($a->getArgumentValue(1) === 'features')) { - $arr = []; - $features = Feature::get(false); - - foreach ($features as $fname => $fdata) { - $arr[$fname] = []; - $arr[$fname][0] = $fdata[0]; - foreach (array_slice($fdata, 1) as $f) { - $set = Config::get('feature', $f[0], $f[3]); - $arr[$fname][1][] = [ - ['feature_' . $f[0], $f[1], $set, $f[2], [L10n::t('Off'), L10n::t('On')]], - ['featurelock_' . $f[0], L10n::t('Lock feature %s', $f[1]), (($f[4] !== false) ? "1" : ''), '', [L10n::t('Off'), L10n::t('On')]] - ]; - } - } - - $tpl = Renderer::getMarkupTemplate('admin/settings_features.tpl'); - $o = Renderer::replaceMacros($tpl, [ - '$form_security_token' => BaseModule::getFormSecurityToken("admin_manage_features"), - '$title' => L10n::t('Manage Additional Features'), - '$features' => $arr, - '$submit' => L10n::t('Save Settings'), - ]); - - return $o; - } -} - function admin_page_server_vital() { // Fetch the host-meta to check if this really is a vital server diff --git a/src/App/Router.php b/src/App/Router.php index 30f48f7c5..af3f8e717 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -124,6 +124,7 @@ class Router $collector->addRoute(['GET', 'POST'], '/addons' , Module\Admin\Addons\Index::class); $collector->addRoute(['GET', 'POST'], '/addons/{addon}' , Module\Admin\Addons\Details::class); + $collector->addRoute(['GET', 'POST'], '/features' , Module\Admin\Features::class); $collector->addRoute(['GET'] , '/federation' , Module\Admin\Federation::class); $collector->addRoute(['GET', 'POST'], '/themes' , Module\Admin\Themes\Index::class); diff --git a/src/Module/Admin/Features.php b/src/Module/Admin/Features.php new file mode 100644 index 000000000..e127b8c19 --- /dev/null +++ b/src/Module/Admin/Features.php @@ -0,0 +1,79 @@ + $fdata) { + foreach (array_slice($fdata, 1) as $f) { + $feature = $f[0]; + $feature_state = 'feature_' . $feature; + $featurelock = 'featurelock_' . $feature; + + if (!empty($_POST[$feature_state])) { + $val = intval($_POST[$feature_state]); + } else { + $val = 0; + } + Config::set('feature', $feature, $val); + + if (!empty($_POST[$featurelock])) { + Config::set('feature_lock', $feature, $val); + } else { + Config::delete('feature_lock', $feature); + } + } + } + + self::getApp()->internalRedirect('admin/features'); + } + + public static function content() + { + parent::content(); + + $a = self::getApp(); + + if (($a->argc > 1) && ($a->getArgumentValue(1) === 'features')) { + $arr = []; + $features = Feature::get(false); + + foreach ($features as $fname => $fdata) { + $arr[$fname] = []; + $arr[$fname][0] = $fdata[0]; + foreach (array_slice($fdata, 1) as $f) { + $set = Config::get('feature', $f[0], $f[3]); + $arr[$fname][1][] = [ + ['feature_' . $f[0], $f[1], $set, $f[2], [L10n::t('Off'), L10n::t('On')]], + ['featurelock_' . $f[0], L10n::t('Lock feature %s', $f[1]), (($f[4] !== false) ? "1" : ''), '', [L10n::t('Off'), L10n::t('On')]] + ]; + } + } + + $tpl = Renderer::getMarkupTemplate('admin/features.tpl'); + $o = Renderer::replaceMacros($tpl, [ + '$form_security_token' => parent::getFormSecurityToken("admin_manage_features"), + '$title' => L10n::t('Manage Additional Features'), + '$features' => $arr, + '$submit' => L10n::t('Save Settings'), + ]); + + return $o; + } + } +} \ No newline at end of file diff --git a/src/Module/BaseAdminModule.php b/src/Module/BaseAdminModule.php index cf434537e..07f3c0786 100644 --- a/src/Module/BaseAdminModule.php +++ b/src/Module/BaseAdminModule.php @@ -56,6 +56,7 @@ abstract class BaseAdminModule extends BaseModule 'users' => ['admin/users' , L10n::t('Users') , 'users'], 'addons' => ['admin/addons' , L10n::t('Addons') , 'addons'], 'themes' => ['admin/themes' , L10n::t('Themes') , 'themes'], + 'features' => ['admin/features' , L10n::t('Additional features') , 'features'], 'tos' => ['admin/tos' , L10n::t('Terms of Service') , 'tos'], ]], ]; diff --git a/view/templates/admin/settings_features.tpl b/view/templates/admin/features.tpl similarity index 100% rename from view/templates/admin/settings_features.tpl rename to view/templates/admin/features.tpl