-<?php\r
-\r
-namespace Friendica\Module\Admin\Themes;\r
-\r
-use Friendica\Content\Text\Markdown;\r
-use Friendica\Core\Config;\r
-use Friendica\Core\L10n;\r
-use Friendica\Core\Renderer;\r
-use Friendica\Core\System;\r
-use Friendica\Core\Theme;\r
-use Friendica\Module\BaseAdminModule;\r
-use Friendica\Util\Strings;\r
-\r
-class Details extends BaseAdminModule\r
-{\r
- public static function post()\r
- {\r
- parent::post();\r
-\r
- $a = self::getApp();\r
-\r
- if ($a->argc > 2) {\r
- // @TODO: Replace with parameter from router\r
- $theme = $a->argv[2];\r
- $theme = Strings::sanitizeFilePathItem($theme);\r
- if (is_file("view/theme/$theme/config.php")) {\r
- require_once "view/theme/$theme/config.php";\r
-\r
- if (function_exists('theme_admin_post')) {\r
- theme_admin_post($a);\r
- }\r
- }\r
-\r
- info(L10n::t('Theme settings updated.'));\r
-\r
- if ($a->isAjax()) {\r
- return;\r
- }\r
-\r
- $a->internalRedirect('admin/themes/' . $theme);\r
- }\r
- }\r
-\r
- public static function content()\r
- {\r
- parent::content();\r
-\r
- $a = self::getApp();\r
-\r
- if ($a->argc > 2) {\r
- // @TODO: Replace with parameter from router\r
- $theme = $a->argv[2];\r
- $theme = Strings::sanitizeFilePathItem($theme);\r
- if (!is_dir("view/theme/$theme")) {\r
- notice(L10n::t("Item not found."));\r
- return '';\r
- }\r
-\r
- $isEnabled = in_array($theme, Theme::getAllowedList());\r
- if ($isEnabled) {\r
- $status = "on";\r
- $action = L10n::t("Disable");\r
- } else {\r
- $status = "off";\r
- $action = L10n::t("Enable");\r
- }\r
-\r
- if (!empty($_GET['action']) && $_GET['action'] == 'toggle') {\r
- parent::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');\r
-\r
- if ($isEnabled) {\r
- Theme::uninstall($theme);\r
- info(L10n::t('Theme %s disabled.', $theme));\r
- } elseif (Theme::install($theme)) {\r
- info(L10n::t('Theme %s successfully enabled.', $theme));\r
- } else {\r
- info(L10n::t('Theme %s failed to install.', $theme));\r
- }\r
-\r
- $a->internalRedirect('admin/themes/' . $theme);\r
- }\r
-\r
- $readme = null;\r
- if (is_file("view/theme/$theme/README.md")) {\r
- $readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);\r
- } elseif (is_file("view/theme/$theme/README")) {\r
- $readme = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";\r
- }\r
-\r
- $admin_form = '';\r
- if (is_file("view/theme/$theme/config.php")) {\r
- require_once "view/theme/$theme/config.php";\r
-\r
- if (function_exists('theme_admin')) {\r
- $admin_form = '<iframe onload="resizeIframe(this);" src="/admin/themes/' . $theme . '/embed?mode=minimal" width="100%" height="600px" frameborder="no"></iframe>';\r
- }\r
- }\r
-\r
- $screenshot = [Theme::getScreenshot($theme), L10n::t('Screenshot')];\r
- if (!stristr($screenshot[0], $theme)) {\r
- $screenshot = null;\r
- }\r
-\r
- $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');\r
- return Renderer::replaceMacros($t, [\r
- '$title' => L10n::t('Administration'),\r
- '$page' => L10n::t('Themes'),\r
- '$toggle' => L10n::t('Toggle'),\r
- '$settings' => L10n::t('Settings'),\r
- '$baseurl' => System::baseUrl(true),\r
- '$addon' => $theme,\r
- '$status' => $status,\r
- '$action' => $action,\r
- '$info' => Theme::getInfo($theme),\r
- '$function' => 'themes',\r
- '$admin_form' => $admin_form,\r
- '$str_author' => L10n::t('Author: '),\r
- '$str_maintainer' => L10n::t('Maintainer: '),\r
- '$screenshot' => $screenshot,\r
- '$readme' => $readme,\r
-\r
- '$form_security_token' => parent::getFormSecurityToken("admin_themes"),\r
- ]);\r
- }\r
-\r
- $a->internalRedirect('admin/themes');\r
- }\r
-}
\ No newline at end of file
+<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Admin\Themes;
+
+use Friendica\Content\Text\Markdown;
+use Friendica\Core\Renderer;
+use Friendica\Core\Theme;
+use Friendica\DI;
+use Friendica\Module\BaseAdmin;
+use Friendica\Util\Strings;
+
+class Details extends BaseAdmin
+{
+ public static function content(array $parameters = [])
+ {
+ parent::content($parameters);
+
+ $theme = Strings::sanitizeFilePathItem($parameters['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') {
+ 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"),
+ ]);
+ }
+}