From a13bc149338b3d2b1b34cf053f28b5d7e34742c4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 15 Apr 2019 01:11:46 -0400 Subject: [PATCH] Move admin/themes to src/Module - Add Module\Admin\Themes\Index class - Add route for admin/themes - Add themes admin aside menu entry - Add admin/addons/index.tpl template - Remove theme list from mod/admin --- mod/admin.php | 38 --------- src/App/Router.php | 2 + src/Module/Admin/Themes/Index.php | 109 ++++++++++++++++++++++++++ src/Module/BaseAdminModule.php | 1 + view/templates/admin/addons/index.tpl | 24 ++++++ 5 files changed, 136 insertions(+), 38 deletions(-) create mode 100644 src/Module/Admin/Themes/Index.php create mode 100644 view/templates/admin/addons/index.tpl diff --git a/mod/admin.php b/mod/admin.php index af4c874c2c..a717943d6b 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -2017,44 +2017,6 @@ function admin_page_themes(App $a) '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"), ]); } - - // reload active themes - if (!empty($_GET['a']) && $_GET['a'] == "r") { - BaseModule::checkFormSecurityTokenRedirectOnError(System::baseUrl() . '/admin/themes', 'admin_themes', 't'); - foreach ($themes as $th) { - if ($th['allowed']) { - Theme::uninstall($th['name']); - Theme::install($th['name']); - } - } - info("Themes reloaded"); - $a->internalRedirect('admin/themes'); - } - - /* - * List themes - */ - - $addons = []; - foreach ($themes as $th) { - $addons[] = [$th['name'], (($th['allowed']) ? "on" : "off"), Theme::getInfo($th['name'])]; - } - - $t = Renderer::getMarkupTemplate('admin/addons.tpl'); - return Renderer::replaceMacros($t, [ - '$title' => L10n::t('Administration'), - '$page' => L10n::t('Themes'), - '$submit' => L10n::t('Save Settings'), - '$reload' => L10n::t('Reload active themes'), - '$baseurl' => System::baseUrl(true), - '$function' => 'themes', - '$addons' => $addons, - '$pcount' => count($themes), - '$noplugshint' => L10n::t('No themes found on the system. They should be placed in %1$s', '/view/themes'), - '$experimental' => L10n::t('[Experimental]'), - '$unsupported' => L10n::t('[Unsupported]'), - '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"), - ]); } /** diff --git a/src/App/Router.php b/src/App/Router.php index ca362f4842..e1accefd9f 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -122,6 +122,8 @@ class Router $collector->addRoute(['GET'] , '[/]' , Module\Admin\Summary::class); $collector->addRoute(['GET'] , '/federation' , Module\Admin\Federation::class); + $collector->addRoute(['GET', 'POST'], '/themes' , Module\Admin\Themes\Index::class); + $collector->addRoute(['GET', 'POST'], '/tos' , Module\Admin\Tos::class); }); } diff --git a/src/Module/Admin/Themes/Index.php b/src/Module/Admin/Themes/Index.php new file mode 100644 index 0000000000..2b89c4e200 --- /dev/null +++ b/src/Module/Admin/Themes/Index.php @@ -0,0 +1,109 @@ +internalRedirect('admin/themes'); + } + + $themes = []; + $files = glob('view/theme/*'); + if (is_array($files)) { + foreach ($files as $file) { + $theme = basename($file); + + // Is there a style file? + $theme_files = glob('view/theme/' . $theme . '/style.*'); + + // If not then quit + if (count($theme_files) == 0) { + continue; + } + + $is_experimental = intval(file_exists($file . '/experimental')); + $is_supported = 1 - (intval(file_exists($file . '/unsupported'))); + $is_allowed = intval(in_array($theme, $allowed_themes)); + + if ($is_allowed || $is_supported || Config::get('system', 'show_unsupported_themes')) { + $themes[] = ['name' => $theme, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed]; + } + } + } + + $addons = []; + foreach ($themes as $theme) { + $addons[] = [$theme['name'], (($theme['allowed']) ? 'on' : 'off'), Theme::getInfo($theme['name'])]; + } + + $t = Renderer::getMarkupTemplate('admin/addons/index.tpl'); + return Renderer::replaceMacros($t, [ + '$title' => L10n::t('Administration'), + '$page' => L10n::t('Themes'), + '$submit' => L10n::t('Save Settings'), + '$reload' => L10n::t('Reload active themes'), + '$baseurl' => System::baseUrl(true), + '$function' => 'themes', + '$addons' => $addons, + '$pcount' => count($themes), + '$noplugshint' => L10n::t('No themes found on the system. They should be placed in %1$s', '/view/themes'), + '$experimental' => L10n::t('[Experimental]'), + '$unsupported' => L10n::t('[Unsupported]'), + '$form_security_token' => parent::getFormSecurityToken('admin_themes'), + ]); + } +} \ No newline at end of file diff --git a/src/Module/BaseAdminModule.php b/src/Module/BaseAdminModule.php index 90f7810378..330b9dd749 100644 --- a/src/Module/BaseAdminModule.php +++ b/src/Module/BaseAdminModule.php @@ -53,6 +53,7 @@ abstract class BaseAdminModule extends BaseModule 'federation' => ['admin/federation' , L10n::t('Federation Statistics') , 'federation'] ]], 'configuration' => [L10n::t('Configuration'), [ + 'themes' => ['admin/themes' , L10n::t('Themes') , 'themes'], 'tos' => ['admin/tos' , L10n::t('Terms of Service') , 'tos'], ]], ]; diff --git a/view/templates/admin/addons/index.tpl b/view/templates/admin/addons/index.tpl new file mode 100644 index 0000000000..4a2b057bf6 --- /dev/null +++ b/view/templates/admin/addons/index.tpl @@ -0,0 +1,24 @@ + +
+

{{$title}} - {{$page}}

+{{if $pcount eq 0}} +
+ {{$noplugshint}} +
+{{else}} + {{$reload}} + +{{/if}} +