mirror of
https://github.com/friendica/friendica
synced 2025-04-26 17:10:10 +00:00
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:
parent
98eb53c20f
commit
2ce15cae1a
8 changed files with 427 additions and 501 deletions
|
@ -30,116 +30,80 @@ use Friendica\Util\Strings;
|
|||
|
||||
class Details extends BaseAdmin
|
||||
{
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
parent::post($parameters);
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if ($a->argc > 2) {
|
||||
// @TODO: Replace with parameter from router
|
||||
$theme = $a->argv[2];
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
if (is_file("view/theme/$theme/config.php")) {
|
||||
require_once "view/theme/$theme/config.php";
|
||||
|
||||
if (function_exists('theme_admin_post')) {
|
||||
theme_admin_post($a);
|
||||
}
|
||||
}
|
||||
|
||||
info(DI::l10n()->t('Theme settings updated.'));
|
||||
|
||||
if (DI::mode()->isAjax()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DI::baseUrl()->redirect('admin/themes/' . $theme);
|
||||
}
|
||||
}
|
||||
|
||||
public static function content(array $parameters = [])
|
||||
{
|
||||
parent::content($parameters);
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if ($a->argc > 2) {
|
||||
// @TODO: Replace with parameter from router
|
||||
$theme = $a->argv[2];
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
if (!is_dir("view/theme/$theme")) {
|
||||
notice(DI::l10n()->t("Item not found."));
|
||||
return '';
|
||||
}
|
||||
|
||||
$isEnabled = in_array($theme, Theme::getAllowedList());
|
||||
if ($isEnabled) {
|
||||
$status = "on";
|
||||
$action = DI::l10n()->t("Disable");
|
||||
} else {
|
||||
$status = "off";
|
||||
$action = DI::l10n()->t("Enable");
|
||||
}
|
||||
|
||||
if (!empty($_GET['action']) && $_GET['action'] == 'toggle') {
|
||||
parent::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');
|
||||
|
||||
if ($isEnabled) {
|
||||
Theme::uninstall($theme);
|
||||
info(DI::l10n()->t('Theme %s disabled.', $theme));
|
||||
} elseif (Theme::install($theme)) {
|
||||
info(DI::l10n()->t('Theme %s successfully enabled.', $theme));
|
||||
} else {
|
||||
info(DI::l10n()->t('Theme %s failed to install.', $theme));
|
||||
}
|
||||
|
||||
DI::baseUrl()->redirect('admin/themes/' . $theme);
|
||||
}
|
||||
|
||||
$readme = null;
|
||||
if (is_file("view/theme/$theme/README.md")) {
|
||||
$readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);
|
||||
} elseif (is_file("view/theme/$theme/README")) {
|
||||
$readme = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";
|
||||
}
|
||||
|
||||
$admin_form = '';
|
||||
if (is_file("view/theme/$theme/config.php")) {
|
||||
require_once "view/theme/$theme/config.php";
|
||||
|
||||
if (function_exists('theme_admin')) {
|
||||
$admin_form = '<iframe onload="resizeIframe(this);" src="/admin/themes/' . $theme . '/embed?mode=minimal" width="100%" height="600px" frameborder="no"></iframe>';
|
||||
}
|
||||
}
|
||||
|
||||
$screenshot = [Theme::getScreenshot($theme), DI::l10n()->t('Screenshot')];
|
||||
if (!stristr($screenshot[0], $theme)) {
|
||||
$screenshot = null;
|
||||
}
|
||||
|
||||
$t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$title' => DI::l10n()->t('Administration'),
|
||||
'$page' => DI::l10n()->t('Themes'),
|
||||
'$toggle' => DI::l10n()->t('Toggle'),
|
||||
'$settings' => DI::l10n()->t('Settings'),
|
||||
'$baseurl' => DI::baseUrl()->get(true),
|
||||
'$addon' => $theme,
|
||||
'$status' => $status,
|
||||
'$action' => $action,
|
||||
'$info' => Theme::getInfo($theme),
|
||||
'$function' => 'themes',
|
||||
'$admin_form' => $admin_form,
|
||||
'$str_author' => DI::l10n()->t('Author: '),
|
||||
'$str_maintainer' => DI::l10n()->t('Maintainer: '),
|
||||
'$screenshot' => $screenshot,
|
||||
'$readme' => $readme,
|
||||
|
||||
'$form_security_token' => parent::getFormSecurityToken("admin_themes"),
|
||||
]);
|
||||
$theme = Strings::sanitizeFilePathItem($parameters['theme']);
|
||||
if (!is_dir("view/theme/$theme")) {
|
||||
notice(DI::l10n()->t("Item not found."));
|
||||
return '';
|
||||
}
|
||||
|
||||
DI::baseUrl()->redirect('admin/themes');
|
||||
$isEnabled = in_array($theme, Theme::getAllowedList());
|
||||
if ($isEnabled) {
|
||||
$status = "on";
|
||||
$action = DI::l10n()->t("Disable");
|
||||
} else {
|
||||
$status = "off";
|
||||
$action = DI::l10n()->t("Enable");
|
||||
}
|
||||
|
||||
if (!empty($_GET['action']) && $_GET['action'] == 'toggle') {
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');
|
||||
|
||||
if ($isEnabled) {
|
||||
Theme::uninstall($theme);
|
||||
info(DI::l10n()->t('Theme %s disabled.', $theme));
|
||||
} elseif (Theme::install($theme)) {
|
||||
info(DI::l10n()->t('Theme %s successfully enabled.', $theme));
|
||||
} else {
|
||||
notice(DI::l10n()->t('Theme %s failed to install.', $theme));
|
||||
}
|
||||
|
||||
DI::baseUrl()->redirect('admin/themes/' . $theme);
|
||||
}
|
||||
|
||||
$readme = null;
|
||||
if (is_file("view/theme/$theme/README.md")) {
|
||||
$readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);
|
||||
} elseif (is_file("view/theme/$theme/README")) {
|
||||
$readme = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";
|
||||
}
|
||||
|
||||
$admin_form = '';
|
||||
if (is_file("view/theme/$theme/config.php")) {
|
||||
require_once "view/theme/$theme/config.php";
|
||||
|
||||
if (function_exists('theme_admin')) {
|
||||
$admin_form = '<iframe onload="resizeIframe(this);" src="/admin/themes/' . $theme . '/embed?mode=minimal" width="100%" height="600px" frameborder="no"></iframe>';
|
||||
}
|
||||
}
|
||||
|
||||
$screenshot = [Theme::getScreenshot($theme), DI::l10n()->t('Screenshot')];
|
||||
if (!stristr($screenshot[0], $theme)) {
|
||||
$screenshot = null;
|
||||
}
|
||||
|
||||
$t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$title' => DI::l10n()->t('Administration'),
|
||||
'$page' => DI::l10n()->t('Themes'),
|
||||
'$toggle' => DI::l10n()->t('Toggle'),
|
||||
'$settings' => DI::l10n()->t('Settings'),
|
||||
'$baseurl' => DI::baseUrl()->get(true),
|
||||
'$addon' => $theme,
|
||||
'$status' => $status,
|
||||
'$action' => $action,
|
||||
'$info' => Theme::getInfo($theme),
|
||||
'$function' => 'themes',
|
||||
'$admin_form' => $admin_form,
|
||||
'$str_author' => DI::l10n()->t('Author: '),
|
||||
'$str_maintainer' => DI::l10n()->t('Maintainer: '),
|
||||
'$screenshot' => $screenshot,
|
||||
'$readme' => $readme,
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken("admin_themes"),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,15 +30,9 @@ class Embed extends BaseAdmin
|
|||
{
|
||||
public static function init(array $parameters = [])
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
if ($a->argc > 2) {
|
||||
// @TODO: Replace with parameter from router
|
||||
$theme = $a->argv[2];
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
if (is_file("view/theme/$theme/config.php")) {
|
||||
$a->setCurrentTheme($theme);
|
||||
}
|
||||
$theme = Strings::sanitizeFilePathItem($parameters['theme']);
|
||||
if (is_file("view/theme/$theme/config.php")) {
|
||||
DI::app()->setCurrentTheme($theme);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,67 +40,49 @@ class Embed extends BaseAdmin
|
|||
{
|
||||
parent::post($parameters);
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if ($a->argc > 2) {
|
||||
// @TODO: Replace with parameter from router
|
||||
$theme = $a->argv[2];
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
if (is_file("view/theme/$theme/config.php")) {
|
||||
$theme = Strings::sanitizeFilePathItem($parameters['theme']);
|
||||
if (is_file("view/theme/$theme/config.php")) {
|
||||
require_once "view/theme/$theme/config.php";
|
||||
if (function_exists('theme_admin_post')) {
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings');
|
||||
|
||||
require_once "view/theme/$theme/config.php";
|
||||
|
||||
if (function_exists('theme_admin_post')) {
|
||||
theme_admin_post($a);
|
||||
}
|
||||
theme_admin_post(DI::app());
|
||||
}
|
||||
|
||||
info(DI::l10n()->t('Theme settings updated.'));
|
||||
|
||||
if (DI::mode()->isAjax()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
|
||||
}
|
||||
|
||||
if (DI::mode()->isAjax()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
|
||||
}
|
||||
|
||||
public static function content(array $parameters = [])
|
||||
{
|
||||
parent::content($parameters);
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if ($a->argc > 2) {
|
||||
// @TODO: Replace with parameter from router
|
||||
$theme = $a->argv[2];
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
if (!is_dir("view/theme/$theme")) {
|
||||
notice(DI::l10n()->t('Unknown theme.'));
|
||||
return '';
|
||||
}
|
||||
|
||||
$admin_form = '';
|
||||
if (is_file("view/theme/$theme/config.php")) {
|
||||
require_once "view/theme/$theme/config.php";
|
||||
|
||||
if (function_exists('theme_admin')) {
|
||||
$admin_form = theme_admin($a);
|
||||
}
|
||||
}
|
||||
|
||||
// Overrides normal theme style include to strip user param to show embedded theme settings
|
||||
Renderer::$theme['stylesheet'] = 'view/theme/' . $theme . '/style.pcss';
|
||||
|
||||
$t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',
|
||||
'$form' => $admin_form,
|
||||
'$form_security_token' => parent::getFormSecurityToken("admin_theme_settings"),
|
||||
]);
|
||||
$theme = Strings::sanitizeFilePathItem($parameters['theme']);
|
||||
if (!is_dir("view/theme/$theme")) {
|
||||
notice(DI::l10n()->t('Unknown theme.'));
|
||||
return '';
|
||||
}
|
||||
|
||||
return '';
|
||||
$admin_form = '';
|
||||
if (is_file("view/theme/$theme/config.php")) {
|
||||
require_once "view/theme/$theme/config.php";
|
||||
|
||||
if (function_exists('theme_admin')) {
|
||||
$admin_form = theme_admin(DI::app());
|
||||
}
|
||||
}
|
||||
|
||||
// Overrides normal theme style include to strip user param to show embedded theme settings
|
||||
Renderer::$theme['stylesheet'] = 'view/theme/' . $theme . '/style.pcss';
|
||||
|
||||
$t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',
|
||||
'$form' => $admin_form,
|
||||
'$form_security_token' => self::getFormSecurityToken("admin_theme_settings"),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue