<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @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\App;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
+use Friendica\Module\Response;
+use Friendica\Util\Profiler;
use Friendica\Util\Strings;
+use Psr\Log\LoggerInterface;
-class Embed extends BaseAdminModule
+class Embed extends BaseAdmin
{
- public static function init()
+ /** @var App */
+ protected $app;
+ /** @var App\Mode */
+ protected $mode;
+
+ public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Mode $mode, array $server, array $parameters = [])
{
- $a = self::getApp();
-
- 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);
- }
+ parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+ $this->app = $app;
+ $this->mode = $mode;
+
+ $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
+ if (is_file("view/theme/$theme/config.php")) {
+ $this->app->setCurrentTheme($theme);
}
}
- public static function post()
+ protected function post(array $request = [], array $post = [])
{
- parent::post();
-
- $a = self::getApp();
+ self::checkAdminAccess();
- 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($this->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);
- }
- }
-
- info(L10n::t('Theme settings updated.'));
-
- if ($a->isAjax()) {
- return;
+ theme_admin_post($this->app);
}
+ }
- $a->internalRedirect('admin/themes/' . $theme . '/embed?mode=minimal');
+ if ($this->mode->isAjax()) {
+ return;
}
+
+ $this->baseUrl->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
}
- public static function content()
+ protected function content(array $request = []): string
{
parent::content();
- $a = self::getApp();
-
- 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(L10n::t('Unknown theme.'));
- return '';
- }
+ $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
+ if (!is_dir("view/theme/$theme")) {
+ notice($this->t('Unknown theme.'));
+ return '';
+ }
- $admin_form = '';
- if (is_file("view/theme/$theme/config.php")) {
- require_once "view/theme/$theme/config.php";
+ $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);
- }
+ if (function_exists('theme_admin')) {
+ $admin_form = theme_admin($this->app);
}
-
- $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"),
- ]);
}
- return '';
+ // 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"),
+ ]);
}
}