Use router parameters in Admin modules

- Remove 10 @TODO tags

# Conflicts:
#	src/Module/Admin/DBSync.php
#	src/Module/Admin/Themes/Details.php
#	src/Module/Admin/Themes/Embed.php
This commit is contained in:
Hypolite Petovan 2020-09-08 10:38:35 -04:00
parent 98eb53c20f
commit 2ce15cae1a
8 changed files with 427 additions and 501 deletions

View file

@ -34,24 +34,20 @@ class Details extends BaseAdmin
{
parent::post($parameters);
$a = DI::app();
$addon = Strings::sanitizeFilePathItem($parameters['addon']);
if ($a->argc > 2) {
// @TODO: Replace with parameter from router
$addon = $a->argv[2];
$addon = Strings::sanitizeFilePathItem($addon);
if (is_file('addon/' . $addon . '/' . $addon . '.php')) {
include_once 'addon/' . $addon . '/' . $addon . '.php';
if (function_exists($addon . '_addon_admin_post')) {
$func = $addon . '_addon_admin_post';
$func($a);
}
$redirect = 'admin/addons/' . $addon;
DI::baseUrl()->redirect('admin/addons/' . $addon);
if (is_file('addon/' . $addon . '/' . $addon . '.php')) {
include_once 'addon/' . $addon . '/' . $addon . '.php';
if (function_exists($addon . '_addon_admin_post')) {
$func = $addon . '_addon_admin_post';
$func(DI::app());
}
}
DI::baseUrl()->redirect('admin/addons');
DI::baseUrl()->redirect($redirect);
}
public static function content(array $parameters = [])
@ -62,79 +58,73 @@ class Details extends BaseAdmin
$addons_admin = Addon::getAdminList();
if ($a->argc > 2) {
// @TODO: Replace with parameter from router
$addon = $a->argv[2];
$addon = Strings::sanitizeFilePathItem($addon);
if (!is_file("addon/$addon/$addon.php")) {
notice(DI::l10n()->t('Addon not found.'));
Addon::uninstall($addon);
DI::baseUrl()->redirect('admin/addons');
}
if (($_GET['action'] ?? '') == 'toggle') {
parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't');
// Toggle addon status
if (Addon::isEnabled($addon)) {
Addon::uninstall($addon);
info(DI::l10n()->t('Addon %s disabled.', $addon));
} else {
Addon::install($addon);
info(DI::l10n()->t('Addon %s enabled.', $addon));
}
DI::baseUrl()->redirect('admin/addons/' . $addon);
}
// display addon details
if (Addon::isEnabled($addon)) {
$status = 'on';
$action = DI::l10n()->t('Disable');
} else {
$status = 'off';
$action = DI::l10n()->t('Enable');
}
$readme = null;
if (is_file("addon/$addon/README.md")) {
$readme = Markdown::convert(file_get_contents("addon/$addon/README.md"), false);
} elseif (is_file("addon/$addon/README")) {
$readme = '<pre>' . file_get_contents("addon/$addon/README") . '</pre>';
}
$admin_form = '';
if (array_key_exists($addon, $addons_admin)) {
require_once "addon/$addon/$addon.php";
$func = $addon . '_addon_admin';
$func($a, $admin_form);
}
$t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
return Renderer::replaceMacros($t, [
'$title' => DI::l10n()->t('Administration'),
'$page' => DI::l10n()->t('Addons'),
'$toggle' => DI::l10n()->t('Toggle'),
'$settings' => DI::l10n()->t('Settings'),
'$baseurl' => DI::baseUrl()->get(true),
'$addon' => $addon,
'$status' => $status,
'$action' => $action,
'$info' => Addon::getInfo($addon),
'$str_author' => DI::l10n()->t('Author: '),
'$str_maintainer' => DI::l10n()->t('Maintainer: '),
'$admin_form' => $admin_form,
'$function' => 'addons',
'$screenshot' => '',
'$readme' => $readme,
'$form_security_token' => parent::getFormSecurityToken('admin_themes'),
]);
$addon = Strings::sanitizeFilePathItem($parameters['addon']);
if (!is_file("addon/$addon/$addon.php")) {
notice(DI::l10n()->t('Addon not found.'));
Addon::uninstall($addon);
DI::baseUrl()->redirect('admin/addons');
}
DI::baseUrl()->redirect('admin/addons');
if (($_GET['action'] ?? '') == 'toggle') {
self::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't');
// Toggle addon status
if (Addon::isEnabled($addon)) {
Addon::uninstall($addon);
info(DI::l10n()->t('Addon %s disabled.', $addon));
} else {
Addon::install($addon);
info(DI::l10n()->t('Addon %s enabled.', $addon));
}
DI::baseUrl()->redirect('admin/addons/' . $addon);
}
// display addon details
if (Addon::isEnabled($addon)) {
$status = 'on';
$action = DI::l10n()->t('Disable');
} else {
$status = 'off';
$action = DI::l10n()->t('Enable');
}
$readme = null;
if (is_file("addon/$addon/README.md")) {
$readme = Markdown::convert(file_get_contents("addon/$addon/README.md"), false);
} elseif (is_file("addon/$addon/README")) {
$readme = '<pre>' . file_get_contents("addon/$addon/README") . '</pre>';
}
$admin_form = '';
if (array_key_exists($addon, $addons_admin)) {
require_once "addon/$addon/$addon.php";
$func = $addon . '_addon_admin';
$func($a, $admin_form);
}
$t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
return Renderer::replaceMacros($t, [
'$title' => DI::l10n()->t('Administration'),
'$page' => DI::l10n()->t('Addons'),
'$toggle' => DI::l10n()->t('Toggle'),
'$settings' => DI::l10n()->t('Settings'),
'$baseurl' => DI::baseUrl()->get(true),
'$addon' => $addon,
'$status' => $status,
'$action' => $action,
'$info' => Addon::getInfo($addon),
'$str_author' => DI::l10n()->t('Author: '),
'$str_maintainer' => DI::l10n()->t('Maintainer: '),
'$admin_form' => $admin_form,
'$function' => 'addons',
'$screenshot' => '',
'$readme' => $readme,
'$form_security_token' => self::getFormSecurityToken('admin_addons'),
]);
}
}