]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Admin/Themes/Embed.php
Revert "Revert "Replace Module::init() with Constructors""
[friendica.git] / src / Module / Admin / Themes / Embed.php
index 675e33c8465cfc77930cc5fb0d3584f0e461a50c..0d2a2dc047f30a506cb4e9f62323ec049e3e6ff4 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Module\Admin\Themes;
 
+use Friendica\App;
+use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
-use Friendica\DI;
 use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 
 class Embed extends BaseAdmin
 {
-       public static function init(array $parameters = [])
+       /** @var App */
+       protected $app;
+       /** @var App\BaseURL */
+       protected $baseUrl;
+       /** @var App\Mode */
+       protected $mode;
+
+       public function __construct(App $app, App\BaseURL $baseUrl, App\Mode $mode, L10n $l10n, 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);
-                       }
+               parent::__construct($l10n, $parameters);
+
+               $this->app     = $app;
+               $this->baseUrl = $baseUrl;
+               $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(array $parameters = [])
+       public function post()
        {
-               parent::post($parameters);
+               self::checkAdminAccess();
 
-               $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($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(DI::l10n()->t('Theme settings updated.'));
-
-                       if (DI::mode()->isAjax()) {
-                               return;
+                               theme_admin_post($this->app);
                        }
+               }
 
-                       DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
+               if ($this->mode->isAjax()) {
+                       return;
                }
+
+               $this->baseUrl->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
        }
 
-       public static function content(array $parameters = [])
+       public function content(): string
        {
-               parent::content($parameters);
+               parent::content();
 
-               $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 '';
-                       }
+               $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);
                        }
-
-                       // 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"),
-                       ]);
                }
 
-               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"),
+               ]);
        }
 }